forked from MineClone5/MineClone5
Fix hoppers placing >1 lava buckets into furnace
This commit is contained in:
parent
dd7980553a
commit
91b2fee45d
|
@ -235,12 +235,12 @@ minetest.register_abm({
|
||||||
|
|
||||||
-- Iterates through all items in the given inventory and
|
-- Iterates through all items in the given inventory and
|
||||||
-- return the slot of the first item which matches a condition
|
-- return the slot of the first item which matches a condition
|
||||||
local get_eligible_transfer_item = function(inventory, list, condition)
|
local get_eligible_transfer_item = function(src_inventory, src_list, dst_inventory, dst_list, condition)
|
||||||
local size = inventory:get_size(list)
|
local size = src_inventory:get_size(src_list)
|
||||||
local stack
|
local stack
|
||||||
for i=1, size do
|
for i=1, size do
|
||||||
stack = inventory:get_stack(list, i)
|
stack = src_inventory:get_stack(src_list, i)
|
||||||
if not stack:is_empty() and condition(stack) then
|
if not stack:is_empty() and condition(stack, src_inventory, src_list, dst_inventory, dst_list) then
|
||||||
return i
|
return i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -253,6 +253,21 @@ local is_not_shulker_box = function(itemstack)
|
||||||
return g == 0 or g == nil
|
return g == 0 or g == nil
|
||||||
end
|
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({
|
minetest.register_abm({
|
||||||
label = "Hopper/container item exchange",
|
label = "Hopper/container item exchange",
|
||||||
nodenames = {"mcl_hoppers:hopper"},
|
nodenames = {"mcl_hoppers:hopper"},
|
||||||
|
@ -288,7 +303,8 @@ minetest.register_abm({
|
||||||
if g == 3 then
|
if g == 3 then
|
||||||
-- For shulker boxes, only select non-shulker boxes
|
-- For shulker boxes, only select non-shulker boxes
|
||||||
local sinv = minetest.get_inventory({type="node", pos = pos})
|
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
|
end
|
||||||
if slot_id then
|
if slot_id then
|
||||||
mcl_util.move_item_container(pos, "main", slot_id, downpos)
|
mcl_util.move_item_container(pos, "main", slot_id, downpos)
|
||||||
|
@ -296,7 +312,6 @@ minetest.register_abm({
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
label = "Side-hopper/container item exchange",
|
label = "Side-hopper/container item exchange",
|
||||||
nodenames = {"mcl_hoppers:hopper_side"},
|
nodenames = {"mcl_hoppers:hopper_side"},
|
||||||
|
@ -338,14 +353,16 @@ minetest.register_abm({
|
||||||
elseif g == 3 then
|
elseif g == 3 then
|
||||||
-- Put non-shulker boxes into shulker box
|
-- Put non-shulker boxes into shulker box
|
||||||
local sinv = minetest.get_inventory({type="node", pos = pos})
|
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
|
if slot_id then
|
||||||
mcl_util.move_item_container(pos, "main", slot_id, front)
|
mcl_util.move_item_container(pos, "main", slot_id, front)
|
||||||
end
|
end
|
||||||
elseif g == 4 then
|
elseif g == 4 then
|
||||||
-- Put fuel into fuel slot
|
-- Put fuel into fuel slot
|
||||||
local sinv = minetest.get_inventory({type="node", pos = pos})
|
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
|
if slot_id then
|
||||||
mcl_util.move_item_container(pos, "main", slot_id, front, "fuel")
|
mcl_util.move_item_container(pos, "main", slot_id, front, "fuel")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue