diff --git a/mods/bed/init.lua b/mods/bed/init.lua index 98e4d2b..4072d0b 100644 --- a/mods/bed/init.lua +++ b/mods/bed/init.lua @@ -475,7 +475,8 @@ player_effects.register_effect( speed = 0, jump = 0, gravity = 0, - } + }, + icon = "bed_effect.png", }) -- Achievements diff --git a/mods/bed/textures/bed_effect.png b/mods/bed/textures/bed_effect.png new file mode 100644 index 0000000..c398a22 Binary files /dev/null and b/mods/bed/textures/bed_effect.png differ diff --git a/mods/hunger/init.lua b/mods/hunger/init.lua index b66ca8e..757e2ea 100644 --- a/mods/hunger/init.lua +++ b/mods/hunger/init.lua @@ -382,5 +382,6 @@ player_effects.register_effect( duration = 2, physics = { speed = 0.6, - } + }, + icon = "hunger_effect_eating.png", }) diff --git a/mods/hunger/textures/hunger_effect_eating.png b/mods/hunger/textures/hunger_effect_eating.png new file mode 100644 index 0000000..94e19aa Binary files /dev/null and b/mods/hunger/textures/hunger_effect_eating.png differ diff --git a/mods/player_effects/init.lua b/mods/player_effects/init.lua index adb15f3..666ba9c 100644 --- a/mods/player_effects/init.lua +++ b/mods/player_effects/init.lua @@ -4,6 +4,7 @@ -- local S = minetest.get_translator("player_effects") +local DISPLAY_ICONS = true player_effects = {} @@ -34,12 +35,44 @@ local function load_effects() end end +local huds = {} + +local function display_effect_icons(player) + if not DISPLAY_ICONS then + return + end + + local name = player:get_player_name() + for _,h in pairs(huds[name]) do + player:hud_remove(h) + end + huds[name] = {} + local i = 0 + for en, _ in pairs(player_effects.effects[name]) do + local effect = player_effects.get_registered_effect(en) + if effect.icon then + local id = player:hud_add({ + hud_elem_type = "image", + position = { x = 1, y = 0 }, + offset = { x = -52 - i*52, y = 270 }, + text = effect.icon, + scale = { x = 3, y = 3 }, + size = { x = 16, y = 16 }, + alignment = { x = 1, y = 1 }, + }) + table.insert(huds[name], id) + i = i + 1 + end + end +end + function player_effects.register_effect(name, def) local rd = { title = def.title or name, -- good-looking name of the effect description = def.description or S("The @1 effect", name), -- description of what the effect does duration = def.duration or 1, -- how long the effect lasts, <0 is infinite and has to be disabled manually - physics = def.physics or {} -- physics overrides for the player + physics = def.physics or {}, -- physics overrides for the player + icon = def.icon, -- effect icon for HUD } player_effects.registered_effects[name] = rd @@ -85,6 +118,7 @@ function player_effects.apply_effect(player, ename) end player:set_physics_override(phys) + display_effect_icons(player) save_effects() end @@ -115,6 +149,7 @@ function player_effects.remove_effect(player, ename) player:set_physics_override(phys) player_effects.effects[player:get_player_name()][ename] = nil + display_effect_icons(player) save_effects() end @@ -140,6 +175,8 @@ function player_effects.refresh_effects(player) player:set_physics_override(phys) + display_effect_icons(player) + save_effects() end @@ -148,6 +185,7 @@ function player_effects.clear_effects(player) player:set_physics_override({speed = 1, jump = 1, gravity = 1}) player_effects.effects[player:get_player_name()] = {} + display_effect_icons(player) save_effects() end @@ -189,6 +227,7 @@ local function on_joinplayer(player) if player_effects.effects[name] == nil then player_effects.effects[name] = {} end + huds[name] = {} player_effects.refresh_effects(player)