File tree Expand file tree Collapse file tree
src/main/java/clashsoft/brewingapi/potion/type Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,11 +39,10 @@ public AbstractPotionType register()
3939 int potionID = this .getPotionID ();
4040 if (potionID != -1 )
4141 {
42- if (potionTypes .containsKey (potionID ) )
42+ if (potionTypes .put (potionID , this ) != null )
4343 {
4444 CSLog .warning ("Registering duplicate potion ID " + potionID );
4545 }
46- potionTypes .put (potionID , this );
4746 }
4847
4948 potionTypeList .add (this );
Original file line number Diff line number Diff line change 1+ package clashsoft .brewingapi .potion .type ;
2+
3+ import net .minecraft .potion .PotionEffect ;
4+
5+ import clashsoft .cslib .logging .CSLog ;
6+
7+ /**
8+ * A {@link IPotionType} implementation that is used when
9+ * {@link PotionType#getFromEffect_(PotionEffect)} returns null. In that case, a
10+ * new instance of this class is created and registered using
11+ * {@link #register()}. That ensures that {@link PotionTypeDelegates} do not
12+ * throw {@link NullPointerException}s because their stored potion type is null.
13+ * Potion types of this class do not get added to the creative inventory.
14+ *
15+ * @author Clashsoft
16+ */
17+ public class DummyPotionType extends PotionType
18+ {
19+ public DummyPotionType ()
20+ {
21+ super ();
22+ }
23+
24+ public DummyPotionType (PotionEffect effect , int maxAmplifier , int maxDuration )
25+ {
26+ super (effect , maxAmplifier , maxDuration );
27+ }
28+
29+ @ Override
30+ public DummyPotionType register ()
31+ {
32+ int potionID = this .getPotionID ();
33+ if (potionID != -1 )
34+ {
35+ if (potionTypes .put (potionID , this ) != null )
36+ {
37+ CSLog .warning ("Registering duplicate potion ID " + potionID );
38+ }
39+ }
40+
41+ potionTypeList .add (this );
42+
43+ return this ;
44+ }
45+ }
Original file line number Diff line number Diff line change @@ -396,7 +396,7 @@ public static IPotionType getFromEffect(PotionEffect effect)
396396 {
397397 return new PotionTypeDelegate (effect , potionType );
398398 }
399- return new PotionType (effect , effect .getAmplifier (), effect .getDuration ());
399+ return new DummyPotionType (effect , effect .getAmplifier (), effect .getDuration ()). register ( );
400400 }
401401
402402 protected static IPotionType getFromEffect_ (PotionEffect effect )
You can’t perform that action at this time.
0 commit comments