more code, simpler mixin

This commit is contained in:
gnembon committed 2021-11-29 00:10:29 +01:00
1 parent 28a5e7acf1
commit f5900cffc6
1 file changed
+12 -10
@@ -1,8 +1,11 @@
package carpet.mixins; package carpet.mixins;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ExperienceOrbEntity; import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@@ -10,26 +13,25 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ExperienceOrbEntity.class) @Mixin(ExperienceOrbEntity.class)
public abstract class ExperienceOrbEntityMixin { public abstract class ExperienceOrbEntityMixin extends Entity
{
@Shadow @Shadow
private int pickingCount; private int pickingCount;
@Shadow @Shadow
private int amount; private int amount;
public ExperienceOrbEntityMixin(EntityType<?> type, World world)
{
super(type, world);
}
@Shadow @Shadow
protected abstract int repairPlayerGears(PlayerEntity player, int amount); protected abstract int repairPlayerGears(PlayerEntity player, int amount);
@Inject( @Inject(method = "onPlayerCollision", at = @At("HEAD"))
method = "onPlayerCollision",
at = @At(
value = "FIELD",
target = "net/minecraft/entity/player/PlayerEntity.experiencePickUpDelay:I",
ordinal = 0
)
)
private void addXP(PlayerEntity player, CallbackInfo ci) { private void addXP(PlayerEntity player, CallbackInfo ci) {
if (CarpetSettings.xpNoCooldown) { if (CarpetSettings.xpNoCooldown && !world.isClient) {
player.experiencePickUpDelay = 0; player.experiencePickUpDelay = 0;
// reducing the count to 1 and leaving vanilla to deal with it // reducing the count to 1 and leaving vanilla to deal with it
while (this.pickingCount > 1) { while (this.pickingCount > 1) {