Changing Food regen rate

Discussion in 'Plugin Development' started by Sweatyyyy, Nov 27, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Sweatyyyy

    How do I change the food regen rate? For example so my hunger rises by +1 every 5 seconds regardless of how much health I have
     
  2. Offline

    felixfritz

    I think that the health raises by +1 every 5 seconds, not the hunger ;)

    If you only want to regenerate, if the player has more than 8 hunger bars filled up, it's quiet easy. Just listen for the "EntityRegainHealthEvent" and check, if event.getRegainReason() == RegainReason.SATIATED. Then you could check, how many hunger bars the player has filled up and either cancel the event or leave it as it is.

    If you want to regenerate, if the player has less than 8 hunger bars filled up, that's going to be difficult. You would have to schedule a repeating task that gets called every 5 or 8 seconds and then check, how many hunger bars the player has filled up. Depending on how much hunger is filled up, regenerate the player by half a heart (if needed) or do nothing. Note that you might not want to regenerate the player, if he has over 8 hunger bars filled.

    Also note that due to the new health system, don't check if the player has more than 20 hearts filled up. Check, if the added hearts goes over player.getMaxHealth(). If you try to add too much health to the player, it won't do anything in-game.
     
Thread Status:
Not open for further replies.

Share This Page