Skip to content

helix / LootFunction

Class: LootFunction

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

One loot function - a transform applied to a generated item stack. The same vocabulary is used inside loot-table entries/pools (LootTable) and as the whole body of an ItemModifier, so it is defined once here and shared.

Functions are built from typed concepts (an ItemValue's own components, not hand-written JSON) wherever a value object can supply them.

LootFunction.setCount(4) LootFunction.setComponents(Item.DIAMOND_SWORD.named("Excalibur"))

Methods

toJson()

toJson(version): Record<string, unknown>

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

The function JSON, with embedded values rendered for version.

Parameters

version

VersionProfile

Returns

Record<string, unknown>


enchantWithLevels()

static enchantWithLevels(levels, treasure?): LootFunction

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

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:61

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

Returns

LootFunction


of()

static of(fn, fields?): LootFunction

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

Escape hatch: a function by id with already-built fields, e.g. LootFunction.of("set_name", { name: "Boss Loot" }). minecraft: is added to a bare id.

Parameters

fn

string

fields?

Record<string, unknown> = {}

Returns

LootFunction


setComponents()

static setComponents(item): LootFunction

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

minecraft:set_components - apply item's data components to the stack, reusing the item's own component definitions (ItemValue.componentsJson) so a loot drop carries the exact components the same item would give. No-op JSON on pre-component versions.

Parameters

item

ItemValue

Returns

LootFunction


setCount()

static setCount(count, add?): LootFunction

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

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

Parameters

count

NumberProvider

add?

boolean = false

Returns

LootFunction

Released under the MIT License · Credits