Alpha: this compiler is under active development and updates will break your projects. Not recommended for real use yet.
Skip to content

helix / ItemDataSchema

Class: ItemDataSchema<T> โ€‹

Defined in: core/values/item-data.ts:32

An item's custom_data, typed by T, so a wrong key or value fails to compile.

const Bow = ItemData<{ pick?: number }>(Item.CROSSBOW); Bow.is({ pick: 1 }) // item predicate Bow.set({ pick: 1 }) // loot function for an item modifier Bow.on(Path.Player.held(Slot.MAINHAND), "pick") // path on a holder Bow.model({ pick: 1 }, picked) // item-model condition Bow.switchModel("pick", [0, 1, 2], (k) => ...) // a model per value Bow.in(Selector.self(), Slot.MAINHAND) // the held item, to check and edit

Type Parameters โ€‹

T โ€‹

T extends object

Constructors โ€‹

Constructor โ€‹

new ItemDataSchema<T>(item): ItemDataSchema<T>

Defined in: core/values/item-data.ts:33

Parameters โ€‹

item โ€‹

ItemValue

Returns โ€‹

ItemDataSchema<T>

Properties โ€‹

item โ€‹

readonly item: ItemValue

Defined in: core/values/item-data.ts:33

Methods โ€‹

in() โ€‹

in(who, slot): HeldData<T>

Defined in: core/values/item-data.ts:56

The item in who's slot, or a container block's, to check and edit. See HeldData.

Parameters โ€‹

who โ€‹

PosValue | Selector

slot โ€‹

SlotRange

Returns โ€‹

HeldData<T>


is() โ€‹

is(match): ItemValue

Defined in: core/values/item-data.ts:36

The item, when its custom_data holds match. A copy, so the base item is left as it was.

Parameters โ€‹

match โ€‹

DataMatch<T>

Returns โ€‹

ItemValue


key() โ€‹

key(key): NbtPathValue

Defined in: core/values/item-data.ts:46

key inside custom_data, as for storage that copy_custom_data reads from.

Parameters โ€‹

key โ€‹

keyof T & string

Returns โ€‹

NbtPathValue


model() โ€‹

model(match, onTrue, onFalse?): ItemModel

Defined in: core/values/item-data.ts:61

Draws onTrue when the stack's custom_data holds match, onFalse otherwise.

Parameters โ€‹

match โ€‹

DataMatch<T>

onTrue โ€‹

ItemModel

onFalse? โ€‹

ItemModel = ...

Returns โ€‹

ItemModel


on() โ€‹

on(item, key): NbtPathValue

Defined in: core/values/item-data.ts:51

key in the custom_data of the item at item, e.g. Path.Player.held(Slot.OFFHAND).

Parameters โ€‹

item โ€‹

NbtPathValue

key โ€‹

keyof T & string

Returns โ€‹

NbtPathValue


set() โ€‹

set(data): LootFunction

Defined in: core/values/item-data.ts:41

Merges data into the stack's custom_data.

Parameters โ€‹

data โ€‹

Partial<T>

Returns โ€‹

LootFunction


switchModel() โ€‹

switchModel<K>(key, values, model): ItemModel

Defined in: core/values/item-data.ts:72

Draws model(value) for the value of key the stack holds, out of values. The first value also draws for a stack without key, since a model condition can't see a missing key.

Type Parameters โ€‹

K โ€‹

K extends string

Parameters โ€‹

key โ€‹

K

values โ€‹

readonly NonNullable<T[K]>[]

model โ€‹

(value) => ItemModel

Returns โ€‹

ItemModel

Released under the MIT License ยท Credits
These docs were written with AI; the layout and every page have been reviewed by a human.