Food items are one of the most common additions to any mod. In Minecraft, any item can be made edible by attaching a FoodProperties instance to its properties. This tutorial walks through defining nutrition, saturation, and optional status effects, all from the common module, then wires up the model and creative tab entries through datagen. We will be creating a Tomato.
ItemRegistry.Food Properties
Food behaviour is defined through a FoodProperties object built with its inner Builder. Declare a public static final constant in ItemRegistry so the same properties object can be reused:
The two required values are:
nutrition(int): the number of hunger points restored (each shank is 2 points, so 4 restores two full shanks).saturationModifier(float): the saturation multiplier. Actual saturation gained isnutrition × saturationModifier × 2, so 4 × 0.3 × 2 = 2.4 saturation points.
Two optional modifiers worth knowing about are:
.alwaysEdible(): allows eating even when the hunger bar is full, like golden apples..fast(): shortens the eating animation to match dried kelp.
Registering the Item
Register the food item by passing TOMATO_PROPERTIES to Item.Properties.food():
No subclass is needed for a basic food item. The food() call on the properties object is all that is required to make a plain Item edible.
Status Effects on Eating
To apply a status effect when the food is eaten, add one or more .effect() calls to the builder. Each call takes a MobEffectInstance and a probability between 0.0 (never) and 1.0 (always):
The MobEffectInstance constructor takes the effect, duration in ticks, and amplifier (0 for level I, 1 for level II, and so on). The example above always grants Speed I for 10 seconds and has a 10% chance of inflicting Poison I for 3 seconds.
Creative Tab and Language File
Open CreativeTabRegistry and add the new food item to the display items list of your existing tab:
Add a display name by opening ExampleLanguageProvider and adding a line to addTranslations():
Datagen
Food items use the flat 2D inventory model, so they are handled by registerSimpleFlatItemModel. Open ExampleModelProvider and add the tomato to registerModels:
Create a 16x16 PNG texture at common/src/main/resources/assets/examplemod/textures/item/tomato.png and run NeoForge Data to generate the model files.
Testing In-Game
Launch the client and find the food item in your creative tab. Switch to survival mode (or use /gamemode survival) and lower your hunger bar with /effect give @s minecraft:hunger 10 4, then eat the item. Verify that the hunger and saturation bars increase correctly and that the Speed effect appears in the active effects overlay.
saturation in the debug screen overlay, or by using a mod such as AppleSkin.You can find the source for this tutorial here:
View Source on GitHubCustom Tools (MultiLoader 26.1+)
Implement a custom Tier with a dedicated incorrect-blocks tag, register sword, pickaxe, and axe items, generate handheld item models, and verify harvest level ordering with datagen block tags.
Continue →