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

# scripting/LevelScriptWorld

## Classes

- [LevelScriptWorld](https://jsprismarine.dev/api/@jsprismarine/prismarine/scripting/LevelScriptWorld/classes/LevelScriptWorld.md)

## Interfaces

### ScriptWorldPlayer

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:141](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L141)

A player of the level, as the scripts reach one.

#### Properties

##### id

> `readonly` **id**: `string`

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

The player's entity id, as the Script API writes it.

##### name?

> `readonly` `optional` **name?**: `string`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:145](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L145)

The player's name.

##### screens?

> `readonly` `optional` **screens?**: `Pick`\<[`DataDrivenScreens`](https://jsprismarine.dev/api/@jsprismarine/prismarine/scripting/DataDrivenScreens/index.md#datadrivenscreens), `"close"` \| `"show"` \| `"update"`\>

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:156](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L156)

The player's data-driven `@minecraft/server-ui` screens, as `DataDrivenScreens` sends them.
A player without them is shown none, and `show()` settles as `UserBusy`.

##### spawned?

> `readonly` `optional` **spawned?**: `boolean`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:166](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L166)

Whether the player's entity is in the level yet. A player who joined is told to the scripts at
once, and their first `playerSpawn` waits for this, since a script reads the player through
the entity. A player without it counts as spawned.

#### Methods

##### closeForms()?

> `optional` **closeForms**(): `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:151](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L151)

Closes every form the player has open, as a `ClientboundCloseFormPacket`.

###### Returns

`void`

##### drawDebugShapes()?

> `optional` **drawDebugShapes**(`changes`): `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:160](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L160)

Draws, redraws or removes debug shapes, as a `PrimitiveShapesPacket`. A player without it sees none.

###### Parameters

###### changes

readonly [`ScriptDebugShapeChange`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptdebugshapechange)[]

###### Returns

`void`

##### sendMessage()

> **sendMessage**(`message`): `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:147](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L147)

Puts a line of chat on the player's screen.

###### Parameters

###### message

`string`

###### Returns

`void`

##### showForm()?

> `optional` **showForm**(`formId`, `json`): `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:149](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L149)

Sends the player a form, as a `ModalFormRequestPacket`. A player without it is sent none.

###### Parameters

###### formId

`number`

###### json

`string`

###### Returns

`void`

##### transfer()?

> `optional` **transfer**(`target`): `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:158](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L158)

Sends the player to another server, as a `TransferPacket`. A player without it stays.

###### Parameters

###### target

[`ScriptTransferTarget`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scripttransfertarget)

###### Returns

`void`

***

### ScriptWorldSources

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:170](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L170)

What [LevelScriptWorld](https://jsprismarine.dev/api/@jsprismarine/prismarine/scripting/LevelScriptWorld/classes/LevelScriptWorld.md) reads of its level.

#### Properties

##### access?

> `readonly` `optional` **access?**: [`ScriptLevelAccess`](#scriptlevelaccess)

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:198](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L198)

The level's entities, blocks, items and commands. [NO\_LEVEL\_ACCESS](#no-level-access) when absent.

##### chat

> `readonly` **chat**: `Pick`\<[`ChatManager`](https://jsprismarine.dev/api/@jsprismarine/prismarine/chat/ChatManager/classes/ChatManager.md), `"addGuard"`\> & `Partial`\<`Pick`\<[`ChatManager`](https://jsprismarine.dev/api/@jsprismarine/prismarine/chat/ChatManager/classes/ChatManager.md), `"onSent"`\>\>

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:188](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L188)

The server's chat, whose guard stage a player's line goes past, and which tells who
listens of each line that went out.

##### entitySystems?

> `readonly` `optional` **entitySystems?**: [`ScriptEntitySystems`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/entities/world/index.md#scriptentitysystems)

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:209](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L209)

The level's entity and player systems, which the entity members reach.

##### http?

> `readonly` `optional` **http?**: [`ScriptHttpChannel`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scripthttpchannel)

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:207](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L207)

The channel the scripts' HTTP requests travel over. Without one, each request fails.

##### packDirectories?

> `readonly` `optional` **packDirectories?**: readonly `string`[]

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:203](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L203)

The level's behavior packs, whose `structures/` the structure manager reads. The level has
no pack structures when absent.

##### playerActions?

> `readonly` `optional` **playerActions?**: [`ScriptPlayerActions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/scripting/scriptPlayerActions/index.md#scriptplayeractions)

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:232](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L232)

The item use and block breaking of the level's players. Without them, the scripts see neither.

##### warn?

