Hoppers: Only put fuels into furnace fuel slots

This commit is contained in:
Wuzzy 2017-02-21 03:22:25 +01:00
parent 649fca5aff
commit 2491213db3

View File

@ -160,6 +160,20 @@ minetest.register_abm({
end, 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({ minetest.register_abm({
nodenames = {"mcl_hoppers:hopper"}, nodenames = {"mcl_hoppers:hopper"},
neighbors = {"group:container"}, neighbors = {"group:container"},
@ -225,7 +239,12 @@ minetest.register_abm({
if g == 2 or g == 3 then if g == 2 or g == 3 then
mcl_util.move_item_container(pos, "main", -1, front) mcl_util.move_item_container(pos, "main", -1, front)
elseif g == 4 then 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
end end
}) })