API reference / @jsprismarine/blocks / BlockStateModel
Class: BlockStateModel
Defined in: packages/blocks/src/state.ts:33
The states one block carries and the dense index of each combination.
The canonical order is the states sorted by name, which is the order the block's NBT compound is written in before it is hashed into a runtime id, so an index here and the wire agree on which state is which. Within that order the first state is the most significant digit of a mixed-radix number, so incrementing an index walks the last state's values first.
Constructors
Constructor
new BlockStateModel(
states):BlockStateModel
Defined in: packages/blocks/src/state.ts:48
Parameters
states
Iterable<BlockStateDefinition>
The states in any order; the model sorts them by name.
Returns
BlockStateModel
Throws
When two states share a name, or a state has no values.
Properties
defaultIndex
readonlydefaultIndex:number
Defined in: packages/blocks/src/state.ts:39
The index of the combination made of every state's default value.
size
readonlysize:number
Defined in: packages/blocks/src/state.ts:37
How many combinations the states produce; 1 for a block with no state.
states
readonlystates: readonlyBlockStateDefinition[]
Defined in: packages/blocks/src/state.ts:35
The states in canonical order: sorted by name.
Methods
decode()
decode(
index):Readonly<Record<string,BlockStateValue>>
Defined in: packages/blocks/src/state.ts:114
The combination one dense index stands for.
Parameters
index
number
Returns
Readonly<Record<string, BlockStateValue>>
Throws
When the index is not in [0, size).
encode()
encode(
values):number
Defined in: packages/blocks/src/state.ts:87
The dense index of one combination.
Parameters
values
Readonly<Record<string, BlockStateValue>>
Every state's value; a missing state takes its default.
Returns
number
Throws
When a name is not one of the block's states, or a value is outside the state's domain.
names()
names(): readonly
string[]
Defined in: packages/blocks/src/state.ts:128
The state names in canonical order.
Returns
readonly string[]
state()
state(
name):BlockStateDefinition|undefined
Defined in: packages/blocks/src/state.ts:133
One state by name, or undefined when the block does not carry it.
Parameters
name
string
Returns
BlockStateDefinition | undefined