Food is a core aspect of survival Minecraft, so when creating edible items you have to consider the food's usage with other edible items.
Unless you're making a mod with overpowered items, you should consider:
- How much hunger your edible item adds or removes.
- What potion effect(s) does it grant?
- Is it early-game or endgame accessible?
Adding the Food Component
To add a food component to an item, we can pass it to the Item.Properties instance:
java
new Item.Properties().food(new FoodProperties.Builder().build())1
Right now, this just makes the item edible and nothing more.
The FoodProperties.Builder class has some methods that allow you to modify what happens when a player eats your item:
| Method | Description |
|---|---|
nutrition | Sets the amount of hunger points your item will replenish. |
saturationModifier | Sets the amount of saturation points your item will add. |
alwaysEdible | Allows your item to be eaten regardless of hunger level. |
When you've modified the builder to your liking, you can call the build() method to get the FoodProperties.
If you want to add status effects to the player when they eat your food, you will need to add a Consumable component alongside the FoodProperties component as seen in the following example:
java
public static final Consumable POISON_FOOD_CONSUMABLE_COMPONENT = Consumables.defaultFood()
// The duration is in ticks, 20 ticks = 1 second
.onConsume(new ApplyStatusEffectsConsumeEffect(new MobEffectInstance(MobEffects.POISON, 6 * 20, 1), 1.0f))
.build();
public static final FoodProperties POISON_FOOD_COMPONENT = new FoodProperties.Builder()
.alwaysEdible()
.build();1
2
3
4
5
6
7
2
3
4
5
6
7
Similar to the example in the Creating Your First Item page, I'll be using the above component:
java
public static final Item POISONOUS_APPLE = register(
"poisonous_apple",
Item::new,
new Item.Properties().food(POISON_FOOD_COMPONENT, POISON_FOOD_CONSUMABLE_COMPONENT)
);1
2
3
4
5
2
3
4
5
This makes the item:
- Always edible, it can be eaten regardless of hunger level.
- Always give Poison II for 6 seconds when eaten.

