From 2c5038ad058cff4219b09ce5b6c7c113e7d43fe7 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 5 Mar 2019 01:50:51 +0100 Subject: [PATCH] Player skins: Adjust inventory preview image, too --- mods/HUD/mcl_inventory/creative.lua | 14 ++++-- mods/HUD/mcl_inventory/depends.txt | 1 + mods/HUD/mcl_inventory/init.lua | 15 ++++-- mods/PLAYER/mcl_player/init.lua | 14 +++++- mods/PLAYER/simple_skins/init.lua | 47 +++++++++--------- .../PLAYER/simple_skins/textures/player_1.png | Bin 0 -> 2625 bytes 6 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 mods/PLAYER/simple_skins/textures/player_1.png diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index dd5d0bd8..f2afb964 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -4,6 +4,9 @@ local players = {} -- Containing all the items for each Creative Mode tab local inventory_lists = {} +local show_armor = minetest.get_modpath("3d_armor") ~= nil +local mod_player = minetest.get_modpath("mcl_player") ~= nil + -- TODO: Brewing is disabled. Add brewing (uncommented code) when it is implemented properly -- Create tables @@ -271,15 +274,20 @@ mcl_inventory.set_creative_formspec = function(player, start_i, pagenum, inv_siz inv_bg = "crafting_inventory_creative_survival.png" -- Show armor and player image - local show_armor = minetest.get_modpath("3d_armor") - local img = "player.png" + local img, img_player + if mod_player then + img_player = mcl_player.player_get_preview(player) + else + img_player = "player.png" + end + img = img_player 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 = "player.png"..s1 + img = img_player..s1 end player_preview = "image[3.9,1.4;1.2333,2.4666;"..img.."]" end diff --git a/mods/HUD/mcl_inventory/depends.txt b/mods/HUD/mcl_inventory/depends.txt index a174c0ee..46d93c42 100644 --- a/mods/HUD/mcl_inventory/depends.txt +++ b/mods/HUD/mcl_inventory/depends.txt @@ -1,3 +1,4 @@ mcl_init +mcl_player? _mcl_autogroup? 3d_armor? diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 4bd2ef80..3989af19 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -1,8 +1,7 @@ mcl_inventory = {} -local show_armor = false -if minetest.get_modpath("3d_armor") ~= nil then show_armor = true end - +local show_armor = minetest.get_modpath("3d_armor") ~= nil +local mod_player = minetest.get_modpath("mcl_player") ~= nil -- Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left local function return_item(itemstack, dropper, pos, inv) @@ -59,14 +58,20 @@ local function set_inventory(player, armor_change_only) local player_name = player:get_player_name() -- Show armor and player image - local img = "player.png" + local img, img_player + if mod_player then + img_player = mcl_player.player_get_preview(player) + else + img_player = "player.png" + end + img = img_player 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") if s1 ~= nil then s1 = img:sub(s1+21) - img = "player.png"..s1 + img = img_player..s1 end player_preview = "image[1.1,0.2;2,4;"..img.."]" end diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index 599acd65..b01c0b4d 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -70,10 +70,22 @@ function mcl_player.player_set_model(player, model_name) player_model[name] = model_name end -function mcl_player.player_set_textures(player, textures) +function mcl_player.player_set_textures(player, textures, preview) local name = player:get_player_name() player_textures[name] = textures player:set_properties({textures = textures,}) + if preview then + player:set_attribute("mcl_player:preview", preview) + end +end + +function mcl_player.player_get_preview(player) + local preview = player:get_attribute("mcl_player:preview") + if not preview then + return "player.png" + else + return preview + end end function mcl_player.player_set_animation(player, anim_name, speed) diff --git a/mods/PLAYER/simple_skins/init.lua b/mods/PLAYER/simple_skins/init.lua index 3a41490f..077278b7 100644 --- a/mods/PLAYER/simple_skins/init.lua +++ b/mods/PLAYER/simple_skins/init.lua @@ -3,7 +3,7 @@ -- Released by TenPlus1 and based on Zeg9's code under MIT license skins = { - skins = {}, meta = {}, + skins = {}, previews = {}, meta = {}, modpath = minetest.get_modpath("simple_skins"), skin_count = 0, -- counter of _custom_ skins (all skins except character.png) } @@ -49,18 +49,30 @@ while true do skins.skin_count = skins.skin_count + 1 end -skins.set_player_skin = function(player, skin) +skins.set_player_skin = function(player, skin_id) if not player then - return + return false end local playername = player:get_player_name() + local skin, preview + if skin_id == nil or type(skin_id) ~= "number" or skin_id < 0 or skin_id > skins.skin_count then + return false + elseif skin_id == 0 then + skin = "character" + preview = "player" + else + skin = "character_" .. tostring(skin_id) + preview = "player_" .. tostring(skin_id) + end skins.skins[playername] = skin - player:set_attribute("simple_skins:skin", skins.skins[playername]) + skins.previews[playername] = preview + player:set_attribute("simple_skins:skin_id", skin_id) skins.update_player_skin(player) if minetest.get_modpath("3d_armor") then armor.textures[playername].skin = skin .. ".png" armor:update_player_visuals(player) end + return true end skins.update_player_skin = function(player) @@ -68,27 +80,21 @@ skins.update_player_skin = function(player) return end local playername = player:get_player_name() - mcl_player.player_set_textures(player, { skins.skins[playername] .. ".png" }) + mcl_player.player_set_textures(player, { skins.skins[playername] .. ".png" }, skins.previews[playername] .. ".png" ) end -- load player skin on join minetest.register_on_joinplayer(function(player) local name = player:get_player_name() - local skin = player:get_attribute("simple_skins:skin") + local skin_id = player:get_attribute("simple_skins:skin_id") local set_skin -- do we already have a skin in player attributes? - if skin then - set_skin = skin - + if skin_id then + set_skin = tonumber(skin_id) -- otherwise use random skin if not set else - local r = math.random(0, skins.skin_count) - if r == 0 then - set_skin = "character" - else - set_skin = "character_" .. r - end + set_skin = math.random(0, skins.skin_count) end if set_skin then skins.set_player_skin(player, set_skin) @@ -125,16 +131,11 @@ minetest.register_chatcommand("setskin", { end local skin - if skin_id == nil or skin_id > skins.skin_count or skin_id < 0 then + local ok = skins.set_player_skin(player, skin_id) + if not ok then return false, S("Invalid skin number! Valid numbers: 0 to @1", skins.skin_count) - elseif skin_id == 0 then - skin = "character" - else - skin = "character_" .. tostring(skin_id) end - - skins.set_player_skin(player, skin) - local skinfile = skin..".png" + local skinfile = "Skin #"..skin_id local your_msg = S("Your skin has been set to: @1", skinfile) if name == playername then diff --git a/mods/PLAYER/simple_skins/textures/player_1.png b/mods/PLAYER/simple_skins/textures/player_1.png new file mode 100644 index 0000000000000000000000000000000000000000..3d7af2a980c2412be1f72e39fd6d7ffeda8f7fb3 GIT binary patch literal 2625 zcmV-H3cmG;P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+O3yqa^*MbOT=L03%Wmi{6 z^u#>*NqQ7T5}Anv?e>5EecZqJgkGb|Qd{Yzcs{x39+jKspU-m*KHu~E!++d-Yj^SE zL8K{hP0!D=-~LLwe7#Wf+djUxyE@--+B;DA9Qb~c&20B?zxEE4;?o}9->$#!Y5pag z_Z#Os>^u0+-?;+D62?o>#hpU(oSV&(SV8JZxu$y-I$4|YmFN7|*tzxx@ILQ;VCVI1 zPv4<%zPugE4~*XSAV1pE=QQ!#io(~--yZb!ImK_-owM3G`-x6-0jc8NpguymcXS*; zneJpeP0Bg6?~3pNMGbfJd`+9%|&f`$|Jz0NRMVvajjt})J-Zd*$=_BbyA z*^Y2xg`VY7gR2Q^iRSpZmT>3ocfJ`KGp|6;7#J+@#&3uFtH%H3_#EgQlWqvUJvg;X za5PP`3}epD^n#FZUQFfUdk^=EZu~FACK!|pb0a|Y;~8Q|_|jIoJSX~z&(1%o5$bve z03zlV784Q-_=1>23BJZyLjcDHKg!Bu%5lIz5Q!_e12-uZ$Z65$=A9aD-zf2E##$gk zQb`qRNFd0{S6sE#<&$U{aMb+plkPUJK5lv!q-ZT6`vuCz%1RaSMY zt-f@Jjg)rYvdgZ!?Y{M(wUbUha>}WvoqqI_weY6xH`c-r=Kh|w@Umu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