Skip to content

Commit

Permalink
Partial fixes for #4064
Browse files Browse the repository at this point in the history
  • Loading branch information
williewillus committed Jul 24, 2022
1 parent 1d2092b commit 62458c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -77,10 +79,16 @@ public static boolean brainwashEntity(Mob entity, List<Enemy> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions Xplat/src/main/resources/botania_xplat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"AccessorFireBlock",
"AccessorGoalSelector",
"AccessorHopperBlockEntity",
"AccessorHurtByTargetGoal",
"AccessorIngredient",
"AccessorItemEntity",
"AccessorLivingEntity",
Expand Down

0 comments on commit 62458c3

Please sign in to comment.