Skip to content

API reference / @jsprismarine/prismarine / scripting/scriptComponents / ScriptComponentBridge

Class: ScriptComponentBridge ​

Defined in: packages/prismarine/src/scripting/scriptComponents.ts:143

Where the content's adapter behaviors send hooks, and where each level's scripts bind their sink once they have registered their components. The content is the server's, so one bridge serves every level: a block hook goes to the level its block names, and an item hook to the level of the entity that used the item. Until a level's scripts bind, and with no script host, that level's hooks are dropped at the cost of one check.

Constructors ​

Constructor ​

new ScriptComponentBridge(): ScriptComponentBridge

Returns ​

ScriptComponentBridge

Methods ​

addBlock() ​

addBlock(identifier, type): void

Defined in: packages/prismarine/src/scripting/scriptComponents.ts:176

Records a block type that names custom components, which the block writes are checked against.

Parameters ​

identifier ​

string

type ​

ScriptComponentType

Returns ​

void


bind() ​

bind(sink, level?): () => void

Defined in: packages/prismarine/src/scripting/scriptComponents.ts:155

Sends a level's hooks to sink from now on.

Parameters ​

sink ​

ScriptComponentSink

level? ​

BoundScriptLevel = ONLY_LEVEL

The level the scripts run in; left out, the one level of a single-level server.

Returns ​

A function that stops it.

() => void


block() ​

block(event, level?): boolean

Defined in: packages/prismarine/src/scripting/scriptComponents.ts:185

Raises a block hook in a level's scripts.

Parameters ​

event ​

ScriptBlockHookEvent

level? ​

string

The level the block is in, as its HookBlock names it.

Returns ​

boolean

Whether a script canceled it.


blockWrites() ​

blockWrites(dimension, level?): BlockWriteListener

Defined in: packages/prismarine/src/scripting/scriptComponents.ts:221

The listener for one world's block writes: onBreak for a block that names custom components and is gone, then onPlace for one that arrives, which also starts its ticks.

Parameters ​

dimension ​

string

The world's dimension, as the scripts name it.

level? ​

string

The world's level; left out, the default level.

Returns ​

BlockWriteListener


handlesBlock() ​

handlesBlock(uses, hook, level?): boolean

Defined in: packages/prismarine/src/scripting/scriptComponents.ts:202

Whether a level's scripts registered one of the components with the hook.

Parameters ​

uses ​

readonly ScriptComponentUse[]

hook ​

"onPlace" | "onBreak" | "onRandomTick" | "onTick" | "onPlayerInteract" | "onStepOn" | "onEntityFallOn" | "onEntity" | "onRedstoneUpdate" | "onBlockStateChange" | "beforeOnPlayerPlace" | "onPlayerBreak"

level? ​

string

Returns ​

boolean


item() ​

item(event): void

Defined in: packages/prismarine/src/scripting/scriptComponents.ts:192

Raises an item hook in the scripts of the level of the entity that used the item.

Parameters ​

event ​

ScriptItemHookEvent

Returns ​

void


scheduleTick() ​

scheduleTick(block, tick, level?): void

Defined in: packages/prismarine/src/scripting/scriptComponents.ts:211

Schedules the next tick of a block with minecraft:tick in a level, somewhere in its interval.

Parameters ​

block ​

ScriptBlockLocation

tick ​

TickInterval

level? ​

string

Returns ​

void