Skip to content

API reference / @jsprismarine/entity-goals / GoalSupport

Class: GoalSupport ​

Defined in: support.ts:82

Everything the 170 goals have in common, behind one object.

A goal implementation never touches EntityInstance, EntityActuator or GoalWorld directly. It asks this for what it needs, which keeps each goal to its own condition and its own effect, and keeps the seams in one place when the server grows a member.

Constructors ​

Constructor ​

new GoalSupport(entity, world?): GoalSupport

Defined in: support.ts:86

Parameters ​

entity ​

EntityInstance

The entity the goal runs on.

world? ​

GoalWorld = emptyGoalWorld

The world seam, which answers nothing when the server supplied none.

Returns ​

GoalSupport

Properties ​

entity ​

readonly entity: EntityInstance

Defined in: support.ts:88

The entity the goal runs on.


readonly navigator: Navigator

Defined in: support.ts:84

Moves the entity, pathing with the A* finder when the world has a view.


world ​

readonly world: GoalWorld = emptyGoalWorld

Defined in: support.ts:90

The world seam, which answers nothing when the server supplied none.

Accessors ​

actuator ​

Get Signature ​

get actuator(): EntityActuator | undefined

Defined in: support.ts:100

Moves, looks and jumps; undefined when the caller supplied no actuator.

Returns ​

EntityActuator | undefined

Methods ​

accepts() ​

accepts(entries, mob): boolean

Defined in: support.ts:292

Whether any entry of an entity_types table accepts the mob.

Parameters ​

entries ​

readonly TargetEntityType[]

mob ​

GoalMob

Returns ​

boolean


between() ​

between(min, max): number

Defined in: support.ts:153

A whole number in [min, max], which is how the duration ranges are drawn.

Parameters ​

min ​

number

max ​

number

Returns ​

number


canSee() ​

canSee(mob): boolean

Defined in: support.ts:227

Whether the entity can see the mob; true when the world does not answer.

Parameters ​

mob ​

GoalMob

Returns ​

boolean


chance() ​

chance(probability): boolean

Defined in: support.ts:146

Whether a chance in [0, 1] comes up this tick.

Parameters ​

probability ​

number

Returns ​

boolean


distanceTo() ​

distanceTo(position): number

Defined in: support.ts:120

The straight-line distance from the entity to a position.

Parameters ​

position ​

EntityPosition

Returns ​

number


entryFor() ​

entryFor(entries, mob): TargetEntityType | undefined

Defined in: support.ts:281

The entity_types entry that accepts the mob, or undefined when none does.

Parameters ​

entries ​

readonly TargetEntityType[]

mob ​

GoalMob

Returns ​

TargetEntityType | undefined


findAttackTarget() ​

findAttackTarget(entries, radius, candidates?): GoalMob | undefined

Defined in: support.ts:237

The nearest entry accepted target, after applying Java's combat target rules.

Parameters ​

entries ​

readonly TargetEntityType[]

radius ​

number

candidates? ​

readonly GoalMob[]

Returns ​

GoalMob | undefined


findTarget() ​

findTarget(entries, radius, candidates?): GoalMob | undefined

Defined in: support.ts:265

Finds the first mob an entity_types table accepts.

The table's own max_dist bounds each entry, the goal's within_radius bounds the search, and must_see is checked against GoalSupport.canSee.

Parameters ​

entries ​

readonly TargetEntityType[]

radius ​

number

candidates? ​

readonly GoalMob[]

Returns ​

GoalMob | undefined


fire() ​

fire(hook, other?): void

Defined in: support.ts:304

Fires one of a goal's event hooks.

A hook aimed at self runs through EntityInstance.fire, so its effects land on the entity's next tick like every other event. A hook aimed at another subject goes to GoalWorld.trigger, because routing an event to another entity is the server's job.

Parameters ​

hook ​

GoalEvent | undefined

other? ​

GoalMob

Returns ​

void


fireAll() ​

fireAll(hooks, other?): void

Defined in: support.ts:319

Fires every hook of a list, which the goals that write on_reach as an array need.

Parameters ​

hooks ​

readonly GoalEvent[]

other? ​

GoalMob

Returns ​

void


flag() ​

flag(name): boolean

Defined in: support.ts:159

One of the entity's own boolean facts, such as in_water or is_sitting.

Parameters ​

name ​

"is_baby" | "has_container_open" | "has_nametag" | "has_ranged_weapon" | "has_silk_touch" | "has_target" | "has_trade_supply" | "in_caravan" | "in_clouds" | "in_contact_with_water" | "in_lava" | "in_water" | "in_water_or_rain" | "is_avoiding_mobs" | "is_bound_to_creaking_heart" | "is_climbing" | "is_humid" | "is_immobile" | "is_in_village" | "is_leashed" | "is_missing_health" | "is_moving" | "is_navigating" | "is_panicking" | "is_persistent" | "is_raider" | "is_riding" | "is_sitting" | "is_sleeping" | "is_sneak_held" | "is_sneaking" | "is_snow_covered" | "is_sprinting" | "is_tamed" | "is_underground" | "is_underwater" | "is_visible" | "on_fire" | "on_ground" | "on_hot_block" | "on_ladder" | "surface_mob" | "taking_fire_damage"

