Skip to content

Commit 4434c5d

Browse files
committed
Fixed crash when a witch uses a potion
1 parent 3f2435d commit 4434c5d

File tree

4 files changed

+57
-34
lines changed

4 files changed

+57
-34
lines changed

entity/EntityPotion2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void onImpact(MovingObjectPosition movingObjectPosition)
6868
if (!this.worldObj.isRemote)
6969
{
7070
ItemStack potion = this.getPotion();
71-
List<IPotionType> types = ((ItemPotion2) potion.getItem()).getEffects(potion);
71+
List<IPotionType> types = ((ItemPotion2) potion.getItem()).getPotionTypes(potion);
7272

7373
if (types != null && !types.isEmpty())
7474
{

item/ItemPotion2.java

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,50 +66,73 @@ public CreativeTabs[] getCreativeTabs()
6666
return new CreativeTabs[] { BrewingAPI.potions, CreativeTabs.tabBrewing, CreativeTabs.tabAllSearch };
6767
}
6868

69+
@Override
70+
public List<PotionEffect> getEffects(ItemStack stack)
71+
{
72+
if (stack == null || this.isWater(stack))
73+
{
74+
return Collections.EMPTY_LIST;
75+
}
76+
77+
List<PotionEffect> effects = new LinkedList();
78+
List<IPotionType> types = this.getPotionTypes(stack);
79+
80+
for (IPotionType type : types)
81+
{
82+
PotionEffect effect = type.getEffect();
83+
if (effect != null)
84+
{
85+
effects.add(effect);
86+
}
87+
}
88+
89+
return effects;
90+
}
91+
6992
public List<IPotionType> getLegacyEffects(ItemStack stack)
7093
{
71-
List<PotionEffect> effects = Items.potionitem.getEffects(stack);
72-
List<IPotionType> potionTypes = new ArrayList(effects.size());
94+
List<PotionEffect> effects = super.getEffects(stack);
95+
List<IPotionType> types = new LinkedList();
7396
for (PotionEffect effect : effects)
7497
{
75-
potionTypes.add(PotionType.getFromEffect(effect));
98+
types.add(PotionType.getFromEffect(effect));
7699
}
77-
return potionTypes;
100+
return types;
78101
}
79102

80103
/**
81104
* Returns a list of potion effects for the specified itemstack.
82105
*/
83-
@Override
84-
public List<IPotionType> getEffects(ItemStack stack)
106+
public List<IPotionType> getPotionTypes(ItemStack stack)
85107
{
86-
if (stack != null && !this.isWater(stack))
108+
if (stack == null || this.isWater(stack))
109+
{
110+
return Collections.EMPTY_LIST;
111+
}
112+
113+
NBTTagCompound compound = stack.getTagCompound();
114+
if (compound != null)
87115
{
88-
NBTTagCompound compound = stack.getTagCompound();
89-
if (compound != null)
116+
if (this.effectCache.containsKey(compound))
90117
{
91-
if (this.effectCache.containsKey(compound))
92-
{
93-
return this.effectCache.get(compound);
94-
}
95-
else
96-
{
97-
List<IPotionType> result = PotionType.getPotionTypes(stack);
98-
this.effectCache.put(compound, result);
99-
return result;
100-
}
118+
return this.effectCache.get(compound);
101119
}
102120
else
103121
{
104-
return this.getLegacyEffects(stack);
122+
List<IPotionType> result = PotionType.getPotionTypes(stack);
123+
this.effectCache.put(compound, result);
124+
return result;
105125
}
106126
}
107-
return Collections.EMPTY_LIST;
127+
else
128+
{
129+
return this.getLegacyEffects(stack);
130+
}
108131
}
109132

110133
public boolean hasEffects(ItemStack stack)
111134
{
112-
List<IPotionType> effects = this.getEffects(stack);
135+
List<IPotionType> effects = this.getPotionTypes(stack);
113136
return effects != null && !effects.isEmpty();
114137
}
115138

@@ -176,7 +199,7 @@ public int getLiquidColor(ItemStack stack)
176199
return 0x0C0CFF;
177200
}
178201

179-
List<IPotionType> effects = this.getEffects(stack);
202+
List<IPotionType> effects = this.getPotionTypes(stack);
180203

