Solved RegainHealthEvent Saturation

Discussion in 'Spigot Plugin Development' started by wand555, Mar 25, 2020.

  1. I'm cancelling the EntityRegainHealthEvent because I want to prevent people from regaining health by consuming food. So far so good, but I noticed that the player loses saturation/food way too quick. After some debugging with getFoodLevel() and getSaturation() I realized that minecraft still converts saturation to hearts before I cancel it. This results in the player losing all their saturation/food after consumption (if they don't have full life). Is there any way sort of SaturationLevelChangeEvent or a formular which does the conversion between health, saturation and hunger?
    Only way to do this I can imagine to do is, would be to store what a player ate and the hunger/saturation amount when he hasn't got full life, then cancel FoodLevelChangeEvent when the level decreases and decrement the amount mapped with the item. Repeat that until the amount is 0, but I believe there are much more elegant solutions.
  2. Don't cancel the event, just set the health back to what it was before regain
  3. It still "converts" saturation into hearts. I solved this by avoiding it entirely. Just setting the gamerule naturalRegeneration to false