From e47bd634d4a35a087d342c10629fc7af9cb90612 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 5 Mar 2019 10:29:49 +0100 Subject: [PATCH] Player skins: Update inventory preview (part 2) --- mods/HUD/mcl_inventory/creative.lua | 32 ++++++++++++++++++++++++++++ mods/HUD/mcl_inventory/init.lua | 6 ++++++ mods/PLAYER/simple_skins/depends.txt | 1 + mods/PLAYER/simple_skins/init.lua | 3 +++ 4 files changed, 42 insertions(+) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index f2afb964..d9ad2e94 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -570,6 +570,38 @@ if minetest.settings:get_bool("creative_mode") then end end + mcl_inventory.update_inventory_formspec = function(player) + local page = nil + + local name = player:get_player_name() + + if players[name].page then + page = players[name].page + else + page = "nix" + end + + -- Figure out current scroll bar from formspec + local formspec = player:get_inventory_formspec() + local start_i = players[name].start_i + + local inv_size + if page == "nix" then + local inv = minetest.get_inventory({type="detached", name="creative_"..name}) + inv_size = inv:get_size("main") + elseif page ~= nil and page ~= "inv" then + inv_size = #(inventory_lists[page]) + else + inv_size = 0 + end + + local filter = players[name].filter + if filter == nil then + filter = "" + end + + mcl_inventory.set_creative_formspec(player, start_i, start_i / (9*5) + 1, inv_size, false, page, filter) + end end minetest.register_on_joinplayer(function(player) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 3989af19..415c3075 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -127,6 +127,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end end) +if not minetest.settings:get_bool("creative_mode") then + mcl_inventory.update_inventory_formspec = function(player) + set_inventory(player) + end +end + -- Drop crafting grid items on leaving minetest.register_on_leaveplayer(function(player) return_fields(player, "craft") diff --git a/mods/PLAYER/simple_skins/depends.txt b/mods/PLAYER/simple_skins/depends.txt index 1927ce89..e0804a6f 100644 --- a/mods/PLAYER/simple_skins/depends.txt +++ b/mods/PLAYER/simple_skins/depends.txt @@ -1,3 +1,4 @@ mcl_player +mcl_inventory? intllib? 3d_armor? diff --git a/mods/PLAYER/simple_skins/init.lua b/mods/PLAYER/simple_skins/init.lua index 077278b7..98d3e7e8 100644 --- a/mods/PLAYER/simple_skins/init.lua +++ b/mods/PLAYER/simple_skins/init.lua @@ -72,6 +72,9 @@ skins.set_player_skin = function(player, skin_id) armor.textures[playername].skin = skin .. ".png" armor:update_player_visuals(player) end + if minetest.get_modpath("mcl_inventory") then + mcl_inventory.update_inventory_formspec(player) + end return true end