Skip to content

Commit cfded0e

Browse files
committed
Added DummyPotionType
1 parent a54f128 commit cfded0e

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)