Skip to content

items

The items library lets you define custom item templates that combine a base Minecraft item with custom_model_data (for resource-pack model overrides) and scripted callbacks that react to player actions.

local items = require "core:items"

Creates a named item template and registers it for automatic event dispatch. Returns a template object.

FieldTypeRequiredDescription
idstringBase Minecraft item ID (e.g. "stick", "minecraft:diamond_sword")
modelDatanumberCustomModelData value (for resource-pack model)
keystringInternal identifier; auto-generated if omitted
namestringCustom item name (& color codes)
lorestring[]Lore lines
unbreakablebooleanUnbreakable flag

Callback fields — each is optional, triggered when the held/used item matches id + modelData:

CallbackTriggerSignatureCancellable
onUseRight-click with itemfn(player, hand, item, template)
onAttackAttack an entity while holdingfn(player, target, item, template)
onConsumeEat/drink the itemfn(player, item, template)
onPickupPlayer picks up the itemfn(player, item, count, template)
onInteractEntityRight-click an entity with itemfn(player, entity, hand, item, template)
onTickEach tick while heldfn(player, item, hand, template)hand is "main"|"off"
onInventoryTickEach tick while in any inventory slotfn(player, item, slot, template)

Returning false from a cancellable callback cancels the underlying event.

MethodReturnsDescription
template:make(count?)ItemStackCreates an item stack with the template’s properties
template:matches(item)booleanChecks if an ItemStack matches this template
template:has(player)booleantrue if the player has any matching item in their inventory

Returns true if the item matches the template by id + modelData.

Returns the matching template for the given ItemStack, or nil.

Returns true if the player has any matching item in their inventory (same as template:has(player)).

local items = require "core:items"
local wand = items.define {
id = "stick",
modelData = 1001,
name = "&5Magic Wand",
lore = { "&7Right-click to cast a spell" },
unbreakable = true,
onUse = function(player, hand, item, template)
player:sendMessage("&5*whoosh*")
player.world:playSound("minecraft:entity.ender_dragon.growl", player.pos, 1.0, 1.0)
end,
onAttack = function(player, target, item, template)
target:damage(5)
end,
onTick = function(player, item, hand, template)
player:sendActionBar("&dWand ready (" .. hand .. ")")
end,
}
local ring = items.define {
id = "gold_nugget",
modelData = 2001,
name = "&eRing of Regeneration",
onInventoryTick = function(player, item, slot, template)
player:heal(0.5)
end,
}
-- Give items to a player
register("wand") \{ ctx ->
ctx.player:give(wand:make(1))
}
register("ring") \{ ctx ->
ctx.player:give(ring:make(1))
}
-- Check if a player has the ring
register("hasring") \{ ctx ->
if ring:has(ctx.player) then
ctx.player:sendMessage("&aYou have the ring!")
else
ctx.player:sendMessage("&cYou don't have the ring.")
end
}
  • Items are matched by id + modelData. If modelData is omitted, matching is by id only (use with caution — every item of that base type will trigger callbacks).
  • IDs without a namespace automatically get minecraft: prepended.
  • The library registers its event listeners once on require, so all templates share a single listener per event.
  • Custom items require a resource pack with a model override for the base item and custom_model_data to be visually distinct from the base item.