From 91b2fee45ded14bd70cd588f2c9d9d01dfcaf8c5 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 12 Jun 2017 19:06:33 +0200 Subject: [PATCH] Fix hoppers placing >1 lava buckets into furnace --- mods/ITEMS/mcl_hoppers/init.lua | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index e749512838..92beb3d951 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -235,12 +235,12 @@ minetest.register_abm({ -- Iterates through all items in the given inventory and -- return the slot of the first item which matches a condition -local get_eligible_transfer_item = function(inventory, list, condition) - local size = inventory:get_size(list) +local get_eligible_transfer_item = function(src_inventory, src_list, dst_inventory, dst_list, condition) + local size = src_inventory:get_size(src_list) local stack for i=1, size do - stack = inventory:get_stack(list, i) - if not stack:is_empty() and condition(stack) then + stack = src_inventory:get_stack(src_list, i) + if not stack:is_empty() and condition(stack, src_inventory, src_list, dst_inventory, dst_list) then return i end end @@ -253,6 +253,21 @@ local is_not_shulker_box = function(itemstack) return g == 0 or g == nil end +-- Returns true if itemstack is fuel, but not for lava bucket if destination already has one +local is_transferrable_fuel = function(itemstack, src_inventory, src_list, dst_inventory, dst_list) + if mcl_util.is_fuel(itemstack) then + if itemstack:get_name() == "bucket:bucket_lava" then + return dst_inventory:is_empty(dst_list) + else + return true + end + else + return false + end +end + + + minetest.register_abm({ label = "Hopper/container item exchange", nodenames = {"mcl_hoppers:hopper"}, @@ -288,7 +303,8 @@ minetest.register_abm({ if g == 3 then -- For shulker boxes, only select non-shulker boxes local sinv = minetest.get_inventory({type="node", pos = pos}) - slot_id = get_eligible_transfer_item(sinv, "main", is_not_shulker_box) + local dinv = minetest.get_inventory({type="node", pos = downpos}) + slot_id = get_eligible_transfer_item(sinv, "main", dinv, "main", is_not_shulker_box) end if slot_id then mcl_util.move_item_container(pos, "main", slot_id, downpos) @@ -296,7 +312,6 @@ minetest.register_abm({ end, }) - minetest.register_abm({ label = "Side-hopper/container item exchange", nodenames = {"mcl_hoppers:hopper_side"}, @@ -338,14 +353,16 @@ minetest.register_abm({ elseif g == 3 then -- Put non-shulker boxes into shulker box local sinv = minetest.get_inventory({type="node", pos = pos}) - local slot_id = get_eligible_transfer_item(sinv, "main", is_not_shulker_box) + local dinv = minetest.get_inventory({type="node", pos = front}) + local slot_id = get_eligible_transfer_item(sinv, "main", dinv, "main", is_not_shulker_box) if slot_id then mcl_util.move_item_container(pos, "main", slot_id, front) end elseif g == 4 then -- Put fuel into fuel slot local sinv = minetest.get_inventory({type="node", pos = pos}) - local slot_id = get_eligible_transfer_item(sinv, "main", mcl_util.is_fuel) + local dinv = minetest.get_inventory({type="node", pos = front}) + local slot_id, stack = get_eligible_transfer_item(sinv, "main", dinv, "fuel", is_transferrable_fuel) if slot_id then mcl_util.move_item_container(pos, "main", slot_id, front, "fuel") end