Potions
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.
Custom Potions
Adding a potion follows a similar path as adding an item. You will create an instance of your potion and register it by calling BrewingRecipeRegistry.registerPotionRecipe
.
INFO
When Fabric API is present, BrewingRecipeRegistry.registerPotionRecipe
is made accessible through an Access Widener.
Creating the Potion
Let's start by declaring a field to store your Potion
instance. We will be directly using the initializer class to hold this.
java
public static final Potion TATER_POTION =
Registry.register(
Registries.POTION,
new Identifier("fabric-docs-reference", "tater"),
new Potion(
new StatusEffectInstance(
FabricDocsReferenceEffects.TATER_EFFECT,
3600,
0)));
We pass an instance of StatusEffectInstance
, which takes 3 parameters:
StatusEffect type
- An effect. We use our custom effect here. Alternatively you can access vanilla effects throughnet.minecraft.entity.effect.StatusEffects
.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 effect, please see the Effects guide.
Registering the Potion
In our initializer, we call BrewingRecipeRegistry.registerPotionRecipe
.
java
BrewingRecipeRegistry.registerPotionRecipe(Potions.WATER, Items.POTATO, TATER_POTION);
registerPotionRecipe
takes 3 parameters:
Potion input
- The starting potion. Usually this can be a Water Bottle or an Awkward Potion.Item item
- The item which is the main ingredient of the potion.Potion output
- The resultant potion.
If you use Fabric API, the mixin invoker is not necessary and a direct call to BrewingRecipeRegistry.registerPotionRecipe
can be done.
The full example:
java
public class FabricDocsReferencePotions implements ModInitializer {
public static final Potion TATER_POTION =
Registry.register(
Registries.POTION,
new Identifier("fabric-docs-reference", "tater"),
new Potion(
new StatusEffectInstance(
FabricDocsReferenceEffects.TATER_EFFECT,
3600,
0)));
@Override
public void onInitialize() {
BrewingRecipeRegistry.registerPotionRecipe(Potions.WATER, Items.POTATO, TATER_POTION);
// Use the mixin invoker if you are not using Fabric API
// BrewingRecipeRegistryInvoker.invokeRegisterPotionRecipe(Potions.WATER, Items.POTATO, TATER_POTION);
}
}
Once registered, you can brew a Tater potion using a potato.
INFO
Registering Potions Using an Ingredient
With the help of Fabric API, it's possible to register a potion using an Ingredient
instead of an Item
using net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistry
.
Registering the Potion without Fabric API
Without Fabric API, BrewingRecipeRegistry.registerPotionRecipe
will be private. In order to access this method, use the following mixin invoker or use an Access Widener.
java
@Mixin(BrewingRecipeRegistry.class)
public interface BrewingRecipeRegistryInvoker {
@Invoker("registerPotionRecipe")
static void invokeRegisterPotionRecipe(Potion input, Item item, Potion output) {
throw new AssertionError();
}
}