compost_control.lua: bugfixes and new output for stuff
This commit is contained in:
parent
19636ac7c5
commit
fe3f75cf0b
1 changed files with 14 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue