default/player_api/3darmor/skinsdb - dinamically set the model player on client conection

* improves previous commit 3b5cbef6529040620dd8e064f04e082cab5bb436
  and previous 3d_armor commit d7ae85b7f614ae4c37227c7d3a0c78013507ce4f ,
  the problem is that both server and client must be equal protocol, so
  this ugly hack check if this was loaded into FinalMinetest or Multicraft
  to dinamically check client nature and re-registering the model when
  server and client do not have same player models due the colisionbox check
* NOTE: the check already need to check if the engine is old and the server not,
  so the conditional just try to do exact check agains TRUE boolean.
* Closed https://codeberg.org/minenux/minetest-game-minetest/issues/12
  fixed the problem of collisionbox for the lufix player in ugly way but
  much more effectivelly due can be mixed in FinalMinetest and Multicraft
* fix model preview based on client view, not on server engine version
  for the skindb mod
This commit is contained in:
mckaygerhard 2023-08-13 20:03:40 -04:00
parent d47102d5bf
commit 0445c9f90d
4 changed files with 119 additions and 21 deletions

View File

@ -306,13 +306,11 @@ end
-- Armor Player Model -- Armor Player Model
local modelchar local modelchar
local eyeheithg local eyeheithg = 1.5 -- must be autodetected at client connection due different protocols
if armor.is_50 then if armor.is_50 then
modelchar = "3d_armor_character50.b3d" modelchar = "3d_armor_character50.b3d"
eyeheithg = 1.47
else else
modelchar = "3d_armor_character40.b3d" modelchar = "3d_armor_character40.b3d"
eyeheithg = 1.625
end end
armor.player_register_model(modelchar, { armor.player_register_model(modelchar, {
animation_speed = 30, animation_speed = 30,
@ -353,8 +351,54 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end) end)
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
armor.player_set_model(player, modelchar)
local player_name = player:get_player_name() local player_name = player:get_player_name()
local engineold = armor.is_50
if player_name then
local info = minetest.get_player_information(player_name)
-- ugly hack due mixed protocols:
if info then
local test = info.version_string or "5.0"
if test:find("0.4") or test:find("4.0") or test:find("4.1") then
engineold = true
modelchar = "3d_armor_character40.b3d"
eyeheithg = 1.47
else
engineold = false
modelchar = "3d_armor_character50.b3d"
eyeheithg = 1.625
end
-- only refix register model when protocols are mixed, will slow down server
if engineold == true and armor.is_50 == true then
minetest.log("warning", "[3d_armor] performance impact: mixed protocols DETECTED on player .. "..player_name.." doin re-register model hack")
armor.player_register_model(modelchar, {
animation_speed = 30,
textures = {
armor.default_skin..".png",
"3d_armor_trans.png",
"3d_armor_trans.png",
},
animations = {
stand = {x=0, y=79},
lay = {x=162, y=166},
walk = {x=168, y=187},
mine = {x=189, y=198},
walk_mine = {x=200, y=219},
sit = {x=81, y=160},
-- compatibility w/ the emote mod
wave = {x = 192, y = 196, override_local = true},
point = {x = 196, y = 196, override_local = true},
freeze = {x = 205, y = 205, override_local = true},
},
eye_height = eyeheithg,
})
end
end
end
armor.player_set_model(player, modelchar)
player:set_properties({eye_height = eyeheithg})
minetest.after(0.1, function(player) minetest.after(0.1, function(player)
local pplayer = minetest.get_player_by_name(player_name) local pplayer = minetest.get_player_by_name(player_name)
if pplayer and init_player_armor(player) == false then if pplayer and init_player_armor(player) == false then

View File

@ -6,22 +6,70 @@
local animation_blend = 0 local animation_blend = 0
local hp_player_maximun = tonumber(minetest.settings:get('default_hp_player_maximun')) or 40 local hp_player_maximun = tonumber(minetest.settings:get('default_hp_player_maximun')) or 40
local modelchar local modelchar
local eyeheithg local eyeheithg = 1.5 -- must be autodetected at client connection due different protocols
local collsibox = {-0.3, 0.5, -0.3, 0.3, 1.7, 0.3}
local is_50 = minetest.has_feature("object_use_texture_alpha") or nil local is_50 = minetest.has_feature("object_use_texture_alpha") or nil
if is_50 then function dynamicmodel(player_name)
core.PLAYER_MAX_HP_DEFAULT = hp_player_maximun
modelchar = "character50.b3d" if not player_name then
eyeheithg = 1.47 if is_50 then
else core.PLAYER_MAX_HP_DEFAULT = hp_player_maximun
core.PLAYER_MAX_HP = hp_player_maximun modelchar = "character50.b3d"
modelchar = "character40.b3d" eyeheithg = 1.625
eyeheithg = 1.625 collsibox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}
else
modelchar = "character40.b3d"
eyeheithg = 1.47
core.PLAYER_MAX_HP = hp_player_maximun
collsibox = {-0.3, -1, -0.3, 0.3, 0.75, 0.3}
end
return
end
local engineold = is_50
local info = minetest.get_player_information(player_name)
-- ugly hack due mixed protocols:
if info then
local test = info.version_string or "5.0"
if test:find("0.4") or test:find("4.0") or test:find("4.1") then
engineold = true
modelchar = "character40.b3d"
eyeheithg = 1.47
collsibox = {-0.3, -1, -0.3, 0.3, 0.75, 0.3}
else
engineold = false
modelchar = "character50.b3d"
eyeheithg = 1.625
collsibox = {-0.3, 0.0, -0.3, 0.3, 1.5, 0.3}
end
-- only refix register model when protocols are mixed, will slow down server
if engineold == true and is_50 == true then
minetest.log("warning", "[default/player_api] performance impact: mixed protocols DETECTED on player .. "..player_name.." doin re-register model hack")
default.player_register_model( modelchar, {
animation_speed = 30,
textures = {"character.png", },
animations = {
-- Standard animations.
stand = {x = 0, y = 79},
lay = {x = 162, y = 166},
walk = {x = 168, y = 187},
mine = {x = 189, y = 198},
walk_mine = {x = 200, y = 219},
sit = {x = 81, y = 160},
},
collisionbox = collsibox,
stepheight = 0.6,
eye_height = eyeheithg,
})
end
end
end end
default.registered_player_models = { } default.registered_player_models = { }
dynamicmodel(nil)
-- Local for speed. -- Local for speed.
local models = default.registered_player_models local models = default.registered_player_models
@ -68,7 +116,7 @@ function default.player_set_model(player, model_name)
textures = {"player.png", "player_back.png"}, textures = {"player.png", "player_back.png"},
visual = "upright_sprite", visual = "upright_sprite",
visual_size = {x = 1, y = 2}, visual_size = {x = 1, y = 2},
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.75, 0.3}, collisionbox = collsibox,
stepheight = 0.6, stepheight = 0.6,
eye_height = eyeheithg, eye_height = eyeheithg,
}) })
@ -112,14 +160,16 @@ default.player_register_model( modelchar, {
walk_mine = {x = 200, y = 219}, walk_mine = {x = 200, y = 219},
sit = {x = 81, y = 160}, sit = {x = 81, y = 160},
}, },
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, collisionbox = collsibox,
stepheight = 0.6, stepheight = 0.6,
eye_height = eyeheithg, eye_height = eyeheithg,
}) })
-- Update appearance when the player joins -- Update appearance when the player joins
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
default.player_attached[player:get_player_name()] = false local player_name = player:get_player_name()
dynamicmodel(player_name)
default.player_attached[player_name] = false
default.player_set_model(player, modelchar) default.player_set_model(player, modelchar)
player:set_local_animation( player:set_local_animation(
{x = 0, y = 79}, {x = 0, y = 79},
@ -128,7 +178,7 @@ minetest.register_on_joinplayer(function(player)
{x = 200, y = 219}, {x = 200, y = 219},
30 30
) )
player:set_properties({hp_max = hp_player_maximun}) player:set_properties({hp_max = hp_player_maximun, eye_height = eyeheithg, collisionbox = collsibox})
end) end)
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)

