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