From 62458c3d79aa705c7fc613a40479eef9c05ce099 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sun, 24 Jul 2022 11:41:02 -0700 Subject: [PATCH] Partial fixes for #4064 --- .../subtile/functional/SubTileHeiseiDream.java | 14 +++++++++++--- .../botania/mixin/AccessorHurtByTargetGoal.java | 12 ++++++++++++ Xplat/src/main/resources/botania_xplat.mixins.json | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 Xplat/src/main/java/vazkii/botania/mixin/AccessorHurtByTargetGoal.java diff --git a/Xplat/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHeiseiDream.java b/Xplat/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHeiseiDream.java index 7aa935bcfe..4cd1043f8a 100644 --- a/Xplat/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHeiseiDream.java +++ b/Xplat/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileHeiseiDream.java @@ -25,8 +25,10 @@ import vazkii.botania.api.subtile.TileEntityFunctionalFlower; import vazkii.botania.common.block.ModSubtiles; import vazkii.botania.mixin.AccessorGoalSelector; +import vazkii.botania.mixin.AccessorHurtByTargetGoal; import vazkii.botania.mixin.AccessorMob; +import java.util.Arrays; import java.util.List; public class SubTileHeiseiDream extends TileEntityFunctionalFlower { @@ -77,10 +79,16 @@ public static boolean brainwashEntity(Mob entity, List mobs) { // Move any HurtByTargetGoal to highest priority GoalSelector targetSelector = ((AccessorMob) entity).getTargetSelector(); for (WrappedGoal entry : ((AccessorGoalSelector) targetSelector).getAvailableGoals()) { - if (entry.getGoal() instanceof HurtByTargetGoal) { + if (entry.getGoal() instanceof HurtByTargetGoal goal) { + // Remove all ignorals. We can't actually resize or overwrite + // the array, but we can fill it with classes that will never pass + // the game logic's checks. + var ignoreClasses = ((AccessorHurtByTargetGoal) goal).getIgnoreDamageClasses(); + Arrays.fill(ignoreClasses, Void.TYPE); + // Concurrent modification OK since we break out of the loop - targetSelector.removeGoal(entry.getGoal()); - targetSelector.addGoal(-1, entry.getGoal()); + targetSelector.removeGoal(goal); + targetSelector.addGoal(-1, goal); break; } } diff --git a/Xplat/src/main/java/vazkii/botania/mixin/AccessorHurtByTargetGoal.java b/Xplat/src/main/java/vazkii/botania/mixin/AccessorHurtByTargetGoal.java new file mode 100644 index 0000000000..8d2525f4d6 --- /dev/null +++ b/Xplat/src/main/java/vazkii/botania/mixin/AccessorHurtByTargetGoal.java @@ -0,0 +1,12 @@ +package vazkii.botania.mixin; + +import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(HurtByTargetGoal.class) +public interface AccessorHurtByTargetGoal { + @Accessor("toIgnoreDamage") + Class[] getIgnoreDamageClasses(); +} diff --git a/Xplat/src/main/resources/botania_xplat.mixins.json b/Xplat/src/main/resources/botania_xplat.mixins.json index 5801a6f917..5e456a1a02 100644 --- a/Xplat/src/main/resources/botania_xplat.mixins.json +++ b/Xplat/src/main/resources/botania_xplat.mixins.json @@ -18,6 +18,7 @@ "AccessorFireBlock", "AccessorGoalSelector", "AccessorHopperBlockEntity", + "AccessorHurtByTargetGoal", "AccessorIngredient", "AccessorItemEntity", "AccessorLivingEntity",