Skip to content

API reference / @jsprismarine/prismarine / BlockStateSchema

Class: BlockStateSchema ​

Defined in: prismarine/src/block/state/BlockStateSchema.ts:26

Which properties a block has and which values each accepts.

This is what makes blocks modular. A runtime id is a hash of a block's own name and state, so a block is fully described by its schema alone - a plugin registering myplugin:cool_block needs to agree with nobody, and cannot shift the ids of anyone else's blocks. The vanilla catalog below is just the schemas that ship by default.

Constructors ​

Constructor ​

new BlockStateSchema(name, properties?): BlockStateSchema

Defined in: prismarine/src/block/state/BlockStateSchema.ts:43

Parameters ​

name ​

string

properties? ​

Record<string, BlockStateProperty> = {}

Returns ​

BlockStateSchema

Properties ​

name ​

readonly name: string

Defined in: prismarine/src/block/state/BlockStateSchema.ts:27


properties ​

readonly properties: Readonly<Record<string, BlockStateProperty>>

Defined in: prismarine/src/block/state/BlockStateSchema.ts:28

Methods ​

createState() ​

createState(properties?): BlockState

Defined in: prismarine/src/block/state/BlockStateSchema.ts:83

Builds a state from partial properties, filling the rest with defaults.

Parameters ​

properties? ​

Record<string, BlockStateValue> = {}

Returns ​

BlockState

Throws ​

if a property is unknown to this block or its value is not accepted - a silent fallback would surface much later as a block the client cannot resolve.


getAllStates() ​

getAllStates(): BlockState[]

Defined in: prismarine/src/block/state/BlockStateSchema.ts:104

Every state this block can be in - the cartesian product of its properties.

Returns ​

BlockState[]


getDefaultState() ​

getDefaultState(): BlockState

Defined in: prismarine/src/block/state/BlockStateSchema.ts:69

The state a freshly placed block starts in.

The same frozen instance every time. Reading a position no sub chunk covers answers with air's default state, so an idle world's random tick pass called this tens of thousands of times a tick and spent most of the tick in the constructor.

Returns ​

BlockState


getPropertyTypes() ​

getPropertyTypes(): Record<string, BlockStatePropertyType>

Defined in: prismarine/src/block/state/BlockStateSchema.ts:54

The NBT type of every property, in the shape BlockState.toNBT wants.

The same object every time. Reading and writing a sub chunk asks once per palette entry, and rebuilding the record meant two intermediate arrays and an object per ask.

Returns ​

Record<string, BlockStatePropertyType>