Skip to content

helix / ItemModel

Class: ItemModel

Defined in: core/values/item-model.ts:248

The client item model - the tagged union under an item definition's model field (assets/<ns>/items/<name>.json), selecting how a stack renders. Mirrors the full vanilla schema (misode's assets/item/ generator): a flat ItemModel.model, or one of the branching arms (composite / condition / select / range_dispatch), the terminals (empty / bundle/selected_item), or a special block-entity model. Every arm has a .raw() sibling escape hatch; registered via dp.itemDefinition(name, model) (or emitted by dp.model for the flat case). All model-resource fields accept a ModelRef or a <ns>:path.

ItemModel.rangeDispatch("minecraft:damage", [ { threshold: 0, model: ItemModel.model("ns:item/sword") }, { threshold: 0.5, model: ItemModel.model("ns:item/sword_cracked") }, ])

Methods

toJson()

toJson(): Record<string, unknown>

Defined in: core/values/item-model.ts:345

Returns

Record<string, unknown>


bundleSelectedItem()

static bundleSelectedItem(): ItemModel

Defined in: core/values/item-model.ts:331

Render the bundle's currently-selected item.

Returns

ItemModel


composite()

static composite(models): ItemModel

Defined in: core/values/item-model.ts:264

Render every sub-model on top of one another.

Parameters

models

ItemModel[]

Returns

ItemModel


condition()

static condition(property, onTrue, onFalse, opts?): ItemModel

Defined in: core/values/item-model.ts:273

Boolean branch on property (see CONDITION_PROPERTIES); opts carries that property's extra fields (e.g. { component } for has_component, { keybind } for keybind_down, { index } for custom_model_data).

Parameters

property

string

onTrue

ItemModel

onFalse

ItemModel

opts?

Record<string, unknown> = {}

Returns

ItemModel


empty()

static empty(): ItemModel

Defined in: core/values/item-model.ts:326

Render nothing.

Returns

ItemModel


model()

static model(ref, tints?): ItemModel

Defined in: core/values/item-model.ts:256

Flat sprite/model with optional per-layer tints - the common case.

Parameters

ref

ModelResource

tints?

TintSource[]

Returns

ItemModel


rangeDispatch()

static rangeDispatch(property, entries, opts?): ItemModel

Defined in: core/values/item-model.ts:310

Numeric threshold dispatch on property (see RANGE_DISPATCH_PROPERTIES). opts.scale multiplies the raw value; opts.fallback renders below the lowest threshold; any other key is a property-specific field.

Parameters

property

string

entries

RangeEntry[]

opts?
fallback?

ItemModel

scale?

number

Returns

ItemModel


raw()

static raw(json): ItemModel

Defined in: core/values/item-model.ts:341

Verbatim item-model JSON escape hatch (wins over the typed arms).

Parameters

json

Record<string, unknown>

Returns

ItemModel


select()

static select(property, cases, fallback?, opts?): ItemModel

Defined in: core/values/item-model.ts:291

Match property (see SELECT_PROPERTIES) against cases; opts carries that property's extra fields (e.g. { block_state_property } for block_state).

Parameters

property

string

cases

SelectCase[]

fallback?

ItemModel

opts?

Record<string, unknown> = {}

Returns

ItemModel


special()

static special(base, model): ItemModel

Defined in: core/values/item-model.ts:336

A hardcoded block-entity model (base is the model providing the transforms).

Parameters

base

ModelResource

model

SpecialModel

Returns

ItemModel

Released under the MIT License · Credits