diff --git a/technic/helpers.lua b/technic/helpers.lua index 5caff842..b860e067 100644 --- a/technic/helpers.lua +++ b/technic/helpers.lua @@ -272,3 +272,16 @@ function technic.can_insert_unique_stack(pos, node, incoming_stack, direction) end return technic.default_can_insert(pos, node, incoming_stack, direction) end + +function technic.process_recipe(recipe, inv) + local dst_copy = inv:get_list("dst") + for _,item in ipairs(recipe.output) do + if not inv:room_for_item("dst", ItemStack(item)) then + inv:set_list("dst", dst_copy) + return false + end + inv:add_item("dst", item) + end + inv:set_list("src", recipe.new_input) + return true +end diff --git a/technic/machines/other/coal_alloy_furnace.lua b/technic/machines/other/coal_alloy_furnace.lua index b81d81cb..198d4db8 100644 --- a/technic/machines/other/coal_alloy_furnace.lua +++ b/technic/machines/other/coal_alloy_furnace.lua @@ -118,22 +118,18 @@ minetest.register_abm({ end -- Get what to cook if anything - local result = technic.get_recipe("alloy", inv:get_list("src")) + local recipe = technic.get_recipe("alloy", inv:get_list("src")) local was_active = false if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then was_active = true meta:set_int("fuel_time", meta:get_int("fuel_time") + 1) - if result then + if recipe then meta:set_int("src_time", meta:get_int("src_time") + 1) - if meta:get_int("src_time") >= result.time then + if meta:get_int("src_time") >= recipe.time then meta:set_int("src_time", 0) - local result_stack = ItemStack(result.output) - if inv:room_for_item("dst", result_stack) then - inv:set_list("src", result.new_input) - inv:add_item("dst", result_stack) - end + technic.process_recipe(recipe, inv) end else meta:set_int("src_time", 0) @@ -175,9 +171,7 @@ minetest.register_abm({ return end - local recipe = technic.get_recipe("alloy", inv:get_list("src")) - - if not recipe then + if not technic.get_recipe("alloy", inv:get_list("src")) then if was_active then meta:set_string("infotext", S("@1 is empty", machine_name)) technic.swap_node(pos, "technic:coal_alloy_furnace") diff --git a/technic/machines/register/machine_base.lua b/technic/machines/register/machine_base.lua index e4841043..e2c04a64 100644 --- a/technic/machines/register/machine_base.lua +++ b/technic/machines/register/machine_base.lua @@ -132,8 +132,8 @@ function technic.register_base_machine(nodename, data) meta:set_int("src_time", meta:get_int("src_time") + round(def.speed*10)) end while true do - local result = inv:get_list("src") and technic.get_recipe(typename, inv:get_list("src")) - if not result then + local recipe = inv:get_list("src") and technic.get_recipe(typename, inv:get_list("src")) + if not recipe then technic.swap_node(pos, nodename) meta:set_string("infotext", infotext_idle) meta:set_int(tier.."_EU_demand", 0) @@ -144,39 +144,21 @@ function technic.register_base_machine(nodename, data) technic.swap_node(pos, nodename.."_active") meta:set_string("infotext", infotext_active .. "\n" .. S("Demand: @1", technic.EU_string(machine_demand[EU_upgrade+1]))) - if meta:get_int("src_time") < round(result.time*10) then + if meta:get_int("src_time") < round(recipe.time*10) then if not powered then technic.swap_node(pos, nodename) meta:set_string("infotext", infotext_unpowered) end return end - local output = result.output - if type(output) ~= "table" then output = { output } end - local output_stacks = {} - for _, o in ipairs(output) do - table.insert(output_stacks, ItemStack(o)) - end - local room_for_output = true - inv:set_size("dst_tmp", inv:get_size("dst")) - inv:set_list("dst_tmp", inv:get_list("dst")) - for _, o in ipairs(output_stacks) do - if not inv:room_for_item("dst_tmp", o) then - room_for_output = false - break - end - inv:add_item("dst_tmp", o) - end - if not room_for_output then + if not technic.process_recipe(recipe, inv) then technic.swap_node(pos, nodename) meta:set_string("infotext", infotext_idle) meta:set_int(tier.."_EU_demand", 0) - meta:set_int("src_time", round(result.time*10)) + meta:set_int("src_time", round(recipe.time*10)) return end - meta:set_int("src_time", meta:get_int("src_time") - round(result.time*10)) - inv:set_list("src", result.new_input) - inv:set_list("dst", inv:get_list("dst_tmp")) + meta:set_int("src_time", meta:get_int("src_time") - round(recipe.time*10)) end end