forked from VoxeLibre/VoxeLibre
Player skins: Adjust inventory preview image, too
This commit is contained in:
parent
a4d40560c3
commit
2c5038ad05
|
@ -4,6 +4,9 @@ local players = {}
|
||||||
-- Containing all the items for each Creative Mode tab
|
-- Containing all the items for each Creative Mode tab
|
||||||
local inventory_lists = {}
|
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
|
-- TODO: Brewing is disabled. Add brewing (uncommented code) when it is implemented properly
|
||||||
|
|
||||||
-- Create tables
|
-- 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"
|
inv_bg = "crafting_inventory_creative_survival.png"
|
||||||
|
|
||||||
-- Show armor and player image
|
-- Show armor and player image
|
||||||
local show_armor = minetest.get_modpath("3d_armor")
|
local img, img_player
|
||||||
local img = "player.png"
|
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.."]"
|
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
|
if show_armor and armor.textures[playername] and armor.textures[playername].preview then
|
||||||
img = armor.textures[playername].preview
|
img = armor.textures[playername].preview
|
||||||
local s1 = img:find("character_preview")
|
local s1 = img:find("character_preview")
|
||||||
if s1 ~= nil then
|
if s1 ~= nil then
|
||||||
s1 = img:sub(s1+21)
|
s1 = img:sub(s1+21)
|
||||||
img = "player.png"..s1
|
img = img_player..s1
|
||||||
end
|
end
|
||||||
player_preview = "image[3.9,1.4;1.2333,2.4666;"..img.."]"
|
player_preview = "image[3.9,1.4;1.2333,2.4666;"..img.."]"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
mcl_init
|
mcl_init
|
||||||
|
mcl_player?
|
||||||
_mcl_autogroup?
|
_mcl_autogroup?
|
||||||
3d_armor?
|
3d_armor?
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
mcl_inventory = {}
|
mcl_inventory = {}
|
||||||
|
|
||||||
local show_armor = false
|
local show_armor = minetest.get_modpath("3d_armor") ~= nil
|
||||||
if minetest.get_modpath("3d_armor") ~= nil then show_armor = true end
|
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
|
-- 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)
|
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()
|
local player_name = player:get_player_name()
|
||||||
|
|
||||||
-- Show armor and player image
|
-- 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.."]"
|
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
|
if show_armor and armor.textures[player_name] and armor.textures[player_name].preview then
|
||||||
img = armor.textures[player_name].preview
|
img = armor.textures[player_name].preview
|
||||||
local s1 = img:find("character_preview")
|
local s1 = img:find("character_preview")
|
||||||
if s1 ~= nil then
|
if s1 ~= nil then
|
||||||
s1 = img:sub(s1+21)
|
s1 = img:sub(s1+21)
|
||||||
img = "player.png"..s1
|
img = img_player..s1
|
||||||
end
|
end
|
||||||
player_preview = "image[1.1,0.2;2,4;"..img.."]"
|
player_preview = "image[1.1,0.2;2,4;"..img.."]"
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,10 +70,22 @@ function mcl_player.player_set_model(player, model_name)
|
||||||
player_model[name] = model_name
|
player_model[name] = model_name
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_player.player_set_textures(player, textures)
|
function mcl_player.player_set_textures(player, textures, preview)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
player_textures[name] = textures
|
player_textures[name] = textures
|
||||||
player:set_properties({textures = 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
|
end
|
||||||
|
|
||||||
function mcl_player.player_set_animation(player, anim_name, speed)
|
function mcl_player.player_set_animation(player, anim_name, speed)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
-- Released by TenPlus1 and based on Zeg9's code under MIT license
|
-- Released by TenPlus1 and based on Zeg9's code under MIT license
|
||||||
|
|
||||||
skins = {
|
skins = {
|
||||||
skins = {}, meta = {},
|
skins = {}, previews = {}, meta = {},
|
||||||
modpath = minetest.get_modpath("simple_skins"),
|
modpath = minetest.get_modpath("simple_skins"),
|
||||||
skin_count = 0, -- counter of _custom_ skins (all skins except character.png)
|
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
|
skins.skin_count = skins.skin_count + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
skins.set_player_skin = function(player, skin)
|
skins.set_player_skin = function(player, skin_id)
|
||||||
if not player then
|
if not player then
|
||||||
return
|
return false
|
||||||
end
|
end
|
||||||
local playername = player:get_player_name()
|
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
|
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)
|
skins.update_player_skin(player)
|
||||||
if minetest.get_modpath("3d_armor") then
|
if minetest.get_modpath("3d_armor") then
|
||||||
armor.textures[playername].skin = skin .. ".png"
|
armor.textures[playername].skin = skin .. ".png"
|
||||||
armor:update_player_visuals(player)
|
armor:update_player_visuals(player)
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
skins.update_player_skin = function(player)
|
skins.update_player_skin = function(player)
|
||||||
|
@ -68,27 +80,21 @@ skins.update_player_skin = function(player)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local playername = player:get_player_name()
|
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
|
end
|
||||||
|
|
||||||
-- load player skin on join
|
-- load player skin on join
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
|
||||||
local name = player:get_player_name()
|
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
|
local set_skin
|
||||||
-- do we already have a skin in player attributes?
|
-- do we already have a skin in player attributes?
|
||||||
if skin then
|
if skin_id then
|
||||||
set_skin = skin
|
set_skin = tonumber(skin_id)
|
||||||
|
|
||||||
-- otherwise use random skin if not set
|
-- otherwise use random skin if not set
|
||||||
else
|
else
|
||||||
local r = math.random(0, skins.skin_count)
|
set_skin = math.random(0, skins.skin_count)
|
||||||
if r == 0 then
|
|
||||||
set_skin = "character"
|
|
||||||
else
|
|
||||||
set_skin = "character_" .. r
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if set_skin then
|
if set_skin then
|
||||||
skins.set_player_skin(player, set_skin)
|
skins.set_player_skin(player, set_skin)
|
||||||
|
@ -125,16 +131,11 @@ minetest.register_chatcommand("setskin", {
|
||||||
end
|
end
|
||||||
|
|
||||||
local skin
|
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)
|
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
|
end
|
||||||
|
local skinfile = "Skin #"..skin_id
|
||||||
skins.set_player_skin(player, skin)
|
|
||||||
local skinfile = skin..".png"
|
|
||||||
|
|
||||||
local your_msg = S("Your skin has been set to: @1", skinfile)
|
local your_msg = S("Your skin has been set to: @1", skinfile)
|
||||||
if name == playername then
|
if name == playername then
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
Reference in New Issue