Skip to content

API reference / @jsprismarine/entities / GoalScheduler

Class: GoalScheduler ​

Defined in: entities/src/goals.ts:142

Runs one goal per control flag, choosing by priority.

The rule the documentation states is "0 is the highest priority ... If the entity is busy doing a low priority behavior and a high priority behavior comes up, the entity will immediately switch". So a candidate takes a flag when the flag is free, or when its holder has a strictly worse priority, and the holder is stopped in the same tick.

A goal with no control flags runs alongside everything else, which is how the targeting goals work.

Constructors ​

Constructor ​

new GoalScheduler(): GoalScheduler

Returns ​

GoalScheduler

Methods ​

add() ​

add(entry): void

Defined in: entities/src/goals.ts:159

Registers a goal, replacing any goal already registered under the name.

Parameters ​

entry ​

ScheduledGoal

Returns ​

void


holderOf() ​

holderOf(flag): string | undefined

Defined in: entities/src/goals.ts:186

The goal holding a control flag now, or undefined when the flag is free.

Parameters ​

flag ​

"move" | "look" | "jump"

Returns ​

string | undefined


names() ​

names(): readonly string[]

Defined in: entities/src/goals.ts:191

Every registered goal name, in priority order.

Returns ​

readonly string[]


remove() ​

remove(name): void

Defined in: entities/src/goals.ts:170

Takes a goal off, stopping it first when it is running.

Parameters ​

name ​

string

Returns ​

void


runningGoals() ​

runningGoals(): readonly string[]

Defined in: entities/src/goals.ts:179

The names of the goals running now, in priority order.

Returns ​

readonly string[]


tick() ​

tick(updateSelector?): void

Defined in: entities/src/goals.ts:203

Runs one tick: stops the running goals that cannot continue, starts the best candidate for each free or preemptible flag, then ticks what runs.

Parameters ​

updateSelector? ​

boolean = true

When false, only running goals that request every-tick updates are ticked; selection and cleanup wait for the next selector pass.

Returns ​

void