181204
if (effects.isEmpty())
182205
{
@@ -202,7 +225,7 @@ public int getLiquidColor(ItemStack stack)
202225
*/
203226
public boolean isEffectInstant(ItemStack stack)
204227
{
205-
List<IPotionType> effects = this.getEffects(stack);
228+
List<IPotionType> effects = this.getPotionTypes(stack);
206229
if (effects.size() == 0)
207230
{
208231
return false;
@@ -223,7 +246,7 @@ public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player)
223246
{
224247
if (!world.isRemote)
225248
{
226-
for (IPotionType potionType : this.getEffects(stack))
249+
for (IPotionType potionType : this.getPotionTypes(stack))
227250
{
228251
potionType.apply(player);
229252
}
@@ -328,7 +351,7 @@ public String getItemStackDisplayName(ItemStack stack)
328351
}
329352
else
330353
{
331-
List<IPotionType> potionTypes = this.getEffects(stack);
354+
List<IPotionType> potionTypes = this.getPotionTypes(stack);
332355
List<IPotionType> effects = new ArrayList();
333356
List<PotionBase> bases = new ArrayList();
334357

@@ -424,7 +447,7 @@ public void addInformation(ItemStack stack, EntityPlayer player, List list, bool
424447
{
425448
if (!this.isWater(stack))
426449
{
427-
List<IPotionType> potionTypes = this.getEffects(stack);
450+
List<IPotionType> potionTypes = this.getPotionTypes(stack);
428451
Multimap<String, AttributeModifier> hashmultimap = TreeMultimap.create(String.CASE_INSENSITIVE_ORDER, AttributeModifierComparator.instance);
429452
int size = potionTypes.size();
430453

@@ -662,7 +685,7 @@ public boolean hasEffect(ItemStack stack, int pass)
662685
{
663686
if (pass == 0 && stack.getItemDamage() > 0)
664687
{
665-
List<IPotionType> list = this.getEffects(stack);
688+
List<IPotionType> list = this.getPotionTypes(stack);
666689
return list != null && !list.isEmpty() && list.get(0).getEffect() != null;
667690
}
668691
return false;

potion/type/PotionType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ public static ItemStack applyIngredient(ItemStack ingredient, ItemStack potion)
579579
PotionBase requiredBase = potionType.getBase();
580580
boolean flag = false;
581581

582-
List<IPotionType> potionTypes = ((ItemPotion2) potion.getItem()).getEffects(potion);
582+
List<IPotionType> potionTypes = ((ItemPotion2) potion.getItem()).getPotionTypes(potion);
583583

584584
if (requiredBase == null)
585585
{
@@ -619,7 +619,7 @@ public static boolean canApplyIngredient(ItemStack ingredient, ItemStack potion)
619619
IPotionType type = getFromIngredient(ingredient);
620620
if (type != null)
621621
{
622-
List<IPotionType> potionTypes = ((ItemPotion2) potion.getItem()).getEffects(potion);
622+
List<IPotionType> potionTypes = ((ItemPotion2) potion.getItem()).getPotionTypes(potion);
623623
return hasBase(type, potionTypes);
624624
}
625625
}
@@ -711,7 +711,7 @@ public static float getExperience(ItemStack stack)
711711
if (stack != null && stack.getItem() instanceof ItemPotion2)
712712
{
713713
ItemPotion2 item = (ItemPotion2) stack.getItem();
714-
List<IPotionType> effects = item.getEffects(stack);
714+
List<IPotionType> effects = item.getPotionTypes(stack);
715715
float value = item.isSplashDamage(stack.getItemDamage()) ? 0.3F : 0.2F;
716716
for (IPotionType b : effects)
717717
{

tileentity/TileEntityBrewingStand2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private boolean canBrew()
8888
{
8989
ItemPotion2 potion = (ItemPotion2) potionStack.getItem();
9090
boolean water = potion.isWater(potionStack);
91-
List<IPotionType> types = potion.getEffects(potionStack);
91+
List<IPotionType> types = potion.getPotionTypes(potionStack);
9292

9393
if (item == Items.glowstone_dust && !water)
9494
{
@@ -150,7 +150,7 @@ private void brewPotions()
150150
ItemPotion2 potionItem = (ItemPotion2) stack.getItem();
151151
int damage = stack.getItemDamage();
152152
boolean water = potionItem.isWater(stack);
153-
List<IPotionType> types = potionItem.getEffects(stack);
153+
List<IPotionType> types = potionItem.getPotionTypes(stack);
154154
List<IPotionType> newTypes = new ArrayList(types.size());
155155

156156
boolean flag = false;

0 commit comments

Comments
 (0)