Appearance
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 โ
who โ
slot โ
Returns โ
HeldData<T>
Overrides โ
Properties โ
on โ
Defined in: core/frontend/nodes/item-slot.ts:28
Inherited from โ
schema โ
readonlyschema:ItemDataSchema<T>
Defined in: core/frontend/nodes/data-view/held.ts:35
slot โ
readonlyslot:SlotRange
Defined in: core/frontend/nodes/item-slot.ts:29
Inherited from โ
who โ
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 โ
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 โ
Returns โ
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 โ
level? โ
number = 1
Returns โ
this
Inherited from โ
has() โ
has(
item):Detector
Defined in: core/frontend/nodes/item-slot.ts:33
Holds when the slot has item.
Parameters โ
item โ
Returns โ
Inherited from โ
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 โ
lacks() โ
lacks(
item):Detector
Defined in: core/frontend/nodes/item-slot.ts:39
Holds when the slot doesn't have item.
Parameters โ
item โ
Returns โ
Inherited from โ
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? โ
Returns โ
this
Inherited from โ
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 โ
ctx? โ
Returns โ
this
Inherited from โ
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 โ
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