CraftBukkit item conversion removes nbt from spawn eggs

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None
    • git-Spigot-df0eb25-411609d (MC: 1.14.2) (Implementing API version 1.14.2-R0.1-SNAPSHOT)
    • Yes

      If an spawn egg ItemStack is converted to/from an NMS ItemStack the "EntityTag" nbt tag is lost. This only applies to spawn eggs added in 1.14.

      Example plugin code:

      public class TestPlugin extends JavaPlugin implements Listener {
      
         @Override
         public void onEnable() {
            for (Material material : new Material[] {Material.VILLAGER_SPAWN_EGG, Material.FOX_SPAWN_EGG}) {
               System.out.println("Material: " + material);
      
               ItemStack item = new ItemStack(material);
      
               NBTTagCompound entityTag = new NBTTagCompound();
               entityTag.set("id", new NBTTagString("minecraft:test"));
      
               net.minecraft.server.v1_14_R1.ItemStack nmsitem = CraftItemStack.asNMSCopy(item);
      
               NBTTagCompound itemnbt = new NBTTagCompound();
               itemnbt.set("EntityTag", entityTag);
      
               nmsitem.setTag(itemnbt);
      
               System.out.println("set item nbt: " + nmsitem.getTag());
      
               nmsitem = CraftItemStack.asNMSCopy(CraftItemStack.asBukkitCopy(nmsitem));
      
               System.out.println("nbt after copy: " + nmsitem.getTag());
            }
         }
      }
      

      Output:

      [11:05:33] [Server thread/INFO]: [TestPlugin] Enabling TestPlugin v1.0
      [11:05:33] [Server thread/INFO]: Material: VILLAGER_SPAWN_EGG
      [11:05:33] [Server thread/INFO]: set item nbt: {EntityTag:{id:"minecraft:test"}}
      [11:05:35] [Server thread/INFO]: nbt after copy: {EntityTag:{id:"minecraft:test"}}
      [11:05:35] [Server thread/INFO]: Material: FOX_SPAWN_EGG
      [11:05:35] [Server thread/INFO]: set item nbt: {EntityTag:{id:"minecraft:test"}}
      [11:05:35] [Server thread/INFO]: nbt after copy: null

            Assignee:
            Unassigned
            Reporter:
            Gero Cammans
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: