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

# Class: ScriptComponentBridge

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

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptComponents.ts#L176)

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

#### Parameters

##### identifier

`string`

##### type

[`ScriptComponentType`](https://jsprismarine.dev/api/@jsprismarine/prismarine/scripting/scriptComponents/index.md#scriptcomponenttype)

#### Returns

`void`

***

### bind()

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

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

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

#### Parameters

##### sink

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

##### level?

[`BoundScriptLevel`](https://jsprismarine.dev/api/@jsprismarine/prismarine/scripting/scriptComponents/index.md#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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptComponents.ts#L185)

Raises a block hook in a level's scripts.

#### Parameters

##### event

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

##### level?

`string`

The level the block is in, as its [HookBlock](https://jsprismarine.dev/api/@jsprismarine/blocks/index.md#hookblock) names it.

#### Returns

`boolean`

Whether a script canceled it.

***

### blockWrites()

> **blockWrites**(`dimension`, `level?`): [`BlockWriteListener`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/World/index.md#blockwritelistener)

Defined in: [packages/prismarine/src/scripting/scriptComponents.ts:221](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptComponents.ts#L221)

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`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/World/index.md#blockwritelistener)

***

### handlesBlock()

> **handlesBlock**(`uses`, `hook`, `level?`): `boolean`

Defined in: [packages/prismarine/src/scripting/scriptComponents.ts:202](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptComponents.ts#L202)

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

#### Parameters

##### uses

readonly [`ScriptComponentUse`](https://jsprismarine.dev/api/@jsprismarine/script-host/host/world/index.md#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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptComponents.ts#L192)

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

#### Parameters

##### event

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

#### Returns

`void`

***

### scheduleTick()

> **scheduleTick**(`block`, `tick`, `level?`): `void`

Defined in: [packages/prismarine/src/scripting/scriptComponents.ts:211](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/scripting/scriptComponents.ts#L211)

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

#### Parameters

##### block

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

##### tick

[`TickInterval`](https://jsprismarine.dev/api/@jsprismarine/prismarine/scripting/scriptComponents/index.md#tickinterval)

##### level?

`string`

#### Returns

`void`
