mirror of
https://github.com/minetest-mods/3d_armor.git
synced 2024-11-16 23:40:35 +01:00
Add support for multiskin mod
This commit is contained in:
parent
ea29ec6f6f
commit
afce9f1140
|
@ -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_armor_monoid = minetest.global_exists("armor_monoid")
|
||||
local armor_def = setmetatable({}, {
|
||||
|
@ -39,7 +39,7 @@ armor = {
|
|||
"list[current_player;main;0,5.85;8,3;8]",
|
||||
def = armor_def,
|
||||
textures = armor_textures,
|
||||
default_skin = "character",
|
||||
default_skin = "character.png",
|
||||
materials = {
|
||||
wood = "group:wood",
|
||||
cactus = "default:cactus",
|
||||
|
@ -156,16 +156,22 @@ armor.run_callbacks = function(self, callback, player, index, stack)
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
if self.textures[name] then
|
||||
default.player_set_textures(player, {
|
||||
self.textures[name].skin,
|
||||
self.textures[name].armor,
|
||||
self.textures[name].wielditem,
|
||||
})
|
||||
local textures = {
|
||||
"blank.png",
|
||||
"blank.png",
|
||||
self.textures[name].armor,
|
||||
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
|
||||
|
||||
|
@ -177,14 +183,17 @@ armor.set_player_armor = function(self, player)
|
|||
local state = 0
|
||||
local count = 0
|
||||
local material = {count=1}
|
||||
local preview = armor:get_preview(name)
|
||||
local texture = "3d_armor_trans.png"
|
||||
local preview = "3d_armor_preview.png"
|
||||
local texture = "blank.png"
|
||||
local textures = {}
|
||||
local physics = {}
|
||||
local attributes = {}
|
||||
local levels = {}
|
||||
local groups = {}
|
||||
local change = {}
|
||||
if use_multiskin then
|
||||
preview = multiskin.get_preview(player) or preview
|
||||
end
|
||||
for _, phys in pairs(self.physics) do
|
||||
physics[phys] = 1
|
||||
end
|
||||
|
@ -375,33 +384,6 @@ armor.damage = function(self, player, index, stack, use)
|
|||
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)
|
||||
if armor.def[name].init_time == 0 then
|
||||
return "label[0,0;Armor not initialized!]"
|
||||
|
|
|
@ -5,3 +5,4 @@ fire?
|
|||
ethereal?
|
||||
bakedclay?
|
||||
intllib?
|
||||
multiskin?
|
||||
|
|
|
@ -59,25 +59,14 @@ for material, _ in pairs(armor.materials) do
|
|||
end
|
||||
|
||||
-- Mod Compatibility
|
||||
|
||||
if minetest.get_modpath("multiskin") then
|
||||
multiskin.model = "3d_armor_character.b3d"
|
||||
end
|
||||
if minetest.get_modpath("technic") then
|
||||
armor.formspec = armor.formspec..
|
||||
"label[5,2.5;"..S("Radiation")..": armor_group_radiation]"
|
||||
armor:register_armor_group("radiation")
|
||||
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
|
||||
armor.materials.mithril = nil
|
||||
end
|
||||
|
@ -175,24 +164,13 @@ local function init_player_armor(player)
|
|||
for group, _ in pairs(armor.registered_groups) do
|
||||
armor.def[name].groups[group] = 0
|
||||
end
|
||||
local skin = armor:get_player_skin(name)
|
||||
armor.textures[name] = {
|
||||
skin = skin..".png",
|
||||
armor = "3d_armor_trans.png",
|
||||
wielditem = "3d_armor_trans.png",
|
||||
preview = armor.default_skin.."_preview.png",
|
||||
armor = "blank.png",
|
||||
wielditem = "blank.png",
|
||||
}
|
||||
local texture_path = minetest.get_modpath("player_textures")
|
||||
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)
|
||||
minetest.after(0, function(player)
|
||||
armor:set_player_armor(player)
|
||||
end, player)
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -201,9 +179,10 @@ end
|
|||
default.player_register_model("3d_armor_character.b3d", {
|
||||
animation_speed = 30,
|
||||
textures = {
|
||||
armor.default_skin..".png",
|
||||
"3d_armor_trans.png",
|
||||
"3d_armor_trans.png",
|
||||
armor.default_skin,
|
||||
"blank.png",
|
||||
"blank.png",
|
||||
"blank.png",
|
||||
},
|
||||
animations = {
|
||||
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)
|
||||
default.player_set_model(player, "3d_armor_character.b3d")
|
||||
minetest.after(0, function(player)
|
||||
|
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 215 B After Width: | Height: | Size: 215 B |
|
@ -66,7 +66,7 @@ end
|
|||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
wieldview.wielded_item[name] = ""
|
||||
minetest.after(0, function(player)
|
||||
minetest.after(1, function(player)
|
||||
wieldview:update_wielded_item(player)
|
||||
end, player)
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue
Block a user