Skip to content

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

entity/data/persistence ​

Interfaces ​

DataEntityRecord ​

Defined in: packages/prismarine/src/entity/data/persistence.ts:52

Everything a saved data-driven entity needs back to be the same entity.

Properties ​

attributes ​

readonly attributes: Readonly<Partial<Record<AttributeName, number>>>

Defined in: packages/prismarine/src/entity/data/persistence.ts:76

Attribute name to its current value; the bounds come back from the components.

beamTarget? ​

readonly optional beamTarget?: EntityPosition

Defined in: packages/prismarine/src/entity/data/persistence.ts:113

The block an end crystal's beam points at.

breedCooldown ​

readonly breedCooldown: number

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

canPickUpLoot? ​

readonly optional canPickUpLoot?: boolean

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

Whether a mob that picks up by chance rolled that it may, Java's CanPickUpLoot.

carried? ​

readonly optional carried?: string

Defined in: packages/prismarine/src/entity/data/persistence.ts:93

The main hand as an item identifier, which a record written before equipment held the main hand carries. It loads only when equipment has no main hand.

color? ​

readonly optional color?: number

Defined in: packages/prismarine/src/entity/data/persistence.ts:82

Palette color set through an accepted dye.

componentGroups ​

readonly componentGroups: readonly string[]

Defined in: packages/prismarine/src/entity/data/persistence.ts:62

The component groups active when it was saved, in the order they became active.

componentState? ​

readonly optional componentState?: Readonly<Record<string, unknown>> | Readonly<Record<string, ComponentStateRecord | null>>

Defined in: packages/prismarine/src/entity/data/persistence.ts:74

The state each active component keeps between ticks, such as a timer or an air supply, by component name, with null for a component that holds none. A record written before this field existed leaves it out, and its components keep the state they initialize with.

Saved as ComponentStates.snapshot gives it, and read back as the file holds it: restoring checks each value against its component and reports one that does not fit, which it could not do for an entry the reader had already dropped.

containerSlots? ​

readonly optional containerSlots?: readonly (ItemDrop | null)[]

Defined in: packages/prismarine/src/entity/data/persistence.ts:107

Slots in the minecraft:inventory container, empty slots represented by null.

curedBy? ​

readonly optional curedBy?: string

Defined in: packages/prismarine/src/entity/data/persistence.ts:88

The player who cured this villager of being a zombie villager.

deathTime? ​

readonly optional deathTime?: number

Defined in: packages/prismarine/src/entity/data/persistence.ts:128

Ticks since a living entity died, Java's DeathTime, for one saved during its death.

equipment? ​

readonly optional equipment?: Readonly<Partial<Record<"head" | "chest" | "feet" | "mainhand" | "offhand" | "body" | "legs", ItemDrop>>>

Defined in: packages/prismarine/src/entity/data/persistence.ts:103

What each equipment slot holds, with each complete stack. A slot an alias reads through equipmentInventorySlots holds the same stack as its container slot.

equipmentInventorySlots? ​

readonly optional equipmentInventorySlots?: Partial<Record<"head" | "chest" | "feet" | "mainhand" | "offhand" | "body" | "legs", number>>

Defined in: packages/prismarine/src/entity/data/persistence.ts:105

The equipment slots read through a container slot, such as a horse's armor, by container index.

fireTicks? ​

readonly optional fireTicks?: number

Defined in: packages/prismarine/src/entity/data/persistence.ts:126

Remaining ticks an entity stays on fire.

fuseTicks? ​

readonly optional fuseTicks?: number

Defined in: packages/prismarine/src/entity/data/persistence.ts:123

Remaining ticks on an active component-defined explosion fuse.

home? ​

readonly optional home?: EntityPosition

Defined in: packages/prismarine/src/entity/data/persistence.ts:84

Where minecraft:home or a set_home_position event pinned the entity.

identifier ​

readonly identifier: string

Defined in: packages/prismarine/src/entity/data/persistence.ts:54

The entity type, such as minecraft:villager_v2.

