药水
药水是能为实体提供效果的消耗品。 玩家可以使用酿造台酿造药水,或者从其他游戏机制中以物品形式获取它们。
自定义药水
新增药水和新增物品的方式类似。 新增药水和新增物品的方式类似。 你将创建的你的药水的一个实例,并通过调用 BrewingRecipeRegistry.registerPotionRecipe 注册它。
INFO
当 Fabric API 存在时,BrewingRecipeRegistry.registerPotionRecipe 的访问权限会被访问加宽器(Access Widener)设置为 public 。
创建药水
让我们从声明一个用于储存你的 Potion 实例的字段开始。 我们将直接使用入口点类来持有这个字段。 我们将直接使用入口点类来持有这个字段。
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)));我们传入一个 StatusEffectInstance 实例,它的构造方法接收以下 3 个参数:
StatusEffect type- 一个状态效果。 我们在这里使用我们的自定义效果。 此外你也可以通过net.minecraft.entity.effect.StatusEffects访问原版效果。 我们在这里使用我们的自定义效果。 药水是能为实体提供效果的消耗品。 玩家可以使用酿造台酿造药水,或者从其他游戏机制中以物品形式获取它们。int duration- 状态效果的持续时间(以刻计算)。int amplifier- 状态效果的增幅。 比如 急迫 II 的增幅是 1。 比如 急迫 II 的增幅是 1。
INFO
为了创建你自己的效果,请参阅 状态效果 的指南。
注册药水配方
在我们的入口点中,我们调用 BrewingRecipeRegistry.registerPotionRecipe。
java
BrewingRecipeRegistry.registerPotionRecipe(Potions.WATER, Items.POTATO, TATER_POTION);registerPotionRecipe 接收以下 3 个参数:
Potion input- 初始的药水。 通常可以是水瓶或粗制的药水。 通常可以是水瓶或粗制的药水。Item item- 作为药水主要原料的物品。Potion output- 产出的药水。
如果你使用 Fabric API,就没有必要使用 Mixin 注入 @Invoker,可以直接调用 BrewingRecipeRegistry.registerPotionRecipe。
完整的示例:
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);
}
}注册完成后,你就可以用马铃薯酿造土豆药水。

INFO
Registering Potions Using an Ingredient
在 Fabric API 的帮助下,使用 net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistry 可以使用 Ingredient 而非 Item 来注册药水配方。
:::
不使用 Fabric API 注册药水配方
没有 Fabric API 时,BrewingRecipeRegistry.registerPotionRecipe 将会是 private 的。 为了访问这个方法,请使用如下的 @Invoker Mixin,或使用访问加宽器(Access Widener)。 为了访问这个方法,请使用如下的 @Invoker Mixin,或使用访问加宽器(Access Widener)。
java
@Mixin(BrewingRecipeRegistry.class)
public interface BrewingRecipeRegistryInvoker {
@Invoker("registerPotionRecipe")
static void invokeRegisterPotionRecipe(Potion input, Item item, Potion output) {
throw new AssertionError();
}
}

