From 613be0d8418c044807040bb4c9b72ae4c118f5cd Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 2 Jan 2017 16:13:25 +1100 Subject: [PATCH] SPIGOT-2980: Improve SpawnEgg NBT application and ItemStack conversion. --- nms-patches/ItemStack.patch | 35 +++++++++++++++---- .../craftbukkit/inventory/CraftItemStack.java | 5 ++- .../inventory/CraftMetaSpawnEgg.java | 6 ++-- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/nms-patches/ItemStack.patch b/nms-patches/ItemStack.patch index 6e539e7167..0d778c7164 100644 --- a/nms-patches/ItemStack.patch +++ b/nms-patches/ItemStack.patch @@ -20,7 +20,17 @@ public final class ItemStack { public static final ItemStack a = new ItemStack((Item) null); -@@ -46,28 +59,56 @@ +@@ -42,32 +55,68 @@ + this(item, i, 0); + } + ++ // CraftBukkit start + public ItemStack(Item item, int i, int j) { ++ this(item, i, j, true); ++ } ++ ++ public ItemStack(Item item, int i, int j, boolean convert) { ++ // CraftBukkit end this.item = item; this.damage = j; this.count = i; @@ -28,7 +38,9 @@ + if (MinecraftServer.getServer() != null) { + this.setData(j); + } -+ this.convertStack(); ++ if (convert) { ++ this.convertStack(); ++ } + // CraftBukkit end if (this.damage < 0) { - this.damage = 0; @@ -82,7 +94,7 @@ this.F(); } -@@ -94,11 +135,138 @@ +@@ -94,11 +143,138 @@ } public EnumInteractionResult placeItem(EntityHuman entityhuman, World world, BlockPosition blockposition, EnumHand enumhand, EnumDirection enumdirection, float f, float f1, float f2) { @@ -222,7 +234,7 @@ return enuminteractionresult; } -@@ -122,7 +290,7 @@ +@@ -122,7 +298,7 @@ nbttagcompound.setByte("Count", (byte) this.count); nbttagcompound.setShort("Damage", (short) this.damage); if (this.tag != null) { @@ -231,7 +243,7 @@ } return nbttagcompound; -@@ -157,11 +325,30 @@ +@@ -157,11 +333,30 @@ } public void setData(int i) { @@ -264,7 +276,7 @@ } public int k() { -@@ -198,6 +385,11 @@ +@@ -198,6 +393,11 @@ if (this.f()) { if (this.isDamaged(i, entityliving.getRandom())) { entityliving.b(this); @@ -276,7 +288,16 @@ this.subtract(1); if (entityliving instanceof EntityHuman) { EntityHuman entityhuman = (EntityHuman) entityliving; -@@ -509,6 +701,12 @@ +@@ -239,7 +439,7 @@ + } + + public ItemStack cloneItemStack() { +- ItemStack itemstack = new ItemStack(this.item, this.count, this.damage); ++ ItemStack itemstack = new ItemStack(this.item, this.count, this.damage, false); // CraftBukkit + + if (this.tag != null) { + itemstack.tag = this.tag.g(); +@@ -509,6 +709,12 @@ nbttaglist.add(nbttagcompound); } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index f12b67be43..6adbbd4acc 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -40,9 +40,12 @@ public final class CraftItemStack extends ItemStack { return net.minecraft.server.ItemStack.a; } - net.minecraft.server.ItemStack stack = new net.minecraft.server.ItemStack(item, original.getAmount(), original.getDurability()); + net.minecraft.server.ItemStack stack = new net.minecraft.server.ItemStack(item, original.getAmount(), original.getDurability(), false); if (original.hasItemMeta()) { setItemMeta(stack, original.getItemMeta()); + } else { + // Converted after setItemMeta + stack.convertStack(); } return stack; } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java index b98c02ff1e..360f95f75b 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java @@ -70,7 +70,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { void applyToItem(NBTTagCompound tag) { super.applyToItem(tag); - if (entityTag == null) { + if (!isSpawnEggEmpty() && entityTag == null) { entityTag = new NBTTagCompound(); } @@ -78,7 +78,9 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { entityTag.setString(ENTITY_ID.NBT, new MinecraftKey(spawnedType.getName()).toString()); } - tag.set(ENTITY_TAG.NBT, entityTag); + if (entityTag != null) { + tag.set(ENTITY_TAG.NBT, entityTag); + } } @Override