Skip to content

Commit 7c2d951

Browse files
committed
Minor changes
1 parent 69f373c commit 7c2d951

4 files changed

Lines changed: 103 additions & 59 deletions

File tree

src/main/java/clashsoft/brewingapi/potion/PotionTypeList.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public void setSplash(boolean flag)
6161
((ItemPotion2) this.stack.getItem()).setSplash(this.stack, flag);
6262
}
6363

64+
public void setStack(ItemStack stack)
65+
{
66+
this.load(stack, true);
67+
}
68+
6469
/**
6570
* Loads this {@link PotionTypeList} from the given {@link ItemStack}
6671
* {@code stack} the syncs the list with it. If {@code oldEffects} is true
@@ -89,7 +94,7 @@ public void load(ItemStack stack, boolean oldEffects)
8994
IPotionType type = PotionType.getFromNBT(compound);
9095
if (type != null)
9196
{
92-
super.add(type);
97+
this.add(type);
9398
}
9499
}
95100
}

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55

66
import clashsoft.brewingapi.potion.PotionList;
7+
import clashsoft.brewingapi.potion.PotionTypeList;
78
import clashsoft.brewingapi.potion.base.IPotionBase;
89
import clashsoft.brewingapi.potion.type.IPotionType;
910
import clashsoft.brewingapi.potion.type.PotionType;
@@ -29,6 +30,87 @@ public static List<IPotionRecipe> getRecipes()
2930
return recipes;
3031
}
3132

33+
/**
34+
* Checks if the given {@link ItemStack} {@code ingredient} is a valid
35+
* potion ingredient.
36+
*
37+
* @param ingredient
38+
* the igredient
39+
* @return true, if the stack is a valid potion ingredient
40+
*/
41+
public static boolean isIngredient(ItemStack ingredient)
42+
{
43+
for (IPotionRecipe recipe : recipes)
44+
{
45+
if (CSStacks.equals(recipe.getIngredient(), ingredient))
46+
{
47+
return true;
48+
}
49+
}
50+
return false;
51+
}
52+
53+
/**
54+
* Checks if the given {@link ItemStack} {@code ingredient} is applicable to
55+
* the given {@link ItemStack} {@code potion}. It does that by going through
56+
* the list of all {@link PotionRecipe}s and calling their
57+
* {@link IPotionRecipe#canApply(ItemStack, PotionTypeList)}. If one of
58+
* these calls returns {@code true}, the ingredient is applicable and
59+
* {@code true} is returned.
60+
*
61+
* @param ingredient
62+
* the ingredient
63+
* @param potion
64+
* the potion
65+
* @return true, if the ingredient is applicable to the potion.
66+
*/
67+
public static boolean canApplyIngredient(ItemStack input, ItemStack ingredient)
68+
{
69+
return canApplyIngredient(new PotionTypeList(input), ingredient);
70+
}
71+
72+
public static boolean canApplyIngredient(PotionTypeList input, ItemStack ingredient)
73+
{
74+
for (IPotionRecipe recipe : recipes)
75+
{
76+
if (recipe.canApply(ingredient, input))
77+
{
78+
return true;
79+
}
80+
}
81+
return false;
82+
}
83+
84+
/**
85+
* Applies the given {@link ItemStack} {@code ingredient} to the given
86+
* {@link ItemStack} {@code potion}. It does that by going through the list
87+
* of all {@link PotionRecipe}s and calling their
88+
* {@link IPotionRecipe#apply(PotionTypeList)} method.
89+
*
90+
* @param ingredient
91+
* the ingredient
92+
* @param potion
93+
* the potion
94+
* @return the potion with applied ingredients
95+
*/
96+
public static ItemStack applyIngredient(ItemStack input, ItemStack ingredient)
97+
{
98+
return applyIngredient(new PotionTypeList(input), ingredient);
99+
}
100+
101+
public static ItemStack applyIngredient(PotionTypeList input, ItemStack ingredient)
102+
{
103+
for (IPotionRecipe recipe : recipes)
104+
{
105+
if (recipe.canApply(ingredient, input))
106+
{
107+
recipe.apply(ingredient, input);
108+
}
109+
}
110+
input.save();
111+
return input.getPotion();
112+
}
113+
32114
/**
33115
* Gets a {@link PotionRecipe} from the given {@link ItemStack}
34116
* {@code ingredient}.

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

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.*;
44

55
import clashsoft.brewingapi.item.ItemPotion2;
6-
import clashsoft.brewingapi.potion.PotionTypeList;
76
import clashsoft.brewingapi.potion.base.IPotionBase;
87
import clashsoft.brewingapi.potion.base.PotionBase;
98
import clashsoft.brewingapi.potion.recipe.IPotionRecipe;
@@ -389,13 +388,17 @@ public static IPotionType getRandom(Random random)
389388
public static IPotionType getFromEffect(PotionEffect effect)
390389
{
391390
if (effect == null)
391+
{
392392
return null;
393+
}
393394

394-
IPotionType potionType = getFromEffect_(effect);
395+
IPotionType potionType = getFromID(effect.getPotionID());
395396
if (potionType != null)
396397
{
398+
// Type exists, create a delegate with the custom potion effect.
397399
return new PotionTypeDelegate(effect, potionType);
398400
}
401+
// Type does not exist, create a dummy type and register it.
399402
return new DummyPotionType(effect, effect.getAmplifier(), effect.getDuration()).register();
400403
}
401404

@@ -446,70 +449,31 @@ public static List<IPotionType> getPotionTypes(ItemStack potion)
446449
}
447450

448451
/**
449-
* Checks if the given {@link ItemStack} {@code ingredient} is a valid
450-
* potion ingredient.
451-
*
452-
* @param ingredient
453-
* the igredient
454-
* @return true, if the stack is a valid potion ingredient
452+
* @deprecated Use {@link PotionRecipes#isIngredient(ItemStack)} instead.
455453
*/
456454
public static boolean isPotionIngredient(ItemStack ingredient)
457455
{
458456
return PotionRecipes.get(ingredient) != null;
459457
}
460458

461459
/**
462-
* Applies the given {@link ItemStack} {@code ingredient} to the given
463-
* {@link ItemStack} {@code potion}. It does that by going through the list
464-
* of all {@link PotionRecipe}s and calling their
465-
* {@link IPotionRecipe#apply(PotionTypeList)} method.
466-
*
467-
* @param ingredient
468-
* the ingredient
469-
* @param potion
470-
* the potion
471-
* @return the potion with applied ingredients
460+
* @deprecated Use
461+
* {@link PotionRecipes#applyIngredient(ItemStack, ItemStack)}
462+
* instead.
472463
*/
473464
public static ItemStack applyIngredient(ItemStack ingredient, ItemStack potion)
474465
{
475-
PotionTypeList potionTypes = new PotionTypeList(potion);
476-
for (IPotionRecipe recipe : PotionRecipes.getRecipes())
477-
{
478-
if (recipe.canApply(ingredient, potionTypes))
479-
{
480-
recipe.apply(ingredient, potionTypes);
481-
}
482-
}
483-
potionTypes.save();
484-
485-
return potionTypes.getPotion();
466+
return PotionRecipes.applyIngredient(potion, ingredient);
486467
}
487468

488469
/**
489-
* Checks if the given {@link ItemStack} {@code ingredient} is applicable to
490-
* the given {@link ItemStack} {@code potion}. It does that by going through
491-
* the list of all {@link PotionRecipe}s and calling their
492-
* {@link IPotionRecipe#canApply(ItemStack, PotionTypeList)}. If one of
493-
* these calls returns {@code true}, the ingredient is applicable and
494-
* {@code true} is returned.
495-
*
496-
* @param ingredient
497-
* the ingredient
498-
* @param potion
499-
* the potion
500-
* @return true, if the ingredient is applicable to the potion.
470+
* @deprecated Use
471+
* {@link PotionRecipes#applyIngredient(ItemStack, ItemStack)}
472+
* instead.
501473
*/
502474
public static boolean canApplyIngredient(ItemStack ingredient, ItemStack potion)
503475
{
504-
PotionTypeList potionTypes = new PotionTypeList(potion);
505-
for (IPotionRecipe recipe : PotionRecipes.getRecipes())
506-
{
507-
if (recipe.canApply(ingredient, potionTypes))
508-
{
509-
return true;
510-
}
511-
}
512-
return false;
476+
return PotionRecipes.canApplyIngredient(potion, ingredient);
513477
}
514478

515479
public static IPotionType getFromID(int potionID)

src/main/java/clashsoft/brewingapi/tileentity/TileEntityBrewingStand2.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,7 @@ private void brewPotions()
103103
PotionTypeList potionTypes = this.potionTypes[i];
104104
if (potionTypes != null)
105105
{
106-
for (IPotionRecipe recipe : PotionRecipes.getRecipes())
107-
{
108-
if (recipe.canApply(ingredient, potionTypes))
109-
{
110-
recipe.apply(ingredient, potionTypes);
111-
}
112-
}
113-
potionTypes.save();
106+
this.brewingItemStacks[i] = PotionRecipes.applyIngredient(potionTypes, ingredient);
114107
}
115108
}
116109

0 commit comments

Comments
 (0)