Inventory
Snapshot of the bot's inventory at capture time. Re-call client:inventory() (or getInventory()) to refresh — values don't auto-update.
local client = getClient()
local inventory = client:inventory() -- or getInventory()
inventory.slots -- total slot count
inventory.items -- table keyed by inventory key
-- Lookups
inventory:getItem(invKey)
inventory:getItem(blockType, invType)
for invKey, item in pairs(inventory.items) do
item.id -- block type
item.type -- inventory item type (see below)
item.amount
end
Constructors
getInventory()
| Field | Type |
|---|---|
| Signature | () → Inventory |
| Returns | Inventory — fresh snapshot of the parent bot's cells |
| Common errors | "getInventory: no parent client" (script has no bound bot), "getInventory: parent client not found" |
| Async | yes |
Shortcut for getClient():inventory(). Errors when no parent is bound (e.g. running from the global executor).
client:inventory()
| Field | Type |
|---|---|
| Signature | (self: Client) → Inventory |
| Returns | Inventory — snapshot of this bot's cells |
| Async | yes |
Same as getInventory() but lets you target a sibling bot resolved via getClient(key).
Fields
inventory.slots
| Field | Type |
|---|---|
| Signature | Inventory.slots: number |
| Returns | number — count of cells currently in use |
The protocol has no separate "max slots" surface — call client:expandInventory() to grow it.
inventory.items
| Field | Type |
|---|---|
| Signature | Inventory.items: {[number]: InventoryItem} |
| Returns | {[number]: InventoryItem} — cells keyed by invKey = (inventory_type << 16) | block_id |
The composite key lets the same block_id live in two cells when it exists as both a Block and a Seed (e.g. Obsidian + Obsidian Seed).
for invKey, item in pairs(inventory.items) do
print(invKey, item.id, item.type, item.amount, item.name)
end
Lookups
inventory:getItem(invKey)
| Field | Type |
|---|---|
| Signature | (self: Inventory, invKey: number) → InventoryItem? |
| Returns | InventoryItem? — nil when no cell matches |
| Async | no |
local seedKey = (InventoryItemType.seed << 16) | 9 -- Obsidian Seed
local item = inventory:getItem(seedKey)
inventory:getItem(blockType, invType)
| Field | Type |
|---|---|
| Signature | (self: Inventory, blockType: number, invType: number) → InventoryItem? |
| Returns | InventoryItem? — nil when no cell matches |
| Async | no |
invType is the raw InventoryItemType enum (0..12) — the boundary handles the upper-byte packing for you, so getItem(9, InventoryItemType.seed) resolves to the Obsidian Seed cell.
local item = inventory:getItem(9, InventoryItemType.seed)
InventoryItem fields
| Field | Type | Notes |
|---|---|---|
id | number | Block id (same number you'd pass to client:place). |
type | number | Raw InventoryItemType enum (0..12), unpacked. |
amount | number | Stack count. |
name | string | From block_types.json; falls back to "#<id>". |
Inventory item types
InventoryItemType.block -- 0 (default)
InventoryItemType.background -- 1
InventoryItemType.seed -- 2 (use client:plant shortcut)
InventoryItemType.water -- 3
InventoryItemType.wearable -- 4
InventoryItemType.weapon -- 5
InventoryItemType.throwable -- 6
InventoryItemType.consumable -- 7
InventoryItemType.shard -- 8
InventoryItemType.blueprint -- 9
InventoryItemType.familiar -- 10
InventoryItemType.food -- 11 (FAMFood)
InventoryItemType.wiring -- 12
Drop, trash, equip, expand and use are on the client.