Inventory & Items
Inventory API (inventory)
Section titled “Inventory API (inventory)”inventory.createStack(itemId)→ItemStackHandleinventory.createStack(itemId, quantity)→ItemStackHandleinventory.createStack({ itemId, quantity?, durability?, maxDurability?, metadata? })→ItemStackHandleinventory.emptyStack()→ItemStackHandleinventory.isEmpty(stack)→ booleaninventory.areStackable(a, b)→ booleaninventory.areSameType(a, b)→ boolean
Example
Section titled “Example”var pickaxe = inventory.createStack({ itemId: "IronPickaxe", quantity: 1, durability: 150, maxDurability: 250, metadata: { enchanted: true, level: 3 }});
console.info(pickaxe.itemId, pickaxe.durability + "/" + pickaxe.maxDurability);ItemStack (ItemStackHandle)
Section titled “ItemStack (ItemStackHandle)”Properties
Section titled “Properties”itemIdquantitydurabilitymaxDurabilitybrokenunbreakableemptyvalidblockKey
Metadata
Section titled “Metadata”getMetadata()→ object | nullgetMetadataValue(key)→ anyhasMetadata(key?)→ boolean
Modification (returns new instances)
Section titled “Modification (returns new instances)”withQuantity(quantity)→ItemStackHandle | nullwithDurability(durability)→ItemStackHandlewithIncreasedDurability(delta)→ItemStackHandlewithMaxDurability(maxDurability)→ItemStackHandlewithRestoredDurability(durability)→ItemStackHandlewithMetadata(metadata)→ItemStackHandlewithMetadata(key, value)→ItemStackHandle
Convenience
Section titled “Convenience”damage(amount)→ItemStackHandlerepair(amount)→ItemStackHandlefullyRepair()→ItemStackHandle
Comparison
Section titled “Comparison”isStackableWith(other)→ booleanisSameItemType(other)→ booleanisEquivalentType(other)→ boolean
Serialization
Section titled “Serialization”toObject()→ objecttoString()→ string
ItemContainer (ItemContainerHandle)
Section titled “ItemContainer (ItemContainerHandle)”Access containers from players, chests, or block entities:
var container = player.getInventory();var chestContainer = world.getBlockAt(x, y, z).getContainer();Properties
Section titled “Properties”size- Number of slots in containercapacity- Max items per slotempty- Is container empty?
Slot Operations
Section titled “Slot Operations”getItem(slot)→ItemStackHandle | null- Get item in specific slotsetItem(slot, item)→TransactionResultHandle- Replace item in slotaddToSlot(slot, item)→TransactionResultHandle- Add/merge to slotremoveFromSlot(slot, quantity)→TransactionResultHandle- Remove quantity from slotclearSlot(slot)→TransactionResultHandle- Clear slot completely
Container Operations
Section titled “Container Operations”addItem(item)→TransactionResultHandle- Add item to any available slotremoveItem(itemId, quantity)→TransactionResultHandle- Remove item from containerclear()→TransactionResultHandle- Clear entire containercanAddItems(items[])→ boolean - Check if items can fit
Search & Query
Section titled “Search & Query”count(itemId)→ number - Count matching itemsfindSlot(itemId)→ number | -1 - Find first matching slotfindSlots(itemId)→ number[] - Find all matching slotscontains(itemId)→ boolean - Check if container has itemgetQuantity(itemId)→ number - Get total quantityhas(itemId, quantity)→ boolean - Check if has enoughcontainsStackable(item)→ boolean - Check if can stack
Iteration
Section titled “Iteration”forEach(callback)- Iterate all items:(item, slot) => {}map(callback)- Map items to array:(item, slot) => valuefilter(callback)- Filter items:(item, slot) => booleangetAll()→ItemStackHandle[]- Get all items as arraygetAllSlots()→ object[] - Get all slots (including empty)
Example
Section titled “Example”// Get player inventoryvar inv = player.getInventory();
// Add itemsvar stone = inventory.createStack('Stone', 64);var result = inv.addItem(stone);if (result.success) { console.info('Added stone, remainder:', result.remainder ? result.remainder.quantity : 0);}
// Search for itemsvar diamondSlot = inv.findSlot('Diamond');if (diamondSlot >= 0) { var diamond = inv.getItem(diamondSlot); console.info('Found', diamond.quantity, 'diamonds in slot', diamondSlot);}
// Iterate and filtervar valuable = inv.filter(function(item) { return item.itemId.includes('Diamond') || item.itemId.includes('Gold');});console.info('Found', valuable.length, 'valuable items');TransactionResult (TransactionResultHandle)
Section titled “TransactionResult (TransactionResultHandle)”All container operations return transaction results:
Properties
Section titled “Properties”success- Operation succeeded?message- Optional error/info messageremainder- Remaining items that didn’t fitslotBefore- Item/items before operationslotAfter- Item/items after operationslot- Affected slot number
Example
Section titled “Example”var result = container.addItem(stone);if (!result.success) { console.warn('Failed:', result.message);} else if (result.remainder) { console.info('Added but', result.remainder.quantity, 'items remain');}Entity Inventory Access
Section titled “Entity Inventory Access”// Access player inventory (returns ItemContainerHandle)var playerInv = player.getInventory();
// Access living entity inventory (future)var entityInv = entity.getInventory();Planned: Advanced Inventory
Section titled “Planned: Advanced Inventory”InventoryHandle
Section titled “InventoryHandle”- Section access: hotbar, storage, armor, utility, tools, backpack
- Active slot management for hotbar, tools, and utility
- Smart operations:
smartMoveItem,quickStack,takeAll,putAll - High-level helpers:
giveItem,takeItem,hasItem,getItemQuantity