mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-04 23:31:05 +01:00
Add mcl_hunger.is_eating(name) API
This commit is contained in:
parent
be711ea727
commit
93dff87a5e
1 changed files with 18 additions and 0 deletions
|
@ -43,6 +43,18 @@ mcl_hunger.debug = false
|
||||||
-- Cooldown timers for each player, to force a short delay between consuming 2 food items
|
-- Cooldown timers for each player, to force a short delay between consuming 2 food items
|
||||||
mcl_hunger.last_eat = {}
|
mcl_hunger.last_eat = {}
|
||||||
|
|
||||||
|
-- Is player eating API
|
||||||
|
function mcl_hunger.is_eating(name)
|
||||||
|
local result
|
||||||
|
if name then
|
||||||
|
if type(name) ~= "string" then
|
||||||
|
name = name:get_player_name()
|
||||||
|
end
|
||||||
|
result = mcl_hunger.eat_internal[name].is_eating_no_padding
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
-- Variables for each player, to handle delayed eating
|
-- Variables for each player, to handle delayed eating
|
||||||
mcl_hunger.eat_internal = {}
|
mcl_hunger.eat_internal = {}
|
||||||
|
|
||||||
|
@ -52,6 +64,7 @@ minetest.register_on_joinplayer(function(player)
|
||||||
|
|
||||||
mcl_hunger.eat_internal[name] = {
|
mcl_hunger.eat_internal[name] = {
|
||||||
is_eating = false,
|
is_eating = false,
|
||||||
|
is_eating_no_padding = false,
|
||||||
itemname = nil,
|
itemname = nil,
|
||||||
item_definition = nil,
|
item_definition = nil,
|
||||||
hp_change = nil,
|
hp_change = nil,
|
||||||
|
@ -184,6 +197,7 @@ local function clear_eat_internal_and_timers(player, player_name)
|
||||||
playerphysics.remove_physics_factor(player, "speed", "mcl_hunger:eating_speed")
|
playerphysics.remove_physics_factor(player, "speed", "mcl_hunger:eating_speed")
|
||||||
mcl_hunger.eat_internal[player_name] = {
|
mcl_hunger.eat_internal[player_name] = {
|
||||||
is_eating = false,
|
is_eating = false,
|
||||||
|
is_eating_no_padding = false,
|
||||||
itemname = nil,
|
itemname = nil,
|
||||||
item_definition = nil,
|
item_definition = nil,
|
||||||
hp_change = nil,
|
hp_change = nil,
|
||||||
|
@ -253,6 +267,9 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
-- Eating delay code
|
-- Eating delay code
|
||||||
if mcl_hunger.eat_internal[player_name].is_eating or mcl_hunger.eat_internal[player_name]._custom_do_delayed then
|
if mcl_hunger.eat_internal[player_name].is_eating or mcl_hunger.eat_internal[player_name]._custom_do_delayed then
|
||||||
|
mcl_hunger.eat_internal[player_name].is_eating = true
|
||||||
|
mcl_hunger.eat_internal[player_name].is_eating_no_padding = true
|
||||||
|
|
||||||
local control = player:get_player_control()
|
local control = player:get_player_control()
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local current_itemstack = player:get_wielded_item()
|
local current_itemstack = player:get_wielded_item()
|
||||||
|
@ -340,6 +357,7 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
elseif eat_start_timers[player] and eat_start_timers[player] > 0.2 then
|
elseif eat_start_timers[player] and eat_start_timers[player] > 0.2 then
|
||||||
playerphysics.remove_physics_factor(player, "speed", "mcl_hunger:eating_speed")
|
playerphysics.remove_physics_factor(player, "speed", "mcl_hunger:eating_speed")
|
||||||
|
mcl_hunger.eat_internal[player_name].is_eating_no_padding = false
|
||||||
|
|
||||||
elseif eat_start_timers[player] and eat_start_timers[player] > mcl_hunger.EATING_TOUCHSCREEN_DELAY_PADDING then
|
elseif eat_start_timers[player] and eat_start_timers[player] > mcl_hunger.EATING_TOUCHSCREEN_DELAY_PADDING then
|
||||||
clear_eat_internal_and_timers(player, player_name)
|
clear_eat_internal_and_timers(player, player_name)
|
||||||
|
|
Loading…
Reference in a new issue