Adding food
This tutorial will assume that you already understand Creating your First Item
Adding a FoodComponent
to an item’s settings makes that item food. A FoodComponent
can be created using a FoodComponent.Builder
. Try reading the inline documentation (Javadocs) of the builder to understand what’s going on here, or continue reading for an explanation:
public static final Item EXAMPLE_FOOD = new Item(new QuiltItemSettings().food(
new FoodComponent.Builder()
.hunger(2)
.saturationModifier(1)
.snack()
.alwaysEdible()
.meat()
.statusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, 10), 0.8f)
.build()
));
Now that you tried using the Javadocs cough, cough, here is an alternate explanation:
- We instantiate a new builder. Using this, we can configure the
FoodComponent
before finally turning it into a properFoodComponent
. Note that all the following values are by default 0, false or empty. - We set the hunger to 2, which corresponds to one of the total 10 drumsticks in Minecraft.
- We set the saturation modifier, which, multiplied by the hunger value and 2, is added to the saturation.
- We make it a snack, which means that it gets eaten quickly, just like dried kelp.
- We make it always edible (even when hunger is full), just like suspicious stew.
- We mark it as meat, so that wolves can eat it.
- We add a Night Vision status effect which will be applied for 10 seconds with a 80% chance.
- Finally, we create a proper
FoodComponent
from the builder using thebuild
method.