Skip to content

Inventory Module

The Inventory Module block
Inventory Module. Asset render of the block model, not an in-game screenshot.

The Inventory Module lets programs look into containers next to it, count items and move items between them. For safety, a program can only use the containers the owner approved.

Inventory Module

Shaped crafting table recipe. Progression: intermediate automation. Ingredients: 5 × Iron Ingot, 1 × Hopper, 2 × Copper Ingot, 1 × Redstone. It appears in the recipe book once you pick up one of its ingredients.

Place it touching the containers, such as chests, barrels, hoppers or furnaces, and link it to a Network Repeater. Sides are named by world direction: north, south, east, west, up, down.

Only the owner can do this:

  1. Open the module with an empty hand.
  2. Type the side into Face, such as north, and a name into Name, such as storage.
  3. Select Inventory.

To remove an approval, leave the name empty and select Inventory again. Breaking or replacing the container removes its approval: approve the new one again.

Single-block containers with up to 54 slots that expose their slots to automation, like hoppers do. A furnace’s input, fuel and output follow the side you use. Double chests, minecarts, locked containers and unopened loot chests are not supported.

Yes. A drive program on the module uses device.inventories() and device.inventory(face), and receives device.contentsChanged and device.itemChanged, for the approved faces only, even while the computer is unloaded.

inventoryModules.named(alias)

Refer to an Inventory Module by its name. Use it in a constant, then handle its events with on NAME.event(...).

Parameters: alias: string. Gives: InventoryModule. Cost: 4 operations.

const chests = inventoryModules.named("chests")

inventory.module(alias)

Resolve an inventory module by name.

Parameters: alias: string. Gives: InventoryModule, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied. Capability: inventory.read. Cost: 16 operations.

module, err = inventory.module("warehouse")

inventory.from(alias)

Resolve a configured adjacent inventory alias.

Parameters: alias: string. Gives: Inventory, or an error. Errors: device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, world.unloaded. Capability: inventory.read. Cost: 16 operations.

storage, err = inventory.from("storage")

inventory.from(name) opens an approved container directly by the name given in the form.

Properties: chests.connected, chests.id, chests.kind, chests.name. They are read-only.

chests.adjacent()

List neighboring blocks with face, block ID and whether they expose items.

Gives: list, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied, world.unloaded. Capability: inventory.read. Cost: 16 operations.

around, err = module.adjacent()

chests.inventories()

List approved faces with name, face and available.

Gives: list, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied. Capability: inventory.read. Cost: 16 operations.

faces, err = module.inventories()

chests.inventory(face)

Resolve the approved inventory on a face as an Inventory.

Parameters: face: enum or string. Gives: handle, or an error. Errors: argument.invalid, device.type, device.unavailable, device.unknown, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, world.unloaded. Capability: inventory.read. Cost: 16 operations.

storage, err = module.inventory("north")

inventory(face) and inventory.from(name) give an Inventory:

storage.contains(item)

Test whether at least one of the item is present.

Parameters: item: string. Gives: bool, or an error. Errors: device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, item.identifier, item.unknown, world.unloaded. Capability: inventory.read. Cost: 12 operations.

present, err = storage.contains("minecraft:iron_ingot")

storage.count(item)

Count the item ID across its component variants.

Parameters: item: string. Gives: number, or an error. Errors: device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, item.identifier, item.unknown, world.unloaded. Capability: inventory.read. Cost: 12 operations.

count, err = storage.count("minecraft:iron_ingot")

storage.fullness()

Read occupied capacity as a fraction between zero and one.

Gives: number, or an error. Errors: device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, world.unloaded. Capability: inventory.read. Cost: 12 operations.

value, err = storage.fullness()

storage.getSlot(index)

Read an immutable snapshot of a zero-based slot.

Parameters: index: number. Gives: dict, or an error. Errors: argument.range, device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, world.unloaded. Capability: inventory.read. Cost: 12 operations.

slot, err = storage.getSlot(0)

storage.isEmpty()

Test whether every visible slot is empty.

Gives: bool, or an error. Errors: device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, world.unloaded. Capability: inventory.read. Cost: 12 operations.

value, err = storage.isEmpty()

storage.items()

Total each item ID present, keyed by ID.

Gives: dict, or an error. Errors: device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, world.unloaded. Capability: inventory.read. Cost: 12 operations.

value, err = storage.items()

storage.moveTo(destination, item, amount)

Move up to 256 items while preserving each component variant.

Parameters: destination: Inventory, item: string, amount: number. Gives: number, or an error. Errors: argument.range, device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.same, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, item.identifier, item.unknown, world.unloaded. Capability: inventory.transfer. Cost: 24 operations.

moved, err = storage.moveTo(output, "minecraft:iron_ingot", 16)

storage.occupied()

Count non-empty sided slots.

Gives: number, or an error. Errors: device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, world.unloaded. Capability: inventory.read. Cost: 12 operations.

value, err = storage.occupied()

storage.size()

Count sided slots.

Gives: number, or an error. Errors: device.unavailable, host.denied, inventory.limit, inventory.missing, inventory.stale, inventory.unavailable, inventory.unknown, inventory.unsupported, world.unloaded. Capability: inventory.read. Cost: 12 operations.

value, err = storage.size()
EventWhen it runs
contentsChanged(face)Runs when the items in an approved inventory change.
itemChanged(face, item, count, previous)Runs when the total count of one item type changes, such as minecraft:iron_ingot.
connectedRuns when the device becomes reachable, for example after its area loads.
disconnectedRuns when the device stops being reachable: unloaded, unlinked or removed.
programStartedRuns when the device's own program starts.
programStoppedRuns when the device's own program stops.
programFailed(message)Runs when the device's own program stops on an error.

Contents are compared every 20 ticks, only while a program listens.

  • Item IDs are namespaced registry IDs such as minecraft:iron_ingot. Counts include all variants of an item.
  • moveTo moves up to 256 items per call, respects slot rules and stack sizes, and never duplicates or deletes items. A partial or zero move is a normal result.
  • Every call checks the approval, the owner, the loaded area and world protection again.
const chests = inventoryModules.named("chests")
on chests.itemChanged(face, item, count, previous) {
if item is "minecraft:diamond" and count > previous {
print("Diamonds: " + str(count))
}
}
on timer.every(200) {
storage = chests.inventory(Direction.NORTH)
output = chests.inventory(Direction.UP)
moved = storage.moveTo(output, "minecraft:cobblestone", 64)
if moved > 0 {
print("Moved " + str(moved) + " cobblestone")
}
}