From 33c7cbf09e3bd9a0a6cb52bfc1fd769a68e81d94 Mon Sep 17 00:00:00 2001 From: Michal Cieslakiewicz Date: Mon, 19 Nov 2018 13:37:04 +0100 Subject: [PATCH] biogasmachines: gasifier: fixed working tray item processing. Fixed incorrect behaviour when machine was restarted with non-empty working tray. Now device checks this tray before source (input) inventory and if item is present, sets it for processing. Signed-off-by: Michal Cieslakiewicz --- biogasmachines/gasifier.lua | 48 ++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/biogasmachines/gasifier.lua b/biogasmachines/gasifier.lua index dc60314..824ec2b 100644 --- a/biogasmachines/gasifier.lua +++ b/biogasmachines/gasifier.lua @@ -416,27 +416,37 @@ local function on_timer(pos, elapsed) end -- choose item local inputname = nil - for i, r in pairs(biogas_recipes) do - if inv:contains_item("src", ItemStack(i .. " 1")) and - inv:room_for_item("dst", - ItemStack("tubelib_addons1:biogas " .. - tostring(r.count))) and - (not r.extra or inv:room_for_item("dst", r.extra)) - then - inputname = i - prodtime = r.time - break + if not inv:is_empty("cur") then + -- leftover item, start from beginning + local inp = inv:get_stack("cur", 1) + inputname = inp:get_name() + if not biogas_recipes[inputname] then + return gasifier_fault(pos) -- oops end + prodtime = biogas_recipes[inputname].time + else + -- prepare item, next tick will start processing + for i, r in pairs(biogas_recipes) do + if inv:contains_item("src", ItemStack(i .. " 1")) and + inv:room_for_item("dst", + ItemStack("tubelib_addons1:biogas " .. + tostring(r.count))) and + (not r.extra or inv:room_for_item("dst", r.extra)) + then + inputname = i + prodtime = r.time + break + end + end + if not inputname then + return true + end + local inp = inv:remove_item("src", ItemStack(inputname .. " 1")) + if inp:is_empty() then + return gasifier_fault(pos) -- oops + end + inv:add_item("cur", inp) end - if not inputname then - return true - end - -- move item to working tray, next tick will start processing - local inp = inv:remove_item("src", ItemStack(inputname .. " 1")) - if inp:is_empty() then - return gasifier_fault(pos) -- oops - end - inv:add_item("cur", inp) meta:set_string("item_name", inputname) itemcnt = prodtime else