Skip to content

Low-stock warning

You need: a computer, a Network Repeater, an Inventory Module named chests, a Display Module named screen and a single chest.

  1. Place the chest directly north of the Inventory Module, touching it.
  2. Link the module and the display to the repeater and name them.
  3. Approve the chest (owner only): open the module’s form, type north into Face and storage into Name, then select Inventory. Without this step programs cannot see into the chest.

This is the Low stock warning starter:

starter-low-stock.fsig
// 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.

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.

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.