From 21c37ac8c0678fa7010b13c479f74a63cdc0e474 Mon Sep 17 00:00:00 2001 From: UselessBullets <80850784+UselessBullets@users.noreply.github.com> Date: Thu, 24 Oct 2024 01:27:24 -0500 Subject: [PATCH] hopefully fixed getIsBlock syncing issue --- .../mizurin/shieldmod/mixins/ShieldMixin.java | 20 +++-- .../shieldmod/mixins/SynchedEntityMixin.java | 85 ------------------- src/main/resources/shieldmod.mixins.json | 1 - 3 files changed, 13 insertions(+), 93 deletions(-) delete mode 100644 src/main/java/mizurin/shieldmod/mixins/SynchedEntityMixin.java diff --git a/src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java b/src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java index 9517729..20b0d3e 100644 --- a/src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java +++ b/src/main/java/mizurin/shieldmod/mixins/ShieldMixin.java @@ -39,6 +39,9 @@ public ShieldMixin(World world) { super(world); } + @Unique + private static final int DATA_BLOCKING = 23; + // shadows allow us to access variables in a class we are mixing to. @Shadow public InventoryPlayer inventory; @@ -72,8 +75,11 @@ public ShieldMixin(World world) { @Unique private int fireTicks; - @Unique - private boolean isBlock; + @Inject(method = "init", at = @At("TAIL")) + public void defineSynchedData(CallbackInfo ci) { + entityData.define(DATA_BLOCKING, (byte)0); + } + @Override public void shieldmod$Parry(int parryTicks) { @@ -97,11 +103,11 @@ public ShieldMixin(World world) { @Override public boolean shieldmod$getIsBlock() { - return isBlock; + return entityData.getByte(DATA_BLOCKING) != 0; } @Override public void shieldmod$setIsBlock(boolean bool) { - this.isBlock = bool; + this.entityData.set(DATA_BLOCKING, bool ? (byte)1 : (byte)0); } @Override public int shieldmod$getCounterTicks(){ @@ -341,15 +347,15 @@ public void tickMixin(CallbackInfo ci){ if (stack.getItem() instanceof ShieldItem) { ShieldItem shield = ((ShieldItem) stack.getItem()); - if (isBlock && (shield.tool == ShieldMaterials.TOOL_LEATHER || shield.tool == ShieldMaterials.TOOL_WOOD)) { + if (shieldmod$getIsBlock() && (shield.tool == ShieldMaterials.TOOL_LEATHER || shield.tool == ShieldMaterials.TOOL_WOOD)) { this.xd *= 0.65D; this.zd *= 0.65D; } - else if (isBlock && shield.tool == ShieldMaterials.TOOL_DIAMOND){ + else if (shieldmod$getIsBlock() && shield.tool == ShieldMaterials.TOOL_DIAMOND){ this.xd *= 0.20D; this.zd *= 0.20D; } - else if (isBlock){ + else if (shieldmod$getIsBlock()){ this.xd *= 0.4D; this.zd *= 0.4D; } diff --git a/src/main/java/mizurin/shieldmod/mixins/SynchedEntityMixin.java b/src/main/java/mizurin/shieldmod/mixins/SynchedEntityMixin.java deleted file mode 100644 index b5fe264..0000000 --- a/src/main/java/mizurin/shieldmod/mixins/SynchedEntityMixin.java +++ /dev/null @@ -1,85 +0,0 @@ -package mizurin.shieldmod.mixins; - - -import com.mojang.nbt.CompoundTag; -import mizurin.shieldmod.interfaces.ParryInterface; -import net.minecraft.core.entity.EntityLiving; -import net.minecraft.core.entity.player.EntityPlayer; -import net.minecraft.core.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = EntityPlayer.class, remap = false) - -public class SynchedEntityMixin extends EntityLiving implements ParryInterface { - public SynchedEntityMixin(World world) { - super(world); - } - - @Inject(method = "Lnet/minecraft/core/entity/player/EntityPlayer;(Lnet/minecraft/core/world/World;)V", at = @At("TAIL")) - private void injectEntity(World world, CallbackInfo ci){ - this.entityData.define(23, (byte)0); - } - - @Inject(method = "Lnet/minecraft/core/entity/player/EntityPlayer;readAdditionalSaveData(Lcom/mojang/nbt/CompoundTag;)V", at = @At("TAIL")) - public void injectAddSaveData(CompoundTag tag, CallbackInfo ci){ - tag.putByte("shieldmod$getIsBlock", shieldmod$getIsBlock() ? (byte) 1 : (byte)0); - } - - @Inject(method = "Lnet/minecraft/core/entity/player/EntityPlayer;addAdditionalSaveData(Lcom/mojang/nbt/CompoundTag;)V", at = @At("TAIL")) - public void injectReadSaveData(CompoundTag tag, CallbackInfo ci){ - entityData.set(23, tag.getByte("shieldmod$getIsBlock")); - } - - @Override - public int shieldmod$getParryTicks() { - return 0; - } - - @Override - public void shieldmod$Parry(int parryTicks) { - - } - - @Override - public int shieldmod$getBlockTicks() { - return 0; - } - - @Override - public void shieldmod$Block(int blockTicks) { - - } - - @Override - public boolean shieldmod$getIsBlock() { - return this.entityData.getByte(23) != 0; - } - - @Override - public void shieldmod$setIsBlock(boolean bool) { - this.entityData.set(23, bool ? (byte)1 : (byte)0); - } - - @Override - public int shieldmod$getCounterTicks() { - return 0; - } - - @Override - public void shieldmod$Counter(int counterTicks) { - - } - - @Override - public int shieldmod$getFireTicks() { - return 0; - } - - @Override - public void shieldmod$Fire(int fireTicks) { - - } -} diff --git a/src/main/resources/shieldmod.mixins.json b/src/main/resources/shieldmod.mixins.json index a5a88a8..d6f0d58 100644 --- a/src/main/resources/shieldmod.mixins.json +++ b/src/main/resources/shieldmod.mixins.json @@ -12,7 +12,6 @@ "FieldMixin", "KnockBackMixin", "ShieldMixin", - "SynchedEntityMixin", "WorldFeatureLabyrinthMixin", "WorldMixin" ],