mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 13:53:45 +01:00
Fix broken player init in mcl_hunger causing crash
This commit is contained in:
parent
6d6fc3f34c
commit
b9377a0dbf
@ -1,19 +1,32 @@
|
||||
mcl_hunger.registered_foods = {}
|
||||
|
||||
function mcl_hunger.init_player(player)
|
||||
local meta = player:get_meta()
|
||||
if meta:get_string("mcl_hunger:hunger") == "" then
|
||||
meta:set_string("mcl_hunger:hunger", tostring(20))
|
||||
end
|
||||
if meta:get_string("mcl_hunger:saturation") == "" then
|
||||
meta:set_string("mcl_hunger:saturation", tostring(mcl_hunger.SATURATION_INIT))
|
||||
end
|
||||
if meta:get_string("mcl_hunger:exhaustion") == "" then
|
||||
meta:set_string("mcl_hunger:exhaustion", tostring(0))
|
||||
end
|
||||
end
|
||||
|
||||
if mcl_hunger.active then
|
||||
function mcl_hunger.get_hunger(player)
|
||||
local hunger = player:get_meta():get_string("mcl_hunger:hunger") or 20
|
||||
return tonumber(hunger)
|
||||
local hunger = tonumber(player:get_meta():get_string("mcl_hunger:hunger")) or 20
|
||||
return hunger
|
||||
end
|
||||
|
||||
function mcl_hunger.get_saturation(player)
|
||||
local saturation = player:get_meta():get_string("mcl_hunger:saturation") or mcl_hunger.SATURATION_INIT
|
||||
return tonumber(saturation)
|
||||
local saturation = tonumber(player:get_meta():get_string("mcl_hunger:saturation")) or mcl_hunger.SATURATION_INIT
|
||||
return saturation
|
||||
end
|
||||
|
||||
function mcl_hunger.get_exhaustion(player)
|
||||
local exhaustion = player:get_meta():get_string("mcl_hunger:exhaustion") or 0
|
||||
return tonumber(exhaustion)
|
||||
local exhaustion = tonumber(player:get_meta():get_string("mcl_hunger:exhaustion")) or 0
|
||||
return exhaustion
|
||||
end
|
||||
|
||||
function mcl_hunger.set_hunger(player, hunger, update_hudbars)
|
||||
|
@ -96,15 +96,9 @@ if mcl_hunger.debug then
|
||||
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
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
mcl_hunger.set_hunger(player, 20, false)
|
||||
mcl_hunger.set_saturation(player, mcl_hunger.SATURATION_INIT, false)
|
||||
mcl_hunger.set_exhaustion(player, 0, false)
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
mcl_hunger.init_player(player)
|
||||
init_hud(player)
|
||||
mcl_hunger.poison_damage[name] = 0
|
||||
mcl_hunger.poison_hunger[name] = 0
|
||||
@ -193,6 +187,7 @@ end)
|
||||
else
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
mcl_hunger.init_player(player)
|
||||
mcl_hunger.last_eat[player:get_player_name()] = -1
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user