Skip to content

Commit

Permalink
Fix custom item code getting generated for items with damage (Fixes #598
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Phoenix616 committed Jul 4, 2024
1 parent ec8032a commit 6a2a3a4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static String getName(ItemStack itemStack, int maxWidth) {
}

String metaData = "";
if (itemStack.hasItemMeta()) {
if (hasCustomData(itemStack)) {
metaData = "#" + Metadata.getItemCode(itemStack);
}

Expand All @@ -284,6 +284,29 @@ public static String getName(ItemStack itemStack, int maxWidth) {
return code + durability + metaData;
}

/**
* Check whether the provided ItemStack has custom data (in the past called "ItemMeta"). This will ignore
* the durability of an item.
*
* @param itemStack The ItemStack to check
* @return Whether the item has custom data
*/
private static boolean hasCustomData(ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta instanceof Damageable) {
if (!((Damageable) itemMeta).hasDamage()) {
return true;
}
}
Map<String, Object> data = itemMeta.serialize();
// if the data map contains more than the metadata type and the damage
// then the item does indeed have custom data set
return data.size() > 2;
}

/**
* Get an item name shortened to a max length that is still reversable by {@link #getMaterial(String)}
*
Expand Down

0 comments on commit 6a2a3a4

Please sign in to comment.