View File

@ -13,7 +13,6 @@ local S
if minetest.get_translator ~= nil then if minetest.get_translator ~= nil then
S = minetest.get_translator("skins") S = minetest.get_translator("skins")
is_50 = true
else else
if minetest.get_modpath("intllib") then if minetest.get_modpath("intllib") then
dofile(minetest.get_modpath("intllib").."/init.lua") dofile(minetest.get_modpath("intllib").."/init.lua")
@ -166,8 +165,13 @@ skins.formspec.main = function(name)
-- if preview enabled then add player model to formspec (5.4dev only) -- if preview enabled then add player model to formspec (5.4dev only)
if skins.preview == true then if skins.preview == true then
info = minetest.get_player_information(name)
if info then
local test = info.version_string or "5"
if test:find("0.4.") or test:find("4.0.") or test:find("5.0.") or test:find("5.1.") or test:find("5.2.") or test:find("5.3.") then is_54 = false else is_54 = true end
end
if is_54 then if is_54 then
formspec = formspec .. "model[6,-0.2;1.5,3;player;character.b3d;" formspec = formspec .. "model[6,-0.2;1.5,3;player;character50.b3d;"
.. skins.skins[name] .. ".png;0,180;false;true]" .. skins.skins[name] .. ".png;0,180;false;true]"
else else
local head = "[combine:8x8:-8,-8="..skins.skins[name]..".png" local head = "[combine:8x8:-8,-8="..skins.skins[name]..".png"

View File

@ -1,4 +1,4 @@
name = skins name = skins
depends = default, player_api depends = default
optional_depends = sfinv, inventory_plus, intllib, unified_inventory optional_depends = sfinv, inventory_plus, intllib, unified_inventory, player_api
description = SKIN manager mod, Simple_Skin modified mod that allow players to set their individual skins. description = SKIN manager mod, Simple_Skin modified mod that allow players to set their individual skins.