Skip to content

API reference / @jsprismarine/entity-brains / Behavior

Class: Behavior ​

Defined in: behavior/control.ts:79

A behavior with memory preconditions and a duration. Java's abstract Behavior.

tryStart draws a duration uniformly from [minDuration, maxDuration] and records when the behavior times out. canStillUse returns false by default, so a behavior that does not override it runs for exactly one tick.

Implements ​

Constructors ​

Constructor ​

new Behavior(name, entryCondition, hooks?, duration?): Behavior

Defined in: behavior/control.ts:90

Parameters ​

name ​

string

entryCondition ​

MemoryConditions

hooks? ​

BehaviorHooks = {}

duration? ​

Partial<BehaviorDuration> = {}

Returns ​

Behavior

Properties ​

name ​

readonly name: string

Defined in: behavior/control.ts:80

The Java class name, which is what a debug read-out shows.

Implementation of ​

BehaviorControl.name

Accessors ​

requiredMemories ​

Get Signature ​

get requiredMemories(): readonly MemoryModuleType<unknown>[]

Defined in: behavior/control.ts:107

Every memory the behavior reads or writes. The brain registers each one when the behavior is added, which is how a memory a mob never declares still gets a slot.

Returns ​

readonly MemoryModuleType<unknown>[]

Every memory the behavior reads or writes. The brain registers each one when the behavior is added, which is how a memory a mob never declares still gets a slot.

Implementation of ​

BehaviorControl.requiredMemories


status ​

Get Signature ​

get status(): BehaviorStatus

Defined in: behavior/control.ts:103

Returns ​

BehaviorStatus

Implementation of ​

BehaviorControl.status

Methods ​

doStop() ​

doStop(context, timestamp): void

Defined in: behavior/control.ts:133

Marks the behavior stopped and runs the stop hook.

Parameters ​

context ​

BrainContext

timestamp ​

number

Returns ​

void

Implementation of ​

BehaviorControl.doStop


tickOrStop() ​

tickOrStop(context, timestamp): void

Defined in: behavior/control.ts:124

Runs the tick hook while the behavior has time left and canStillUse holds, and stops it otherwise.

Parameters ​

context ​

BrainContext

timestamp ​

number

Returns ​

void

Implementation of ​

BehaviorControl.tickOrStop


tryStart() ​

tryStart(context, timestamp): boolean

Defined in: behavior/control.ts:112

Checks the memory conditions and checkExtraStartConditions, then draws how long this run lasts.

Parameters ​

context ​

BrainContext

timestamp ​

number

Returns ​

boolean

Implementation of ​

BehaviorControl.tryStart