When reducing inventory’s size, drop extra items
Now items that can’t fit in the new inventory are dropped, so the player doesn’t lose anything.
This commit is contained in:
parent
66ddd2571c
commit
80ab1f0a3c
|
@ -678,7 +678,17 @@ local function update_inv_size(player, data)
|
||||||
data.hotbar_len = data.legacy_inventory and 8 or 9
|
data.hotbar_len = data.legacy_inventory and 8 or 9
|
||||||
data.inv_size = 4 * data.hotbar_len
|
data.inv_size = 4 * data.hotbar_len
|
||||||
|
|
||||||
|
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
local inv_size = inv:get_size("main")
|
||||||
|
-- Drop items that can’t fit in new inventory size.
|
||||||
|
if inv_size > data.inv_size then
|
||||||
|
sort_inventory(player, data)
|
||||||
|
for i = data.inv_size + 1, inv_size, 1 do
|
||||||
|
minetest.item_drop(inv:get_stack("main", i), player, player:get_pos())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
inv:set_size("main", data.inv_size)
|
inv:set_size("main", data.inv_size)
|
||||||
|
|
||||||
player:hud_set_hotbar_itemcount(data.hotbar_len)
|
player:hud_set_hotbar_itemcount(data.hotbar_len)
|
||||||
|
|
Ŝarĝante…
Reference in New Issue