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
-- 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
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
-- Set poison bar

View File

@ -164,11 +164,13 @@ 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))
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
local timer = 0 -- Half second timer