Returns ​

boolean


horizontalDistanceTo() ​

horizontalDistanceTo(position): number

Defined in: support.ts:125

The distance from the entity to a position, ignoring height.

Parameters ​

position ​

EntityPosition

Returns ​

number


isAttackable() ​

isAttackable(mob): boolean

Defined in: support.ts:232

Whether Java's combat target rules allow this mob to be selected or retained.

Parameters ​

mob ​

GoalMob

Returns ​

boolean


isBrightOutside() ​

isBrightOutside(): boolean

Defined in: support.ts:185

Whether the world answers Java's bright-outside precondition.

Returns ​

boolean


isNight() ​

isNight(): boolean

Defined in: support.ts:179

Whether it is night, which the sleep, nap and village goals gate on.

Returns ​

boolean


isRaining() ​

isRaining(): boolean

Defined in: support.ts:190

Whether it is raining or thundering now.

Returns ​

boolean


lookAt() ​

lookAt(position): void

Defined in: support.ts:329

Points the entity's head at a position.

Parameters ​

position ​

EntityPosition

Returns ​

void


lookAtMob() ​

lookAtMob(mob): void

Defined in: support.ts:334

Points the entity's head at another mob's eyes, falling back to its position.

Parameters ​

mob ​

GoalMob

Returns ​

void


matches() ​

matches(filter, other?): boolean

Defined in: support.ts:196

Evaluates a filter with the entity as self and an optional other entity as other.

Parameters ​

filter ​

Filter | undefined

other? ​

GoalMob

Returns ​

boolean


measure() ​

measure(name): number | undefined

Defined in: support.ts:164

One of the entity's own numeric facts, such as actor_health.

Parameters ​

name ​

"actor_health" | "distance_to_nearest_player" | "home_distance" | "inactivity_timer" | "is_altitude" | "is_brightness" | "is_mark_variant" | "is_skin_id" | "is_temperature_value" | "is_variant" | "light_level" | "owner_distance" | "redstone_strength_at_position" | "rider_count" | "target_distance" | "y_rotation"

Returns ​

number | undefined


mobs() ​

mobs(radius, families?): readonly GoalMob[]

Defined in: support.ts:202

The mobs within the radius, nearest first, or none when the world answers none.

Parameters ​

radius ​

number

families? ​

readonly string[]

Returns ​

readonly GoalMob[]


navigation(): NavigationView | undefined

Defined in: support.ts:105

The blocks around the entity, or undefined when the world answers none.

Returns ​

NavigationView | undefined


nearestPlayer() ​

nearestPlayer(radius): GoalMob | undefined

Defined in: support.ts:212

The nearest player within the radius, or undefined when there is none.

Parameters ​

radius ​

number

Returns ​

GoalMob | undefined


noActionTime() ​

noActionTime(): number

Defined in: support.ts:135

Java's mob inactivity counter, used by RandomStrollGoal.canUse.

Returns ​

number


players() ​

players(radius): readonly GoalMob[]

Defined in: support.ts:207

The players within the radius, nearest first.

Parameters ​

radius ​

number

Returns ​

readonly GoalMob[]


playSound() ​

playSound(name): void

Defined in: support.ts:324

Plays one of the entity's sound events.

Parameters ​

name ​

string | undefined

Returns ​

void


position() ​

position(): EntityPosition

Defined in: support.ts:115

Where the entity is, or the origin when no actuator answers.

Returns ​

EntityPosition


profile() ​

profile(): NavigationProfile

Defined in: support.ts:110

The path finder's rules for this entity, from its minecraft:navigation.* component.

Returns ​

NavigationProfile


random() ​

random(): number

Defined in: support.ts:130

The next value of the entity's random source, in [0, 1).

Returns ​

number


randomInt() ​

randomInt(bound): number

Defined in: support.ts:140

Draws a Java bounded integer, preserving the world's integer RNG stream when available.

Parameters ​

bound ​

number

Returns ​

number


report() ​

report(message): void

Defined in: support.ts:339

Records something the goal met and could not carry out.

Parameters ​

message ​

string

Returns ​

void


setTarget() ​

setTarget(mob): void

Defined in: support.ts:222

Sets the entity's attack target and fires minecraft:on_target_acquired.

Parameters ​

mob ​

GoalMob | undefined

Returns ​

void


target() ​

target(): GoalMob | undefined

Defined in: support.ts:217

The entity's attack target.

Returns ​

GoalMob | undefined


timeOfDay() ​

timeOfDay(): number | undefined

Defined in: support.ts:174

Time of day in ticks, in [0, 24000), or undefined when nothing answers.

Returns ​

number | undefined


worldView() ​

worldView(): FilterWorldView | undefined

Defined in: support.ts:169

The world facts the time, weather and difficulty tests read.

Returns ​

FilterWorldView | undefined