From 0f208f77f205b9a27e570218446a88504da58ebf Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Sat, 3 Jan 2026 00:21:39 -0500 Subject: [PATCH] fix: refactor modes update --- oregen-manager.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/oregen-manager.lua b/oregen-manager.lua index 3d29fb6..aa75535 100644 --- a/oregen-manager.lua +++ b/oregen-manager.lua @@ -95,7 +95,7 @@ function createModes (items) return result end -function updateModes (ticker, current_modes) +function updateModes (current_modes, current_stock) local lower_lim, upper_lim local limits = {} for item, _ in pairs(current_modes) do @@ -111,16 +111,16 @@ function updateModes (ticker, current_modes) upper = upper_lim, } end - for _, item in pairs(ticker.stock()) do - if limits[item.name] ~= nil then - if item.count <= limits[item.name].lower then - current_modes[item.name] = {"recipe"} - elseif item.count >= limits[item.name].upper then - current_modes[item.name] = { - "export", - item.count - limits[item.name].lower, - } - end + for item, limits in pairs(limits) do + local count = current_stock[item] + if count == nil then count = 0 end + if count <= limits.lower then + current_modes[item] = {"recipe"} + elseif count >= limits.upper then + current_modes[item] = { + "export", + count - limits.lower, + } end end end @@ -208,9 +208,9 @@ function run (ticker, export_storage, current_modes) os.sleep(SLEEP_T) return run (ticker, export_storage, current_modes) end - updateModes(ticker, current_modes) local export_amounts = getAmounts(export_storage.list) local stock_amounts = getAmounts(ticker.stock) + updateModes(current_modes, stock_amounts) cycleItems(ticker, stock_amounts) for item, mode in pairs(current_modes) do -- mode[1] is mode, mode[2] is amt_extra when exporting