Add support for multiskin mod

This commit is contained in:
stujones11 2017-05-10 20:16:17 +01:00
parent ea29ec6f6f
commit afce9f1140
7 changed files with 35 additions and 89 deletions

@ -1,4 +1,4 @@
local skin_previews = {} local use_multiskin = minetest.global_exists("multiskin")
local use_player_monoids = minetest.global_exists("player_monoids") local use_player_monoids = minetest.global_exists("player_monoids")
local use_armor_monoid = minetest.global_exists("armor_monoid") local use_armor_monoid = minetest.global_exists("armor_monoid")
local armor_def = setmetatable({}, { local armor_def = setmetatable({}, {
@ -39,7 +39,7 @@ armor = {
"list[current_player;main;0,5.85;8,3;8]", "list[current_player;main;0,5.85;8,3;8]",
def = armor_def, def = armor_def,
textures = armor_textures, textures = armor_textures,
default_skin = "character", default_skin = "character.png",
materials = { materials = {
wood = "group:wood", wood = "group:wood",
cactus = "default:cactus", cactus = "default:cactus",
@ -156,16 +156,22 @@ armor.run_callbacks = function(self, callback, player, index, stack)
end end
armor.update_player_visuals = function(self, player) armor.update_player_visuals = function(self, player)
if not player then local name = self:get_valid_player(player, "[update_player_visuals]")
if not name then
return return
end end
local name = player:get_player_name() local textures = {
if self.textures[name] then "blank.png",
default.player_set_textures(player, { "blank.png",
self.textures[name].skin,
self.textures[name].armor, self.textures[name].armor,
self.textures[name].wielditem, self.textures[name].wielditem,
}) }
if use_multiskin then
multiskin.textures[name] = textures
multiskin.update_player_visuals(player)
else
textures[1] = armor.default_skin
default.player_set_textures(player, textures)
end end
end end
@ -177,14 +183,17 @@ armor.set_player_armor = function(self, player)
local state = 0 local state = 0
local count = 0 local count = 0
local material = {count=1} local material = {count=1}
local preview = armor:get_preview(name) local preview = "3d_armor_preview.png"
local texture = "3d_armor_trans.png" local texture = "blank.png"
local textures = {} local textures = {}
local physics = {} local physics = {}
local attributes = {} local attributes = {}
local levels = {} local levels = {}
local groups = {} local groups = {}
local change = {} local change = {}
if use_multiskin then
preview = multiskin.get_preview(player) or preview
end
for _, phys in pairs(self.physics) do for _, phys in pairs(self.physics) do
physics[phys] = 1 physics[phys] = 1
end end
@ -375,33 +384,6 @@ armor.damage = function(self, player, index, stack, use)
end end
end end
armor.get_player_skin = function(self, name)
local skin = nil
if self.skin_mod == "skins" or self.skin_mod == "simple_skins" then
skin = skins.skins[name]
elseif self.skin_mod == "u_skins" then
skin = u_skins.u_skins[name]
elseif self.skin_mod == "wardrobe" then
local skins = wardrobe.playerSkins or {}
if skins[name] then
skin = string.gsub(skins[name], "%.png$","")
end
end
return skin or armor.default_skin
end
armor.add_preview = function(self, preview)
skin_previews[preview] = true
end
armor.get_preview = function(self, name)
local preview = armor:get_player_skin(name).."_preview.png"
if skin_previews[preview] then
return preview
end
return "character_preview.png"
end
armor.get_armor_formspec = function(self, name, listring) armor.get_armor_formspec = function(self, name, listring)
if armor.def[name].init_time == 0 then if armor.def[name].init_time == 0 then
return "label[0,0;Armor not initialized!]" return "label[0,0;Armor not initialized!]"

@ -5,3 +5,4 @@ fire?
ethereal? ethereal?
bakedclay? bakedclay?
intllib? intllib?
multiskin?

@ -59,25 +59,14 @@ for material, _ in pairs(armor.materials) do
end end
-- Mod Compatibility -- Mod Compatibility
if minetest.get_modpath("multiskin") then
multiskin.model = "3d_armor_character.b3d"
end
if minetest.get_modpath("technic") then if minetest.get_modpath("technic") then
armor.formspec = armor.formspec.. armor.formspec = armor.formspec..
"label[5,2.5;"..S("Radiation")..": armor_group_radiation]" "label[5,2.5;"..S("Radiation")..": armor_group_radiation]"
armor:register_armor_group("radiation") armor:register_armor_group("radiation")
end end
local skin_mods = {"skins", "u_skins", "simple_skins", "wardrobe"}
for _, mod in pairs(skin_mods) do
local path = minetest.get_modpath(mod)
if path then
local dir_list = minetest.get_dir_list(path.."/textures")
for _, fn in pairs(dir_list) do
if fn:find("_preview.png$") then
armor:add_preview(fn)
end
end
armor.skin_mod = mod
end
end
if not minetest.get_modpath("moreores") then if not minetest.get_modpath("moreores") then
armor.materials.mithril = nil armor.materials.mithril = nil
end end
@ -175,24 +164,13 @@ local function init_player_armor(player)
for group, _ in pairs(armor.registered_groups) do for group, _ in pairs(armor.registered_groups) do
armor.def[name].groups[group] = 0 armor.def[name].groups[group] = 0
end end
local skin = armor:get_player_skin(name)
armor.textures[name] = { armor.textures[name] = {
skin = skin..".png", armor = "blank.png",
armor = "3d_armor_trans.png", wielditem = "blank.png",
wielditem = "3d_armor_trans.png",
preview = armor.default_skin.."_preview.png",
} }
local texture_path = minetest.get_modpath("player_textures") minetest.after(0, function(player)
if texture_path then
local dir_list = minetest.get_dir_list(texture_path.."/textures")
for _, fn in pairs(dir_list) do
if fn == "player_"..name..".png" then
armor.textures[name].skin = fn
break
end
end
end
armor:set_player_armor(player) armor:set_player_armor(player)
end, player)
return true return true
end end
@ -201,9 +179,10 @@ end
default.player_register_model("3d_armor_character.b3d", { default.player_register_model("3d_armor_character.b3d", {
animation_speed = 30, animation_speed = 30,
textures = { textures = {
armor.default_skin..".png", armor.default_skin,
"3d_armor_trans.png", "blank.png",
"3d_armor_trans.png", "blank.png",
"blank.png",
}, },
animations = { animations = {
stand = {x=0, y=79}, stand = {x=0, y=79},
@ -215,22 +194,6 @@ default.player_register_model("3d_armor_character.b3d", {
}, },
}) })
minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
if not name then
return
end
for field, _ in pairs(fields) do
if string.find(field, "skins_set") then
minetest.after(0, function(player)
local skin = armor:get_player_skin(name)
armor.textures[name].skin = skin..".png"
armor:set_player_armor(player)
end, player)
end
end
end)
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
default.player_set_model(player, "3d_armor_character.b3d") default.player_set_model(player, "3d_armor_character.b3d")
minetest.after(0, function(player) minetest.after(0, function(player)

Before

Width:  |  Height:  |  Size: 215 B

After

Width:  |  Height:  |  Size: 215 B

@ -66,7 +66,7 @@ end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
wieldview.wielded_item[name] = "" wieldview.wielded_item[name] = ""
minetest.after(0, function(player) minetest.after(1, function(player)
wieldview:update_wielded_item(player) wieldview:update_wielded_item(player)
end, player) end, player)
end) end)