-
Notifications
You must be signed in to change notification settings - Fork 1
Goal_en
If you don't know anything about PathfinderGoal, please go to related pages and check related materials or do it yourself to understand the mechanism.
Develop related content about Goal operation, many times you need to understand how Minecraft PathfinderGoal works and you need have concepts related to Pathfinder. If necessary, you need to resort to decompilation tools, or even anti-obfuscation tools.
In PathfinderAPI, we provide you with an abstract class called Goal to customize PathfinderGoal.
Normally, your Goal will use the path-finding method, we provide Use Navigation.
This assumes that you have implemented a MyGoal.
Through GoalItem we can build a Goal object that can be used for entity.
Note that the Goal here is different from the Goal implemented in the code.
WrappedGoal wrappedGoal = new FocessGoalItem(new MyGoal (...)).build(0, false);
With the above code, you can create a Goal object that can be used for entity.
In addition to FocessGoalItem, we also provide NMSGoalItem for creating some Goal objects provided by Minecraft itself.
import static com.focess.pathfinder.goals.NearestAttackableTargetGoalItem. *;
Zombie zombie = ...;
WrappedGoal wrappedGoal =
Goals.TARGET.NEAREST_ATTACKABLE_TARGET
.clear()
.writeEntityInsentient(WrappedEntityInsentient.getWrappedEntityInsentient (zombie))
.writeClass(EntityClasses.getEntityClass (EntityType.SKELETON))
.writeInt(RECIPROCAL_CHANCE)
.writeBoolean(true)
.writeBoolean(CHECK_CAN_NAVIGATE)
.writePredicate(TARGET_PREDICATE).build(3, true);
Just like this, you can get a Goal object. Note that here we all use the #build (int priority, boolean isTarget) method to build a Goal.
Here ** priority ** refers to the priority of the Goal, and ** isTarget ** refers to whether the Goal is a Target type Goal.
I believe in the Deal with Entity part you already know how to get GoalSelector through PathfinderAPI.
GoalSelector goalSelector = focessEntity.getGoalSelector();
Use #getGoalItems() to get the constructed objects of all Goal objects of this entity.
Use #getGoal(GoalItem goalItem) to get the Goal objects corresponding to some constructed objects of this entity.
With #getGoalItems() and #getGoal(GoalItem goalItem) we can easily get all Goal objects of the entity.
for (GoalItem goalItem: entity.getGoalSelector().getGoalItems())
for (WrappedGoal wrappedGoal: entity.getGoalSelector().getGoal(goalItem))
...
Similarly, you can directly get all Goal objects via #getGoals.
Use #addGoal(WrappedGoal wrappedGoal) to add a Goal object to the entity.
Use #removeGoal(GoalItem goalItem) or #removeExactGoal(WrappedGoal wrappedGoal) to delete the entity's Goal object.
Use #containsGoal(GoalItem goalItem) or #containsExactGoal(WrappedGoal wrappedGoal) to determine whether a certain Goal or a GoalItem exists.