🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.20.4
This page is written for version:
1.20.4
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:
To add a food component to an item, we can pass it to the FabricItemSettings
instance:
new FabricItemSettings().food(new FoodComponent.Builder().build())
Right now, this just makes the item edible and nothing more.
The FoodComponent.Builder
class has many methods that allow you to modify what happens when a player eats your item:
Method | Description |
---|---|
hunger | Sets the amount of hunger points your item will replenish. |
saturationModifier | Sets the amount of saturation points your item will add. |
meat | Declares your item as meat. Carnivorous entities, such as wolves, will be able to eat it. |
alwaysEdible | Allows your item to be eaten regardless of hunger level. |
snack | Declares your item as a snack. |
statusEffect | Adds a status effect when you eat your item. Usually a status effect instance and chance is passed to this method, where chance is a decimal percentage (1f = 100% ) |
When you've modified the builder to your liking, you can call the build()
method to get the FoodComponent
Using the example created in the Creating Your First Item page, I'll be using the following options for the builder:
public static final FoodComponent SUSPICIOUS_FOOD_COMPONENT = new FoodComponent.Builder()
.alwaysEdible()
.snack()
// The duration is in ticks, 20 ticks = 1 second
.statusEffect(new StatusEffectInstance(StatusEffects.POISON, 6 * 20, 1), 1.0f)
.build();
This makes the item: