default/player_Api dinamically set the model player on client conection

* improves previous commit 13cd243a031ca6c52457032e0bffc8576b549b3a ,
  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
This commit is contained in:
mckaygerhard 2023-08-13 18:42:56 -04:00
parent 23eb8437f4
commit a110849017

View File

@ -5,20 +5,66 @@
-- Note: This is currently broken due to a bug in Irrlicht, leave at 0
local animation_blend = 0
local modelchar
local eyeheithg
local eyeheithg = 1.5 -- must be autodetected at client connection due different protocols
local collsibox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}
local is_50 = minetest.has_feature("object_use_texture_alpha") or nil
function dynamicmodel(player_name)
if not player_name then
if is_50 then
modelchar = "character50.b3d"
eyeheithg = 1.47
eyeheithg = 1.625
else
modelchar = "character40.b3d"
eyeheithg = 1.47
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, 0.0, -0.3, 0.3, 1.7, 0.3}
else
engineold = false
modelchar = "character50.b3d"
eyeheithg = 1.625
collsibox = {-0.3, 0.0, -0.3, 0.3, 1.7, 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
default.registered_player_models = { }
dynamicmodel(nil)
-- Local for speed.
local models = default.registered_player_models
@ -39,7 +85,7 @@ default.player_register_model( modelchar, {
walk_mine = { x=200, y=219, },
sit = { x= 81, y=160, },
},
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
collisionbox = collsibox,
stepheight = 0.6,
eye_height = eyeheithg,
})
@ -83,7 +129,7 @@ function default.player_set_model(player, model_name)
textures = { "player.png", "player_back.png", },
visual = "upright_sprite",
visual_size = {x=1, y=2},
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.75, 0.3},
collisionbox = collsibox,
stepheight = 0.6,
eye_height = eyeheithg,
})
@ -116,7 +162,9 @@ end
-- Update appearance when the player joins
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)
player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)