Skip to content

Commit

Permalink
Fixed crash when a witch uses a potion
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Apr 19, 2014
1 parent 3f2435d commit 4434c5d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
2 changes: 1 addition & 1 deletion entity/EntityPotion2.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void onImpact(MovingObjectPosition movingObjectPosition)
if (!this.worldObj.isRemote)
{
ItemStack potion = this.getPotion();
List<IPotionType> types = ((ItemPotion2) potion.getItem()).getEffects(potion);
List<IPotionType> types = ((ItemPotion2) potion.getItem()).getPotionTypes(potion);

if (types != null && !types.isEmpty())
{
Expand Down
79 changes: 51 additions & 28 deletions item/ItemPotion2.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,50 +66,73 @@ public CreativeTabs[] getCreativeTabs()
return new CreativeTabs[] { BrewingAPI.potions, CreativeTabs.tabBrewing, CreativeTabs.tabAllSearch };
}

@Override
public List<PotionEffect> getEffects(ItemStack stack)
{
if (stack == null || this.isWater(stack))
{
return Collections.EMPTY_LIST;
}

List<PotionEffect> effects = new LinkedList();
List<IPotionType> types = this.getPotionTypes(stack);

for (IPotionType type : types)
{
PotionEffect effect = type.getEffect();
if (effect != null)
{
effects.add(effect);
}
}

return effects;
}

public List<IPotionType> getLegacyEffects(ItemStack stack)
{
List<PotionEffect> effects = Items.potionitem.getEffects(stack);
List<IPotionType> potionTypes = new ArrayList(effects.size());
List<PotionEffect> effects = super.getEffects(stack);
List<IPotionType> types = new LinkedList();
for (PotionEffect effect : effects)
{
potionTypes.add(PotionType.getFromEffect(effect));
types.add(PotionType.getFromEffect(effect));
}
return potionTypes;
return types;
}

/**
* Returns a list of potion effects for the specified itemstack.
*/
@Override
public List<IPotionType> getEffects(ItemStack stack)
public List<IPotionType> getPotionTypes(ItemStack stack)
{
if (stack != null && !this.isWater(stack))
if (stack == null || this.isWater(stack))
{
return Collections.EMPTY_LIST;
}

NBTTagCompound compound = stack.getTagCompound();
if (compound != null)
{
NBTTagCompound compound = stack.getTagCompound();
if (compound != null)
if (this.effectCache.containsKey(compound))
{
if (this.effectCache.containsKey(compound))
{
return this.effectCache.get(compound);
}
else
{
List<IPotionType> result = PotionType.getPotionTypes(stack);
this.effectCache.put(compound, result);
return result;
}
return this.effectCache.get(compound);
}
else
{
return this.getLegacyEffects(stack);
List<IPotionType> result = PotionType.getPotionTypes(stack);
this.effectCache.put(compound, result);
return result;
}
}
return Collections.EMPTY_LIST;
else
{
return this.getLegacyEffects(stack);
}
}

public boolean hasEffects(ItemStack stack)
{
List<IPotionType> effects = this.getEffects(stack);
List<IPotionType> effects = this.getPotionTypes(stack);
return effects != null && !effects.isEmpty();
}

Expand Down Expand Up @@ -176,7 +199,7 @@ public int getLiquidColor(ItemStack stack)
return 0x0C0CFF;
}

List<IPotionType> effects = this.getEffects(stack);
List<IPotionType> effects = this.getPotionTypes(stack);

if (effects.isEmpty())
{
Expand All @@ -202,7 +225,7 @@ public int getLiquidColor(ItemStack stack)
*/
public boolean isEffectInstant(ItemStack stack)
{
List<IPotionType> effects = this.getEffects(stack);
List<IPotionType> effects = this.getPotionTypes(stack);
if (effects.size() == 0)
{
return false;
Expand All @@ -223,7 +246,7 @@ public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player)
{
if (!world.isRemote)
{
for (IPotionType potionType : this.getEffects(stack))
for (IPotionType potionType : this.getPotionTypes(stack))
{
potionType.apply(player);
}
Expand Down Expand Up @@ -328,7 +351,7 @@ public String getItemStackDisplayName(ItemStack stack)
}
else
{
List<IPotionType> potionTypes = this.getEffects(stack);
List<IPotionType> potionTypes = this.getPotionTypes(stack);
List<IPotionType> effects = new ArrayList();
List<PotionBase> bases = new ArrayList();

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

Expand Down Expand Up @@ -662,7 +685,7 @@ public boolean hasEffect(ItemStack stack, int pass)
{
if (pass == 0 && stack.getItemDamage() > 0)
{
List<IPotionType> list = this.getEffects(stack);
List<IPotionType> list = this.getPotionTypes(stack);
return list != null && !list.isEmpty() && list.get(0).getEffect() != null;
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions potion/type/PotionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public static ItemStack applyIngredient(ItemStack ingredient, ItemStack potion)
PotionBase requiredBase = potionType.getBase();
boolean flag = false;

List<IPotionType> potionTypes = ((ItemPotion2) potion.getItem()).getEffects(potion);
List<IPotionType> potionTypes = ((ItemPotion2) potion.getItem()).getPotionTypes(potion);

if (requiredBase == null)
{
Expand Down Expand Up @@ -619,7 +619,7 @@ public static boolean canApplyIngredient(ItemStack ingredient, ItemStack potion)
IPotionType type = getFromIngredient(ingredient);
if (type != null)
{
List<IPotionType> potionTypes = ((ItemPotion2) potion.getItem()).getEffects(potion);
List<IPotionType> potionTypes = ((ItemPotion2) potion.getItem()).getPotionTypes(potion);
return hasBase(type, potionTypes);
}
}
Expand Down Expand Up @@ -711,7 +711,7 @@ public static float getExperience(ItemStack stack)
if (stack != null && stack.getItem() instanceof ItemPotion2)
{
ItemPotion2 item = (ItemPotion2) stack.getItem();
List<IPotionType> effects = item.getEffects(stack);
List<IPotionType> effects = item.getPotionTypes(stack);
float value = item.isSplashDamage(stack.getItemDamage()) ? 0.3F : 0.2F;
for (IPotionType b : effects)
{
Expand Down
4 changes: 2 additions & 2 deletions tileentity/TileEntityBrewingStand2.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private boolean canBrew()
{
ItemPotion2 potion = (ItemPotion2) potionStack.getItem();
boolean water = potion.isWater(potionStack);
List<IPotionType> types = potion.getEffects(potionStack);
List<IPotionType> types = potion.getPotionTypes(potionStack);

if (item == Items.glowstone_dust && !water)
{
Expand Down Expand Up @@ -150,7 +150,7 @@ private void brewPotions()
ItemPotion2 potionItem = (ItemPotion2) stack.getItem();
int damage = stack.getItemDamage();
boolean water = potionItem.isWater(stack);
List<IPotionType> types = potionItem.getEffects(stack);
List<IPotionType> types = potionItem.getPotionTypes(stack);
List<IPotionType> newTypes = new ArrayList(types.size());

boolean flag = false;
Expand Down

0 comments on commit 4434c5d

Please sign in to comment.