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
readonlyattributes: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?
readonlyoptionalbeamTarget?:EntityPosition
Defined in: packages/prismarine/src/entity/data/persistence.ts:113
The block an end crystal's beam points at.
breedCooldown
readonlybreedCooldown:number
Defined in: packages/prismarine/src/entity/data/persistence.ts:111
canPickUpLoot?
readonlyoptionalcanPickUpLoot?: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?
readonlyoptionalcarried?: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?
readonlyoptionalcolor?:number
Defined in: packages/prismarine/src/entity/data/persistence.ts:82
Palette color set through an accepted dye.
componentGroups
readonlycomponentGroups: readonlystring[]
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?
readonlyoptionalcomponentState?: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?
readonlyoptionalcontainerSlots?: 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?
readonlyoptionalcuredBy?:string
Defined in: packages/prismarine/src/entity/data/persistence.ts:88
The player who cured this villager of being a zombie villager.
deathTime?
readonlyoptionaldeathTime?: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?
readonlyoptionalequipment?: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?
readonlyoptionalequipmentInventorySlots?: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?
readonlyoptionalfireTicks?:number
Defined in: packages/prismarine/src/entity/data/persistence.ts:126
Remaining ticks an entity stays on fire.
fuseTicks?
readonlyoptionalfuseTicks?:number
Defined in: packages/prismarine/src/entity/data/persistence.ts:123
Remaining ticks on an active component-defined explosion fuse.
home?
readonlyoptionalhome?:EntityPosition
Defined in: packages/prismarine/src/entity/data/persistence.ts:84
Where minecraft:home or a set_home_position event pinned the entity.
identifier
readonlyidentifier:string
Defined in: packages/prismarine/src/entity/data/persistence.ts:54
The entity type, such as minecraft:villager_v2.
inventory?
readonlyoptionalinventory?: readonlystring[]
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?
readonlyoptionalinvulnerable?: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?
readonlyoptionalleashHolderIdentity?: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
readonlyloveTicks:number
Defined in: packages/prismarine/src/entity/data/persistence.ts:110
merchant?
readonlyoptionalmerchant?: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?
readonlyoptionalnameTag?:string
Defined in: packages/prismarine/src/entity/data/persistence.ts:80
Custom name set through an accepted name tag.
ownerIdentity?
readonlyoptionalownerIdentity?:string
Defined in: packages/prismarine/src/entity/data/persistence.ts:86
Stable identity of the player who tamed or launched this entity.
persistentIdentity
readonlypersistentIdentity:string
Defined in: packages/prismarine/src/entity/data/persistence.ts:56
Stable identity used to reconnect persistent relationships after a reload.
pitch
readonlypitch:number
Defined in: packages/prismarine/src/entity/data/persistence.ts:78
pool?
readonlyoptionalpool?: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?
readonlyoptionalprojectile?: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
readonlyage:number
stuck
readonlystuck:boolean
velocity
readonlyvelocity:EntityPosition
properties
readonlyproperties:Readonly<Record<string,PropertyValue>>
Defined in: packages/prismarine/src/entity/data/persistence.ts:64
Entity property name to its value.
showBottom?
readonlyoptionalshowBottom?: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
readonlysitting:boolean
Defined in: packages/prismarine/src/entity/data/persistence.ts:108
sleeping
readonlysleeping:boolean
Defined in: packages/prismarine/src/entity/data/persistence.ts:109
sleepingPos?
readonlyoptionalsleepingPos?:EntityPosition
Defined in: packages/prismarine/src/entity/data/persistence.ts:115
The bed the entity lies in, Java's sleeping_pos.
spawnData?
readonlyoptionalspawnData?: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?
readonlyoptionaltradeTier?:number
Defined in: packages/prismarine/src/entity/data/persistence.ts:124
yaw
readonlyyaw:number
Defined in: packages/prismarine/src/entity/data/persistence.ts:77
Variables
DATA_ENTITY_TAG
constDATA_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
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
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
record
content?
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
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
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?
Returns
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
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
record
Returns
void