mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-22 00:04:59 +01:00
[Bleeding] Fixed some issues with no-effect potions, and added more potion tests. Fixes BUKKIT-1251
By: Celtic Minstrel <celtic.minstrel.ca@some.place>
This commit is contained in:
parent
82f7680bd0
commit
da44559df3
2 changed files with 60 additions and 29 deletions
|
@ -31,6 +31,9 @@ public class Potion {
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
this.name = type.getDamageValue();
|
this.name = type.getDamageValue();
|
||||||
}
|
}
|
||||||
|
if (type == null || type == PotionType.WATER) {
|
||||||
|
this.level = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated In favour of {@link #Potion(PotionType, int)} */
|
/** @deprecated In favour of {@link #Potion(PotionType, int)} */
|
||||||
|
@ -104,7 +107,7 @@ public class Potion {
|
||||||
public Potion(int name) {
|
public Potion(int name) {
|
||||||
this(PotionType.getByDamageValue(name & POTION_BIT));
|
this(PotionType.getByDamageValue(name & POTION_BIT));
|
||||||
this.name = name & NAME_BIT;
|
this.name = name & NAME_BIT;
|
||||||
if (name == 0) {
|
if ((name & POTION_BIT) == 0) {
|
||||||
// If it's 0 it would've become PotionType.WATER, but it should actually be mundane potion
|
// If it's 0 it would've become PotionType.WATER, but it should actually be mundane potion
|
||||||
this.type = null;
|
this.type = null;
|
||||||
}
|
}
|
||||||
|
@ -363,7 +366,7 @@ public class Potion {
|
||||||
public static Potion fromDamage(int damage) {
|
public static Potion fromDamage(int damage) {
|
||||||
PotionType type = PotionType.getByDamageValue(damage & POTION_BIT);
|
PotionType type = PotionType.getByDamageValue(damage & POTION_BIT);
|
||||||
Potion potion;
|
Potion potion;
|
||||||
if (type == null) {
|
if (type == null || (type == PotionType.WATER && damage != 0)) {
|
||||||
potion = new Potion(damage & NAME_BIT);
|
potion = new Potion(damage & NAME_BIT);
|
||||||
} else {
|
} else {
|
||||||
int level = (damage & TIER_BIT) >> TIER_SHIFT;
|
int level = (damage & TIER_BIT) >> TIER_SHIFT;
|
||||||
|
@ -406,4 +409,8 @@ public class Potion {
|
||||||
throw new IllegalArgumentException("brewer can only be set internally");
|
throw new IllegalArgumentException("brewer can only be set internally");
|
||||||
brewer = other;
|
brewer = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNameId() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -85,38 +85,62 @@ public class PotionTest {
|
||||||
assertTrue((potion.toDamageValue() & 0x3F) == (PotionType.POISON.getDamageValue() | 0x20));
|
assertTrue((potion.toDamageValue() & 0x3F) == (PotionType.POISON.getDamageValue() | 0x20));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void useNulls() {
|
public void nullType() {
|
||||||
try {
|
new Potion(null, 2);
|
||||||
new Potion(null, 2);
|
}
|
||||||
fail("cannot use null type in constructor with a level");
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
@Test(expected=IllegalArgumentException.class)
|
||||||
new Potion(PotionType.POISON, 3);
|
public void maxLevelConstruct() {
|
||||||
fail("level must be less than 3 in constructor");
|
new Potion(PotionType.POISON, 3);
|
||||||
} catch (IllegalArgumentException ex) {
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
public void maxLevelSet() {
|
||||||
Potion potion = new Potion(PotionType.POISON);
|
Potion potion = new Potion(PotionType.POISON);
|
||||||
try {
|
potion.setLevel(3);
|
||||||
potion.setLevel(3);
|
}
|
||||||
fail("level must be set less than 3");
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
@Test(expected=IllegalArgumentException.class)
|
||||||
potion.apply((ItemStack) null);
|
public void nullStack() {
|
||||||
fail("cannot apply to a null itemstack");
|
Potion potion = new Potion(PotionType.POISON);
|
||||||
} catch (IllegalArgumentException ex) {
|
potion.apply((ItemStack) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
@Test(expected=IllegalArgumentException.class)
|
||||||
potion.apply((LivingEntity) null);
|
public void nullEntity() {
|
||||||
fail("cannot apply to a null entity");
|
Potion potion = new Potion(PotionType.POISON);
|
||||||
} catch (IllegalArgumentException ex) {
|
potion.apply((LivingEntity) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void water() {
|
||||||
|
Potion potion = new Potion(PotionType.WATER);
|
||||||
|
assertEquals(0, potion.getLevel());
|
||||||
|
assertFalse(potion.isSplash());
|
||||||
|
assertFalse(potion.hasExtendedDuration());
|
||||||
|
assertEquals(0, potion.toDamageValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mundane() {
|
||||||
|
Potion potion = new Potion(0);
|
||||||
|
assertFalse(potion.getType() == PotionType.WATER);
|
||||||
|
assertFalse(potion.toDamageValue() == 0);
|
||||||
|
assertEquals(8192, potion.toDamageValue());
|
||||||
|
Potion potion2 = Potion.fromDamage(8192);
|
||||||
|
assertEquals(potion, potion2);
|
||||||
|
assertEquals(0, potion.getLevel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void awkward() {
|
||||||
|
Potion potion = new Potion(16);
|
||||||
|
assertEquals(16, potion.getNameId());
|
||||||
|
assertFalse(potion.isSplash());
|
||||||
|
assertFalse(potion.hasExtendedDuration());
|
||||||
|
assertNull(potion.getType());
|
||||||
|
assertEquals(16, potion.toDamageValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int EXTENDED_BIT = 0x40;
|
private static final int EXTENDED_BIT = 0x40;
|
||||||
|
|
Loading…
Add table
Reference in a new issue