3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

SPIGOT-4030: Improve CraftItemStack.hasItemMeta

Dieser Commit ist enthalten in:
md_5 2018-07-17 17:13:55 +10:00
Ursprung 1526726b57
Commit 8c9dea83c3
2 geänderte Dateien mit 16 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -553,7 +553,7 @@ public final class CraftItemStack extends ItemStack {
@Override @Override
public boolean hasItemMeta() { public boolean hasItemMeta() {
return hasItemMeta(handle); return hasItemMeta(handle) && !CraftItemFactory.instance().equals(getItemMeta(), null);
} }
static boolean hasItemMeta(net.minecraft.server.ItemStack item) { static boolean hasItemMeta(net.minecraft.server.ItemStack item) {

Datei anzeigen

@ -11,6 +11,7 @@ import net.minecraft.server.ITileEntity;
import net.minecraft.server.Item; import net.minecraft.server.Item;
import net.minecraft.server.ItemBlock; import net.minecraft.server.ItemBlock;
import net.minecraft.server.ItemBlockWallable; import net.minecraft.server.ItemBlockWallable;
import net.minecraft.server.NBTTagInt;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Color; import org.bukkit.Color;
@ -140,6 +141,20 @@ public class ItemMetaTest extends AbstractTestingBase {
assertThat(bukkit, is((ItemStack) craft)); assertThat(bukkit, is((ItemStack) craft));
} }
@Test
public void testTaggedButNotMeta() {
CraftItemStack craft = CraftItemStack.asCraftCopy(new ItemStack(Material.SHEARS));
craft.handle.setDamage(0);
assertThat("Should have NBT tag", CraftItemStack.hasItemMeta(craft.handle), is(true));
assertThat("NBT Tag should contain Damage", craft.handle.getTag().get("Damage"), instanceOf(NBTTagInt.class));
assertThat("But we should not have meta", craft.hasItemMeta(), is(false));
ItemStack pureBukkit = new ItemStack(Material.SHEARS);
assertThat("Bukkit and craft stacks should be similar", craft.isSimilar(pureBukkit), is(true));
assertThat("Bukkit and craft stacks should be equal", craft.equals(pureBukkit), is(true));
}
@Test @Test
public void testBlockStateMeta() { public void testBlockStateMeta() {
List<Block> queue = new ArrayList<>(); List<Block> queue = new ArrayList<>();