Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Heisei Dream (partially fixes #4064) #4337

Open
wants to merge 2 commits into
base: 1.19.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package vazkii.botania.common;

public interface HurtByTargetGoalAccess {
void botania$setBrainwashed();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package vazkii.botania.common;

public interface TargetingConditionsAccess {
void botania$setBrainwashed();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import vazkii.botania.api.block_entity.FunctionalFlowerBlockEntity;
import vazkii.botania.api.block_entity.RadiusDescriptor;
import vazkii.botania.common.HurtByTargetGoalAccess;
import vazkii.botania.common.block.BotaniaFlowerBlocks;
import vazkii.botania.mixin.GoalSelectorAccessor;
import vazkii.botania.mixin.HurtByTargetGoalAccessor;
Expand Down Expand Up @@ -89,6 +90,8 @@ public static boolean brainwashEntity(Mob entity, List<Enemy> mobs) {
// Concurrent modification OK since we break out of the loop
targetSelector.removeGoal(goal);
targetSelector.addGoal(-1, goal);

((HurtByTargetGoalAccess) goal).botania$setBrainwashed();
break;
}
}
Expand Down
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);
}
}
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;
}
}
2 changes: 2 additions & 0 deletions Xplat/src/main/resources/botania_xplat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"GoalSelectorAccessor",
"HopperBlockEntityAccessor",
"HurtByTargetGoalAccessor",
"HurtByTargetGoalMixin",
"IngredientAccessor",
"ItemEntityAccessor",
"ItemEntityMixin",
Expand All @@ -50,6 +51,7 @@
"SoundTypeAccessor",
"SpawnPlacementsMixin",
"StatsAccessor",
"TargetingConditionsMixin",
"TextureSlotAccessor",
"ThrowableProjectileMixin",
"WitherEntityAccessor"
Expand Down