Skip to content

Commit 590add6

Browse files
committed
Added PotionRecipes.addRecipe for effects
1 parent c433d4f commit 590add6

3 files changed

Lines changed: 54 additions & 20 deletions

File tree

src/main/java/clashsoft/brewingapi/potion/recipe/PotionRecipes.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package clashsoft.brewingapi.potion.recipe;
22

3+
import gnu.trove.map.hash.TCustomHashMap;
4+
35
import java.util.ArrayList;
46
import java.util.List;
57
import java.util.Map;
68

7-
import gnu.trove.map.hash.TCustomHashMap;
89
import clashsoft.brewingapi.potion.type.IPotionType;
910
import clashsoft.brewingapi.potion.type.PotionBase;
11+
import clashsoft.brewingapi.potion.type.PotionType;
1012
import clashsoft.cslib.minecraft.util.ItemStackHashingStrategy;
1113

1214
import net.minecraft.item.ItemStack;
15+
import net.minecraft.potion.PotionEffect;
1316

1417
public class PotionRecipes
1518
{
@@ -86,7 +89,7 @@ public static void registerRecipe(PotionRecipe recipe)
8689
/**
8790
* Creates and registers a new {@link PotionRecipe} from the given
8891
* {@link ItemStack} {@code input} and the given {@link IPotionType}
89-
* {@code output}.
92+
* {@code potionType}.
9093
*
9194
* @param input
9295
* the input stack
@@ -101,7 +104,7 @@ public static void addRecipe(ItemStack ingredient, IPotionType potionType)
101104
/**
102105
* Creates and registers a new {@link PotionRecipe} from the given
103106
* {@link ItemStack} {@code input}, the given {@link PotionBase}
104-
* {@code base} and the given {@link IPotionType} {@code output}.
107+
* {@code base} and the given {@link IPotionType} {@code potionType}.
105108
*
106109
* @param input
107110
* the input stack
@@ -115,4 +118,39 @@ public static void addRecipe(ItemStack ingredient, PotionBase base, IPotionType
115118
if (ingredient != null)
116119
registerRecipe(new PotionRecipe(ingredient, base, potionType));
117120
}
121+
122+
/**
123+
* Creates and registers a new {@link PotionRecipe} from the given
124+
* {@link ItemStack} {@code input} and the given {@link PotionEffect}
125+
* {@code effect}.This automatically finds a {@link PotionType} for the
126+
* effect.
127+
*
128+
* @param input
129+
* the input stack
130+
* @param effect
131+
* the output effect
132+
*/
133+
public static void addRecipe(ItemStack ingredient, PotionEffect effect)
134+
{
135+
addRecipe(ingredient, null, effect);
136+
}
137+
138+
/**
139+
* Creates and registers a new {@link PotionRecipe} from the given
140+
* {@link ItemStack} {@code input}, the given {@link PotionBase}
141+
* {@code base} and the given {@link PotionEffect} {@code effect}. This
142+
* automatically finds a {@link PotionType} for the effect.
143+
*
144+
* @param input
145+
* the input stack
146+
* @param base
147+
* the required potion base
148+
* @param effect
149+
* the output effect
150+
*/
151+
public static void addRecipe(ItemStack ingredient, PotionBase base, PotionEffect effect)
152+
{
153+
if (ingredient != null)
154+
registerRecipe(new PotionRecipe(ingredient, base, PotionType.getFromEffect(effect)));
155+
}
118156
}

src/main/java/clashsoft/brewingapi/potion/type/IPotionType.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
public interface IPotionType extends Comparable<IPotionType>
2121
{
2222
/** Name of the tag compound that stores the potion type list */
23-
public static final String COMPOUND_NAME = "Brewing";
23+
public static final String COMPOUND_NAME = "Brewing";
2424

2525
/** Version identifier for NBTs. **/
26-
public static final String NBT_VERSION = "1.1";
26+
public static final String NBT_VERSION = "1.1";
2727

2828
/** List that stores ALL PotionTypes, also PotionBase types **/
29-
public static TIntObjectMap potionTypes = new TIntObjectHashMap();
30-
public static List<IPotionType> potionTypeList = new ArrayList();
31-
public static List<IPotionType> combinableTypes = new ArrayList();
32-
public static List<IPotionType> effectTypes = new ArrayList();
29+
public static TIntObjectMap<IPotionType> potionTypes = new TIntObjectHashMap();
30+
public static List<IPotionType> potionTypeList = new ArrayList();
31+
public static List<IPotionType> combinableTypes = new ArrayList();
32+
public static List<IPotionType> effectTypes = new ArrayList();
3333

3434
/**
3535
* Returns an unique identifier for this potion type.

src/main/java/clashsoft/brewingapi/potion/type/PotionType.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,20 @@ public static IPotionType getRandom(Random rng)
388388

389389
public static IPotionType getFromEffect(PotionEffect effect)
390390
{
391+
if (effect == null)
392+
return null;
393+
391394
IPotionType potionType = getFromEffect_(effect);
392395
if (potionType != null)
393396
{
394397
return new PotionTypeDelegate(effect, potionType);
395398
}
396-
return effect == null ? null : new PotionType(effect, effect.getAmplifier(), effect.getDuration());
399+
return new PotionType(effect, effect.getAmplifier(), effect.getDuration());
397400
}
398401

399402
protected static IPotionType getFromEffect_(PotionEffect effect)
400403
{
401-
return effect == null ? null : (IPotionType) getFromID(effect.getPotionID());
404+
return effect == null ? null : getFromID(effect.getPotionID());
402405
}
403406

404407
/**
@@ -560,16 +563,9 @@ public static boolean hasBase(IPotionType type, List<IPotionType> types)
560563
return false;
561564
}
562565

563-
public static PotionType getFromID(int potionID)
566+
public static IPotionType getFromID(int potionID)
564567
{
565-
for (IPotionType pt : potionTypeList)
566-
{
567-
if (pt.getPotionID() == potionID)
568-
{
569-
return (PotionType) pt;
570-
}
571-
}
572-
return null;
568+
return potionTypes.get(potionID);
573569
}
574570

575571
/**

0 commit comments

Comments
 (0)