forked from VazkiiMods/Botania
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Heisei Dream (fixes VazkiiMods#4064)
Does two things: - Set the ATTACK_TARGET memory for mobs using the new Brain system (ie it works on Piglins now) - Override checks in TargetingConditions that prevented Illagers from attacking each other
- Loading branch information
Showing
6 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
Xplat/src/main/java/vazkii/botania/common/HurtByTargetGoalAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package vazkii.botania.common; | ||
|
||
public interface HurtByTargetGoalAccess { | ||
void botania$setBrainwashed(); | ||
} |
5 changes: 5 additions & 0 deletions
5
Xplat/src/main/java/vazkii/botania/common/TargetingConditionsAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package vazkii.botania.common; | ||
|
||
public interface TargetingConditionsAccess { | ||
void botania$setBrainwashed(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Xplat/src/main/java/vazkii/botania/mixin/HurtByTargetGoalMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package vazkii.botania.mixin; | ||
|
||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal; | ||
import net.minecraft.world.entity.ai.goal.target.TargetGoal; | ||
import net.minecraft.world.entity.ai.targeting.TargetingConditions; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import vazkii.botania.common.HurtByTargetGoalAccess; | ||
import vazkii.botania.common.TargetingConditionsAccess; | ||
|
||
@Mixin(HurtByTargetGoal.class) | ||
abstract class HurtByTargetGoalMixin extends TargetGoal implements HurtByTargetGoalAccess { | ||
@Shadow | ||
@Final | ||
private static TargetingConditions HURT_BY_TARGETING; | ||
@Unique | ||
private boolean brainwashed; | ||
|
||
private static final TargetingConditions BRAINWASHED_CONDITIONS = HURT_BY_TARGETING.copy(); | ||
|
||
static { | ||
((TargetingConditionsAccess) BRAINWASHED_CONDITIONS).botania$setBrainwashed(); | ||
} | ||
|
||
public HurtByTargetGoalMixin(Mob $$0, boolean $$1) { | ||
super($$0, $$1); | ||
} | ||
|
||
@Override | ||
public void botania$setBrainwashed() { | ||
this.brainwashed = true; | ||
} | ||
|
||
@Redirect( | ||
method = "canUse()Z", | ||
at = @At( | ||
target = "Lnet/minecraft/world/entity/ai/goal/target/HurtByTargetGoal;canAttack(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/ai/targeting/TargetingConditions;)Z", | ||
value = "INVOKE" | ||
) | ||
) | ||
boolean replaceAttackPredicate(HurtByTargetGoal instance, LivingEntity livingEntity, TargetingConditions targetingConditions) { | ||
return this.canAttack(livingEntity, this.brainwashed ? BRAINWASHED_CONDITIONS : HURT_BY_TARGETING); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
Xplat/src/main/java/vazkii/botania/mixin/TargetingConditionsMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package vazkii.botania.mixin; | ||
|
||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.ai.targeting.TargetingConditions; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import vazkii.botania.common.TargetingConditionsAccess; | ||
|
||
@Mixin(TargetingConditions.class) | ||
abstract class TargetingConditionsMixin implements TargetingConditionsAccess { | ||
private boolean brainwashed; | ||
|
||
@Redirect( | ||
method = "test", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/entity/LivingEntity;canAttack(Lnet/minecraft/world/entity/LivingEntity;)Z" | ||
) | ||
) | ||
boolean redirectCanAttack(LivingEntity instance, LivingEntity entity) { | ||
return this.brainwashed || instance.canAttack(entity); | ||
} | ||
|
||
@Redirect( | ||
method = "test", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/entity/LivingEntity;canAttackType(Lnet/minecraft/world/entity/EntityType;)Z" | ||
) | ||
) | ||
boolean redirectCanAttackType(LivingEntity instance, EntityType<?> entityType) { | ||
return this.brainwashed || instance.canAttackType(entityType); | ||
} | ||
|
||
@Redirect( | ||
method = "test", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/entity/LivingEntity;isAlliedTo(Lnet/minecraft/world/entity/Entity;)Z" | ||
) | ||
) | ||
boolean redirectIsAlliedTo(LivingEntity instance, Entity entity) { | ||
return !this.brainwashed && instance.isAlliedTo(entity); | ||
} | ||
|
||
@Override | ||
public void botania$setBrainwashed() { | ||
this.brainwashed = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters