From 0167a2f41b1cb98152adc9640e6d471ceb3f257e Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 21 May 2017 01:32:05 +0200 Subject: [PATCH] Change food bar when player is food poisoned --- mods/PLAYER/mcl_hunger/hunger.lua | 26 ++++++++++++++---- mods/PLAYER/mcl_hunger/init.lua | 18 ++++++------ .../textures/mcl_hunger_bar_foodpoison.png | Bin 0 -> 72 bytes .../textures/mcl_hunger_icon_foodpoison.png | Bin 0 -> 206 bytes 4 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 mods/PLAYER/mcl_hunger/textures/mcl_hunger_bar_foodpoison.png create mode 100644 mods/PLAYER/mcl_hunger/textures/mcl_hunger_icon_foodpoison.png diff --git a/mods/PLAYER/mcl_hunger/hunger.lua b/mods/PLAYER/mcl_hunger/hunger.lua index 636dc527d..107e60705 100644 --- a/mods/PLAYER/mcl_hunger/hunger.lua +++ b/mods/PLAYER/mcl_hunger/hunger.lua @@ -53,6 +53,15 @@ function mcl_hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_t return func(itemstack, user, pointed_thing) end +-- Reset HUD bars after poisoning +local function reset_bars(player) + hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png") + hb.change_hudbar(player, "hunger", nil, nil, "hbhunger_icon.png", nil, "hbhunger_bar.png") + if mcl_hunger.debug then + hb.change_hudbar(player, "exhaustion", nil, nil, nil, nil, "mcl_hunger_bar_exhaustion.png") + end +end + -- Poison player local function poisonp(tick, time, time_left, damage, exhaustion, player) -- First check if player is still there @@ -69,8 +78,7 @@ local function poisonp(tick, time, time_left, damage, exhaustion, player) else mcl_hunger.poisonings[player:get_player_name()] = mcl_hunger.poisonings[player:get_player_name()] - 1 if mcl_hunger.poisonings[player:get_player_name()] <= 0 then - -- Reset HUD bar color - hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png") + reset_bars(player) end end @@ -85,7 +93,7 @@ end -- Immediately stop all poisonings for this player function mcl_hunger.stop_poison(player) mcl_hunger.poisonings[player:get_player_name()] = 0 - hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png") + reset_bars(player) end local poisonrandomizer = PseudoRandom(os.time()) @@ -181,8 +189,16 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso do_poison = true end if do_poison then - -- Set poison bar - hb.change_hudbar(user, "health", nil, nil, "hbhunger_icon_health_poison.png", nil, "hbhunger_bar_health_poison.png") + -- Set poison bars + if poison and poison > 0 then + hb.change_hudbar(user, "health", nil, nil, "hbhunger_icon_health_poison.png", nil, "hbhunger_bar_health_poison.png") + end + if exhaust and exhaust > 0 then + hb.change_hudbar(user, "hunger", nil, nil, "mcl_hunger_icon_foodpoison.png", nil, "mcl_hunger_bar_foodpoison.png") + if mcl_hunger.debug then + hb.change_hudbar(user, "exhaustion", nil, nil, nil, nil, "mcl_hunger_bar_foodpoison.png") + end + end mcl_hunger.poisonings[name] = mcl_hunger.poisonings[name] + 1 poisonp(1, poisontime, 0, poison, exhaust, user) end diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index 14526927c..088d85e7d 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -10,10 +10,12 @@ if minetest.setting_getbool("enable_damage") then mcl_hunger = {} mcl_hunger.food = {} --- Debug Mode. If enabled, saturation and exhaustion are shown as well -local debug = minetest.setting_getbool("mcl_hunger_debug") -if debug == nil then - debug = false +-- Debug Mode. If enabled, saturation and exhaustion are shown as well. +-- NOTE: Read-only. The setting should only be read at the beginning, this mod is not +-- prepared to change this setting later. +mcl_hunger.debug = minetest.setting_getbool("mcl_hunger_debug") +if mcl_hunger.debug == nil then + mcl_hunger.debug = false end --[[ Data value format notes: @@ -57,7 +59,7 @@ end local function init_hud(player) hb.init_hudbar(player, "hunger", mcl_hunger.get_hunger(player)) - if debug then + if mcl_hunger.debug then hb.init_hudbar(player, "saturation", mcl_hunger.get_saturation(player), mcl_hunger.get_hunger(player)*10) hb.init_hudbar(player, "exhaustion", mcl_hunger.get_exhaustion(player)) end @@ -65,7 +67,7 @@ end -- HUD updating functions for Debug Mode. No-op if not in Debug Mode function mcl_hunger.update_saturation_hud(player, saturation, hunger) - if debug then + if mcl_hunger.debug then local satulimit if hunger then satulimit = hunger * 10 @@ -74,7 +76,7 @@ function mcl_hunger.update_saturation_hud(player, saturation, hunger) end end function mcl_hunger.update_exhaustion_hud(player, exhaustion) - if debug then + if mcl_hunger.debug then hb.change_hudbar(player, "exhaustion", exhaustion) end end @@ -83,7 +85,7 @@ dofile(minetest.get_modpath("mcl_hunger").."/hunger.lua") -- register saturation hudbar hb.register_hudbar("hunger", 0xFFFFFF, S("Food"), { icon = "hbhunger_icon.png", bgicon = "hbhunger_bgicon.png", bar = "hbhunger_bar.png" }, 20, 20, false) -if debug then +if mcl_hunger.debug then hb.register_hudbar("saturation", 0xFFFFFF, S("Saturation"), { icon = "mcl_hunger_icon_saturation.png", bgicon = "mcl_hunger_bgicon_saturation.png", bar = "mcl_hunger_bar_saturation.png" }, mcl_hunger.SATURATION_INIT, 200, false, S("%s: %d/%d")) hb.register_hudbar("exhaustion", 0xFFFFFF, S("Exhaust."), { icon = "mcl_hunger_icon_exhaustion.png", bgicon = "mcl_hunger_bgicon_exhaustion.png", bar = "mcl_hunger_bar_exhaustion.png" }, 0, mcl_hunger.EXHAUST_LVL, false, S("%s: %d/%d")) end diff --git a/mods/PLAYER/mcl_hunger/textures/mcl_hunger_bar_foodpoison.png b/mods/PLAYER/mcl_hunger/textures/mcl_hunger_bar_foodpoison.png new file mode 100644 index 0000000000000000000000000000000000000000..02580e14920c80f1af0d0f81f499ed41a9a89c48 GIT binary patch literal 72 zcmeAS@N?(olHy`uVBq!ia0vp^Oh7Ea0U|e_vV07r_&r@5Ln;`PH8MLHly(I&n3QWV US}YTg2TCz`y85}Sb4q9e0MauKyZ`_I literal 0 HcmV?d00001 diff --git a/mods/PLAYER/mcl_hunger/textures/mcl_hunger_icon_foodpoison.png b/mods/PLAYER/mcl_hunger/textures/mcl_hunger_icon_foodpoison.png new file mode 100644 index 0000000000000000000000000000000000000000..63f64182c30592376ff3d29832968e0017051bd1 GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1SD^+kpz+qY$ZW{!5{_$L*6p>i9o8^)5S5Q zf-!l4$O|LGgMyq@k18t_IZo(hb}EFO|C_tjf#o`z%aN?++hX%y^IY_7;#S}4vL?5z z?X`-GM1ie@ZJPKbLh*2~7Y+-$(HP literal 0 HcmV?d00001