From e82591297cc690190ead6da9851daba44f199b59 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 17 Jan 2026 19:02:39 -0500 Subject: [PATCH] fix: fix startup logic Previous: if a KEEP_STOCKED material was between lower and upper, it would sit there on startup, regardless of whether material was needed in export. New logic is that materials between the lower and upper bound will try to export until the lower bound is reached on startup. --- oregen-manager.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/oregen-manager.lua b/oregen-manager.lua index 6bab48b..aad4f4d 100644 --- a/oregen-manager.lua +++ b/oregen-manager.lua @@ -200,7 +200,7 @@ function createModes (items) return result end -function updateModes (current_modes, current_stock) +function updateModes (current_modes, current_stock, first_run) local lower_lim, upper_lim local limits = {} for item, _ in pairs(current_modes) do @@ -221,7 +221,7 @@ function updateModes (current_modes, current_stock) if count == nil then count = 0 end if count <= limits.lower then current_modes[item] = {"recipe"} - elseif count >= limits.upper then + elseif count >= limits.upper or first_run then current_modes[item] = { "export", count - limits.lower, @@ -324,14 +324,14 @@ function export (ticker, item, amt) ticker.requestFiltered(EXPORT_ADDR, request) end -function run (ticker, export_storage, current_modes) +function run (ticker, export_storage, current_modes, first_run) if SPEEDOMETER ~= "" and peripheral.call(SPEEDOMETER, "getSpeed") == 0 then os.sleep(SLEEP_T) - return run (ticker, export_storage, current_modes) + return run (ticker, export_storage, current_modes, first_run) end local export_amounts = getAmounts(export_storage.list) local stock_amounts = getAmounts(ticker.stock) - updateModes(current_modes, stock_amounts) + updateModes(current_modes, stock_amounts, first_run) for item, mode in pairs(current_modes) do -- mode[1] is mode, mode[2] is amt_extra when exporting if mode[1] == "recipe" then @@ -355,5 +355,5 @@ if arg ~= nil and arg[1] == "run" then local ticker = peripheral.wrap(STOCK_TICKER) local export_storage = peripheral.wrap(EXPORT_STORAGE) local current_modes = createModes(KEEP_STOCKED) - run(ticker, export_storage, current_modes) + run(ticker, export_storage, current_modes, true) end