diff --git a/Common/src/main/java/at/petrak/hexcasting/common/misc/Brainsweeping.java b/Common/src/main/java/at/petrak/hexcasting/common/misc/Brainsweeping.java index 0e3bd318..7821c3c7 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/misc/Brainsweeping.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/misc/Brainsweeping.java @@ -17,11 +17,13 @@ import org.jetbrains.annotations.Nullable; public class Brainsweeping { // Keeping these functions in Brainsweeping just so we have to change less code public static void brainsweep(Mob entity) { - IXplatAbstractions.INSTANCE.brainsweep(entity); + if (isValidTarget(entity)) { + IXplatAbstractions.INSTANCE.brainsweep(entity); + } } public static boolean isBrainswept(Mob entity) { - return IXplatAbstractions.INSTANCE.isBrainswept(entity); + return isValidTarget(entity) && IXplatAbstractions.INSTANCE.isBrainswept(entity); } // TODO: make this a tag diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/MixinMob.java b/Common/src/main/java/at/petrak/hexcasting/mixin/MixinMob.java index 4fc642d4..9fa7af63 100644 --- a/Common/src/main/java/at/petrak/hexcasting/mixin/MixinMob.java +++ b/Common/src/main/java/at/petrak/hexcasting/mixin/MixinMob.java @@ -1,15 +1,13 @@ package at.petrak.hexcasting.mixin; import at.petrak.hexcasting.common.misc.Brainsweeping; -import net.minecraft.sounds.SoundEvent; import net.minecraft.world.entity.Mob; 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; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -// Prevents the villager from any of its brain goals or making ambient noise +// Prevents brainswept mobs from having an AI tick @Mixin(Mob.class) public class MixinMob { @Inject(method = "serverAiStep", at = @At("HEAD"), cancellable = true) @@ -20,11 +18,11 @@ public class MixinMob { } } - @Inject(method = "getAmbientSound", at = @At("HEAD"), cancellable = true) - protected void onGetAmbientSound(CallbackInfoReturnable ci) { + @Inject(method = "playAmbientSound", at = @At("HEAD"), cancellable = true) + protected void onPlayAmbientSound(CallbackInfo ci) { var self = (Mob) (Object) this; if (Brainsweeping.isBrainswept(self)) { - ci.setReturnValue(null); + ci.cancel(); } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/MixinVillager.java b/Common/src/main/java/at/petrak/hexcasting/mixin/MixinVillager.java index 9e509d42..0cbc8b59 100644 --- a/Common/src/main/java/at/petrak/hexcasting/mixin/MixinVillager.java +++ b/Common/src/main/java/at/petrak/hexcasting/mixin/MixinVillager.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -// Prevents the villager from any of its brain goals or making ambient noise +// Prevents the villager from any of its brain goals @Mixin(Villager.class) public class MixinVillager { @Inject(method = "registerBrainGoals", at = @At("HEAD"), cancellable = true) diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorLivingEntity.java b/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorLivingEntity.java deleted file mode 100644 index 2331d9fc..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorLivingEntity.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.petrak.hexcasting.mixin.accessor; - -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.Brain; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(LivingEntity.class) -public interface AccessorLivingEntity { - @Accessor("brain") - void hex$SetBrain(Brain brain); -} diff --git a/Common/src/main/resources/hexplat.mixins.json b/Common/src/main/resources/hexplat.mixins.json index e91b5450..2c480007 100644 --- a/Common/src/main/resources/hexplat.mixins.json +++ b/Common/src/main/resources/hexplat.mixins.json @@ -5,7 +5,7 @@ "refmap": "hexcasting.mixins.refmap.json", "package": "at.petrak.hexcasting.mixin", "mixins": [ - "MixinMob", "MixinVillager", "accessor.AccessorLivingEntity", "accessor.AccessorUseOnContext", + "MixinMob", "MixinVillager", "accessor.AccessorUseOnContext", "accessor.CriteriaTriggersAccessor" ] } diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/CCBrainswept.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/CCBrainswept.java index e9df52d6..34406f74 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/CCBrainswept.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/CCBrainswept.java @@ -3,7 +3,9 @@ package at.petrak.hexcasting.fabric.cc; import dev.onyxstudios.cca.api.v3.component.Component; import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; public class CCBrainswept implements Component, AutoSyncedComponent { public static final String TAG_BRAINSWEPT = "brainswept"; @@ -25,6 +27,13 @@ public class CCBrainswept implements Component, AutoSyncedComponent { HexCardinalComponents.BRAINSWEPT.sync(this.owner); } + @Override + public void applySyncPacket(FriendlyByteBuf buf) { + AutoSyncedComponent.super.applySyncPacket(buf); + if (owner instanceof Mob mob && brainswept) + mob.removeFreeWill(); + } + @Override public void readFromNbt(CompoundTag tag) { this.brainswept = tag.getBoolean(TAG_BRAINSWEPT); diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java index 8ea1639a..44ac4090 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java @@ -84,6 +84,8 @@ public class FabricXplatImpl implements IXplatAbstractions { var cc = HexCardinalComponents.BRAINSWEPT.get(mob); cc.setBrainswept(true); // CC API does the syncing for us + + mob.removeFreeWill(); } @Override diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java index c96bc406..5c348e5a 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java @@ -13,7 +13,6 @@ import at.petrak.hexcasting.api.spell.casting.CastingHarness; import at.petrak.hexcasting.api.spell.casting.ResolvedPattern; import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.common.lib.HexItems; -import at.petrak.hexcasting.common.misc.Brainsweeping; import at.petrak.hexcasting.common.network.IMessage; import at.petrak.hexcasting.forge.cap.CapSyncers; import at.petrak.hexcasting.forge.cap.HexCapabilities; @@ -81,15 +80,13 @@ public class ForgeXplatImpl implements IXplatAbstractions { @Override public void brainsweep(Mob mob) { - if (Brainsweeping.isValidTarget(mob)) { - mob.getPersistentData().putBoolean(TAG_BRAINSWEPT, true); + mob.getPersistentData().putBoolean(TAG_BRAINSWEPT, true); - mob.removeFreeWill(); + mob.removeFreeWill(); - if (mob.level instanceof ServerLevel) { - ForgePacketHandler.getNetwork() - .send(PacketDistributor.TRACKING_ENTITY.with(() -> mob), MsgBrainsweepAck.of(mob)); - } + if (mob.level instanceof ServerLevel) { + ForgePacketHandler.getNetwork() + .send(PacketDistributor.TRACKING_ENTITY.with(() -> mob), MsgBrainsweepAck.of(mob)); } }