minetest-balanced_diet-cd2025/saturation_hud.lua

40 lines
1.3 KiB
Lua
Raw Permalink Normal View History

2023-03-23 10:24:39 -07:00
balanced_diet.registered_saturation_huds = {}
2023-03-19 14:38:05 -07:00
2023-03-23 10:24:39 -07:00
function balanced_diet.register_saturation_hud(def)
table.insert(balanced_diet.registered_saturation_huds, def)
2023-03-19 14:38:05 -07:00
end
2023-04-10 09:33:39 -07:00
balanced_diet.saturation_attribute:register_on_change(function(self, player, value, old_value)
if value ~= old_value then
for _, hud_def in ipairs(balanced_diet.registered_saturation_huds) do
hud_def.on_saturation_change(player, value)
end
2023-03-19 14:38:05 -07:00
end
end)
2023-04-10 09:33:39 -07:00
balanced_diet.saturation_attribute:register_on_max_change(function(self, player, saturation_max, old_max)
if saturation_max ~= old_max then
for _, hud_def in ipairs(balanced_diet.registered_saturation_huds) do
hud_def.on_saturation_max_change(player, saturation_max)
end
2023-03-19 14:38:05 -07:00
end
end)
minetest.register_on_joinplayer(function(player)
2023-04-10 09:33:39 -07:00
local saturation = balanced_diet.saturation_attribute:get(player, os.time())
local saturation_max = balanced_diet.saturation_attribute:get_max(player)
2023-03-23 10:24:39 -07:00
for _, hud_def in ipairs(balanced_diet.registered_saturation_huds) do
if hud_def.on_joinplayer then
hud_def.on_joinplayer(player, saturation, saturation_max)
end
2023-03-19 14:38:05 -07:00
end
end)
minetest.register_on_leaveplayer(function(player)
2023-03-23 10:24:39 -07:00
for _, hud_def in ipairs(balanced_diet.registered_saturation_huds) do
2023-03-19 14:38:05 -07:00
if hud_def.on_leaveplayer then
hud_def.on_leaveplayer(player)
end
end
end)