From 0bb0ba91d9218540945cdbbc834d8f599dec7f05 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 20 May 2017 20:07:10 +0200 Subject: [PATCH] Hunger: Remove some redundant HUD bar changes --- mods/PLAYER/mcl_hunger/hunger.lua | 21 ++++++++++++--------- mods/PLAYER/mcl_hunger/init.lua | 6 ++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/mods/PLAYER/mcl_hunger/hunger.lua b/mods/PLAYER/mcl_hunger/hunger.lua index f1acb8d4ef..e5aa7e206c 100644 --- a/mods/PLAYER/mcl_hunger/hunger.lua +++ b/mods/PLAYER/mcl_hunger/hunger.lua @@ -139,21 +139,24 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sou }) end - -- Add saturation (must be defined in item table) if hunger_change then + -- Add saturation (must be defined in item table) local saturation = minetest.registered_items[itemname]._mcl_saturation if not saturation then saturation = 0.0 minetest.log("warning", "[mcl_hunger] No saturation defined for item “"..itemname.."”!") end - mcl_hunger.saturate(name, saturation) - end - -- Food points - if h < 20 and hunger_change then - h = h + hunger_change - if h > 20 then h = 20 end - mcl_hunger.hunger[name] = h - mcl_hunger.set_hunger_raw(user) + mcl_hunger.saturate(name, saturation, false) + + -- Add food points + if h < 20 and hunger_change then + h = h + hunger_change + if h > 20 then h = 20 end + mcl_hunger.hunger[name] = h + mcl_hunger.set_hunger_raw(user) + end + + hb.change_hudbar(user, "saturation", mcl_hunger.saturation[name], mcl_hunger.get_hunger(user)) end -- Poison if poisen then diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index 13f28d66f9..3956327298 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -164,10 +164,12 @@ function mcl_hunger.exhaust(playername, increase) hb.change_hudbar(player, "exhaustion", mcl_hunger.exhaustion[playername]) end -function mcl_hunger.saturate(playername, increase) +function mcl_hunger.saturate(playername, increase, update_hudbar) local player = minetest.get_player_by_name(playername) mcl_hunger.saturation[playername] = math.min(mcl_hunger.saturation[playername] + increase, mcl_hunger.get_hunger(player)) - hb.change_hudbar(player, "saturation", mcl_hunger.saturation[playername], mcl_hunger.get_hunger(player)) + if update_hudbar ~= false then + hb.change_hudbar(player, "saturation", mcl_hunger.saturation[playername], mcl_hunger.get_hunger(player)) + end end local main_timer = 0