compost_control.lua: bugfixes and new output for stuff

This commit is contained in:
Emerson Rosen-Jones 2025-11-14 20:51:27 -05:00
parent 19636ac7c5
commit fe3f75cf0b

View file

@ -7,7 +7,9 @@ local SOURCES =
{ ""
}
local COMPOST_INV = ""
local COMPOST_INPUT = ""
local COMPOST_OUTPUT = ""
local STORAGE = ""
local SLEEP_TIME = 40
@ -27,17 +29,18 @@ function compare_counts (count1, count2)
diffs[item] = count - count2[item]
end
end
return diffs
end
function compost (src, item_name, amount)
if amount < 1 return end
if amount < 1 then return end
local amount_moved = 0
-- 1. scan through inventory until {item} is found
for slot, item in pairs(src.list())
for slot, item in pairs(peripheral.call(src, "list")) do
if item.name == item_name then
-- 2. move up to {amount} to compost, recording amount moved
amount_moved = peripheral.call(
COMPOST_INV, "pullItems", src, slot, amount
COMPOST_INPUT, "pullItems", src, slot, amount
)
break
end
@ -46,7 +49,14 @@ function compost (src, item_name, amount)
return compost(src, item_name, amount - amount_moved)
end
function move_all (src, dest)
for slot, item in pairs(peripheral.call(src, "list")) do
peripheral.call(src, "pushItems", dest, slot)
end
end
while true do
move_all(COMPOST_OUTPUT, STORAGE)
for _, source in ipairs(SOURCES) do
local totals = tally_up(source)
local diffs = compare_counts(totals, CHECKS)