Skip to content

API reference / @jsprismarine/prismarine / entity/data/EntityStore / EntityStore

Class: EntityStore ​

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:87

One world's data-driven entities, by runtime id, and the change log of their state.

Constructors ​

Constructor ​

new EntityStore(report?): EntityStore

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:111

Parameters ​

report? ​

(message) => void

Receives a line for each inverse that failed.

Returns ​

EntityStore

Accessors ​

broken ​

Get Signature ​

get broken(): unknown

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:419

The first inverse that failed to write, or undefined while the store can be trusted. A world whose store is broken stops ticking.

Returns ​

unknown


size ​

Get Signature ​

get size(): number

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:129

How many members the store holds.

Returns ​

number


tick ​

Get Signature ​

get tick(): number

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:396

The number of the open tick, or of the last one sealed, counted from 1 by the store; 0 before the first. A clock that only goes forward, which a meal is counted out on.

Returns ​

number


tickOpen ​

Get Signature ​

get tickOpen(): boolean

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:401

Whether a tick is open, so writes are logged.

Returns ​

boolean

Methods ​

addInverseWriter() ​

addInverseWriter(writer): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:354

Registers a writer for inverse entries; the first one that knows the entity writes it.

Parameters ​

writer ​

InverseWriter

Returns ​

void


admit() ​

admit(entity): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:137

Takes in an entity that is still being built. Queries find it from now on, and its writes are not logged until EntityStore.enter records it.

Parameters ​

entity ​

DataEntity

Returns ​

void


afterUnit() ​

afterUnit(work): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:347

Runs work once the open unit, and every unit around it, has ended, and tells it whether the writes made so far still stand: false when one of those units threw and was undone. This is for what cannot be put back and so cannot wait in EntityStore.undoWith: a packet, a chat line, a player's leave once its goodbye is queued. Work that only stands with the unit's writes waits for true; work that happens either way ignores the flag. It runs once the undo has finished, so its writes are logged like any others.

Work registered in a unit runs after every unit around it closed, in the order registered. A throw from it is reported and does not stop the rest, since the unit's outcome is settled by then. With no unit open, the work runs now and is told true, and a throw passes through, as it would have from the caller.

Parameters ​

work ​

(kept) => void

What to run, told whether the writes made before this call were kept.

Returns ​

void


beginTick() ​

beginTick(): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:359

Opens the next tick of the log, or does nothing when one is already open.

Returns ​

void


chunk() ​

chunk(change, x, z): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:293

Appends a chunk entry, which names a chunk that entered or left the world.

A chunk admitted at the input step enters outside every unit. Only a chunk applied while no tick loop runs, as in a test, can enter inside one, and a chunk entry has no inverse, so every open unit is pinned: if it throws, its writes stay and the failure is reported.

Parameters ​

change ​

"leave" | "enter"

x ​

number

z ​

number

Returns ​

void


counts() ​

counts(): EntityStoreCounts

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:411

What the store counted, for reports.

Returns ​

EntityStoreCounts


detach() ​

detach(entity): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:159

Takes an entity out of the store. Its own writes stop being logged; call EntityStore.recordLeave once its removal has finished.

Parameters ​

entity ​

DataEntity

Returns ​

void


enter() ​

enter(entity, saved): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:145

Records that an admitted entity has entered the world, with the saved form it entered with. Its writes are logged from now on.

Parameters ​

entity ​

DataEntity

saved ​

PlainRecord

Returns ​

void


failed() ​

failed(id): boolean

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:450

Counts one more failed update for an entity and marks it skipped for the rest of the tick.

Parameters ​

id ​

number

Returns ​

boolean

Whether the entity has now failed ENTITY_FAILURE_LIMIT updates in a row.


get() ​

get(id): DataEntity | undefined

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:114

The member with this runtime id, or undefined when the store holds none.

Parameters ​

id ​

number

Returns ​

DataEntity | undefined


has() ​

has(id): boolean

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:119

Whether the store holds an entity with this runtime id.

Parameters ​

id ​

number

Returns ​

boolean


hasEntered() ​

hasEntered(entity): boolean

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:151

Whether a member's entering entry has been recorded, so its writes are logged.

Parameters ​

entity ​

DataEntity

Returns ​

boolean


isSkipped() ​

isSkipped(id): boolean

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:463

Whether an entity failed earlier in this tick and is skipped until the next.

Parameters ​

id ​

number

Returns ​

boolean


lastSealed() ​

lastSealed(): SealedTick | undefined

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:406

The last sealed tick, until the next tick begins, or undefined when there is none.

Returns ​

SealedTick | undefined


occurred() ​

occurred(entry): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:282

Appends an occurrence, which changes no state: something replication sends, or the record of an action a guard vetoed.

Parameters ​

entry ​

OccurrenceEntry

Returns ​

void


onSealed() ​

onSealed(listener): () => void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:387

Hears every tick as it seals. Replication will be the reader; until then the replay scenarios count entries and bytes per tick through this.

Parameters ​

listener ​

(sealed) => void

Returns ​

A function that removes the listener.

() => void


recordLeave() ​

recordLeave(id, saved): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:170

Records that an entity left, with the saved form it had before its removal began. Called last, so that undoing the removal adds the entity back before the changes its removal made to other entities are undone.

Parameters ​

id ​

number

saved ​

PlainRecord

Returns ​

void


replay() ​

replay(entries): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:305

Writes the state each entry leads to, forward, through the registered writers and without logging: a field takes its after-value, an entering entity is added from its saved form and a leaving one is removed. A store built from a snapshot reaches the live store's state this way, which is what makes a snapshot plus the log a replay.

Parameters ​

entries ​

Iterable<ChangeEntry>

Returns ​

