Le pozioni sono oggetti consumabili che conferiscono un effetto a un'entità. Un giocatore può preparare delle pozioni usando l'Alambicco oppure ottenerle come oggetti attraverso varie meccaniche di gioco.
Pozioni Personalizzate
Aggiungere una pozione segue un percorso simile a quello per aggiungere un oggetto. Dovrai creare un'istanza della tua pozione e registrarla chiamando BrewingRecipeRegistry.registerPotionRecipe.
INFO
Quando l'API di Fabric è presente, BrewingRecipeRegistry.registerPotionRecipe è reso disponibile attraverso un Access Widener.
Creare la Pozione
Iniziamo dichiarando un attributo per conservare la tua istanza Potion. Useremo direttamente la classe dell'initializer per conservarla.
java
public class ExampleModPotions implements ModInitializer {
public static final Potion TATER_POTION =
Registry.register(
BuiltInRegistries.POTION,
ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "tater"),
new Potion("tater",
new MobEffectInstance(
ExampleModEffects.TATER,
3600,
0)));1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Passiamo una istanza di StatusEffectInstance, che prende 3 parametri:
StatusEffect type- Un effetto. Qui usiamo il nostro effetto personalizzato. In alternativa puoi accedere agli effetti vanilla attraversonet.minecraft.entity.effect.StatusEffects.int duration- Durata dell'effetto espressa in tick di gioco.int amplifier- Un amplificatore per l'effetto. Per esempio, Sollecitudine II avrebbe un amplificatore di 1.
INFO
Per creare il tuo effetto personalizzato, per favore guarda la guida Effetti.
Registrare la Pozione
Nel nostro initializer, chiamiamo BrewingRecipeRegistry.registerPotionRecipe.
java
public void onInitialize() {1
registerPotionRecipe prende 3 parametri:
Potion input- La pozione iniziale. Solitamente questa può essere una Ampolla d'Acqua o una Pozione Strana.Item item- L'oggetto che rappresenta l'ingrediente principale della pozione.Potion output- La pozione risultante.
Se utilizzi l'API di Fabric, l'invoker mixin non è necessario e si può effettuare una chiamata diretta a BrewingRecipeRegistry.registerPotionRecipe.
L'esempio per intero:
java
public class ExampleModPotions implements ModInitializer {
public static final Potion TATER_POTION =
Registry.register(
BuiltInRegistries.POTION,
ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "tater"),
new Potion("tater",
new MobEffectInstance(
ExampleModEffects.TATER,
3600,
0)));
@Override
public void onInitialize() {
FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> {
builder.addMix(
// Input potion.
Potions.WATER,
// Ingredient
Items.POTATO,
// Output potion.
BuiltInRegistries.POTION.wrapAsHolder(TATER_POTION)
);
});
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Una volta registrato, puoi distillare una pozione Tater usando una patata.

Registrare Pozioni Usando un Ingredient
Con l'aiuto dell'API di Fabric, è possibile registrare una pozione usando un Ingredient anziché un Item usando net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistry.
Registrare la Pozione Senza l'API di Fabric
Senza l'API di Fabric, BrewingRecipeRegistry.registerPotionRecipe sarà privato. Per accedere a questo metodo usa il seguente invoker mixin o usa un Access Widener.
java
Not Found: /home/runner/work/fabric-docs/fabric-docs/reference/latest/src/main/java/com/example/docs/mixin/potion/BrewingRecipeRegistryInvoker.java1


