From 2b3676d5db8916531e9ee6bdaa82052414c8ba0c Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Thu, 13 Nov 2025 15:23:03 -0500 Subject: [PATCH] Update to farm_control for non-replanting support --- farm_control.lua | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/farm_control.lua b/farm_control.lua index ae9abb8..5c9b459 100644 --- a/farm_control.lua +++ b/farm_control.lua @@ -39,7 +39,11 @@ function check_levels (levels, src) local needs_farming = {} for item, data in pairs(levels) do if amounts[item] ~= nil and amounts[item] < data[1] then - table.insert(needs_farming, data[2]) + if data[2] ~= nil then + table.insert(needs_farming, data[2]) + else + table.insert(needs_farming, true) + end end end if needs_farming[1] == nil then @@ -66,19 +70,31 @@ function send_machine (relay_and_side) peripheral.call(relay, RELAY_COMMAND, side, false) end --- TODO make a different loop for crops controlled by a CLI arg --- the other loop doesn't need to load the harvester, but also doesn't need --- to send the harvester unless stock drops below a level -while true do - local needs_farming = check_levels(LEVELS, STORAGE) - if needs_farming ~= nil then - for _, item in ipairs(needs_farming) do - load_stack(item, STORAGE, PLANTER) +-- if the first argument to this program is "replant", a separate machine will +-- be sent out to replant crops between harvests +if arg[1] == "replant" then + while true do + local needs_farming = check_levels(LEVELS, STORAGE) + if needs_farming ~= nil then + for _, item in ipairs(needs_farming) do + load_stack(item, STORAGE, PLANTER) + end + send_machine(PLANTER_RELAY) + os.sleep(SLEEP_TIME) end - send_machine(PLANTER_RELAY) + send_machine(HARVESTER_RELAY) os.sleep(SLEEP_TIME) + 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 - send_machine(HARVESTER_RELAY) - os.sleep(SLEEP_TIME) - pull_items(HARVESTER, STORAGE) end