Skip to content

API reference / @jsprismarine/script-host / host/WorldScripts

host/WorldScripts ​

Classes ​

Interfaces ​

JobSliceInputs ​

Defined in: script-host/src/host/WorldScripts.ts:240

How long the last tick ran, and how long a tick should take, for jobStepsForTick.

Properties ​

lastJobSteps ​

readonly lastJobSteps: number

Defined in: script-host/src/host/WorldScripts.ts:246

The steps the last tick's jobs took; see WorldScripts.jobStepsLastTick.

lastTickMs ​

readonly lastTickMs: number

Defined in: script-host/src/host/WorldScripts.ts:244

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

periodMs ​

readonly periodMs: number

Defined in: script-host/src/host/WorldScripts.ts:242

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:225

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:227

engine ​

readonly engine: ScriptEngine

Defined in: script-host/src/host/WorldScripts.ts:226


ScriptLog ​

Defined in: script-host/src/host/WorldScripts.ts:135

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:138

Parameters ​
message ​

string

Returns ​

void

info() ​

info(message): void

Defined in: script-host/src/host/WorldScripts.ts:136

Parameters ​
message ​

string

Returns ​

void

warn() ​

warn(message): void

Defined in: script-host/src/host/WorldScripts.ts:137

Parameters ​
message ​

string

Returns ​

void


WatchdogSettings ​

Defined in: script-host/src/host/WorldScripts.ts:155

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:157

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

memoryLimit? ​

readonly optional memoryLimit?: number

Defined in: script-host/src/host/WorldScripts.ts:161

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

shutdown ​

readonly shutdown: boolean

Defined in: script-host/src/host/WorldScripts.ts:159

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


WorldScriptsOptions ​

Defined in: script-host/src/host/WorldScripts.ts:182

How a WorldScripts is made.

Properties ​

addonConfig? ​

readonly optional addonConfig?: AddonConfigStore

Defined in: script-host/src/host/WorldScripts.ts:211

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

Defined in: script-host/src/host/WorldScripts.ts:206

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:192

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

Defined in: script-host/src/host/WorldScripts.ts:187

library ​

readonly library: ScriptHostLibrary

Defined in: script-host/src/host/WorldScripts.ts:183

log ​

readonly log: ScriptLog

Defined in: script-host/src/host/WorldScripts.ts:193

members? ​

readonly optional members?: JsprismarineServerMembers

Defined in: script-host/src/host/WorldScripts.ts:201

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:221

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

Returns ​

void

onShutdown? ​

readonly optional onShutdown?: (reason) => void

Defined in: script-host/src/host/WorldScripts.ts:216

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

Parameters ​
reason ​

CriticalException

Returns ​

void

packs ​

readonly packs: readonly ScriptPack[]

Defined in: script-host/src/host/WorldScripts.ts:186

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

seed ​

readonly seed: bigint

Defined in: script-host/src/host/WorldScripts.ts:213

The world's seed, which Math.random is seeded from.

server ​

readonly server: JsprismarineServerInfo

Defined in: script-host/src/host/WorldScripts.ts:195

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

watchdog? ​

readonly optional watchdog?: WatchdogSettings

Defined in: script-host/src/host/WorldScripts.ts:214

world ​

readonly world: ScriptWorld

Defined in: script-host/src/host/WorldScripts.ts:184

Type Aliases ​

CriticalException ​

CriticalException = "Hang" | "StackOverflow" | "OutOfMemory"

Defined in: script-host/src/host/WorldScripts.ts:142

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:128

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:152

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:237

The interpreter steps the jobs of one tick may take together when the world admits no budget of its own (ScriptWorld.jobSteps). A step is a fixed amount of interpreter work, so a replay advances every job as far (ADR 0021), 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:149

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).

Functions ​

jobStepsForTick() ​

jobStepsForTick(__namedParameters): number

Defined in: script-host/src/host/WorldScripts.ts:260

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, 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, so a slow tick still advances its jobs, and never more than a whole period's steps.

Parameters ​

__namedParameters ​

JobSliceInputs

Returns ​

number


watchdogSettings() ​

watchdogSettings(properties): WatchdogSettings

Defined in: script-host/src/host/WorldScripts.ts:168

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