Hunger: Remove some redundant HUD bar changes

This commit is contained in:
Wuzzy 2017-05-20 20:07:10 +02:00
parent daf42e45c3
commit 0bb0ba91d9
2 changed files with 16 additions and 11 deletions

View File

@ -139,22 +139,25 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sou
}) })
end end
-- Add saturation (must be defined in item table)
if hunger_change then if hunger_change then
-- Add saturation (must be defined in item table)
local saturation = minetest.registered_items[itemname]._mcl_saturation local saturation = minetest.registered_items[itemname]._mcl_saturation
if not saturation then if not saturation then
saturation = 0.0 saturation = 0.0
minetest.log("warning", "[mcl_hunger] No saturation defined for item “"..itemname.."”!") minetest.log("warning", "[mcl_hunger] No saturation defined for item “"..itemname.."”!")
end end
mcl_hunger.saturate(name, saturation) mcl_hunger.saturate(name, saturation, false)
end
-- Food points -- Add food points
if h < 20 and hunger_change then if h < 20 and hunger_change then
h = h + hunger_change h = h + hunger_change
if h > 20 then h = 20 end if h > 20 then h = 20 end
mcl_hunger.hunger[name] = h mcl_hunger.hunger[name] = h
mcl_hunger.set_hunger_raw(user) mcl_hunger.set_hunger_raw(user)
end end
hb.change_hudbar(user, "saturation", mcl_hunger.saturation[name], mcl_hunger.get_hunger(user))
end
-- Poison -- Poison
if poisen then if poisen then
-- Set poison bar -- Set poison bar

View File

@ -164,10 +164,12 @@ function mcl_hunger.exhaust(playername, increase)
hb.change_hudbar(player, "exhaustion", mcl_hunger.exhaustion[playername]) hb.change_hudbar(player, "exhaustion", mcl_hunger.exhaustion[playername])
end end
function mcl_hunger.saturate(playername, increase) function mcl_hunger.saturate(playername, increase, update_hudbar)
local player = minetest.get_player_by_name(playername) local player = minetest.get_player_by_name(playername)
mcl_hunger.saturation[playername] = math.min(mcl_hunger.saturation[playername] + increase, mcl_hunger.get_hunger(player)) mcl_hunger.saturation[playername] = math.min(mcl_hunger.saturation[playername] + increase, mcl_hunger.get_hunger(player))
if update_hudbar ~= false then
hb.change_hudbar(player, "saturation", mcl_hunger.saturation[playername], mcl_hunger.get_hunger(player)) hb.change_hudbar(player, "saturation", mcl_hunger.saturation[playername], mcl_hunger.get_hunger(player))
end
end end
local main_timer = 0 local main_timer = 0