[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / world/WorldPersistence

# world/WorldPersistence

## Interfaces

### DragonFightState

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:72](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L72)

The End's dragon fight, as the save stores it.

The fields mirror Java's `minecraft:ender_dragon_fight` SavedData: `dragon_killed`,
`previously_killed`, `needs_state_scanning`, `dragon_uuid`, `exit_portal_location`,
`gateways`, `respawn_stage`, `respawn_time` and `respawn_crystals`. The entity references
are the data-driven runtime's persistent identities, the stable UUID an actor keeps across
saves, because runtime ids are drawn fresh every boot.

#### Properties

##### dragonDeathPosition?

> `optional` **dragonDeathPosition?**: `object`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:87](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L87)

Where the dragon [DragonFightState.dragonUniqueId](#dragonuniqueid) names died, while its portal,
gateway, egg and experience still wait for their chunks to load.

###### x

> **x**: `number`

###### y

> **y**: `number`

###### z

> **z**: `number`

##### dragonKilled

> **dragonKilled**: `boolean`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:74](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L74)

Whether the dragon is dead right now, so none should be spawned.

##### dragonUniqueId?

> `optional` **dragonUniqueId?**: `string`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:80](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L80)

The live dragon's persistent identity, when one has been spawned or adopted.

##### exitPortalLocation?

> `optional` **exitPortalLocation?**: `object`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:82](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L82)

Where the exit portal's podium stands, once found or placed.

###### x

> **x**: `number`

###### y

> **y**: `number`

###### z

> **z**: `number`

##### gateways

> **gateways**: `number`[]

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:89](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L89)

The gateway indices not yet spent, seed-shuffled on first init and popped per kill.

##### needsStateScanning

> **needsStateScanning**: `boolean`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:78](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L78)

Whether the fight still has to scan the world for a podium and a dragon.

##### previouslyKilled

> **previouslyKilled**: `boolean`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:76](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L76)

Whether a dragon has ever been killed in this world, which gates the egg.

##### respawnCrystalIds

> **respawnCrystalIds**: `string`[]

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:95](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L95)

The persistent identities of the four crystals driving a respawn in progress.

##### respawnStage?

> `optional` **respawnStage?**: `"start"` \| `"preparing_to_summon_pillars"` \| `"summoning_pillars"` \| `"summoning_dragon"`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:91](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L91)

The respawn phase in progress, or absent when no respawn sequence runs.

##### respawnTime

> **respawnTime**: `number`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:93](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L93)

Ticks spent in the current respawn phase.

***

### LegacyWorldEntity

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:26](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L26)

A non-player entity snapshot used by providers without actor storage.

#### Properties

##### position

> **position**: `object`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:28](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L28)

###### headYaw?

> `optional` **headYaw?**: `number`

###### pitch?

> `optional` **pitch?**: `number`

###### x

> **x**: `number`

###### y

> **y**: `number`

###### yaw?

> `optional` **yaw?**: `number`

###### z

> **z**: `number`

##### type

> **type**: `string`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:27](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L27)

***

### StructureReference

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:133](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L133)

One structure start an explorer map points at: Java's `StructureStart.references`.

#### Java See

StructureStart.references

#### Properties

##### chunkX

> `readonly` **chunkX**: `number`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:138](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L138)

The chunk the start is in.

##### chunkZ

> `readonly` **chunkZ**: `number`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:139](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L139)

##### dimension

> `readonly` **dimension**: `string`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:135](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L135)

The level's id for the dimension the start is in, such as `minecraft:overworld`.

##### structure

> `readonly` **structure**: `string`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:136](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L136)

***

### WorldGenSettings

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:45](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L45)

The generators a save was made with, in the shape of Java's `world_gen_settings.dat`.

Written once the stems are resolved and read back before they are resolved again, so a world
keeps the terrain it was generated with when the config changes under it. The stems are
stored as Java `dimension` documents, which is what `parseLevelStem` reads.

#### Properties

##### dimensions

> `readonly` **dimensions**: `Readonly`\<`Record`\<`string`, [`LevelStem`](https://jsprismarine.dev/api/@jsprismarine/worldgen/index.md#levelstem)\>\>

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:49](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L49)

The resolved stem of every dimension, by Java dimension id such as `minecraft:the_nether`.

##### seed

> `readonly` **seed**: `string`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:47](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L47)

The seed as a decimal string, since JSON cannot hold a 64-bit integer.

***

### WorldPersistenceData

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:102](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L102)

World state a provider stores outside the chunk data.

#### Properties

##### clockPaused?

> `optional` **clockPaused?**: `boolean`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:123](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L123)

Whether a script paused the overworld clock.

##### dimensionNumbers?

> `optional` **dimensionNumbers?**: `Readonly`\<`Record`\<`string`, `SavedDimensionNumber`\>\>

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:106](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L106)

Each custom dimension's type and Bedrock number, by its UUID; see `DimensionNumbers`.

##### dragonFight?

> `optional` **dragonFight?**: [`DragonFightState`](#dragonfightstate)

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:115](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L115)

The End's dragon fight, present once a world with one has saved.

##### entities?

> `optional` **entities?**: [`LegacyWorldEntity`](#legacyworldentity)[]

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:111](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L111)

Used by providers that do not store actors in chunk data.

##### gameRules?

> `optional` **gameRules?**: \[`string`, \[`number` \| `boolean`, `boolean`\]\][]

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:108](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L108)

##### lastMapId?

> `optional` **lastMapId?**: `number`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:125](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L125)

The last `minecraft:map_id` the level handed out; see `Level.nextMapId`.

##### levelId?

> `optional` **levelId?**: `string`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:104](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L104)

The level's UUID, its identity whatever it is named; see `Level.id`.

##### raids?

