Skip to content

How to make a food item in a Minecraft mod

An item is food when its properties carry food properties (FoodProperties, built with FoodProperties.Builder; Food on 1.16.5, and on 1.12.2 an ItemFood instead). Nutrition is the hunger it fills in half drumsticks, and the saturation modifier is how long that lasts. The builder can also let players eat it when full (alwaysEdible, called alwaysEat before 1.20.5), eat it quickly (fast), and, before 1.21.2, give a mob effect (effect).

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Build the food properties with nutrition and saturation modifier.
  2. Pass them to the item’s properties with .food(…).
  3. Register the item, with its model, texture and name.

The example uses these values. Change them in the code.

Setting In the example What it does
nutrition 6 The hunger it fills, in half drumsticks (bread 5, steak 8).
saturation 0.6 How long it keeps hunger away (bread 0.6, steak 0.8).

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Fabric and NeoForge 1.20.1 to 1.20.4, Forge 1.17.1 to 1.20.1, Fabric 1.16.5 to 1.20

Section titled “Fabric and NeoForge 1.20.1 to 1.20.4, Forge 1.17.1 to 1.20.1, Fabric 1.16.5 to 1.20”

Uses:

  • FoodProperties.Builder.nutrition
  • FoodProperties.Builder.saturationMod
  • Item.Properties.food

It’s registered like any other item: see a new item.

new Item.Properties().food(new FoodProperties.Builder().nutrition(6).saturationMod(0.6F).build())

Uses:

  • FoodProperties.Builder.nutrition
  • FoodProperties.Builder.saturationModifier
  • Item.Properties.food

It’s registered like any other item: see a new item.

new Item.Properties().food(new FoodProperties.Builder().nutrition(6).saturationModifier(0.6F).build())

Uses:

  • FoodProperties.Builder.nutrition
  • FoodProperties.Builder.saturationModifier
  • Item.Properties.food

An item’s properties need its id set before the item is made (setId); register the item with the same id, or the game crashes at startup.

It’s registered like any other item: see a new item.

new Item.Properties().setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath("examplemod", "berry_tart"))).food(new FoodProperties.Builder().nutrition(6).saturationModifier(0.6F).build())

Uses:

  • FoodProperties.Builder.nutrition
  • FoodProperties.Builder.saturationModifier
  • Item.Properties.food

An item’s properties need its id set before the item is made (setId); register the item with the same id, or the game crashes at startup.

It’s registered like any other item: see a new item.

new Item.Properties().setId(ResourceKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath("examplemod", "berry_tart"))).food(new FoodProperties.Builder().nutrition(6).saturationModifier(0.6F).build())

Uses:

  • Food.Builder.nutrition
  • Food.Builder.saturationMod
  • Item.Properties.food

It’s registered like any other item: see a new item.

new Item.Properties().food(new Food.Builder().nutrition(6).saturationMod(0.6F).build())

Uses:

  • ItemFood

In 1.12.2 the item extends ItemFood, whose constructor takes the hunger, the saturation and whether wolves eat it.

src/main/java/com/example/examplemod/item/BerryTartItem.java

package com.example.examplemod.item;
import net.minecraft.item.ItemFood;
// Berry Tart: food worth 6 food points. The second number is the saturation modifier; false means it is not wolf food.
public class BerryTartItem extends ItemFood {
public BerryTartItem() {
super(6, 0.6F, false);
}
}

It’s registered like any other item, as BerryTartItem: see a new item.

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.