hudbars+hbhunger+hbarmor - fix armor bar set to 0% due old loading engines

* for minetest 0.4.16 and 0.4.17 loading of mods is a pain, the
  `on_mods_loaded` still do not exits and only using dependency
  we can get sure a mod its present.
  hudbars need armors parts be present and 100% lodaed to property
  check the armor.def so made optional dependencies only in depends.txt
  cos mod.conf is for newer engines and those works perfectly.
  This only happened at player join or initialization, due
  several errors in the already buggy 3d_armor mod, check:
  https://github.com/minetest-mods/3d_armor/issues/49
This commit is contained in:
mckaygerhard 2023-08-06 01:00:47 -04:00
parent 02120d280e
commit 6327ac1eb0
2 changed files with 6 additions and 4 deletions

View File

@ -1,6 +1,9 @@
default? default?
intllib? intllib?
3d_armor? 3d_armor?
3d_armor_gloves?
shields?
wieldview?
flowers? flowers?
animalmaterials? animalmaterials?
bucket? bucket?

View File

@ -629,6 +629,7 @@ if not modhbarm and modarmors then
function hbarmor.get_armor(player) function hbarmor.get_armor(player)
if not player or not armor.def then if not player or not armor.def then
minetest.log("error", "[hbarmor] Call to hbarmor.get_armor cannot do it cos the payer armor definition its not set at this moment!")
return false return false
end end
local name = player:get_player_name() local name = player:get_player_name()
@ -637,7 +638,7 @@ if not modhbarm and modarmors then
if def and def.state and def.count then if def and def.state and def.count then
hbarmor.set_armor(name, def.state, def.count) hbarmor.set_armor(name, def.state, def.count)
else else
minetest.log("error", "[hudbars] Call to hbarmor.get_armor returned with false!") minetest.log("error", "[hudbars] Call to hbarmor.get_armor returned with false! armor.def[player] invalid")
return false return false
end end
return true return true
@ -675,11 +676,9 @@ local function custom_hud(player)
hb.init_hudbar(player, "breath", math.min(breath, breath_max), breath_max, hide_breath) hb.init_hudbar(player, "breath", math.min(breath, breath_max), breath_max, hide_breath)
if not modhbarm and modarmors then if not modhbarm and modarmors then
local arm = tonumber(hbarmor.armor[name]) local arm = tonumber(hbarmor.armor[name] or 0)
if not arm then arm = 0 end
local hide_ar = hbarmor.autohide and must_hide(name, arm) local hide_ar = hbarmor.autohide and must_hide(name, arm)
hbarmor.get_armor(player) hbarmor.get_armor(player)
arm = tonumber(hbarmor.armor[name])
hb.init_hudbar(player, "armor", arm_printable(arm), 100, hide_ar) hb.init_hudbar(player, "armor", arm_printable(arm), 100, hide_ar)
end end