From f93773ef314b92bd5045ef4b4e80bfd90658fb60 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Tue, 18 May 2021 21:28:14 +0200 Subject: [PATCH] Fix wheat recipe issue --- basic_machines/grinder.lua | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/basic_machines/grinder.lua b/basic_machines/grinder.lua index 53a3b7b..3bcf3f2 100644 --- a/basic_machines/grinder.lua +++ b/basic_machines/grinder.lua @@ -75,24 +75,25 @@ end -- Grinder normaly handles 'num_items' per cycle. 'num_items' is node stage dependent. -- But if 'inp_num' > 1 (wheat recipes), use 'inp_num' and produce one output item. -local function src_to_dst(src_stack, idx, num_items, inp_num, inv, dst_name, num_input) - local taken, output +local function src_to_dst(src_stack, idx, src_name, num_items, inp_num, inv, dst_name) if inp_num > 1 then - if src_stack:get_count() >= inp_num then - taken = src_stack:take_item(inp_num) - output = ItemStack(dst_name) - else - return false + local input = ItemStack(src_name) + input:set_count(inp_num) + local output = ItemStack(dst_name) + if inv:contains_item("src", input) and inv:room_for_item("dst", output) then + inv:remove_item("src", input) + inv:add_item("dst", output) + return true end else - taken = src_stack:take_item(num_items) - output = ItemStack(dst_name) + local taken = src_stack:take_item(num_items) + local output = ItemStack(dst_name) output:set_count(output:get_count() * taken:get_count()) - end - if inv:room_for_item("dst", output) then - inv:set_stack("src", idx, src_stack) - inv:add_item("dst", output) - return true + if inv:room_for_item("dst", output) then + inv:set_stack("src", idx, src_stack) + inv:add_item("dst", output) + return true + end end return false end @@ -104,7 +105,7 @@ local function grinding(pos, crd, nvm, inv) local name = stack:get_name() if Recipes[name] then local recipe = Recipes[name] - if src_to_dst(stack, idx, crd.num_items, recipe.inp_num, inv, recipe.output) then + if src_to_dst(stack, idx, name, crd.num_items, recipe.inp_num, inv, recipe.output) then crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) else crd.State:blocked(pos, nvm)