Update to farm_control for non-replanting support
This commit is contained in:
parent
f567051d7d
commit
2b3676d5db
1 changed files with 29 additions and 13 deletions
|
|
@ -39,7 +39,11 @@ function check_levels (levels, src)
|
||||||
local needs_farming = {}
|
local needs_farming = {}
|
||||||
for item, data in pairs(levels) do
|
for item, data in pairs(levels) do
|
||||||
if amounts[item] ~= nil and amounts[item] < data[1] then
|
if amounts[item] ~= nil and amounts[item] < data[1] then
|
||||||
|
if data[2] ~= nil then
|
||||||
table.insert(needs_farming, data[2])
|
table.insert(needs_farming, data[2])
|
||||||
|
else
|
||||||
|
table.insert(needs_farming, true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if needs_farming[1] == nil then
|
if needs_farming[1] == nil then
|
||||||
|
|
@ -66,10 +70,10 @@ function send_machine (relay_and_side)
|
||||||
peripheral.call(relay, RELAY_COMMAND, side, false)
|
peripheral.call(relay, RELAY_COMMAND, side, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO make a different loop for crops controlled by a CLI arg
|
-- if the first argument to this program is "replant", a separate machine will
|
||||||
-- the other loop doesn't need to load the harvester, but also doesn't need
|
-- be sent out to replant crops between harvests
|
||||||
-- to send the harvester unless stock drops below a level
|
if arg[1] == "replant" then
|
||||||
while true do
|
while true do
|
||||||
local needs_farming = check_levels(LEVELS, STORAGE)
|
local needs_farming = check_levels(LEVELS, STORAGE)
|
||||||
if needs_farming ~= nil then
|
if needs_farming ~= nil then
|
||||||
for _, item in ipairs(needs_farming) do
|
for _, item in ipairs(needs_farming) do
|
||||||
|
|
@ -81,4 +85,16 @@ while true do
|
||||||
send_machine(HARVESTER_RELAY)
|
send_machine(HARVESTER_RELAY)
|
||||||
os.sleep(SLEEP_TIME)
|
os.sleep(SLEEP_TIME)
|
||||||
pull_items(HARVESTER, STORAGE)
|
pull_items(HARVESTER, STORAGE)
|
||||||
|
end
|
||||||
|
-- otherwise, the harvester will just be sent out when a crop's levels drop too
|
||||||
|
-- low
|
||||||
|
else
|
||||||
|
while true do
|
||||||
|
local needs_farming = check_levels(LEVELS, STORAGE)
|
||||||
|
if needs_farming ~= nil then
|
||||||
|
send_machine(HARVESTER_RELAY)
|
||||||
|
end
|
||||||
|
os.sleep(SLEEP_TIME)
|
||||||
|
pull_items(HARVESTER, STORAGE)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue