🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21
This page is written for version:
1.21
Potions are consumables that grants an entity an effect. A player can brew potions using a Brewing Stand or obtain them as items through various other game mechanics.
Just like items and blocks, potions need to be registered.
Let's start by declaring a field to store your Potion
instance. We will be directly using a ModInitializer
-implementing class to hold this.
public static final Potion TATER_POTION =
Registry.register(
Registries.POTION,
Identifier.of("fabric-docs-reference", "tater"),
new Potion(
new StatusEffectInstance(
Registries.STATUS_EFFECT.getEntry(FabricDocsReferenceEffects.TATER_EFFECT),
3600,
0)));
We pass an instance of StatusEffectInstance
, which takes 3 parameters:
RegistryEntry<StatusEffect> type
- An effect. We use our custom effect here. Alternatively you can access vanilla effects through vanilla's StatusEffects
class.int duration
- Duration of the effect in game ticks.int amplifier
- An amplifier for the effect. For example, Haste II would have an amplifier of 1.INFO
To create your own potion effect, please see the Effects guide.
In our initializer, we will use the FabricBrewingRecipeRegistryBuilder.BUILD
event to register our potion using the BrewingRecipeRegistry.registerPotionRecipe
method.
public void onInitialize() {
FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> {
builder.registerPotionRecipe(
// Input potion.
Potions.WATER,
// Ingredient
Items.POTATO,
// Output potion.
Registries.POTION.getEntry(TATER_POTION)
);
});
}
}
// :::1
registerPotionRecipe
takes 3 parameters:
RegistryEntry<Potion> input
- The starting potion's registry entry. Usually this can be a Water Bottle or an Awkward Potion.Item item
- The item which is the main ingredient of the potion.RegistryEntry<Potion> output
- The resultant potion's registry entry.Once registered, you can brew a Tater potion using a potato.