inventory? ​

readonly optional inventory?: readonly string[]

Defined in: packages/prismarine/src/entity/data/persistence.ts:98

Items carried outside the hand, one identifier per item, which a record written before containerSlots held them carries. They load into the inventory container.

invulnerable? ​

readonly optional invulnerable?: boolean

Defined in: packages/prismarine/src/entity/data/persistence.ts:121

Whether the entity refuses all damage, as the respawn sequence's crystals do.

leashHolderIdentity? ​

readonly optional leashHolderIdentity?: string

Defined in: packages/prismarine/src/entity/data/persistence.ts:58

Stable identity of the entity or player holding this entity's leash, when it has one.

loveTicks ​

readonly loveTicks: number

Defined in: packages/prismarine/src/entity/data/persistence.ts:110

merchant? ​

readonly optional merchant?: MerchantSnapshot

Defined in: packages/prismarine/src/entity/data/persistence.ts:139

A trader's offers, their uses and demand, and its experience, so a restart does not redraw them.

nameTag? ​

readonly optional nameTag?: string

Defined in: packages/prismarine/src/entity/data/persistence.ts:80

Custom name set through an accepted name tag.

ownerIdentity? ​

readonly optional ownerIdentity?: string

Defined in: packages/prismarine/src/entity/data/persistence.ts:86

Stable identity of the player who tamed or launched this entity.

persistentIdentity ​

readonly persistentIdentity: string

Defined in: packages/prismarine/src/entity/data/persistence.ts:56

Stable identity used to reconnect persistent relationships after a reload.

pitch ​

readonly pitch: number

Defined in: packages/prismarine/src/entity/data/persistence.ts:78

pool? ​

readonly optional pool?: string

Defined in: packages/prismarine/src/entity/data/persistence.ts:60

The population pool the entity counts against, when a spawn rule produced it.

projectile? ​

readonly optional projectile?: object

Defined in: packages/prismarine/src/entity/data/persistence.ts:133

Flight state for an entity carrying minecraft:projectile, or a firework rocket, which flies by its own system and keeps its motion as Java's rocket does.

age ​

readonly age: number

stuck ​

readonly stuck: boolean

velocity ​

readonly velocity: EntityPosition

properties ​

readonly properties: Readonly<Record<string, PropertyValue>>

Defined in: packages/prismarine/src/entity/data/persistence.ts:64

Entity property name to its value.

showBottom? ​

readonly optional showBottom?: boolean

Defined in: packages/prismarine/src/entity/data/persistence.ts:117

Whether an end crystal draws its base plate; absent keeps the default, true.

sitting ​

readonly sitting: boolean

Defined in: packages/prismarine/src/entity/data/persistence.ts:108

sleeping ​

readonly sleeping: boolean

Defined in: packages/prismarine/src/entity/data/persistence.ts:109

sleepingPos? ​

readonly optional sleepingPos?: EntityPosition

Defined in: packages/prismarine/src/entity/data/persistence.ts:115

The bed the entity lies in, Java's sleeping_pos.

spawnData? ​

readonly optional spawnData?: Readonly<Record<string, unknown>>

Defined in: packages/prismarine/src/entity/data/persistence.ts:141

Entity-specific fields supplied by the source that spawned it.

tradeTier? ​

readonly optional tradeTier?: number

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

yaw ​

readonly yaw: number

Defined in: packages/prismarine/src/entity/data/persistence.ts:77

Variables ​

DATA_ENTITY_TAG ​

const DATA_ENTITY_TAG: "jsprismarine:entity" = 'jsprismarine:entity'

Defined in: packages/prismarine/src/entity/data/persistence.ts:49

The actor tag holding the whole record, as JSON.

Functions ​

actorHealthIn() ​

actorHealthIn(nbt): number | undefined

Defined in: packages/prismarine/src/entity/data/persistence.ts:329

The health an actor record's Attributes list holds, Bedrock's minecraft:health entry and its Current value, as Bedrock Dedicated Server writes every mob's.

Parameters ​

nbt ​

NBTTagCompound

Returns ​

number | undefined

The health, or undefined when the record lists none.


actorMotionIn() ​

actorMotionIn(nbt): EntityPosition | undefined

Defined in: packages/prismarine/src/entity/data/persistence.ts:314

Reads projectile motion from a legacy actor NBT compound.

Parameters ​

nbt ​

NBTTagCompound

Returns ​

EntityPosition | undefined


applyDataEntityRecord() ​

applyDataEntityRecord(entity, record, content?): void

Defined in: packages/prismarine/src/entity/data/persistence.ts:504

Puts a record's state back onto a freshly built entity.

The component groups go on first, because adding a group initializes its components and a component that declares an attribute writes that attribute back to its base. The saved values land after, so a cow restored at four hearts stays at four hearts, and a mob saved mid-timer resumes the timer.

The inventory container keeps the size the caller gave it unless the record holds more than fits, in which case it grows to hold all of it. The caller's next resize to the size the components decide hands back what does not fit, so nothing a record holds is lost.

Parameters ​

entity ​

DataEntity

record ​

DataEntityRecord

content? ​

ServerContent

The content build, which decides each restored item's maximum durability.

Returns ​

void


dataEntityRecordFrom() ​

dataEntityRecordFrom(parsed): DataEntityRecord | undefined

Defined in: packages/prismarine/src/entity/data/persistence.ts:416

The record a parsed value holds, such as the JSON of the actor tag or the copy a change log membership entry carries, checked field by field as dataEntityRecordIn checks it.

Parameters ​

parsed ​

unknown

Returns ​

DataEntityRecord | undefined

The record, or undefined when the value is not an object naming an entity type.


dataEntityRecordIn() ​

dataEntityRecordIn(nbt): DataEntityRecord | undefined

Defined in: packages/prismarine/src/entity/data/persistence.ts:394

The record an actor compound carries, or undefined when it carries none.

Everything past the identifier is read defensively. The tag is this server's own, but a world is full of records written by older versions of it, and a mob that comes back with a default is better than a chunk that refuses to load.

Parameters ​

nbt ​

NBTTagCompound

Returns ​

DataEntityRecord | undefined

The record, or undefined when the tag is absent, unparseable or names no entity type, in which case the caller restores the actor the way it always did.


dataEntityRecordOf() ​

dataEntityRecordOf(entity, pool, leashHolderIdentity?, merchant?): DataEntityRecord

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

The record of one live entity, ready to be written.

Parameters ​

entity ​

DataEntity

The live entity whose state is being saved.

pool ​

string | undefined

The population pool it counts against, when it has one.

leashHolderIdentity? ​

string

Stable identity of its leash holder, when it has one.

merchant? ​

MerchantSnapshot

Returns ​

DataEntityRecord


equipmentDropsOf() ​

equipmentDropsOf(inventory): MobEquipmentSet

Defined in: packages/prismarine/src/entity/data/persistence.ts:225

What each equipment slot of an inventory holds, as drops, with an empty slot left out.

Parameters ​

inventory ​

Pick<EntityInventory, "equipment">

Returns ​

MobEquipmentSet


positionOf() ​

positionOf(value): EntityPosition | undefined

Defined in: packages/prismarine/src/entity/data/persistence.ts:306

A saved position, when the value holds three numbers under x, y and z.

Parameters ​

value ​

unknown

Returns ​

EntityPosition | undefined


savedDropOf() ​

savedDropOf(value): ItemDrop | undefined

Defined in: packages/prismarine/src/entity/data/persistence.ts:247

One saved item stack, after checking each field this runtime reads.

Parameters ​

value ​

unknown

Returns ​

ItemDrop | undefined


writeDataEntityRecord() ​

writeDataEntityRecord(nbt, record): void

Defined in: packages/prismarine/src/entity/data/persistence.ts:235

Writes a record into an actor compound, leaving every other tag alone.

Parameters ​

nbt ​

NBTTagCompound

record ​

DataEntityRecord

Returns ​

void