> `readonly` `optional` **warn?**: (`message`) => `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:205](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L205)

Where the level reports a pack file it cannot read, such as a broken structure.

###### Parameters

###### message

`string`

###### Returns

`void`

##### weather

> `readonly` **weather**: [`WorldWeather`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/Weather/classes/WorldWeather.md)

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:183](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L183)

The level's weather.

##### worldEvents?

> `readonly` `optional` **worldEvents?**: [`ScriptWorldEvents`](https://jsprismarine.dev/api/@jsprismarine/prismarine/scripting/events/worldEvents/index.md#scriptworldevents)

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:234](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L234)

The other world events of the level, which `scripting/events` raises. Without them, the scripts see none.

#### Methods

##### clock()

> **clock**(): `number`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:190](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L190)

The wall clock the input step admitted for the current tick, in milliseconds since the epoch.

###### Returns

`number`

##### commands()?

> `optional` **commands**(`commands`): () => `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:219](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L219)

Puts the scripts' custom commands into the server's command tree.

###### Parameters

###### commands

[`ScriptCommandSet`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptcommandset)

###### Returns

A function that takes them out.

() => `void`

##### components()?

> `optional` **components**(`sink`): () => `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:224](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L224)

Sends the custom component hooks of the level's blocks and items to `sink`.

###### Parameters

###### sink

[`ScriptComponentSink`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptcomponentsink)

###### Returns

A function that stops it.

() => `void`

##### dimensions()

> **dimensions**(): readonly `string`[]

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:172](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L172)

The level's dimensions, as Bedrock names them, in stem order.

###### Returns

readonly `string`[]

##### entityEvents()?

> `optional` **entityEvents**(`listener`): () => `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:230](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L230)

Calls `listener` with each entity that appears in the level, each blow that lands and each
death, once the world has kept it.

###### Parameters

###### listener

(`event`) => `void`

###### Returns

A function that stops it.

() => `void`

##### jobSlice()?

> `optional` **jobSlice**(): `object`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:196](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L196)

How long a tick should take and how long the last one took, as the input step admitted
them, which size the time the scripts' jobs get this tick. Without it, jobs get a fixed
number of steps.

###### Returns

`object`

###### lastTickMs

> `readonly` **lastTickMs**: `number`

###### periodMs

> `readonly` **periodMs**: `number`

##### onPlayerLeaving()?

> `optional` **onPlayerLeaving**(`listener`): () => `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:214](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L214)

Calls `listener` with a player's id as they leave, before their entity goes.

###### Parameters

###### listener

(`player`) => `void`

###### Returns

A function that stops it.

() => `void`

##### players()

> **players**(): readonly [`ScriptWorldPlayer`](#scriptworldplayer)[]

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:181](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L181)

The players in the level, in the order they joined.

###### Returns

readonly [`ScriptWorldPlayer`](#scriptworldplayer)[]

##### registerCustomDimension()?

> `optional` **registerCustomDimension**(`typeId`): `"registered"` \| `"new-after-reload"`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:177](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L177)

Adds a void dimension a script registered in `startup`; see
[ScriptWorld.registerCustomDimension](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#registercustomdimension). Left out, the level takes no new dimension.

###### Parameters

###### typeId

`string`

###### Returns

`"registered"` \| `"new-after-reload"`

##### settleCustomDimensions()?

> `optional` **settleCustomDimensions**(`registered`): `void`

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:179](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L179)

Ends a run's registrations; see [ScriptWorld.settleCustomDimensions](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#settlecustomdimensions).

###### Parameters

###### registered

readonly `string`[]

###### Returns

`void`

## Type Aliases

### ScriptLevelAccess

> **ScriptLevelAccess** = `Pick`\<[`ScriptWorld`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptworld), `"entity"` \| `"entities"` \| `"spawnEntity"` \| `"teleport"` \| `"kill"` \| `"remove"` \| `"setNameTag"` \| `"addTag"` \| `"removeTag"` \| `"inventory"` \| `"setInventoryItem"` \| `"heightRange"` \| `"block"` \| `"setBlock"` \| `"resolveBlock"` \| `"itemType"` \| `"runCommand"` \| `"selectEntities"` \| `"simulatedPlayers"` \| `"placeStructure"` \| `"setGameMode"` \| `"setSelectedSlot"` \| `"applyDamage"` \| `"setSneaking"` \| `"showTitle"` \| `"playSound"` \| `"spawnParticle"` \| `"isEffectType"` \| `"effects"` \| `"addEffect"` \| `"removeEffect"` \| `"blockInventory"` \| `"setBlockInventoryItem"` \| `"equipment"` \| `"setEquipment"` \| `"attribute"` \| `"setAttribute"` \| `"effectTypes"` \| `"dimensionTypes"` \| `"dynamicProperties"` \| `"setDynamicProperties"` \| `"clearDynamicProperties"` \| `"scoreboard"` \| `"catalog"` \| `"blockLight"` \| `"waterlogged"` \| `"setWaterlogged"` \| `"worldSystem"`\>

Defined in: [packages/prismarine/src/scripting/LevelScriptWorld.ts:55](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/LevelScriptWorld.ts#L55)

What the scripts read and write of a level's entities, blocks, items and commands.

## Variables

### NO\_LEVEL\_ACCESS

> `const` **NO\_LEVEL\_ACCESS**: [`ScriptLevelAccess`](#scriptlevelaccess)

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

A level the scripts reach nothing of: no entities, no loaded blocks, no types and no commands.
