@@ -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 ;
0 commit comments