types.ItemStack
A stack of items. Stacks are values: with returns a changed copy and two equal stacks are ==.
Fields
itemStack.count: numberHow many items the stack holds.
itemStack.damage: numberHow worn the stack is: 0 when new, and always 0 for an item without durability.
itemStack.data: anyThe data table set on the stack, or nil when it has none.
local items = require("@ember/items")
-- Stack data travels with the item: read it back when the item is used.
local wand = items.type("wand")
wand.used:connect(function(event)
local charges = if event.item.data then event.item.data.charges else 0
if charges <= 0 then
event.player:send("<gray>The wand is out of charges.")
return
end
-- Put back a copy with one charge fewer.
event.player.inventory:setHeld(event.item:with({ data = { charges = charges - 1 } }), event.hand)
event.player:send(`<light_purple>Zap! {charges - 1} charges left.`)
end)itemStack.glint: boolean?Whether the stack forces the enchantment shimmer on (true) or off (false), or nil when it shows the item's own.
itemStack.id: stringThe item's id, such as "minecraft:diamond".
itemStack.lore: { types.MiniMessage }?The lore lines set on the stack, or nil when it has none.
itemStack.maxCount: numberHow many of the item one slot holds.
itemStack.maxDamage: number?The damage at which the item breaks, or nil when it has no durability.
itemStack.name: types.MiniMessage?The name set on the stack, or nil when it shows the item's own.
Methods
Returns whether the stack is of the item type, or of a type in the item tag.
local items = require("@ember/items")
local players = require("@ember/players")
-- An item tag covers many types at once; `is` checks a stack against a type or a tag.
local logs = items.tag("minecraft:logs")
local apple = items.type("minecraft:apple")
players.joined:connect(function(player)
local held = player.inventory:held()
if held and held:is(logs) then
player:send("<green>That's wood.")
elseif held and held:is(apple) then
player:send(`<red>An apple; a full stack is {held.maxCount}.`)
end
end)Returns whether the stacks are the same item with the same name, lore and data, whatever their counts.
itemStack:with(changes: types.ItemChanges) -> types.ItemStackReturns a copy of the stack with the changes.
local players = require("@ember/players")
local items = require("@ember/items")
-- Stacks are values: `with` returns a changed copy and leaves the original alone.
local medal = items.create("minecraft:gold_nugget", { name = "<gold>Medal" })
players.joined:connect(function(player)
local mine = medal:with({ lore = { `<gray>Awarded to {player.name}` } })
player.inventory:setHeld(mine)
end)Returns a copy of the stack with the fields put back to the item's own, such as item:without("name", "lore").
local items = require("@ember/items")
local players = require("@ember/players")
-- A worn, renamed sword.
local relic = items.create("minecraft:iron_sword", { name = "<gold>Relic", lore = { "<gray>Found in the ruins" }, damage = 200 })
players.joined:connect(function(player)
-- `with` can't clear a field, since nil keeps it; `without` puts fields back to the item's own.
local repaired = relic:without("damage")
local plain = relic:without("name", "lore", "damage")
player.inventory:add(repaired)
player.inventory:add(plain)
end)