Minecraft – How to set a specific team/player hungers bar

minecraft-java-edition

So I want to make my own custom minigame just for me and my friends, and I was wondering if I could set certain players hunger bars, or even teams, to 3 so they can't sprint, I would really love to see a command for this, I already know a lot about commandblocks but this I don't.

Best Answer

You cannot directly set someone's hunger. You can however give people hunger or saturation status effects to manipulate their hunger levels.

To give everyone on blue team Hunger II for 10 seconds:

/effect @a[team=blue] hunger 10 1

To give everyone on red team Saturation V for 20 seconds:

/effect @a[team=red] saturation 400 4

Note that the effect potency (last argument) is one less than what it shows as, and the duration (second to last argument) is in seconds on hunger, but ticks on saturation (blame Mojang).

If you want to make sure someone is at a certain level of hunger, you'll need to periodically:

  1. Give them really potent hunger, making everyone have 0 hunger points
  2. Give them just enough saturation to get them up to the hunger level you want

It's a bit of a workaround to the fact that /entitydata doesn't work on players.