> `optional` **raids?**: [`RaidRecord`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/raid/RaidManager/index.md#raidrecord)[]

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:117](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L117)

The village raids that were running, which carry on after a restart.

##### scriptSettings?

> `optional` **scriptSettings?**: `SavedScriptSettings`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:121](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L121)

What the scripts set on the world that nothing else keeps; see `LevelScriptSettings`.

##### spawn?

> `optional` **spawn?**: `object`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:107](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L107)

###### x

> **x**: `number`

###### y

> **y**: `number`

###### z

> **z**: `number`

##### tickingAreas?

> `optional` **tickingAreas?**: `TickingArea`[]

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:119](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L119)

The ticking areas the command and the scripts added.

##### weather?

> `optional` **weather?**: [`WeatherState`](https://jsprismarine.dev/api/@jsprismarine/engine-systems/index.md#weatherstate)

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:109](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L109)

##### worldGenSettings?

> `optional` **worldGenSettings?**: [`WorldGenSettings`](#worldgensettings)

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:113](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L113)

The seed and stems the save was generated with.

## Type Aliases

### DragonRespawnStage

> **DragonRespawnStage** = *typeof* [`DRAGON_RESPAWN_STAGES`](#dragon-respawn-stages)\[`number`\]

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:61](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L61)

One phase of the dragon respawn sequence.

***

### SavedRaid

> **SavedRaid** = [`RaidRecord`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/raid/RaidManager/index.md#raidrecord)

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:99](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L99)

One village raid as a save holds it: [RaidRecord](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/raid/RaidManager/index.md#raidrecord), which is plain data.

## Variables

### DRAGON\_RESPAWN\_STAGES

> `const` **DRAGON\_RESPAWN\_STAGES**: readonly \[`"start"`, `"preparing_to_summon_pillars"`, `"summoning_pillars"`, `"summoning_dragon"`\]

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:53](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L53)

The four phases of the dragon respawn sequence, Java's `DragonRespawnStage` short of `end`.

## Functions

### isFlatGenerator()

> **isFlatGenerator**(`generator`): `generator is FlatGeneratorDefinition`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:225](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L225)

Whether a stem's generator is `minecraft:flat` with its layers in the stem, narrowing it to
them. A flat stem that names a `flat_level_generator_preset` instead is not one: its layers
live in the pack stack, and the stem is written back as the id it was read with.

#### Parameters

##### generator

[`GeneratorDefinition`](https://jsprismarine.dev/api/@jsprismarine/worldgen/index.md#generatordefinition)

#### Returns

`generator is FlatGeneratorDefinition`

***

### isNoiseGenerator()

> **isNoiseGenerator**(`generator`): `generator is NoiseGeneratorDefinition`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:217](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L217)

Whether a stem's generator is `minecraft:noise`, narrowing it to its settings and biome
source. `GeneratorDefinition` carries an unknown-kind variant typed `type: string`, so a plain
comparison on `type` does not narrow the union by itself.

#### Parameters

##### generator

[`GeneratorDefinition`](https://jsprismarine.dev/api/@jsprismarine/worldgen/index.md#generatordefinition)

#### Returns

`generator is NoiseGeneratorDefinition`

***

### legacyWorldPersistenceDataOf()

> **legacyWorldPersistenceDataOf**(`value`): [`WorldPersistenceData`](#worldpersistencedata)

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:318](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L318)

Validates legacy file data before migrating it and removing its source file.

#### Parameters

##### value

`unknown`

#### Returns

[`WorldPersistenceData`](#worldpersistencedata)

***

### levelStemJsonOf()

> **levelStemJsonOf**(`stem`): `Record`\<`string`, `unknown`\>

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:229](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L229)

A parsed level stem as the Java `dimension` document it came from.

#### Parameters

##### stem

[`LevelStem`](https://jsprismarine.dev/api/@jsprismarine/worldgen/index.md#levelstem)

#### Returns

`Record`\<`string`, `unknown`\>

***

### parseWorldPersistenceData()

> **parseWorldPersistenceData**(`text`): [`WorldPersistenceData`](#worldpersistencedata)

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:339](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L339)

Parses world state encoded as JSON inside provider storage.

#### Parameters

##### text

`string`

#### Returns

[`WorldPersistenceData`](#worldpersistencedata)

***

### structureReferenceKey()

> **structureReferenceKey**(`start`): `string`

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:143](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L143)

The key one [StructureReference](#structurereference) is held under.

#### Parameters

##### start

[`StructureReference`](#structurereference)

#### Returns

`string`

***

### worldPersistenceDataOf()

> **worldPersistenceDataOf**(`value`): [`WorldPersistenceData`](#worldpersistencedata)

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:155](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L155)

Reads persisted world state at the JSON and NBT boundaries.

A malformed spawn, rule, weather or entity entry is dropped. A malformed stem is not: the
stems say which terrain the save holds, and starting with different ones would generate a
different world into the same chunks.

#### Parameters

##### value

`unknown`

#### Returns

[`WorldPersistenceData`](#worldpersistencedata)

#### Throws

When `worldGenSettings` is present and one of its stems does not parse.

***

### worldPersistenceJsonOf()

> **worldPersistenceJsonOf**(`data`): `Record`\<`string`, `unknown`\>

Defined in: [packages/prismarine/src/world/WorldPersistence.ts:197](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldPersistence.ts#L197)

The persisted state as the JSON object a provider stores.

Everything but the stems is already plain data. A parsed stem is not: its biome source and
flat settings carry camel-cased fields and quantized climate values, so it is written back as
the Java document `parseLevelStem` reads.

#### Parameters

##### data

[`WorldPersistenceData`](#worldpersistencedata)

#### Returns

`Record`\<`string`, `unknown`\>
