Optimize hasItemMeta (remove getItemMeta call)#1279
Merged
Conversation
Contributor
|
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.
Contributor
|
Should be correct now 👍 |
aikar
approved these changes
Jul 29, 2018
hugmanrique
commented
Apr 19, 2019
|
|
||
| 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. |
Contributor
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
hasItemStackmethod behave as before.Check the
ItemMetaTest#testTaggedButNotMetamethod to see how this method behaves. (I also added some extra tests).hasItemMeta()will return true ifItemStack.getDamage() != 0or it has theDamagetag or any other tag is set.Closes #1222