Merge pull request 'Added eating animation' (#4169) from eating_animation into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/4169doc_update
commit
9e8661ae95
|
@ -57,6 +57,7 @@ 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 = {}
|
||||||
|
mcl_hunger.eat_anim_hud = {}
|
||||||
|
|
||||||
-- Set per player internal variables for delayed eating
|
-- Set per player internal variables for delayed eating
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
@ -81,6 +82,7 @@ minetest.register_on_joinplayer(function(player)
|
||||||
_custom_do_delayed = false, -- If true, then will execute only _custom_wrapper after holding RMB or LMB within a delay specified by mcl_hunger.EATING_DELAY (Use to bypass minetest.do_item_eat entirely)
|
_custom_do_delayed = false, -- If true, then will execute only _custom_wrapper after holding RMB or LMB within a delay specified by mcl_hunger.EATING_DELAY (Use to bypass minetest.do_item_eat entirely)
|
||||||
}
|
}
|
||||||
playerphysics.remove_physics_factor(player, "speed", "mcl_hunger:eating_speed")
|
playerphysics.remove_physics_factor(player, "speed", "mcl_hunger:eating_speed")
|
||||||
|
player:hud_set_flags({wielditem = true})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Clear when player leaves
|
-- Clear when player leaves
|
||||||
|
@ -88,6 +90,7 @@ minetest.register_on_leaveplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
mcl_hunger.eat_internal[name] = nil
|
mcl_hunger.eat_internal[name] = nil
|
||||||
|
mcl_hunger.eat_anim_hud[name] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
dofile(modpath.."/api.lua")
|
dofile(modpath.."/api.lua")
|
||||||
|
@ -120,11 +123,21 @@ mcl_hunger.poison_hunger = {} -- food poisoning, increasing hunger
|
||||||
|
|
||||||
-- HUD
|
-- HUD
|
||||||
local function init_hud(player)
|
local function init_hud(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
hb.init_hudbar(player, "hunger", mcl_hunger.get_hunger(player))
|
hb.init_hudbar(player, "hunger", mcl_hunger.get_hunger(player))
|
||||||
if mcl_hunger.debug then
|
if mcl_hunger.debug then
|
||||||
hb.init_hudbar(player, "saturation", mcl_hunger.get_saturation(player), mcl_hunger.get_hunger(player))
|
hb.init_hudbar(player, "saturation", mcl_hunger.get_saturation(player), mcl_hunger.get_hunger(player))
|
||||||
hb.init_hudbar(player, "exhaustion", mcl_hunger.get_exhaustion(player))
|
hb.init_hudbar(player, "exhaustion", mcl_hunger.get_exhaustion(player))
|
||||||
end
|
end
|
||||||
|
mcl_hunger.eat_anim_hud[name] = player:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
text = "blank.png",
|
||||||
|
position = {x = 0.5, y = 1},
|
||||||
|
scale = {x = -25, y = -45},
|
||||||
|
alignment = {x = 0, y = -1},
|
||||||
|
offset = {x = 0, y = -30},
|
||||||
|
z_index = -200,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- HUD updating functions for Debug Mode. No-op if not in Debug Mode
|
-- HUD updating functions for Debug Mode. No-op if not in Debug Mode
|
||||||
|
@ -195,6 +208,8 @@ local eat_effects_cooldown = {}
|
||||||
|
|
||||||
local function clear_eat_internal_and_timers(player, player_name)
|
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")
|
||||||
|
player:hud_set_flags({wielditem = true})
|
||||||
|
player:hud_change(mcl_hunger.eat_anim_hud[player_name], "text", "blank.png")
|
||||||
mcl_hunger.eat_internal[player_name] = {
|
mcl_hunger.eat_internal[player_name] = {
|
||||||
is_eating = false,
|
is_eating = false,
|
||||||
is_eating_no_padding = false,
|
is_eating_no_padding = false,
|
||||||
|
@ -299,6 +314,13 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
playerphysics.add_physics_factor(player, "speed", "mcl_hunger:eating_speed", mcl_hunger.EATING_WALK_SPEED)
|
playerphysics.add_physics_factor(player, "speed", "mcl_hunger:eating_speed", mcl_hunger.EATING_WALK_SPEED)
|
||||||
|
|
||||||
|
player:hud_set_flags({wielditem = false})
|
||||||
|
local itemstackdef = current_itemstack:get_definition()
|
||||||
|
local wield_image = itemstackdef.wield_image
|
||||||
|
if not wield_image or wield_image == "" then wield_image = itemstackdef.inventory_image end
|
||||||
|
player:hud_change(mcl_hunger.eat_anim_hud[player_name], "text", wield_image)
|
||||||
|
player:hud_change(mcl_hunger.eat_anim_hud[player_name], "offset", {x = 0, y = 50*math.sin(10*eat_tick_timers[player]+math.random())-50})
|
||||||
|
|
||||||
if eat_effects_cooldown[player] > 0.2 then
|
if eat_effects_cooldown[player] > 0.2 then
|
||||||
eat_effects_cooldown[player] = 0
|
eat_effects_cooldown[player] = 0
|
||||||
|
|
||||||
|
@ -357,6 +379,8 @@ 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")
|
||||||
|
player:hud_set_flags({wielditem = true})
|
||||||
|
player:hud_change(mcl_hunger.eat_anim_hud[player_name], "text", "blank.png")
|
||||||
mcl_hunger.eat_internal[player_name].is_eating_no_padding = false
|
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
|
||||||
|
|
Loading…
Reference in New Issue