Skip to content

API reference / @jsprismarine/entity-brains / MemorySlot

Class: MemorySlot<Value> ​

Defined in: memory.ts:105

One memory's storage. Java's MemorySlot.

timeToLive counts down one per brain tick while a value is present. Long.MAX_VALUE means never expire, which is what MemorySlot.set without a time to live stores.

Type Parameters ​

Value ​

Value

Constructors ​

Constructor ​

new MemorySlot<Value>(): MemorySlot<Value>

Returns ​

MemorySlot<Value>

Properties ​

NEVER_EXPIRE ​

readonly static NEVER_EXPIRE: number = Number.MAX_SAFE_INTEGER

Defined in: memory.ts:107

Java's MemorySlot.NEVER_EXPIRE, Long.MAX_VALUE.

Methods ​

canExpire() ​

canExpire(): boolean

Defined in: memory.ts:151

Whether the slot was given a time to live rather than stored forever.

Returns ​

boolean


clear() ​

clear(): void

Defined in: memory.ts:135

Empties the slot and resets its expiry.

Returns ​

void


hasExpired() ​

hasExpired(): boolean

Defined in: memory.ts:156

Whether the countdown has run out. MemorySlot.tick clears the slot on the next tick.

Returns ​

boolean


hasValue() ​

hasValue(): boolean

Defined in: memory.ts:141

Whether the slot holds a value right now.

Returns ​

boolean


set() ​

set(value, timeToLive?): void

Defined in: memory.ts:129

Stores a value, with an expiry in ticks when one is given.

Parameters ​

value ​

Value

timeToLive? ​

number = MemorySlot.NEVER_EXPIRE

Returns ​

void


tick() ​

tick(): void

Defined in: memory.ts:118

Ages the slot by one tick.

Java checks expiry before decrementing, so a slot set with a time to live of n is readable on n ticks and is cleared on the n + 1th.

Returns ​

void


timeToLive() ​

timeToLive(): number

Defined in: memory.ts:161

Ticks left before the slot clears, or MemorySlot.NEVER_EXPIRE.

Returns ​

number


value() ​

value(): Value | undefined

Defined in: memory.ts:146

The stored value, or undefined while the slot is empty.

Returns ​

Value | undefined