-
Notifications
You must be signed in to change notification settings - Fork 1
Goal
如果你对PathfinderGoal一无所知,请前往相关页面并查询相关资料或者自己动手实践来了解其中的机制。 我们为你提供了一些帮助,这是某些相关教程:
开发有关Goal操作的有关内容,很多时候你需要了解Minecraft PathfinderGoal工作机制以及拥有相关Pathfinder的概念。 必要情况下,需要借助于反编译工具,甚至于反混淆工具。
在PathfinderAPI中,我们为你提供了Goal这个抽象类,用以自定义PathfinderGoal。
通常情况下,你的Goal会用到寻路方面的方法,我们提供了使用Navigation。
这里假设你已经实现了一个MyGoal。
通过GoalItem我们可以来构建一个可以用于实体处理的Goal对象,注意这里的Goal与代码中
实现的Goal不同。
WrappedGoal wrappedGoal = new FocessGoalItem(new MyGoal(...)).build(0,false);
通过以上代码,你就可以创建一个可用于实体处理的Goal对象。
除了FocessGoalItem,我们还提供了NMSGoalItem用于创建Minecraft本身提供的一些Goal对象。
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);
就像这样,你就可以获得一个Goal对象。注意,在这里我们都使用了#build(int priority,boolean isTarget)方法来构建一个Goal。
在这里priority是指该Goal的优先级,isTarget是指该Goal是否为Target类型的Goal。
相信在实体处理部分你已经知道如何通过PathfinderAPI来获取GoalSelector。
GoalSelector goalSelector = focessEntity.getGoalSelector();
使用#getGoalItems()来获取该实体的所有Goal对象的构建对象。
使用 #getGoal(GoalItem goalItem)来获取该实体某些构建对象对应的Goal对象。
通过#getGoalItems()和#getGoal(GoalItem goalItem)我们可以轻松获得实体的所有Goal对象。
for (GoalItem goalItem:entity.getGoalSelector().getGoalItems())
for (WrappedGoal wrappedGoal:entity.getGoalSelector().getGoal(goalItem))
...
同样,通过#getGoals可以直接获得所有Goal对象。
使用 #addGoal(WrappedGoal wrappedGoal)来给实体添加Goal对象。
使用 #removeGoal(GoalItem goalItem)或者#removeExactGoal(WrappedGoal wrappedGoal)来删除实体的Goal对象。
使用 #containsGoal(GoalItem goalItem)或者#containsExactGoal(WrappedGoal wrappedGoal)来判断是否存在某种或者某个Goal。