Skip to content

Instantly share code, notes, and snippets.

@Haven-King
Created October 2, 2020 20:02
Show Gist options
  • Select an option

  • Save Haven-King/b807c3dcf987adee1aa0497c0f3897fa to your computer and use it in GitHub Desktop.

Select an option

Save Haven-King/b807c3dcf987adee1aa0497c0f3897fa to your computer and use it in GitHub Desktop.
@Mixin(VindicatorEntity.class)
public abstract class PassiveVindicatorMixin {
@Redirect(
// The method we want to manipulate
method = "initGoals",
at = @At(
/* We are redirecting the NEW opcode here. This just means we're going to
be returning a different object than the one that is normally returned.
The objects should be compatible, so we want to make sure we return a Goal. */
value = "NEW",
/* This is the class we are replacing. In this case, the FollowTargetGoal.
We are replacing the FollowTargetGoal because this is the goal that actually
tells the Vindicator "you should attack this entity". The attack goal only
uses this target once it's set by a FollowTargetGoal. */
target = "net/minecraft/entity/ai/goal/FollowTargetGoal",
/* There are three places where a new FollowTargetGoal is created in initGoals.
We only need to replace the one that's related to players, since this shouldn't
change the way vindicators react to merchants or iron golems. This will be the first
of the three. Ordinals are 0-indexed, so the first one is ordinal = 0. */
ordinal = 0
)
)
// Our method needs to have the same signature as the
private <T extends LivingEntity> FollowTargetGoal<T> replaceFollowPlayerGoal(MobEntity mobEntity, Class<T> clazz, boolean checkVisibility) {
return new FollowTargetGoal<>(
mobEntity, // This is the vindicator entity. Originally passed to the constructor as `this`.
clazz, // The class that this goal should apply to. Originally passed `PlayerEntity.class`.
10, /* This is a default value, used in the constructors for FollowTargetGoal that use
fewer arguments. We need to include it to use this larger constructor that allow
us to add a predicate. */
checkVisibility, // Whether this goal should check visibility. Originally passed `true`.
false, // Again, a default value from the larger constructor.
e -> !FBPowers.ILLAGER.isActive(e) /* This is the predicate that allows us to determine if the
vindicator should follow the entity in question. */
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment