From a6e2c94028a13b442b0d66175cb32c8a33212219 Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Fri, 24 Jun 2022 05:38:26 -0500 Subject: [PATCH 1/2] Tweak hunger/health mechanics: Ensure hunger is always ticking away, and ensure that health regen is quicker when hunger bar is full. And, tweak saturation to partially use up hunger to heal; instead of healing on top of hunger. --- mods/PLAYER/mcl_hunger/api.lua | 8 ++++++-- mods/PLAYER/mcl_hunger/init.lua | 13 ++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/mods/PLAYER/mcl_hunger/api.lua b/mods/PLAYER/mcl_hunger/api.lua index 20937023a9..60c21df90e 100644 --- a/mods/PLAYER/mcl_hunger/api.lua +++ b/mods/PLAYER/mcl_hunger/api.lua @@ -33,8 +33,9 @@ if mcl_hunger.active then hunger = math.min(20, math.max(0, hunger)) player:get_meta():set_string("mcl_hunger:hunger", tostring(hunger)) if update_hudbars ~= false then - hb.change_hudbar(player, "hunger", hunger) - mcl_hunger.update_saturation_hud(player, nil, hunger) + -- math.floor(hunger) to stop the hunger float value from breaking the hud. + hb.change_hudbar(player, "hunger", math.floor(hunger)) + mcl_hunger.update_saturation_hud(player, nil, math.floor(hunger)) end return true end @@ -68,6 +69,9 @@ if mcl_hunger.active then local s = mcl_hunger.get_saturation(player) if s > 0 then mcl_hunger.set_saturation(player, math.max(s - 1.0, 0)) + h = mcl_hunger.get_hunger(player) + h = math.max(h-0.25, 0) + mcl_hunger.set_hunger(player, h) satuchanged = true elseif s <= 0.0001 then h = mcl_hunger.get_hunger(player) diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index 21c1e08607..373979cd0b 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -28,6 +28,7 @@ mcl_hunger.EXHAUST_SWIM = 10 -- player movement in water mcl_hunger.EXHAUST_SPRINT = 100 -- sprint (per node) mcl_hunger.EXHAUST_DAMAGE = 100 -- taking damage (protected by armor) mcl_hunger.EXHAUST_REGEN = 6000 -- Regenerate 1 HP +mcl_hunger.EXHAUST_HUNGER = 5 -- Natural hunger overtime. mcl_hunger.EXHAUST_LVL = 4000 -- at what exhaustion player saturation gets lowered mcl_hunger.SATURATION_INIT = 5 -- Initial saturation for new/respawning players @@ -147,7 +148,13 @@ minetest.register_globalstep(function(dtime) if food_tick_timer > 4.0 then food_tick_timer = 0 - if food_level >= 18 then -- slow regenration + -- let hunger work always + if player_health > 0 and player_health <= 20 then + mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_HUNGER) --natural hunger overtime always ticking. + mcl_hunger.update_exhaustion_hud(player, mcl_hunger.get_exhaustion(player)) + end + + if food_level >= 18 and food_level < 20 then -- slow regenration if player_health > 0 and player_health < 20 then player:set_hp(player_health+1) mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_REGEN) @@ -164,10 +171,10 @@ minetest.register_globalstep(function(dtime) end end - elseif food_tick_timer > 0.5 and food_level == 20 and food_saturation_level >= 6 then -- fast regeneration + elseif food_tick_timer > 0.5 and food_level == 20 or food_saturation_level > 0 then -- fast regeneration if player_health > 0 and player_health < 20 then food_tick_timer = 0 - player:set_hp(player_health+1) + player:set_hp(player_health+1.5) mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_REGEN) mcl_hunger.update_exhaustion_hud(player, mcl_hunger.get_exhaustion(player)) end From e3abe725228ce0c678761cb49772af25e71ace7a Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Sat, 25 Jun 2022 01:41:10 -0500 Subject: [PATCH 2/2] Fix healing speed, and saturation usage again; to be more accurate. --- mods/PLAYER/mcl_hunger/api.lua | 10 +++------- mods/PLAYER/mcl_hunger/init.lua | 10 +++++----- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/mods/PLAYER/mcl_hunger/api.lua b/mods/PLAYER/mcl_hunger/api.lua index 60c21df90e..3c9cd97e94 100644 --- a/mods/PLAYER/mcl_hunger/api.lua +++ b/mods/PLAYER/mcl_hunger/api.lua @@ -33,9 +33,8 @@ if mcl_hunger.active then hunger = math.min(20, math.max(0, hunger)) player:get_meta():set_string("mcl_hunger:hunger", tostring(hunger)) if update_hudbars ~= false then - -- math.floor(hunger) to stop the hunger float value from breaking the hud. - hb.change_hudbar(player, "hunger", math.floor(hunger)) - mcl_hunger.update_saturation_hud(player, nil, math.floor(hunger)) + hb.change_hudbar(player, "hunger", hunger) + mcl_hunger.update_saturation_hud(player, nil, hunger) end return true end @@ -68,10 +67,7 @@ if mcl_hunger.active then local satuchanged = false local s = mcl_hunger.get_saturation(player) if s > 0 then - mcl_hunger.set_saturation(player, math.max(s - 1.0, 0)) - h = mcl_hunger.get_hunger(player) - h = math.max(h-0.25, 0) - mcl_hunger.set_hunger(player, h) + mcl_hunger.set_saturation(player, math.max(s - 1.5, 0)) satuchanged = true elseif s <= 0.0001 then h = mcl_hunger.get_hunger(player) diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index 373979cd0b..0cae89a7d9 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -28,7 +28,7 @@ mcl_hunger.EXHAUST_SWIM = 10 -- player movement in water mcl_hunger.EXHAUST_SPRINT = 100 -- sprint (per node) mcl_hunger.EXHAUST_DAMAGE = 100 -- taking damage (protected by armor) mcl_hunger.EXHAUST_REGEN = 6000 -- Regenerate 1 HP -mcl_hunger.EXHAUST_HUNGER = 5 -- Natural hunger overtime. +mcl_hunger.EXHAUST_HUNGER = 5 -- Hunger status effect at base level. mcl_hunger.EXHAUST_LVL = 4000 -- at what exhaustion player saturation gets lowered mcl_hunger.SATURATION_INIT = 5 -- Initial saturation for new/respawning players @@ -150,11 +150,11 @@ minetest.register_globalstep(function(dtime) -- let hunger work always if player_health > 0 and player_health <= 20 then - mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_HUNGER) --natural hunger overtime always ticking. + --mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_HUNGER) -- later for hunger status effect mcl_hunger.update_exhaustion_hud(player, mcl_hunger.get_exhaustion(player)) end - if food_level >= 18 and food_level < 20 then -- slow regenration + if food_level >= 18 then -- slow regeneration if player_health > 0 and player_health < 20 then player:set_hp(player_health+1) mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_REGEN) @@ -171,10 +171,10 @@ minetest.register_globalstep(function(dtime) end end - elseif food_tick_timer > 0.5 and food_level == 20 or food_saturation_level > 0 then -- fast regeneration + elseif food_tick_timer > 0.5 and food_level == 20 and food_saturation_level > 0 then -- fast regeneration if player_health > 0 and player_health < 20 then food_tick_timer = 0 - player:set_hp(player_health+1.5) + player:set_hp(player_health+1) mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_REGEN) mcl_hunger.update_exhaustion_hud(player, mcl_hunger.get_exhaustion(player)) end