From 2f70be2d909ba6290a8337c0572851192150f1a0 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Wed, 14 Jun 2023 16:03:00 +0200 Subject: [PATCH] reorder and change back var name --- autocrafter.lua | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/autocrafter.lua b/autocrafter.lua index 71589ce..1a139c4 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -101,16 +101,6 @@ end local function autocraft(inventory, craft) if not craft then return false end - -- check if we have enough material available - local inv_index = count_index(inventory:get_list("src")) - local consumption = calculate_consumption(inv_index, craft.consumption) - if not consumption then - return false - end - -- check if we have enough material available - for itemname, number in pairs(consumption) do - if (not inv_index[itemname]) or inv_index[itemname] < number then return false end - end -- check if output and all replacements fit in dst local output = craft.output.item local out_items = count_index(craft.decremented_input.items) @@ -134,8 +124,17 @@ local function autocraft(inventory, craft) if empty_count < 0 then return false end + -- check if we have enough material available + local inv_index = count_index(inventory:get_list("src")) + local consumption = calculate_consumption(inv_index, craft.consumption) + if not consumption then + return false + end + for itemname, number in pairs(consumption) do + if (not inv_index[itemname]) or inv_index[itemname] < number then return false end + end -- consume material - for itemname, number in pairs(craft.consumption) do + for itemname, number in pairs(consumption) do for _ = 1, number do -- We have to do that since remove_item does not work if count > stack_max inventory:remove_item("src", ItemStack(itemname)) end