Class AbstractGoal<O extends Agent>
- Type Parameters:
O- The type of Agent
- All Implemented Interfaces:
Goal<O>
Goal that a GoalExecutor can run.
It is required for anyone wanting to write their own logic that a Goal can
run to utilize this class. If you desire to use the builtin AI included with
Minecraft, use BuilderProvider.provide(Class) and pass a builder to
it instead.
At the beginning of every "AI" tick, all Goals that are added to
the parent GoalExecutor are iterated through. If a Goal is already
marked as "in use", that goal's continueUpdating() is checked for
true. If continueUpdating() is false, reset()
is invoked, and the Goal is "flagged" as unused for the parent GoalExecutor.
If continueUpdating() is true, update() is invoked
to perform any major logic.
If an Goal is not currently flagged as "in use", then shouldUpdate()
is invoked. If shouldUpdate() is true, the Goal is
marked as "in use", and start() is invoked. After start()
is called, update() will be invoked to be used for the first time
in this "AI tick".
Regardless whether the Goal was "in use" or not, if the Goal
is now "in use", continueUpdating() is called to verify the validity of the
task. If continueUpdating() is false, reset() is called
to clean up the Goal.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractGoal(GoalType type) Creates a newAbstractGoalwith the providedGoal. -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanfinal Optional<GoalExecutor<O>> executor()Gets theGoalExecutorthat is updating this goal, if any.abstract voidreset()Performs any reset necessary for this goal during the current tick.abstract booleanabstract voidstart()Invoked when the goal is "started".final GoalTypetype()Gets theGoalType.abstract voidupdate()Performs any customary logic for this goal to modify the parentAgentin any way, including navigation, health, potion effects, etc.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.spongepowered.api.entity.ai.goal.Goal
canBeInterrupted, canRunConcurrentWith, owner
-
Constructor Details
-
AbstractGoal
Creates a newAbstractGoalwith the providedGoal.- Parameters:
type- The type
-
-
Method Details
-
type
Description copied from interface:GoalGets theGoalType. -
executor
Description copied from interface:GoalGets theGoalExecutorthat is updating this goal, if any.- Specified by:
executorin interfaceGoal<O extends Agent>- Returns:
- The goal or
Optional.empty()if not present
-
start
public abstract void start()Invoked when the goal is "started". A "start" of a goal occurs at the "start" of the "AI" is "ticking". Depending on the case whereshouldUpdate()returnsfalse, anGoalis NOT going to be called, so this method would not be called at the "start" of the tick to "prepare" forupdate(). -
shouldUpdate
public abstract boolean shouldUpdate()Determines whether thisGoalshould be considered for "ticking" orstart(),update(), andreset()are called for that "AI" tick.- Returns:
- Whether this goal should be marked for use in the current tick
-
update
public abstract void update()Performs any customary logic for this goal to modify the parentAgentin any way, including navigation, health, potion effects, etc. Only called whenshouldUpdate()returnstrue, and afterstart()has completed. Likewise, ifcontinueUpdating() -
continueUpdating
public abstract boolean continueUpdating()Called to verify that thisGoalneeds toupdate()in this tick. If this returnsfalse, this goal is removed from use andreset()is called.- Returns:
- Whether this task should update this "tick" or not
-
reset
public abstract void reset()
-