From a3f78165267b1eda0c8ca7301c99f3c0896bb6ab Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Wed, 19 Jul 2023 00:44:11 -0400 Subject: [PATCH] backguard compatibility of hp_max in older clients, (missing breath_max) * honoring customizations of hp_max its not so valid in older clients becouse of a bug in older clients of hardcoded healt player long time ago user requested https://github.com/minetest/minetest/issues/2246 the value was hardcoded into engine and do not allow to be customized by mods until the commit above, this patch takes that into consideration and set the value to 20. * NOTE: as side effect if you started a server that support hp_max modification and try to connect using a older client, client will perfectly supports the already configured healt from client, but will start at 20 initialy, of course with max_hp supported over the value of 20 --- mods/hudbars/default_settings.lua | 5 +++++ mods/hudbars/init.lua | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/mods/hudbars/default_settings.lua b/mods/hudbars/default_settings.lua index d2f11c8..04475ac 100644 --- a/mods/hudbars/default_settings.lua +++ b/mods/hudbars/default_settings.lua @@ -50,3 +50,8 @@ end hb.settings.hp_player_maximun = hb.load_setting("hudbars_hp_player_maximun", "number", 20) hb.settings.br_player_maximun = hb.load_setting("hudbars_br_player_maximun", "number", 10) +if minetest.has_feature("object_use_texture_alpha") then +core.PLAYER_MAX_HP_DEFAULT = hb.settings.hp_player_maximun +else +core.PLAYER_MAX_HP = hb.settings.hp_player_maximun +end diff --git a/mods/hudbars/init.lua b/mods/hudbars/init.lua index 378c37e..3133ff4 100644 --- a/mods/hudbars/init.lua +++ b/mods/hudbars/init.lua @@ -74,6 +74,19 @@ local function player_exists(player) return player ~= nil and player:is_player() end +local function checksupportmax(player) + local statusinfo = minetest.get_server_status() + if string.find(statusinfo,"0.4.1") and not string.find(statusinfo,"0.4.18") and not string.find(statusinfo,"0.4.17.5") then + hb.settings.hp_player_maximun = 20 + hb.settings.br_player_maximun = 10 + if player_exists(player) then + player:set_properties({hp_max = 20}) + else + minetest.log("error","[hudbars] WARNING! minetest version do not support customization of hp_max healt player values") + end + end +end + local function make_label(format_string, format_string_config, label, start_value, max_value) local params = {} local order = format_string_config.order @@ -143,6 +156,7 @@ function hb.get_hudbar_position_index(identifier) end function hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, default_start_hidden, format_string, format_string_config) + checksupportmax() minetest.log("action", "hb.register_hudbar: "..tostring(identifier)) local hudtable = {} local pos, offset @@ -331,6 +345,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta end function hb.init_hudbar(player, identifier, start_value, start_max, start_hidden) + checksupportmax(player) if not player_exists(player) then return false end local hudtable = hb.get_hudtable(identifier) hb.hudtables[identifier].add_all(player, hudtable, start_value, start_max, start_hidden)