From 04daa1295bbdb16d4f168141143248161f3de89f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 9 Mar 2017 18:26:16 +0100 Subject: [PATCH] Show player preview in creative inventory --- mods/HUD/mcl_inventory/creative.lua | 18 ++++++++++++++++++ mods/HUD/mcl_inventory/init.lua | 16 +++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 8dec62f44..8ab1fd5e9 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -210,6 +210,22 @@ mcl_inventory.set_creative_formspec = function(player, start_i, pagenum, show, p if name == "inv" then inv_bg = "crafting_inventory_creative_survival.png" + -- Show armor and player image + local show_armor = minetest.get_modpath("3d_armor") + -- TODO: Use player.png to allow for custom skins + local img = "crafting_player2d.png" + local armor_img = "" + local player_preview = "image[3.9,1.4;1.2333,2.4666;"..img.."]" + if show_armor and armor.textures[playername] and armor.textures[playername].preview then + img = armor.textures[playername].preview + local s1 = img:find("character_preview") + if s1 ~= nil then + s1 = img:sub(s1+21) + img = "crafting_player2d.png"..s1 + end + player_preview = "image[3.9,1.4;1.2333,2.4666;"..img.."]" + end + -- Background images for armor slots (hide if occupied) local armor_slot_imgs = "" local inv = player:get_inventory() @@ -234,6 +250,8 @@ mcl_inventory.set_creative_formspec = function(player, start_i, pagenum, show, p "list[detached:"..playername.."_armor;armor;5.5,1.3;1,1;3]".. "list[detached:"..playername.."_armor;armor;5.5,2.75;1,1;4]".. armor_slot_imgs.. + -- player preview + player_preview.. -- crafting guide button "image_button[9,1;1,1;craftguide_book.png;__mcl_craftguide;]".. "tooltip[__mcl_craftguide;Show crafting recipes]".. diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index be17a2642..1b54cb021 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -31,8 +31,6 @@ local function drop_fields(player, name) end end -local player_armor = {} - local function update_armor(player) return end @@ -47,16 +45,12 @@ local function set_inventory(player) inv:set_size("craft", 4) local player_name = player:get_player_name() + + -- Show armor and player image -- TODO: Use player.png to allow for custom skins local img = "crafting_player2d.png" local armor_img = "" - if show_armor then - armor_img = "" - if player_armor[player_name] ~= nil then - img = img .. player_armor[player_name] - end - end - local img_element = "image[0.6,0.2;3,4;"..img.."]" + local player_preview = "image[0.6,0.2;2,4;"..img.."]" if show_armor and armor.textures[player_name] and armor.textures[player_name].preview then img = armor.textures[player_name].preview local s1 = img:find("character_preview") @@ -64,7 +58,7 @@ local function set_inventory(player) s1 = img:sub(s1+21) img = "crafting_player2d.png"..s1 end - img_element = "image[1.1,0.2;2,4;"..img.."]" + player_preview = "image[1.1,0.2;2,4;"..img.."]" end local armor_slots = {"head", "torso", "legs", "feet"} @@ -78,7 +72,7 @@ local function set_inventory(player) local form = "size[9,8.75]".. "background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png^crafting_inventory.png"..armor_img.."]".. mcl_vars.inventory_header.. - img_element.. + player_preview.. --armor "list[detached:"..player_name.."_armor;armor;0,0;1,1;1]".. "list[detached:"..player_name.."_armor;armor;0,1;1,1;2]"..