Skip to content

Commit 21ea7ca

Browse files
committed
Added interface for @Agadar's Brewing API
1 parent 7bea83e commit 21ea7ca

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.agadar.brewingapi;
2+
3+
import java.util.List;
4+
5+
import clashsoft.brewingapi.potion.PotionTypeList;
6+
import clashsoft.brewingapi.potion.recipe.CustomPotionRecipe;
7+
import clashsoft.brewingapi.potion.recipe.PotionRecipes;
8+
import clashsoft.brewingapi.potion.type.IPotionType;
9+
import clashsoft.brewingapi.potion.type.PotionType;
10+
import clashsoft.cslib.logging.CSLog;
11+
12+
import net.minecraft.item.ItemPotion;
13+
import net.minecraft.item.ItemStack;
14+
import net.minecraft.nbt.NBTTagList;
15+
import net.minecraft.potion.PotionEffect;
16+
17+
/**
18+
* Manages all brewing recipes.
19+
*/
20+
public class BrewingRecipes
21+
{
22+
private static final BrewingRecipes brewingBase = new BrewingRecipes();
23+
24+
/**
25+
* Returns the instance.
26+
*/
27+
public static BrewingRecipes brewing()
28+
{
29+
return brewingBase;
30+
}
31+
32+
/**
33+
* Adds a new brewing recipe, where applying the ingredient to the input
34+
* results in the output.
35+
*
36+
* @param input
37+
* the input potion
38+
* @param ingredient
39+
* the ingredient
40+
* @param output
41+
* the output potion
42+
*/
43+
public void addBrewing(ItemStack input, ItemStack ingredient, ItemStack output)
44+
{
45+
if (input == null || input.stackSize <= 0 || ingredient == null || ingredient.stackSize <= 0 || output == null || output.stackSize <= 0)
46+
{
47+
CSLog.error("Error while adding a brewing recipe - the ItemStacks may not be null or have a stack size smaller than 1.");
48+
return;
49+
}
50+
51+
if (!(input.getItem() instanceof ItemPotion) || !(output.getItem() instanceof ItemPotion))
52+
{
53+
CSLog.error("Error while adding a brewing recipe - the Items of the input and the output ItemStacks have to be instances of ItemPotion.");
54+
return;
55+
}
56+
57+
new CustomPotionRecipe(input, ingredient, output).register();
58+
}
59+
60+
/**
61+
* Returns whether the given {@link ItemStack} is a valid ingredient for any
62+
* brewing recipe.
63+
*
64+
* @param ingredient
65+
* the ingredient
66+
*/
67+
public boolean isPotionIngredient(ItemStack ingredient)
68+
{
69+
return PotionRecipes.isIngredient(ingredient);
70+
}
71+
72+
/**
73+
* Returns the result of applying the given ingredient to the given input.
74+
* Returns null if the brewing recipe does not exist.
75+
*
76+
* @param input
77+
* the input potion
78+
* @param ingredient
79+
* the ingredient
80+
*/
81+
public ItemStack getBrewingResult(ItemStack input, ItemStack ingredient)
82+
{
83+
return PotionRecipes.applyIngredient(input, ingredient);
84+
}
85+
86+
/**
87+
* Translates the given {@link List} of {@link PotionEffect}s to an
88+
* {@link NBTTagList} and adds it to the given {@link ItemStack}'s NBT.
89+
*/
90+
public void setEffects(ItemStack stack, List<PotionEffect> effects)
91+
{
92+
PotionTypeList potionTypes = new PotionTypeList(stack);
93+
for (PotionEffect effect : effects)
94+
{
95+
IPotionType type = PotionType.getFromEffect(effect);
96+
potionTypes.add(type);
97+
}
98+
potionTypes.save();
99+
}
100+
101+
/**
102+
* Calculates the duration modifier for a potion effect according to the
103+
* given parameters.
104+
*/
105+
public float getDurationModifier(boolean splash, int amplification, boolean extended)
106+
{
107+
float modifier = splash ? 0.75F : 1.0F;
108+
modifier /= 2 << amplification;
109+
return extended ? modifier * 8F / 3F : modifier;
110+
}
111+
}

0 commit comments

Comments
 (0)