Do not take remainder stacks.
This commit is contained in:
parent
c400f9d6b9
commit
f78a47cd6f
|
@ -331,32 +331,24 @@ function unified_inventory.move_match(player, src_list, dst_list, match_table, a
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local item_drop = minetest.item_drop
|
local item_drop = minetest.item_drop
|
||||||
local src_dst_list = {src_list, dst_list}
|
local src_dst_list = {src_list, dst_list}
|
||||||
|
local dst_src_list = {dst_list, src_list}
|
||||||
|
|
||||||
local needed = {}
|
local needed = {}
|
||||||
local remained = {}
|
|
||||||
local moved = {}
|
local moved = {}
|
||||||
|
|
||||||
|
-- Remove stacks needed for craft
|
||||||
for item, pos_set in pairs(match_table) do
|
for item, pos_set in pairs(match_table) do
|
||||||
local stack = ItemStack(item)
|
local stack = ItemStack(item)
|
||||||
local stack_max = stack:get_stack_max()
|
local stack_max = stack:get_stack_max()
|
||||||
local bounded_amount = math.min(stack_max, amount)
|
local bounded_amount = math.min(stack_max, amount)
|
||||||
|
|
||||||
-- Remove stacks needed for craft
|
|
||||||
stack:set_count(bounded_amount)
|
stack:set_count(bounded_amount)
|
||||||
|
|
||||||
for pos in pairs(pos_set) do
|
for pos in pairs(pos_set) do
|
||||||
needed[pos] = unified_inventory.remove_item(inv, src_dst_list, stack)
|
needed[pos] = unified_inventory.remove_item(inv, dst_src_list, stack)
|
||||||
end
|
|
||||||
|
|
||||||
-- Remove remainder to free up positions
|
|
||||||
stack:set_count(stack_max)
|
|
||||||
|
|
||||||
for pos in pairs(pos_set) do
|
|
||||||
remained[pos] = unified_inventory.remove_item(inv, src_dst_list, stack)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Move only needed stacks
|
-- Add already removed stacks
|
||||||
for pos, stack in pairs(needed) do
|
for pos, stack in pairs(needed) do
|
||||||
local occupied = inv:get_stack(dst_list, pos)
|
local occupied = inv:get_stack(dst_list, pos)
|
||||||
inv:set_stack(dst_list, pos, stack)
|
inv:set_stack(dst_list, pos, stack)
|
||||||
|
@ -377,16 +369,8 @@ function unified_inventory.move_match(player, src_list, dst_list, match_table, a
|
||||||
moved[pos] = true
|
moved[pos] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Swap items from unused positions to src (moved positions excluded)
|
||||||
unified_inventory.swap_items(inv, dst_list, src_list, moved)
|
unified_inventory.swap_items(inv, dst_list, src_list, moved)
|
||||||
|
|
||||||
-- Re-add remainder stacks
|
|
||||||
for _, stack in pairs(remained) do
|
|
||||||
local oversize = unified_inventory.add_item(inv, src_dst_list, stack)
|
|
||||||
|
|
||||||
if not oversize:is_empty() then
|
|
||||||
item_drop(oversize, player, player:get_pos())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
|
Loading…
Reference in New Issue