OldPlayerRegen saturation depleting faster than it should
LynSnow989 opened this issue · 7 comments
Information
- Server Version: Spigot 1.15.2
- OldCombatMechanics version: 1.8.1
Problem Description
On the EntityRegainHealthEvent, the saturation depletion is not taken on account when cencelling it. So even if the event is cancelled, the player still loses it.
To reproduce this, just eat a golden carrot, get damaged and watch the food start draining after regenerating only 2.5 hearts.
This shouldn't happen as the golden carrot has 16 whole points of saturation.
Proposed Solution
Adding:
p.setSaturation(new Float(p.getSaturation() + e.getAmount()*1.5));
just after cancelling the event, as the player starts regaining health more slowly when saturation is low. That should nagate the saturation depletion when it's not used.
Oh, that's a much better explanation of the issue; and yeah, just tested it and both the saturation and exhaustion work as they should. But now, when saturation reaches 0, the plugin skips one heal:
[18:16:33] [CHAT] [DEBUG][ModulePlayerRegen] Exhaustion before: 2.2360113 Now: 5.2360115 Saturation now: 2.4
[18:16:37] [CHAT] [DEBUG][ModulePlayerRegen] Exhaustion before: 2.713012 Now: 5.7130117 Saturation now: 1.4000001
[18:16:41] [CHAT] [DEBUG][ModulePlayerRegen] Exhaustion before: 2.8410125 Now: 5.8410125 Saturation now: 0.4000001
[18:16:49] [CHAT] [DEBUG][ModulePlayerRegen] Exhaustion before: 0.9410136 Now: 3.9410136 Saturation now: 0.0
[18:16:53] [CHAT] [DEBUG][ModulePlayerRegen] Exhaustion before: 0.65001345 Now: 3.6500134 Saturation now: 0.0
[18:17:01] [CHAT] [DEBUG][ModulePlayerRegen] Exhaustion before: 3.6500134 Now: 6.6500134 Saturation now: 0.0
(used logs text because i couldn't think of another way of showing the skip)
There you can see that the messages take 4 seconds each, but then there's an 8 second pause before the first "Saturation now: 0.0".
I think it has to do with the change of regen speed when the player reaches 0 saturation, but i'm not sure.
Ok so I have investigated this issue and found that you were right about something being off, but it was actually due to the times the foodTickTimer expired much faster than the 4 seconds and the healing was cancelled, but Bukkit still applied exhaustion. Your suggested solution would not work because of different amounts of exhaustion applied by different versions of the game, but applying the exhaustion from before the regen happened 1 tick later effectively voids the increase in exhaustion, and consequently the faster depletion of saturation.
While I was there, I also noticed that the default heal timer was 3 seconds and not 4 like in 1.8, and also that the first time the foodTickTimer expired the player was not healed so they were effectively skipping a healing. This has all been fixed now, so if you can, please try the relevant test version and let me know if that is the case for you too.
Just tested it, it works perfectly, except for this one issue:
If the player loses one saturation point while they are on the timer, the next regeneration will take slightly longer.
But i don't know if it's even worth fixing at this point, as it is really hard to notice if you don't have the debug messages enabled...
In any case, ty for the fix ♥
You're right, I just observed that happening. It seems to have to do with slight timing inaccuracies, such that only 3999ms had elapsed when the next foodTickerTimer expired and so the heal was skipped. I gave it ~10ms of leeway by changing the default config value and it seems to work correctly, if you can please try the newer test version. I also added some extra debug output to be able to observe the timing.
I believe that's due to the way the foodTickerTimer works - which unfortunately I don't think we can change. You can always try tweaking the interval amount. I will be closing this issue for now.