From 1faee082820f6b0ba6582f3705b91335f5f74d2a Mon Sep 17 00:00:00 2001 From: archfan <33993466+archfan7411@users.noreply.github.com> Date: Fri, 5 Apr 2019 02:10:31 -0400 Subject: [PATCH] Fix HUD issues and use hudbars --- mods/thirst/api.lua | 61 +++----------------------------------------- mods/thirst/mod.conf | 2 ++ 2 files changed, 5 insertions(+), 58 deletions(-) create mode 100644 mods/thirst/mod.conf diff --git a/mods/thirst/api.lua b/mods/thirst/api.lua index a75680c..12f41eb 100644 --- a/mods/thirst/api.lua +++ b/mods/thirst/api.lua @@ -4,11 +4,7 @@ local damage_enabled = minetest.settings:get_bool("enable_damage") if damage_enabled then - -- Position of thirst HUD - local hud_position = {x = 0.5, y = 1} - - -- Offset of thirst HUD - local hud_offset = {x = -197, y = -90} + hb.register_hudbar("thirst", 0xFFFFFF, "Thirst", { icon = "thirst_hud_icon.png", bgicon = "thirst_hud_bg.png", bar = "" }, 20, 30, false) -- Maximum thirst value, and default for new players. local max_thirst = 20 @@ -16,9 +12,6 @@ if damage_enabled then -- Global table for the API. thirst = {} - -- Used to store HUD indexes for each player. - thirst.hud = {} - -- Every x seconds, the player thirst is decreased by 1 if they're in water. thirst.water_quench_rate = 2 @@ -31,28 +24,6 @@ if damage_enabled then -- Every x seconds, thirst data is saved. thirst.data_storage_rate = 10 - -- Default thirst HUD def - thirst.hud_def = { - hud_elem_type = "statbar", - position = hud_position, - text = "thirst_hud_icon.png", - scale = {x = 1, y = 1}, - offset = hud_offset, - number = 20, - } - - -- Gets HUD definition with thirst, or full thirst if no amount specified. - thirst.get_hud_def = function(amount) - - amount = amount or 20 - - def = thirst.hud_def - - def.number = amount - - return def - end - -- Returns the thirst a player has, or nil if the player does not exist. thirst.get_player_thirst = function(name) @@ -77,23 +48,6 @@ if damage_enabled then return nil end - -- Sets a player's HUD to a certain thirst level - thirst.set_player_hud_def = function(name, amount) - - local player = minetest.get_player_by_name(name) - - local idx = thirst.hud[name] - - if idx then - - player:hud_change(idx, "number", amount) - - else - - thirst.hud[name] = player:hud_add(thirst.get_hud_def(amount)) - end - end - -- Sets player thirst to a value. thirst.set_player_thirst = function(name, amount) @@ -113,7 +67,7 @@ if damage_enabled then meta:set_int("thirst", amount) - thirst.set_player_hud_def(name, amount) + hb.change_hudbar(player, "thirst", amount, max_thirst, "thirst_hud_icon.png", "thirst_hud_bg.png", "", "Thirst", 0xFFFF) end end @@ -147,18 +101,9 @@ if damage_enabled then local name = player:get_player_name() - thirst.set_player_hud_def(name, thirst.get_player_thirst(name)) + hb.init_hudbar(player, "thirst", thirst.get_player_thirst(name), max_thirst, false) end) - minetest.register_chatcommand("set_thirst", { - params = "", - func = function(name, params) - amount = tonumber(params) - thirst.set_player_thirst(name, amount) - minetest.chat_send_all("Current thirst data:\n" .. dump(thirst.players)) - end - }) - -- Reset player thirst on die. minetest.register_on_respawnplayer(function(player) diff --git a/mods/thirst/mod.conf b/mods/thirst/mod.conf new file mode 100644 index 0000000..1815048 --- /dev/null +++ b/mods/thirst/mod.conf @@ -0,0 +1,2 @@ +name = thirst +depends = hudbars