[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/script-host](https://jsprismarine.dev/api/@jsprismarine/script-host/index.md) / host/WorldScripts

# host/WorldScripts

## Classes

- [WorldScripts](https://jsprismarine.dev/api/@jsprismarine/script-host/host/WorldScripts/classes/WorldScripts.md)

## Interfaces

### JobSliceInputs

Defined in: [script-host/src/host/WorldScripts.ts:248](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L248)

How long the last tick ran, and how long a tick should take, for [jobStepsForTick](#jobstepsfortick).

#### Properties

##### lastJobSteps

> `readonly` **lastJobSteps**: `number`

Defined in: [script-host/src/host/WorldScripts.ts:254](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L254)

The steps the last tick's jobs took; see [WorldScripts.jobStepsLastTick](https://jsprismarine.dev/api/@jsprismarine/script-host/host/WorldScripts/classes/WorldScripts.md#jobstepslasttick).

##### lastTickMs

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

Defined in: [script-host/src/host/WorldScripts.ts:252](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L252)

How long the last tick took, as the input step admitted it.

##### periodMs

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

Defined in: [script-host/src/host/WorldScripts.ts:250](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L250)

The time a tick has at the current tick rate, 50 ms at 20 ticks a second.

***

### ScriptDebugTarget

Defined in: [script-host/src/host/WorldScripts.ts:233](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L233)

Where a debugger attaches to debug one pack: the world's engine and the pack's context in it.

#### Properties

##### context

> `readonly` **context**: `number`

Defined in: [script-host/src/host/WorldScripts.ts:235](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L235)

##### engine

> `readonly` **engine**: [`ScriptEngine`](https://jsprismarine.dev/api/@jsprismarine/script-host/ScriptEngine/classes/ScriptEngine.md)

Defined in: [script-host/src/host/WorldScripts.ts:234](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L234)

***

### ScriptLog

Defined in: [script-host/src/host/WorldScripts.ts:139](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L139)

Where the runtime writes the content log: what scripts print, their errors and the watchdog's.

#### Methods

##### error()

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

Defined in: [script-host/src/host/WorldScripts.ts:142](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L142)

###### Parameters

###### message

`string`

###### Returns

`void`

##### info()

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

Defined in: [script-host/src/host/WorldScripts.ts:140](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L140)

###### Parameters

###### message

`string`

###### Returns

`void`

##### warn()

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

Defined in: [script-host/src/host/WorldScripts.ts:141](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L141)

###### Parameters

###### message

`string`

###### Returns

`void`

***

### WatchdogSettings

Defined in: [script-host/src/host/WorldScripts.ts:159](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L159)

The watchdog settings, under the meaning BDS's `script-watchdog-*` properties give them.

#### Properties

##### hangSteps

> `readonly` **hangSteps**: `number`

Defined in: [script-host/src/host/WorldScripts.ts:161](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L161)

The steps one callback may take, everything it calls included.

##### memoryLimit?

> `readonly` `optional` **memoryLimit?**: `number`

Defined in: [script-host/src/host/WorldScripts.ts:165](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L165)

The bytes every pack's scripts may allocate together; unlimited when absent.

##### shutdown

> `readonly` **shutdown**: `boolean`

Defined in: [script-host/src/host/WorldScripts.ts:163](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L163)

`script-watchdog-enable-shutdown`: whether a critical exception shuts the server down.

***

### WorldScriptsOptions

Defined in: [script-host/src/host/WorldScripts.ts:186](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L186)

How a [WorldScripts](https://jsprismarine.dev/api/@jsprismarine/script-host/host/WorldScripts/classes/WorldScripts.md) is made.

#### Properties

##### addonConfig?

> `readonly` `optional` **addonConfig?**: [`AddonConfigStore`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/addonConfig/index.md#addonconfigstore)

Defined in: [script-host/src/host/WorldScripts.ts:215](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L215)

The packs' config files, which `@jsprismarine/server`'s `config` reads, writes and
follows. Without it, the module leaves `config` out.

##### admin?

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

Defined in: [script-host/src/host/WorldScripts.ts:210](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L210)

The server `@minecraft/server-admin`'s `dedicatedServer` and its functions reach. Without
it, those members do nothing.

##### betaApis?

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

Defined in: [script-host/src/host/WorldScripts.ts:196](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L196)

Whether the world turns on the Beta APIs experiment, which a pack that declares a beta
module version needs. Off when absent, as in a world created without it.

##### config

> `readonly` **config**: [`ScriptConfig`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/pack/index.md#scriptconfig)

Defined in: [script-host/src/host/WorldScripts.ts:191](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L191)

##### library

> `readonly` **library**: [`ScriptHostLibrary`](https://jsprismarine.dev/api/@jsprismarine/script-host/ScriptEngine/classes/ScriptHostLibrary.md)

Defined in: [script-host/src/host/WorldScripts.ts:187](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L187)

##### log

> `readonly` **log**: [`ScriptLog`](#scriptlog)

Defined in: [script-host/src/host/WorldScripts.ts:197](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L197)

##### members?

> `readonly` `optional` **members?**: [`JsprismarineServerMembers`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/jsprismarineMembers/index.md#jsprismarineservermembers)

Defined in: [script-host/src/host/WorldScripts.ts:205](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L205)

What `@jsprismarine/server`'s `performance`, `getPing`, `bossBars` and `playerList` reach
of the running server. Without it, the module leaves those members out, as an older server
would.

##### onPackLoaded?

> `readonly` `optional` **onPackLoaded?**: (`moduleUuid`, `target`) => `void`

Defined in: [script-host/src/host/WorldScripts.ts:229](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L229)

Called when a pack's context is ready and before any of its scripts run, with the UUID of
its script module, so a debugger that attaches here stops at the pack's first line.

###### Parameters

###### moduleUuid

`string`

###### target

[`ScriptDebugTarget`](#scriptdebugtarget)

###### Returns

`void`

##### onShutdown?

> `readonly` `optional` **onShutdown?**: (`reason`) => `void`

Defined in: [script-host/src/host/WorldScripts.ts:224](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L224)

Asked to shut the server down after a critical exception, when the watchdog says to.

###### Parameters

###### reason

[`CriticalException`](#criticalexception)

###### Returns

`void`

##### packs

> `readonly` **packs**: readonly [`ScriptPack`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/pack/index.md#scriptpack)[]

Defined in: [script-host/src/host/WorldScripts.ts:190](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L190)

The world's behavior packs with a script module, in the order the world lists them.

##### randomSeed

> `readonly` **randomSeed**: () => `bigint`

Defined in: [script-host/src/host/WorldScripts.ts:221](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L221)

Draws the seed `Math.random` starts from, once each time the packs load: at the start and
at every reload. A source that changes gives each run new numbers; one that returns the same
seed every time makes every run draw the same ones.

###### Returns

`bigint`

##### server

> `readonly` **server**: [`JsprismarineServerInfo`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/jsprismarineServer/index.md#jsprismarineserverinfo)

Defined in: [script-host/src/host/WorldScripts.ts:199](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L199)

The server the packs run on, which `@jsprismarine/server` tells them about.

##### watchdog?

> `readonly` `optional` **watchdog?**: [`WatchdogSettings`](#watchdogsettings)

Defined in: [script-host/src/host/WorldScripts.ts:222](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L222)

##### world

> `readonly` **world**: [`ScriptWorld`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#scriptworld)

Defined in: [script-host/src/host/WorldScripts.ts:188](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L188)

## Type Aliases

### CriticalException

> **CriticalException** = `"Hang"` \| `"StackOverflow"` \| `"OutOfMemory"`

Defined in: [script-host/src/host/WorldScripts.ts:146](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L146)

A critical exception the watchdog reports, by the name BDS gives its type.

***

### GameTestCommand

> **GameTestCommand** = \{ `kind`: `"run"`; `name`: `string`; \} \| \{ `kind`: `"runset"`; `tag?`: `string`; \} \| \{ `kind`: `"stopall"`; \} \| \{ `kind`: `"clearall"`; \}

Defined in: [script-host/src/host/WorldScripts.ts:132](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L132)

A `/gametest` subcommand, as BDS's command takes them.

## Variables

### DEFAULT\_HANG\_THRESHOLD

> `const` **DEFAULT\_HANG\_THRESHOLD**: `10000` = `10_000`

Defined in: [script-host/src/host/WorldScripts.ts:156](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L156)

BDS's default `script-watchdog-hang-threshold`, in milliseconds.

***

### JOB\_STEPS\_PER\_TICK

> `const` **JOB\_STEPS\_PER\_TICK**: `100` = `100`

Defined in: [script-host/src/host/WorldScripts.ts:245](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L245)

The interpreter steps the jobs of one tick may take together when the world admits no budget
of its own ([ScriptWorld.jobSteps](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#jobsteps)). A step is a fixed amount of interpreter work, so a
replay advances every job as far
([ADR 0021](https://jsprismarine.dev/adr/0021-the-script-watchdog-counts-steps.md)), and a job that
never ends leaves the rest of the tick to everything else.

***

### STEPS\_PER\_MILLISECOND

> `const` **STEPS\_PER\_MILLISECOND**: `10` = `10`

Defined in: [script-host/src/host/WorldScripts.ts:153](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L153)

The steps a callback may take for each millisecond of `script-watchdog-hang-threshold`. A step
is a fixed amount of interpreter work, so this is a default an admin changes, not a
measurement of any machine ([ADR 0021](https://jsprismarine.dev/adr/0021-the-script-watchdog-counts-steps.md)).

## Functions

### jobStepsForTick()

> **jobStepsForTick**(`__namedParameters`): `number`

Defined in: [script-host/src/host/WorldScripts.ts:268](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L268)

The steps this tick's jobs may take. BDS gives `system.runJob` jobs a time slice from its
frame-time estimates, which is what the rest of the tick leaves of its period, so an idle
server advances a job through most of each tick. Here the rest of the last tick is its time
less its jobs' steps at [STEPS\_PER\_MILLISECOND](#steps-per-millisecond), and what that leaves of the period
turns back into steps at the same ratio. The host admits the last tick's time once, at the
input step, so a replay that admits the same times advances every job as far.

Never fewer than [JOB\_STEPS\_PER\_TICK](#job-steps-per-tick), so a slow tick still advances its jobs, and never
more than a whole period's steps.

#### Parameters

##### \_\_namedParameters

[`JobSliceInputs`](#jobsliceinputs)

#### Returns

`number`

***

### watchdogSettings()

> **watchdogSettings**(`properties`): [`WatchdogSettings`](#watchdogsettings)

Defined in: [script-host/src/host/WorldScripts.ts:172](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/WorldScripts.ts#L172)

Reads the watchdog settings from BDS's property names and values.

#### Parameters

##### properties

`Readonly`\<`Record`\<`string`, `string` \| `undefined`\>\>

The `script-watchdog-*` properties, as `server.properties` writes them.

#### Returns

[`WatchdogSettings`](#watchdogsettings)
