From 2491213db3a5b461fdaa36b515e9b9f6ece13ff0 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 21 Feb 2017 03:22:25 +0100 Subject: [PATCH] Hoppers: Only put fuels into furnace fuel slots --- mods/ITEMS/mcl_hoppers/init.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index 9c4f7ad0e..3b426dd02 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -160,6 +160,20 @@ minetest.register_abm({ end, }) +-- 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 stack + for i=1, size do + stack = inventory:get_stack(list, i) + if not stack:is_empty() and condition(stack) then + return i + end + end + return nil +end + minetest.register_abm({ nodenames = {"mcl_hoppers:hopper"}, neighbors = {"group:container"}, @@ -225,7 +239,12 @@ minetest.register_abm({ if g == 2 or g == 3 then mcl_util.move_item_container(pos, "main", -1, front) elseif g == 4 then - mcl_util.move_item_container(pos, "main", -1, front, "fuel") + -- Put fuel into fuel slot + local inv = minetest.get_inventory({type="node", pos = pos}) + local slot_id = get_eligible_transfer_item(inv, "main", mcl_util.is_fuel) + if slot_id then + mcl_util.move_item_container(pos, "main", slot_id, front, "fuel") + end end end })