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

helix / HeldData

Class: HeldData<T> โ€‹

Defined in: core/frontend/nodes/data-view/held.ts:33

An item in an entity's or container block's slot, with its custom_data typed by T. From ItemData(...).in(who, slot). Reading the data (view, edit, component) needs a player's equipment slot or a block's container.<n>; write works on any slot.

const bow = Crossbow.in(Selector.self(), Slot.MAINHAND); ctx.if(bow.is({ pick: 1 }), () => ...); bow.switch("pick", [0, 1, 2], (k) => ...); bow.edit((data) => data.mag.slot(7).take(1));

Extends โ€‹

Type Parameters โ€‹

T โ€‹

T extends object

Constructors โ€‹

Constructor โ€‹

new HeldData<T>(schema, who, slot): HeldData<T>

Defined in: core/frontend/nodes/data-view/held.ts:34

Parameters โ€‹

schema โ€‹

ItemDataSchema<T>

who โ€‹

PosValue | Selector

slot โ€‹

SlotRange

Returns โ€‹

HeldData<T>

Overrides โ€‹

ItemSlotRef.constructor

Properties โ€‹

on โ€‹

readonly on: PosValue | Selector

Defined in: core/frontend/nodes/item-slot.ts:28

Inherited from โ€‹

ItemSlotRef.on


schema โ€‹

readonly schema: ItemDataSchema<T>

Defined in: core/frontend/nodes/data-view/held.ts:35


slot โ€‹

readonly slot: SlotRange

Defined in: core/frontend/nodes/item-slot.ts:29

Inherited from โ€‹

ItemSlotRef.slot


who โ€‹

readonly who: PosValue | Selector

Defined in: core/frontend/nodes/data-view/held.ts:36

Methods โ€‹

apply() โ€‹

apply(...fns): this

Defined in: core/frontend/nodes/item-slot.ts:54

Runs these loot functions on the item, in order.

Parameters โ€‹

fns โ€‹

...LootFunction[]

Returns โ€‹

this

Inherited from โ€‹

ItemSlotRef.apply


component() โ€‹

component(type): NbtView

Defined in: core/frontend/nodes/data-view/held.ts:69

The item's type component, read from the player's NBT.

Parameters โ€‹

type โ€‹

DataComponentType

Returns โ€‹

NbtView


edit() โ€‹

edit(body): void

Defined in: core/frontend/nodes/data-view/held.ts:89

Reads the item's data, runs body on it, then writes back every key body touched. A key removed whole isn't removed from the item.

Parameters โ€‹

body โ€‹

(data) => void

Returns โ€‹

void


enchant() โ€‹

enchant(enchantment, level?): this

Defined in: core/frontend/nodes/item-slot.ts:75

Sets enchantment to level on the item; 0 removes it.

Parameters โ€‹

enchantment โ€‹

Enchantment

level? โ€‹

number = 1

Returns โ€‹

this

Inherited from โ€‹

ItemSlotRef.enchant


has() โ€‹

has(item): Detector

Defined in: core/frontend/nodes/item-slot.ts:33

Holds when the slot has item.

Parameters โ€‹

item โ€‹

ItemLike

Returns โ€‹

Detector

Inherited from โ€‹

ItemSlotRef.has


is() โ€‹

is(match): Detector

Defined in: core/frontend/nodes/data-view/held.ts:43

Holds when the item is the schema's item and its data holds match.

Parameters โ€‹

match โ€‹

DataMatch<T>

Returns โ€‹

Detector


lacks() โ€‹

lacks(item): Detector

Defined in: core/frontend/nodes/item-slot.ts:39

Holds when the slot doesn't have item.

Parameters โ€‹

item โ€‹

ItemLike

Returns โ€‹

Detector

Inherited from โ€‹

ItemSlotRef.lacks


modify() โ€‹

modify(modifier, ctx?): this

Defined in: core/frontend/nodes/item-slot.ts:45

Runs modifier on the item. An unregistered ItemModifier is written into the command.

Parameters โ€‹

modifier โ€‹

ItemModifier | ItemModifierRef

ctx? โ€‹

FunctionContext

Returns โ€‹

this

Inherited from โ€‹

ItemSlotRef.modify


replace() โ€‹

replace(source, ctx?): this

Defined in: core/frontend/nodes/item-slot.ts:61

Puts source in the slot: an item, or a copy of what another slot holds.

Parameters โ€‹

source โ€‹

ItemLike | ItemSlotRef

ctx? โ€‹

FunctionContext

Returns โ€‹

this

Inherited from โ€‹

ItemSlotRef.replace


set() โ€‹

set(data): this

Defined in: core/frontend/nodes/data-view/held.ts:64

Merges data into the item's custom_data.

Parameters โ€‹

data โ€‹

Partial<T>

Returns โ€‹

this


show() โ€‹

show(to, type?): void

Defined in: core/frontend/nodes/data-view/held.ts:75

Prints the item's type component, custom_data by default, in to's chat, for debugging.

Parameters โ€‹

to โ€‹

Selector

type? โ€‹

DataComponentType = DataComponentType.CUSTOM_DATA

Returns โ€‹

void


switch() โ€‹

switch<K>(key, values, body): void

Defined in: core/frontend/nodes/data-view/held.ts:51

Runs body for the value of key the item holds, out of values. The first value also runs for an item without key, since an item check can't see a missing key.

Type Parameters โ€‹

K โ€‹

K extends string

Parameters โ€‹

key โ€‹

K

values โ€‹

readonly NonNullable<T[K]>[]

body โ€‹

(value, ctx) => void

Returns โ€‹

void


view() โ€‹

view(body): void

Defined in: core/frontend/nodes/data-view/held.ts:80

Reads the item's data for body, without writing it back.

Parameters โ€‹

body โ€‹

(data) => void

Returns โ€‹

void


write() โ€‹

write(body): void

Defined in: core/frontend/nodes/data-view/held.ts:98

Like edit, but starts from empty data instead of the item's: for keys body fills in whole. Works on any slot.

Parameters โ€‹

body โ€‹

(data) => void

Returns โ€‹

void

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