Skip to content

Goal_en

MidCoard edited this page Mar 27, 2020 · 4 revisions

Modify Goal

Start

Ready to Work

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.

Meet

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.

Goal

Building Goal

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.

GoalSelector

Get the GoalSelector of an entity

I believe in the Deal with Entity part you already know how to get GoalSelector through PathfinderAPI.

GoalSelector goalSelector = focessEntity.getGoalSelector();

Viewing the GoalItem of an entity

Use #getGoalItems() to get the constructed objects of all Goal objects of this entity.

Viewing the Goal's Goal

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.

Add Goal to Entity

Use #addGoal(WrappedGoal wrappedGoal) to add a Goal object to the entity.

Deleting the Goal's Goal

Use #removeGoal(GoalItem goalItem) or #removeExactGoal(WrappedGoal wrappedGoal) to delete the entity's Goal object.

Determine if the entity has a certain Goal or a GoalItem

Use #containsGoal(GoalItem goalItem) or #containsExactGoal(WrappedGoal wrappedGoal) to determine whether a certain Goal or a GoalItem exists.

开始(Getting Started)

实体处理(Deal with Entity)

Goal操作(Modify Goal)

使用Navigation(Use Navigation)

其他(Other Things)

Clone this wiki locally