Low-stock warning
You need: a computer, a Network Repeater, an Inventory Module named chests, a Display Module named screen and a
single chest.
- Place the chest directly north of the Inventory Module, touching it.
- Link the module and the display to the repeater and name them.
- Approve the chest (owner only): open the module’s form, type
northinto Face andstorageinto Name, then select Inventory. Without this step programs cannot see into the chest.
Program
Section titled “Program”This is the Low stock warning starter:
// Starter: Low stock warning (computer)// Warns on the Display Module "screen" when iron runs low in the chest next to the Inventory Module "chests".// Approve the chest's face in the module's form first.const chests = inventoryModules.named("chests")const screen = displays.named("screen")
on chests.itemChanged(face, item, count, previous) { if item is "minecraft:iron_ingot" and count < 16 { screen.write("Low on iron: " + str(count) + " left") }}Take iron ingots out of the chest until fewer than 16 are left. The screen warns you.
How it works
Section titled “How it works”itemChanged runs when the total of one item type in an approved container changes. It gives the side (face), the
item ID, the new count and the previous count. The program only reacts to iron ingots below 16.
Show the full count
Section titled “Show the full count”Add a handler that also clears the warning when you refill the chest:
const chests = inventoryModules.named("chests")const screen = displays.named("screen")
on chests.itemChanged(face, item, count, previous) { if item is not "minecraft:iron_ingot" { return } if count < 16 { screen.write("Low on iron: " + str(count) + " left") } else { screen.write("Iron: " + str(count)) }}return leaves the handler early for every other item.