diff options
author | Tim <t4im@users.noreply.github.com> | 2015-01-26 21:34:32 +0100 |
---|---|---|
committer | Tim <t4im@users.noreply.github.com> | 2015-01-27 23:41:46 +0100 |
commit | f427bae557f8376e51d296f871f33d56dc541e12 (patch) | |
tree | 96ecf4311ddfb53906002ddd1a10c7a9ef0e14ad | |
parent | cee16932beb27dc467d64b614c5e5c6baa727270 (diff) | |
download | pipeworks-f427bae557f8376e51d296f871f33d56dc541e12.tar pipeworks-f427bae557f8376e51d296f871f33d56dc541e12.tar.gz pipeworks-f427bae557f8376e51d296f871f33d56dc541e12.tar.bz2 pipeworks-f427bae557f8376e51d296f871f33d56dc541e12.tar.xz pipeworks-f427bae557f8376e51d296f871f33d56dc541e12.zip |
also cache the recipe consumption to get rid of an additional loop per craft
-rw-r--r-- | autocrafter.lua | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/autocrafter.lua b/autocrafter.lua index a60b0d8..0fc5c78 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -39,7 +39,7 @@ local function on_recipe_change(pos, inventory) if recipe_changed then local output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe}) - craft = {recipe = recipe, output = output, decremented_input = decremented_input} + craft = {recipe = recipe, consumption=count_index(recipe), output = output, decremented_input = decremented_input} autocrafterCache[hash] = craft end @@ -75,15 +75,7 @@ local function autocraft(inventory, pos) local output_item = craft.output.item if output_item:is_empty() or not inventory:room_for_item("dst", output_item) then return end - -- determine how much we have to consume each craft - local consumption = {} - for _, item in ipairs(recipe) do - if item and not item:is_empty() then - local item_name = item:get_name() - consumption[item_name] = (consumption[item_name] or 0) + 1 - end - end - + local consumption = craft.consumption local inv_index = count_index(inventory:get_list("src")) -- check if we have enough materials available for itemname, number in pairs(consumption) do |