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 Goal
s 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
ModifierConstructorDescriptionprotected
AbstractGoal
(GoalType type) Creates a newAbstractGoal
with the providedGoal
. -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
final Optional<GoalExecutor<O>>
executor()
Gets theGoalExecutor
that is updating this goal, if any.abstract void
reset()
Performs any reset necessary for this goal during the current tick.abstract boolean
abstract void
start()
Invoked when the goal is "started".final GoalType
type()
Gets theGoalType
.abstract void
update()
Performs any customary logic for this goal to modify the parentAgent
in 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 Details
-
AbstractGoal
Creates a newAbstractGoal
with the providedGoal
.- Parameters:
type
- The type
-
-
Method Details
-
type
Description copied from interface:Goal
Gets theGoalType
. -
executor
Description copied from interface:Goal
Gets theGoalExecutor
that is updating this goal, if any.- Specified by:
executor
in 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
, anGoal
is 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 thisGoal
should 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 parentAgent
in 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 thisGoal
needs 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()
-