void

Throws ​

When no writer knows an entry's entity.


sealTick() ​

sealTick(header?): SealedTick | undefined

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:374

Seals the open tick, which is what the tick's close phase does.

Parameters ​

What the world's own clocks and in-flight work are now, which no entry carries.

gameRules ​

readonly (readonly [string, readonly [number | boolean, boolean]])[]

Every game rule, as its name, its value and whether it can be edited.

pendingChunkLoads ​

readonly (readonly [number, string])[]

Each chunk load in flight, as its packed position and its urgency, by position.

pendingLighting ​

{ deferred: number; queued: number; }

How deep the light queue is.

pendingLighting.deferred ​

number

pendingLighting.queued ​

number

randomTickState ​

number

The state of the generator that draws random tick positions.

settlingChunks ​

readonly number[]

The freshly generated chunks still settling, as packed positions in ascending order.

tick ​

number

The level clock, as World.getTicks reads it.

weather ​

{ clearWeatherTime: number; raining: boolean; rainTime: number; thundering: boolean; thunderTime: number; }

The level's weather, as a save holds it.

weather.clearWeatherTime ​

number

weather.raining ​

boolean

weather.rainTime ​

number

weather.thundering ​

boolean

weather.thunderTime ​

number

Returns ​

SealedTick | undefined

The sealed tick, or undefined when no tick was open.


succeeded() ​

succeeded(id): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:458

Clears an entity's run of failures after an update that finished.

Parameters ​

id ​

number

Returns ​

void


undoWith() ​

undoWith(undo): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:327

Registers how to put back a write the log does not carry, such as a grace period or a death in progress, for the open unit to run if it throws. A unit that finishes hands its undos to the unit around it. Outside a unit, or during an undo, this does nothing.

The undos run after the unit's inverse entries, so an undo that puts back a removed entity's state finds the entity the undone removal added back, by its runtime id.

Parameters ​

undo ​

() => void

Puts the state back as it was when this was called.

Returns ​

void


unit() ​

unit(work): UnitOutcome

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:430

Runs one unit of work in a span of its own. When it throws, the span is reverted and the error is returned instead of thrown.

With no tick open there is nothing to revert from, so the work runs as it is and a throw passes through, as it did before the store existed.

Parameters ​

work ​

() => void

Returns ​

UnitOutcome


values() ​

values(): IterableIterator<DataEntity>

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:124

Every member, in the order they were admitted.

Returns ​

IterableIterator<DataEntity>


written() ​

written(entity, field, before, after): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:182

Logs one change to a member's state, with its value before and after.

A write by an entity that has not entered, or that is leaving, is part of a saved form and is dropped. Values are copied into plain data here, so a caller may pass the live value it just stored.

Parameters ​

entity ​

DataEntity

field ​

string

The field's name in the entry's address, such as position or component:minecraft:breathable.

before ​

unknown

after ​

unknown

Returns ​

void


writtenBlock() ​

writtenBlock(x, y, z, layer, before, after): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:236

Logs one change to the block at a position, as block runtime ids.

Parameters ​

x ​

number

y ​

number

z ​

number

layer ​

number

The storage layer, 0 for the block and 1 for what is waterlogged into it.

before ​

number

after ​

number

Returns ​

void


writtenBlockEntity() ​

writtenBlockEntity(x, y, z, field, before, after): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:245

Logs one change to one field of the block entity at a position (blockentity/blockEntityLog.ts names the fields), with its value before and after.

Parameters ​

x ​

number

y ​

number

z ​

number

field ​

string

before ​

PlainData

after ​

PlainData

Returns ​

void


writtenBlockUpdate() ​

writtenBlockUpdate(x, y, z, before, after): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:261

Logs one change to the block update queue: a position queued, moved to an earlier tick or taken off, as the tick it comes due before and after, or null for none.

Parameters ​

x ​

number

y ​

number

z ​

number

before ​

number | null

after ​

number | null

Returns ​

void


writtenFrozen() ​

writtenFrozen(entity, field, before, after): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:197

EntityStore.written for values that are already immutable plain data, such as an entity's frozen component state, which the log can hold as they are.

Copying them would give the same entry. Skipping the copy matters because a mob's component timers, such as its ambient sound countdown, change every tick, so this runs for nearly every mob on every tick.

Parameters ​

entity ​

DataEntity

field ​

string

before ​

PlainData

The value before the write. The caller never changes it afterwards.

after ​

PlainData

The value after the write. The caller never changes it afterwards.

Returns ​

void


writtenLegacy() ​

writtenLegacy(id, field, before, after): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:206

Logs one change to an entity the store does not hold, addressed by its runtime id: a rider whose ride changed after its entity left the store.

Parameters ​

id ​

number | bigint

field ​

string

before ​

unknown

after ​

unknown

Returns ​

void


writtenScheduledTick() ​

writtenScheduledTick(address, before, after): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:270

Logs one scheduled block or fluid tick queued or taken off, with its timing before and after, or null for none.

Parameters ​

address ​
list ​

"block" | "fluid"

type ​

string

x ​

number

y ​

number

z ​

number

before ​

{ priority: number; subTickOrder: number; triggerTick: number; } | null

after ​

{ priority: number; subTickOrder: number; triggerTick: number; } | null

Returns ​

void


writtenSlot() ​

writtenSlot(id, container, slot, before, after): void

Defined in: packages/prismarine/src/entity/data/EntityStore.ts:214

Logs one change to one slot of an entity's container, addressed by its runtime id.

Parameters ​

id ​

number | bigint

container ​

string

Which of the entity's containers, such as inventory or armor.

slot ​

number

before ​

PlainRecord | null

after ​

PlainRecord | null

Returns ​

void