Skip to content

Optimize hasItemMeta (remove getItemMeta call)#1279

Merged
aikar merged 1 commit into
PaperMC:pre/1.13from
hugmanrique:optimize-item-meta
Jul 29, 2018
Merged

Optimize hasItemMeta (remove getItemMeta call)#1279
aikar merged 1 commit into
PaperMC:pre/1.13from
hugmanrique:optimize-item-meta

Conversation

@hugmanrique
Copy link
Copy Markdown
Contributor

@hugmanrique hugmanrique commented Jul 26, 2018

Spigot 1.13 checks if any field (which are manually copied from the ItemStack's "tag" NBT tag) on the ItemMeta class of an ItemStack is set.

We could just check if the "tag" NBT tag is empty, albeit that would break some plugins. The only general tag added on 1.13 is "Damage", and we can just check if the "tag" NBT tag contains any other tag that's not "Damage" (https://minecraft.gamepedia.com/Player.dat_format#Item_structure) making the hasItemStack method behave as before.

Check the ItemMetaTest#testTaggedButNotMeta method to see how this method behaves. (I also added some extra tests).

hasItemMeta() will return true if ItemStack.getDamage() != 0 or it has the Damage tag or any other tag is set.

Closes #1222

@Brokkonaut
Copy link
Copy Markdown
Contributor

Brokkonaut commented Jul 26, 2018

ItemStack testC = new ItemStack(Material.SHEARS);
testC.setDurability((short) 2);
player.getInventory().setItem(0, testC);
ItemStack testD = player.getInventory().getItem(0);
if (!testC.equals(testD)) {
System.out.println("Should be equal but is not");
}

This is fixed now

Spigot 1.13 checks if any field (which are manually copied from the ItemStack's "tag" NBT tag) on the ItemMeta class of an ItemStack is set.

We could just check if the "tag" NBT tag is empty, albeit that would break some plugins. The only general tag added on 1.13 is "Damage", and we can just check if the "tag" NBT tag contains any other tag that's not "Damage" (https://minecraft.gamepedia.com/Player.dat_format#Item_structure) making the `hasItemStack` method behave as before.

Check the `ItemMetaTest#testTaggedButNotMeta` and `ItemMetaTest#testHasItemMeta` methods to see all possible casess to see all possible cases.
@Brokkonaut
Copy link
Copy Markdown
Contributor

Should be correct now 👍


We could just check if the "tag" NBT tag is empty, albeit that would break some plugins. The only general tag added on 1.13 is "Damage", and we can just check if the "tag" NBT tag contains any other tag that's not "Damage" (https://minecraft.gamepedia.com/Player.dat_format#Item_structure) making the `hasItemStack` method behave as before.

Returns true if getDamage() == 0 or has damage tag or other tag is set.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a typo, should be getDamage() != 0

LeonTG pushed a commit to LeonTG/Paper that referenced this pull request May 17, 2026
By: DerFrZocker <derrieple@gmail.com>
LeonTG pushed a commit to LeonTG/Paper that referenced this pull request May 17, 2026
Spigot 1.13 checks if any field (which are manually copied from the ItemStack's "tag" NBT tag) on the ItemMeta class of an ItemStack is set.

We could just check if the "tag" NBT tag is empty, albeit that would break some plugins. The only general tag added on 1.13 is "Damage", and we can just check if the "tag" NBT tag contains any other tag that's not "Damage" (https://minecraft.gamepedia.com/Player.dat_format#Item_structure) making the `hasItemStack` method behave as before.

Check the `ItemMetaTest#testTaggedButNotMeta` method to see how this method behaves. (I also added some extra tests).

`hasItemMeta()` will return true if `ItemStack.getDamage() != 0` or it has the `Damage` tag or any other tag is set.

Closes PaperMC#1222
MelodyYuuka added a commit to MelodyYuuka/Paper that referenced this pull request Jun 3, 2026
MelodyYuuka added a commit to MelodyYuuka/Paper that referenced this pull request Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants