O
- The type of Agentpublic abstract class AbstractAITask<O extends Agent> extends Object implements AITask<O>
AITask
that a Goal
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 GameRegistry.createBuilder(Class)
and pass a builder to
it instead.
At the beginning of every "AI" tick, all AITask
s that are added to
the parent Goal
are iterated through. If an AITask
is already
marked as "in use", that task's continueUpdating()
is checked for
true
. If continueUpdating()
is false
, reset()
is invoked, and the AITask
is "flagged" as unused for the parent Goal
.
If continueUpdating()
is true
, update()
is invoked
to perform any major logic.
If an AITask
is not currently flagged as "in use", then shouldUpdate()
is invoked. If shouldUpdate()
is true
, the AITask
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 AITask
was "in use" or not, if the AITask
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 AITask
.
Constructor and Description |
---|
AbstractAITask(AITaskType type)
Creates a new
AbstractAITask with the provided
AITask . |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
continueUpdating()
|
Optional<Goal<O>> |
getGoal()
Gets the
Goal that is updating this task, if any. |
AITaskType |
getType()
Gets the
AITaskType of this task. |
abstract void |
reset()
Performs any reset necessary for this task during the current tick.
|
abstract boolean |
shouldUpdate()
|
abstract void |
start()
Invoked when the task is "started".
|
abstract void |
update()
Performs any customary logic for this "task" to modify the parent
Agent in any way, including navigation, health, potion effects,
etc. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canBeInterrupted, canRunConcurrentWith, getOwner
public AbstractAITask(AITaskType type)
AbstractAITask
with the provided
AITask
.type
- The typepublic final AITaskType getType()
AITask
AITaskType
of this task.public final Optional<Goal<O>> getGoal()
AITask
Goal
that is updating this task, if any.getGoal
in interface AITask<O extends Agent>
Optional.empty()
if not presentpublic abstract void start()
shouldUpdate()
returns false
, an AITask
is
NOT going to be called, so this method would not be
called at the "start" of the tick to "prepare" for update()
.public abstract boolean shouldUpdate()
AITask
should be considered for "ticking"
or start()
, update()
, and reset()
are called
for that "AI" tick.public abstract void update()
Agent
in any way, including navigation, health, potion effects,
etc. Only called when shouldUpdate()
returns true
,
and after start()
has completed. Likewise, if
continueUpdating()
public abstract boolean continueUpdating()
AITask
needs to update()
in this tick. If this returns false
, this AITask
is removed from use and reset()
is called.public abstract void reset()