Class AbstractGoal<O extends Agent>
- java.lang.Object
-
- org.spongepowered.api.entity.ai.goal.AbstractGoal<O>
-
- Type Parameters:
O- The type of Agent
- All Implemented Interfaces:
Goal<O>
public abstract class AbstractGoal<O extends Agent> extends java.lang.Object implements Goal<O>
An abstract implementation of aGoalthat aGoalExecutorcan 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 parentGoalExecutorare iterated through. If aGoalis already marked as "in use", that goal'scontinueUpdating()is checked fortrue. IfcontinueUpdating()isfalse,reset()is invoked, and theGoalis "flagged" as unused for the parentGoalExecutor. IfcontinueUpdating()istrue,update()is invoked to perform any major logic.If an
Goalis not currently flagged as "in use", thenshouldUpdate()is invoked. IfshouldUpdate()istrue, theGoalis marked as "in use", andstart()is invoked. Afterstart()is called,update()will be invoked to be used for the first time in this "AI tick".Regardless whether the
Goalwas "in use" or not, if theGoalis now "in use",continueUpdating()is called to verify the validity of the task. IfcontinueUpdating()isfalse,reset()is called to clean up theGoal.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractGoal(GoalType type)Creates a newAbstractGoalwith the providedGoal.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract booleancontinueUpdating()java.util.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 booleanshouldUpdate()abstract voidstart()Invoked when the goal is "started".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, wait
-
Methods inherited from interface org.spongepowered.api.entity.ai.goal.Goal
canBeInterrupted, canRunConcurrentWith, owner
-
-
-
-
Constructor Detail
-
AbstractGoal
protected AbstractGoal(GoalType type)
Creates a newAbstractGoalwith the providedGoal.- Parameters:
type- The type
-
-
Method Detail
-
executor
public final java.util.Optional<GoalExecutor<O>> executor()
Description copied from interface:GoalGets theGoalExecutorthat is updating this goal, if any.
-
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()
-
-