Skip to content

Inventory

The inventory API lets you create and manage virtual inventories. Inventories can be opened for players, returning a Container session.

Metatable name: "inventory"

Creates a new inventory. Size must be a multiple of 9 (9–54).

  • size (number) — Number of slots
local inv = mc.createInventory(27)

type: number

Number of slots. Read-only.

Returns the item in the given slot, or nil if empty.

  • slot (number) — Slot index (0‑based)
local item = inv:getItem(0)

Sets a slot to the given item stack.

  • slot (number) — Slot index (0‑based)
  • item (ItemStack or nil) — Item to place, or nil to clear
inv:setItem(0, mc.createItem("diamond", 1))
inv:setItem(1, nil)

Fills every empty slot with the given item.

inv:fill(mc.createItem("stone", 1))

Clears all slots.

inv:clear()

Opens the inventory for a player. Returns a Container session.

  • player (Player) — Target player
  • title (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 end
end)