Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public boolean isSimilar(ItemStack stack) {

@Override
public boolean hasItemMeta() {
return CraftItemStack.hasItemMeta(this.handle) && !CraftItemFactory.instance().equals(this.getItemMeta(), null);
return CraftItemStack.hasItemMeta(this.handle) && (this.handle.getDamageValue() != 0 || this.handle.getComponentsPatch().size() >= (this.handle.getComponentsPatch().get(DataComponentMap.EMPTY, CraftMetaItem.DAMAGE.TYPE) != null ? 2 : 1)); // Paper - keep 1.12 CraftBukkit behavior without calling getItemMeta
}

static boolean hasItemMeta(net.minecraft.world.item.ItemStack item) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -176,6 +177,32 @@ public void testEntityTagMeta() {
}
// Paper end

private void testHasItemMeta(ItemStack stack) {
assertThat(stack.hasItemMeta(), is(false), "Should not have ItemMeta");

stack.setDurability((short) 0);
assertThat(stack.hasItemMeta(), is(false), "ItemStack with zero durability should not have ItemMeta");

stack.setDurability((short) 2);
assertThat(stack.hasItemMeta(), is(true), "ItemStack with non-zero durability should have ItemMeta");

stack.setLore(Collections.singletonList("Lore"));
assertThat(stack.hasItemMeta(), is(true), "ItemStack with lore and durability should have ItemMeta");

stack.setDurability((short) 0);
assertThat(stack.hasItemMeta(), is(true), "ItemStack with lore should have ItemMeta");

stack.setLore(null);
}

@Test
public void testHasItemMeta() {
ItemStack itemStack = new ItemStack(Material.SHEARS);

testHasItemMeta(itemStack);
testHasItemMeta(CraftItemStack.asCraftCopy(itemStack));
}

@Test
public void testEachExtraData() {
final List<StackProvider> providers = Arrays.asList(
Expand Down