Implement item transfer from large src container

This commit is contained in:
Wuzzy 2017-08-04 03:34:28 +02:00
parent d0b1e261ea
commit 4e45d66678
1 changed files with 37 additions and 17 deletions

View File

@ -198,27 +198,35 @@ end
-- Returns true on success and false on failure. -- Returns true on success and false on failure.
function mcl_util.move_item_container(source_pos, destination_pos, source_list, source_stack_id, destination_list) function mcl_util.move_item_container(source_pos, destination_pos, source_list, source_stack_id, destination_list)
local dpos = table.copy(destination_pos) local dpos = table.copy(destination_pos)
local snode = minetest.get_node(source_pos) local spos = table.copy(source_pos)
local dnode = minetest.get_node(destination_pos) local snode = minetest.get_node(spos)
local dnode = minetest.get_node(dpos)
local dctype = minetest.get_item_group(dnode.name, "container") local dctype = minetest.get_item_group(dnode.name, "container")
local sctype = minetest.get_item_group(snode.name, "container") local sctype = minetest.get_item_group(snode.name, "container")
-- Normalize double container by forcing to always use the left segment first -- Normalize double container by forcing to always use the left segment first
if dctype == 6 then local normalize_double_container = function(pos, node, ctype)
dpos = mcl_util.get_double_container_neighbor_pos(destination_pos, dnode.param2, "right") if ctype == 6 then
if not dpos then pos = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right")
if not pos then
return false return false
end end
dnode = minetest.get_node(dpos) node = minetest.get_node(pos)
dctype = minetest.get_item_group(dnode.name, "container") ctype = minetest.get_item_group(node.name, "container")
-- The left segment seems incorrect? We better bail out! -- The left segment seems incorrect? We better bail out!
if dctype ~= 5 then if ctype ~= 5 then
return false return false
end end
end end
return pos, node, ctype
end
local smeta = minetest.get_meta(source_pos) spos, snode, sctype = normalize_double_container(spos, snode, sctype)
dpos, dnode, dctype = normalize_double_container(dpos, dnode, dctype)
if not spos or not dpos then return false end
local smeta = minetest.get_meta(spos)
local dmeta = minetest.get_meta(dpos) local dmeta = minetest.get_meta(dpos)
local sinv = smeta:get_inventory() local sinv = smeta:get_inventory()
@ -238,7 +246,7 @@ function mcl_util.move_item_container(source_pos, destination_pos, source_list,
end end
end end
-- Automatically select stack ID if set to automatic -- Automatically select stack slot ID if set to automatic
if not source_stack_id then if not source_stack_id then
source_stack_id = -1 source_stack_id = -1
end end
@ -248,10 +256,22 @@ function mcl_util.move_item_container(source_pos, destination_pos, source_list,
if dctype == 3 then if dctype == 3 then
cond = is_not_shulker_box cond = is_not_shulker_box
end end
source_stack_id = mcl_util.get_eligible_transfer_item_slot(sinv, source_list, dinv, destination_list, cond) source_stack_id = mcl_util.get_eligible_transfer_item_slot(sinv, source_list, dinv, dpos, cond)
if source_stack_id == nil then if not source_stack_id then
-- Try again if source is a double container
if sctype == 5 then
spos = mcl_util.get_double_container_neighbor_pos(spos, snode.param2, "left")
smeta = minetest.get_meta(spos)
sinv = smeta:get_inventory()
source_stack_id = mcl_util.get_eligible_transfer_item_slot(sinv, source_list, dinv, dpos, cond)
if not source_stack_id then
return false return false
end end
else
return false
end
end
end end
-- Abort transfer if shulker box wants to go into shulker box -- Abort transfer if shulker box wants to go into shulker box