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

helix / LootFunction

Class: LootFunction โ€‹

Defined in: core/values/loot-function.ts:34

A loot function: a transform on a generated item stack. Shared by loot tables and ItemModifiers.

LootFunction.setCount(4) LootFunction.of("set_name", { name: text("Excalibur"), target: "item_name" })

Properties โ€‹

spec โ€‹

readonly spec: LootFunctionSpec

Defined in: core/values/loot-function.ts:35

Methods โ€‹

copyCustomData() โ€‹

static copyCustomData(id, paths, op?): LootFunction

Defined in: core/values/loot-function.ts:95

minecraft:copy_custom_data from storage id: copies each [from, to] path into the stack's custom_data. The only way to write a runtime value onto a player's item.

Parameters โ€‹

id โ€‹

IdValue

paths โ€‹

[NbtPathValue, NbtPathValue][]

op? โ€‹

"merge" | "append" | "replace"

Returns โ€‹

LootFunction


enchantWithLevels() โ€‹

static enchantWithLevels(levels, treasure?): LootFunction

Defined in: core/values/loot-function.ts:103

minecraft:enchant_with_levels - enchant as if at levels (optionally treasure).

Parameters โ€‹

levels โ€‹

NumberProvider

treasure? โ€‹

boolean = false

Returns โ€‹

LootFunction


furnaceSmelt() โ€‹

static furnaceSmelt(): LootFunction

Defined in: core/values/loot-function.ts:119

minecraft:furnace_smelt - replace with the item's smelting result.

Returns โ€‹

LootFunction


of() โ€‹

static of<K>(id, ...args): LootFunction

Defined in: core/values/loot-function.ts:41

Any vanilla loot function, with its arguments typed from vanilla-mcdoc. Keys are camelCase; renamed keys and changed forms are written per version, and one the target lacks throws.

Type Parameters โ€‹

K โ€‹

K extends keyof LootFunctionArgs

Parameters โ€‹

id โ€‹

K | `minecraft:${K}`

args โ€‹

...object extends LootFunctionArgs[K] ? [LootFunctionArgs[K]?] : [LootFunctionArgs[K]]

Returns โ€‹

LootFunction


raw() โ€‹

static raw(fn, fields?): LootFunction

Defined in: core/values/loot-function.ts:51

A function by id with prebuilt JSON fields, for ones vanilla doesn't have.

Parameters โ€‹

fn โ€‹

string

fields? โ€‹

Record<string, unknown> = {}

Returns โ€‹

LootFunction


setComponents() โ€‹

static setComponents(item): LootFunction

Defined in: core/values/loot-function.ts:61

minecraft:set_components: applies item's components, the same ones give would.

Parameters โ€‹

item โ€‹

ItemLike

Returns โ€‹

LootFunction


setCount() โ€‹

static setCount(count, add?): LootFunction

Defined in: core/values/loot-function.ts:56

minecraft:set_count - set (or, with add, increment) the stack size.

Parameters โ€‹

count โ€‹

NumberProvider

add? โ€‹

boolean = false

Returns โ€‹

LootFunction


setCustomData() โ€‹

static setCustomData(tag): LootFunction

Defined in: core/values/loot-function.ts:77

minecraft:set_custom_data: merges tag into the stack's custom_data.

Parameters โ€‹

tag โ€‹

NbtInput

Returns โ€‹

LootFunction


setEnchantments() โ€‹

static setEnchantments(levels, add?): LootFunction

Defined in: core/values/loot-function.ts:69

minecraft:set_enchantments: sets each enchantment to a level; level 0 removes it. With add, levels add to the current ones.

Parameters โ€‹

levels โ€‹

[Enchantment, number][]

add? โ€‹

boolean = false

Returns โ€‹

LootFunction


setItem() โ€‹

static setItem(like): LootFunction

Defined in: core/values/loot-function.ts:111

minecraft:set_item: changes the stack's item type, keeping its count and components. Takes a bare item: the function sets only the type, so components on item would be lost.

Parameters โ€‹

like โ€‹

ItemLike

Returns โ€‹

LootFunction


setLore() โ€‹

static setLore(lines, entity?): LootFunction

Defined in: core/values/loot-function.ts:87

minecraft:set_lore: replaces the lore with lines.

Score, selector and NBT spans are filled in as entity when the function runs, so item modify can write live values into a tooltip.

Parameters โ€‹

lines โ€‹

TextLike[]

entity? โ€‹

LootEntity = "this"

Returns โ€‹

LootFunction

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