Hunger: disable for creative players
This commit is contained in:
parent
00063a721b
commit
d48d6f8dc0
@ -67,12 +67,17 @@ local attribute = {
|
|||||||
local function is_player(player)
|
local function is_player(player)
|
||||||
return (
|
return (
|
||||||
core.is_player(player) and
|
core.is_player(player) and
|
||||||
not player.is_fake_player
|
not player.is_fake_player and
|
||||||
|
not core.is_creative_enabled(player:get_player_name())
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- SATURATION API ---
|
--- SATURATION API ---
|
||||||
function hunger.get_saturation(player)
|
function hunger.get_saturation(player)
|
||||||
|
if not is_player(player) then
|
||||||
|
return settings.level_max
|
||||||
|
end
|
||||||
|
|
||||||
-- This uses get_string so that nil is returned when there is no value as
|
-- This uses get_string so that nil is returned when there is no value as
|
||||||
-- get_string() will return an empty string and tonumber("") == nil.
|
-- get_string() will return an empty string and tonumber("") == nil.
|
||||||
return tonumber(player:get_meta():get_string(attribute.saturation))
|
return tonumber(player:get_meta():get_string(attribute.saturation))
|
||||||
@ -90,6 +95,10 @@ function hunger.register_on_update_saturation(fun)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function hunger.update_saturation(player, level)
|
function hunger.update_saturation(player, level)
|
||||||
|
if not is_player(player) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for _, callback in ipairs(hunger.registered_on_update_saturations) do
|
for _, callback in ipairs(hunger.registered_on_update_saturations) do
|
||||||
local result = callback(player, level)
|
local result = callback(player, level)
|
||||||
if result then
|
if result then
|
||||||
@ -123,16 +132,24 @@ function hunger.change_saturation(player, change)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
hunger.change = hunger.change_saturation -- for backwards compatablity
|
hunger.change = hunger.change_saturation -- for backwards compatibility
|
||||||
--- END SATURATION API ---
|
--- END SATURATION API ---
|
||||||
|
|
||||||
--- POISON API ---
|
--- POISON API ---
|
||||||
function hunger.is_poisoned(player)
|
function hunger.is_poisoned(player)
|
||||||
|
if not is_player(player) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local poisoned = player:get_meta():get_string(attribute.poisoned)
|
local poisoned = player:get_meta():get_string(attribute.poisoned)
|
||||||
return poisoned and poisoned == "yes"
|
return poisoned and poisoned == "yes"
|
||||||
end
|
end
|
||||||
|
|
||||||
function hunger.set_poisoned(player, poisoned)
|
function hunger.set_poisoned(player, poisoned)
|
||||||
|
if not is_player(player) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local texture = poisoned and "hunger_poisen.png" or "hunger.png"
|
local texture = poisoned and "hunger_poisen.png" or "hunger.png"
|
||||||
local attr = poisoned and "yes" or "no"
|
local attr = poisoned and "yes" or "no"
|
||||||
hud.change_item(player, "hunger", {text = texture})
|
hud.change_item(player, "hunger", {text = texture})
|
||||||
@ -164,6 +181,7 @@ function hunger.poison(player, ticks, interval)
|
|||||||
if not is_player(player) then
|
if not is_player(player) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, fun in ipairs(hunger.registered_on_poisons) do
|
for _, fun in ipairs(hunger.registered_on_poisons) do
|
||||||
local rv = fun(player, ticks, interval)
|
local rv = fun(player, ticks, interval)
|
||||||
if rv == true then
|
if rv == true then
|
||||||
@ -201,6 +219,10 @@ function hunger.register_on_exhaust_player(fun)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function hunger.exhaust_player(player, change, cause)
|
function hunger.exhaust_player(player, change, cause)
|
||||||
|
if not is_player(player) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for _, callback in ipairs(hunger.registered_on_exhaust_players) do
|
for _, callback in ipairs(hunger.registered_on_exhaust_players) do
|
||||||
local result = callback(player, change, cause)
|
local result = callback(player, change, cause)
|
||||||
if result then
|
if result then
|
||||||
@ -208,10 +230,6 @@ function hunger.exhaust_player(player, change, cause)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not is_player(player) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local exhaustion = hunger.get_exhaustion(player) or 0
|
local exhaustion = hunger.get_exhaustion(player) or 0
|
||||||
exhaustion = exhaustion + change
|
exhaustion = exhaustion + change
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user