@@ -3,30 +3,30 @@ local enable_damage = core.settings:get_bool("enable_damage")
3
3
4
4
local health_bar_definition = {
5
5
hud_elem_type = " statbar" ,
6
- position = { x = 0.5 , y = 1 },
6
+ position = {x = 0.5 , y = 1 },
7
7
text = " heart.png" ,
8
8
number = core .PLAYER_MAX_HP_DEFAULT ,
9
9
direction = 0 ,
10
- size = { x = 24 , y = 24 },
11
- offset = { x = (- 10 * 24 )- 25 , y = - (48 + 24 + 16 )},
10
+ size = {x = 24 , y = 24 },
11
+ offset = {x = (- 10 * 24 ) - 25 , y = - (48 + 24 + 16 )},
12
12
}
13
13
14
14
local breath_bar_definition = {
15
15
hud_elem_type = " statbar" ,
16
- position = { x = 0.5 , y = 1 },
16
+ position = {x = 0.5 , y = 1 },
17
17
text = " bubble.png" ,
18
18
number = core .PLAYER_MAX_BREATH_DEFAULT ,
19
19
direction = 0 ,
20
- size = { x = 24 , y = 24 },
21
- offset = {x = 25 ,y = - (48 + 24 + 16 )},
20
+ size = {x = 24 , y = 24 },
21
+ offset = {x = 25 , y = - (48 + 24 + 16 )},
22
22
}
23
23
24
24
local hud_ids = {}
25
25
26
26
local function scaleToDefault (player , field )
27
27
-- Scale "hp" or "breath" to the default dimensions
28
28
local current = player [" get_" .. field ](player )
29
- local nominal = core [" PLAYER_MAX_" .. field :upper () .. " _DEFAULT" ]
29
+ local nominal = core [" PLAYER_MAX_" .. field :upper () .. " _DEFAULT" ]
30
30
local max_display = math.max (nominal ,
31
31
math.max (player :get_properties ()[field .. " _max" ], current ))
32
32
return current / max_display * nominal
@@ -49,6 +49,7 @@ local function update_builtin_statbars(player)
49
49
local hud = hud_ids [name ]
50
50
51
51
local immortal = player :get_armor_groups ().immortal == 1
52
+
52
53
if flags .healthbar and enable_damage and not immortal then
53
54
local number = scaleToDefault (player , " hp" )
54
55
if hud .id_healthbar == nil then
@@ -63,19 +64,28 @@ local function update_builtin_statbars(player)
63
64
hud .id_healthbar = nil
64
65
end
65
66
67
+ local show_breathbar = flags .breathbar and enable_damage and not immortal
68
+
69
+ local breath = player :get_breath ()
66
70
local breath_max = player :get_properties ().breath_max
67
- if flags .breathbar and enable_damage and not immortal and
68
- player :get_breath () < breath_max then
71
+ if show_breathbar and breath <= breath_max then
69
72
local number = 2 * scaleToDefault (player , " breath" )
70
- if hud .id_breathbar == nil then
73
+ if not hud .id_breathbar and breath < breath_max then
71
74
local hud_def = table .copy (breath_bar_definition )
72
75
hud_def .number = number
73
76
hud .id_breathbar = player :hud_add (hud_def )
74
- else
77
+ elseif hud . id_breathbar then
75
78
player :hud_change (hud .id_breathbar , " number" , number )
76
79
end
77
- elseif hud .id_breathbar then
78
- player :hud_remove (hud .id_breathbar )
80
+ end
81
+
82
+ if hud .id_breathbar and (not show_breathbar or breath == breath_max ) then
83
+ minetest .after (1 , function (player_name , breath_bar )
84
+ local player = minetest .get_player_by_name (player_name )
85
+ if player then
86
+ player :hud_remove (breath_bar )
87
+ end
88
+ end , name , hud .id_breathbar )
79
89
hud .id_breathbar = nil
80
90
end
81
91
end
0 commit comments