From 80ab1f0a3c0cfe9bb8180802fc297f0bf4c559bc Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sat, 13 Jan 2024 13:01:48 -0600 Subject: [PATCH] =?UTF-8?q?When=20reducing=20inventory=E2=80=99s=20size,?= =?UTF-8?q?=20drop=20extra=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now items that can’t fit in the new inventory are dropped, so the player doesn’t lose anything. --- i4/src/common.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/i4/src/common.lua b/i4/src/common.lua index 34602fa..17cbb7d 100644 --- a/i4/src/common.lua +++ b/i4/src/common.lua @@ -678,7 +678,17 @@ local function update_inv_size(player, data) data.hotbar_len = data.legacy_inventory and 8 or 9 data.inv_size = 4 * data.hotbar_len + 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) player:hud_set_hotbar_itemcount(data.hotbar_len)