From 13825763b024638a73de04cd1fd83675687adc18 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Mon, 29 Jan 2024 04:24:39 +0100 Subject: [PATCH 1/3] Added eating animation --- mods/PLAYER/mcl_hunger/init.lua | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index 61b6b72f2..07fc2083a 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -57,6 +57,7 @@ end -- Variables for each player, to handle delayed eating mcl_hunger.eat_internal = {} +mcl_hunger.eat_anim_hud = {} -- Set per player internal variables for delayed eating 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) } playerphysics.remove_physics_factor(player, "speed", "mcl_hunger:eating_speed") + player:hud_set_flags({wielditem = true}) end) -- Clear when player leaves @@ -88,6 +90,7 @@ minetest.register_on_leaveplayer(function(player) local name = player:get_player_name() mcl_hunger.eat_internal[name] = nil + mcl_hunger.eat_anim_hud[name] = nil end) dofile(modpath.."/api.lua") @@ -120,11 +123,21 @@ mcl_hunger.poison_hunger = {} -- food poisoning, increasing hunger -- HUD local function init_hud(player) + local name = player:get_player_name() hb.init_hudbar(player, "hunger", mcl_hunger.get_hunger(player)) if mcl_hunger.debug then 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)) end + mcl_hunger.eat_anim_hud[name] = player:hud_add({ + hud_elem_type = "image", + text = "blank.png", + position = {x = 1, y = 1}, + scale = {x = 30, y = 30}, + alignment = {x = -1, y = -1}, + offset = {x = -50, y = 50}, + z_index = -200, + }) end -- 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) 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 = false, is_eating_no_padding = false, @@ -299,13 +314,20 @@ minetest.register_globalstep(function(dtime) 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 = -50, y = 50*math.sin(10*eat_tick_timers[player]+math.random())+30}) + if eat_effects_cooldown[player] > 0.2 then eat_effects_cooldown[player] = 0 if not mcl_hunger.eat_internal[player_name].user then mcl_hunger.eat_internal[player_name].user = player end - + if not mcl_hunger.eat_internal[player_name].itemname then mcl_hunger.eat_internal[player_name].itemname = current_itemstack:get_name() end @@ -357,6 +379,8 @@ minetest.register_globalstep(function(dtime) elseif eat_start_timers[player] and eat_start_timers[player] > 0.2 then 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 elseif eat_start_timers[player] and eat_start_timers[player] > mcl_hunger.EATING_TOUCHSCREEN_DELAY_PADDING then From 8d5c9996a22b3f0d6e21cde2bee7584f0a79e380 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Fri, 2 Feb 2024 04:28:20 +0100 Subject: [PATCH 2/3] Centered the eating animation --- mods/PLAYER/mcl_hunger/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index 07fc2083a..1482dafe0 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -132,10 +132,10 @@ local function init_hud(player) mcl_hunger.eat_anim_hud[name] = player:hud_add({ hud_elem_type = "image", text = "blank.png", - position = {x = 1, y = 1}, + position = {x = 0.5, y = 1}, scale = {x = 30, y = 30}, - alignment = {x = -1, y = -1}, - offset = {x = -50, y = 50}, + alignment = {x = 0, y = -1}, + offset = {x = 0, y = -30}, z_index = -200, }) end @@ -319,7 +319,7 @@ minetest.register_globalstep(function(dtime) 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 = -50, y = 50*math.sin(10*eat_tick_timers[player]+math.random())+30}) + 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 eat_effects_cooldown[player] = 0 From e582c3bb9709342830e3111953b0bb445416cab6 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Sun, 14 Apr 2024 08:34:41 +0200 Subject: [PATCH 3/3] Improved look on the mobile device Now the food doesn't cover the full screen on mobile devices... ...at the cost of stretching at ultrawide or portrait aspect ratios. --- mods/PLAYER/mcl_hunger/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index 1482dafe0..0925e375e 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -133,7 +133,7 @@ local function init_hud(player) hud_elem_type = "image", text = "blank.png", position = {x = 0.5, y = 1}, - scale = {x = 30, y = 30}, + scale = {x = -25, y = -45}, alignment = {x = 0, y = -1}, offset = {x = 0, y = -30}, z_index = -200,