mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-29 22:33:46 +01:00
Implement item transfer from large src container
parent
d0b1e261ea
commit
4e45d66678
@ -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")
|
||||||
return false
|
if not pos then
|
||||||
end
|
return false
|
||||||
dnode = minetest.get_node(dpos)
|
end
|
||||||
dctype = minetest.get_item_group(dnode.name, "container")
|
node = minetest.get_node(pos)
|
||||||
-- The left segment seems incorrect? We better bail out!
|
ctype = minetest.get_item_group(node.name, "container")
|
||||||
if dctype ~= 5 then
|
-- The left segment seems incorrect? We better bail out!
|
||||||
return false
|
if ctype ~= 5 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return pos, node, ctype
|
||||||
end
|
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,9 +256,21 @@ 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
|
||||||
return false
|
-- 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
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user