Skip to content

inventory

Slot swaps, drops, item lookups and hotbar selection, scheduled to a safe point in the tick.

Your own inventory, addressed by player-screen slot numbers. For the slots of an open container, use container.

Function Does
inventory.swap(a, b) Swaps two slots
inventory.drop(slot[, all]) Drops from a slot; all defaults to true, the whole stack
inventory.merge(from, to) Moves a stack onto another
inventory.use(slot[, yaw, pitch]) Uses the item in a slot, facing a direction first when given
inventory.item(slot) Live item handle, or nil
inventory.find(item_id) First slot holding that item, or nil
inventory.count(item_id) Total count of that item you carry
inventory.cooldown(item_id) Cooldown progress, 1 right after use down to 0 when ready
inventory.slot(), inventory.set_slot(i) Reads and sets the selected hotbar slot, 0–8

hotbar

Arbitrated slot holds for keeping a hotbar slot selected across ticks. Holds from every module and script compose by priority, and the service restores the pre-override slot when the last hold releases — never save and restore inventory.slot() yourself around a multi-tick hold. For an atomic same-tick switch–use–switch-back, plain set_slot is fine. Holds are silent: the hotbar and the hand keep showing hotbar.base(), the player’s own slot, which number keys and scrolling keep changing while a hold is active.

Function Does
hotbar.hold(slot[, priority]) Holds a hotbar slot 0–8, false when outprioritized
hotbar.release() Releases this script’s hold
hotbar.owns() Whether this script holds the hotbar right now
hotbar.base() The player’s own slot, the one shown while a hold overrides it

The hold belongs to the script and is released automatically on script reload; still pair hold with release in disable.

Slot numbering

Range Holds
0 Crafting result
1–4 Crafting grid
5–8 Armor, helmet to boots
9–35 Main inventory
36–44 Hotbar
45 Offhand
module:event("tick", function()
    local totem = inventory.find("minecraft:totem_of_undying")
    if totem and inventory.item(45):id() ~= "minecraft:totem_of_undying" then
        inventory.swap(totem, 45)
    end
end)
Navigation

Type to search…

↑↓ navigate↵ selectEsc close