From 0445c9f90d34b15b8919b6783b9816fb86f3e874 Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Sun, 13 Aug 2023 20:03:40 -0400 Subject: [PATCH] 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 --- mods/3d_armor/3d_armor/init.lua | 52 ++++++++++++++++++++-- mods/default/player.lua | 76 +++++++++++++++++++++++++++------ mods/skins/init.lua | 8 +++- mods/skins/mod.conf | 4 +- 4 files changed, 119 insertions(+), 21 deletions(-) diff --git a/mods/3d_armor/3d_armor/init.lua b/mods/3d_armor/3d_armor/init.lua index 31c6737..b630934 100644 --- a/mods/3d_armor/3d_armor/init.lua +++ b/mods/3d_armor/3d_armor/init.lua @@ -306,13 +306,11 @@ end -- Armor Player Model local modelchar -local eyeheithg +local eyeheithg = 1.5 -- must be autodetected at client connection due different protocols if armor.is_50 then modelchar = "3d_armor_character50.b3d" - eyeheithg = 1.47 else modelchar = "3d_armor_character40.b3d" - eyeheithg = 1.625 end armor.player_register_model(modelchar, { animation_speed = 30, @@ -353,8 +351,54 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end) minetest.register_on_joinplayer(function(player) - armor.player_set_model(player, modelchar) + 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) local pplayer = minetest.get_player_by_name(player_name) if pplayer and init_player_armor(player) == false then diff --git a/mods/default/player.lua b/mods/default/player.lua index 6f3adfb..8f35b86 100644 --- a/mods/default/player.lua +++ b/mods/default/player.lua @@ -6,22 +6,70 @@ local animation_blend = 0 local hp_player_maximun = tonumber(minetest.settings:get('default_hp_player_maximun')) or 40 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 -if is_50 then - core.PLAYER_MAX_HP_DEFAULT = hp_player_maximun - modelchar = "character50.b3d" - eyeheithg = 1.47 -else - core.PLAYER_MAX_HP = hp_player_maximun - modelchar = "character40.b3d" - eyeheithg = 1.625 +function dynamicmodel(player_name) + + if not player_name then + if is_50 then + core.PLAYER_MAX_HP_DEFAULT = hp_player_maximun + modelchar = "character50.b3d" + 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 default.registered_player_models = { } +dynamicmodel(nil) -- Local for speed. local models = default.registered_player_models @@ -68,7 +116,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, }) @@ -112,14 +160,16 @@ 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, }) -- 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}, @@ -128,7 +178,7 @@ minetest.register_on_joinplayer(function(player) {x = 200, y = 219}, 30 ) - player:set_properties({hp_max = hp_player_maximun}) + player:set_properties({hp_max = hp_player_maximun, eye_height = eyeheithg, collisionbox = collsibox}) end) minetest.register_on_leaveplayer(function(player) diff --git a/mods/skins/init.lua b/mods/skins/init.lua index fe8f8f5..81f42e4 100644 --- a/mods/skins/init.lua +++ b/mods/skins/init.lua @@ -13,7 +13,6 @@ local S if minetest.get_translator ~= nil then S = minetest.get_translator("skins") - is_50 = true else if minetest.get_modpath("intllib") then 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 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 - 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]" else local head = "[combine:8x8:-8,-8="..skins.skins[name]..".png" diff --git a/mods/skins/mod.conf b/mods/skins/mod.conf index da6a90e..53f200c 100644 --- a/mods/skins/mod.conf +++ b/mods/skins/mod.conf @@ -1,4 +1,4 @@ name = skins -depends = default, player_api -optional_depends = sfinv, inventory_plus, intllib, unified_inventory +depends = default +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.