diff --git a/mods/default/player.lua b/mods/default/player.lua index f7c34ab..35dc773 100644 --- a/mods/default/player.lua +++ b/mods/default/player.lua @@ -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 -if is_50 then - modelchar = "character50.b3d" - eyeheithg = 1.47 -else - modelchar = "character40.b3d" - eyeheithg = 1.625 +function dynamicmodel(player_name) + + if not player_name then + if is_50 then + modelchar = "character50.b3d" + 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)