Skip to content

Commit

Permalink
Fix splash potion material on old versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Golfing7 committed Oct 29, 2023
1 parent f7e0e83 commit 276667e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/com/cryptomorin/xseries/XMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ public enum XMaterial {
SPIDER_EYE,
SPIDER_SPAWN_EGG(52, "MONSTER_EGG"),
SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE,
SPLASH_POTION,
SPLASH_POTION("POTION"),
SPONGE,
SPORE_BLOSSOM,
SPRUCE_BOAT("BOAT_SPRUCE"),
Expand Down Expand Up @@ -2097,6 +2097,10 @@ public ItemStack setType(@Nonnull ItemStack item) {

item.setType(material);
if (!Data.ISFLAT && material.getMaxDurability() <= 0) item.setDurability(this.data);
// Splash Potions weren't an official material pre-flattening.
if (!Data.ISFLAT && this == SPLASH_POTION) {
item.setDurability((short) 16384); // Hard-coded as 'data' is only a byte.
}
return item;
}

Expand Down Expand Up @@ -2187,7 +2191,12 @@ public byte getData() {
public ItemStack parseItem() {
Material material = this.parseMaterial();
if (material == null) return null;
return Data.ISFLAT ? new ItemStack(material) : new ItemStack(material, 1, this.data);
ItemStack base = Data.ISFLAT ? new ItemStack(material) : new ItemStack(material, 1, this.data);
// Splash Potions weren't an official material pre-flattening.
if (!Data.ISFLAT && this == SPLASH_POTION) {
base.setDurability((short) 16384); // Hard-coded as 'data' is only a byte.
}
return base;
}

/**
Expand All @@ -2212,6 +2221,10 @@ public Material parseMaterial() {
public boolean isSimilar(@Nonnull ItemStack item) {
Objects.requireNonNull(item, "Cannot compare with null ItemStack");
if (item.getType() != this.parseMaterial()) return false;
// Special case for splash potions.
if (this == SPLASH_POTION) {
return Data.ISFLAT || item.getDurability() == (short) 16384;
}
return Data.ISFLAT || item.getDurability() == this.data || item.getType().getMaxDurability() > 0;
}

Expand Down

0 comments on commit 276667e

Please sign in to comment.