Inventory
The inventory API lets you create and manage virtual inventories. Inventories can be opened for players, returning a Container session.
Metatable name: "inventory"
Creating Inventories
Section titled “Creating Inventories”mc.createInventory(size)
Section titled “mc.createInventory(size)”Creates a new inventory. Size must be a multiple of 9 (9–54).
size(number) — Number of slots
local inv = mc.createInventory(27)Properties
Section titled “Properties”inv.size
Section titled “inv.size”type: number
Number of slots. Read-only.
Methods
Section titled “Methods”inv:getItem(slot)
Section titled “inv:getItem(slot)”Returns the item in the given slot, or nil if empty.
slot(number) — Slot index (0‑based)
local item = inv:getItem(0)inv:setItem(slot, item)
Section titled “inv:setItem(slot, item)”Sets a slot to the given item stack.
slot(number) — Slot index (0‑based)item(ItemStackornil) — Item to place, ornilto clear
inv:setItem(0, mc.createItem("diamond", 1))inv:setItem(1, nil)inv:fill(item)
Section titled “inv:fill(item)”Fills every empty slot with the given item.
item(ItemStack) — Item to fill with
inv:fill(mc.createItem("stone", 1))inv:clear()
Section titled “inv:clear()”Clears all slots.
inv:clear()inv:open(player, title?)
Section titled “inv:open(player, title?)”Opens the inventory for a player. Returns a Container session.
player(Player) — Target playertitle(string, optional) — Window title
The returned container tracks the open session with click handling, forced close, and access to the backing inventory and player.
local container = inv:open(player, "&6My Chest")container:onClick(function(slot, clickType, p, slotItem, cursorItem) if slot == 0 then return false endend)