Player skins: Adjust inventory preview image, too

This commit is contained in:
Wuzzy 2019-03-05 01:50:51 +01:00
parent a4d40560c3
commit 2c5038ad05
6 changed files with 59 additions and 32 deletions

View File

@ -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

View File

@ -1,3 +1,4 @@
mcl_init
mcl_player?
_mcl_autogroup?
3d_armor?

View File

@ -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

View File

@ -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)

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB