diff --git a/oregen-manager.lua b/oregen-manager.lua index 21fad92..3cf8da1 100644 --- a/oregen-manager.lua +++ b/oregen-manager.lua @@ -61,7 +61,7 @@ function createModes (items) return result end -function updateModes (current_modes) +function updateModes (ticker, current_modes) local lower_lim, upper_lim local limits = {} for item, _ in pairs(current_modes) do @@ -154,7 +154,7 @@ function getNumCraftable (recipe, current_stock) for _, ingredient in ipairs(recipe) do item, count = ingredient[1], ingredient[2] if current_stock[item] == nil then return 0 end - local num = math.floor(current_stock[item] / count)) + local num = math.floor(current_stock[item] / count) if result == nil then result = num else @@ -194,7 +194,7 @@ end function run (ticker, export_storage, current_modes) cycleItems(ticker) - updateModes(current_modes) + updateModes(ticker, current_modes) local export_amounts = getAmounts(export_storage.list) local stock_amounts = getAmounts(ticker.stock) for item, mode in pairs(current_modes) do @@ -205,7 +205,9 @@ function run (ticker, export_storage, current_modes) local count = getNumCraftable(recipe, stock_amounts) craftRecipe(ticker, recipe, count) elseif mode[1] == "export" then - local amt_needed = export_amounts[item] + local export_amt = export_amounts[item] + if export_amt == nil then export_amt = 0 end + local amt_needed = KEEP_STOCKED[item] - export_amt local amt = math.min(amt_needed, mode[2]) export(ticker, item, amt) end