bukkit Spawn Eggs Creating an ItemStack of a SpawnEgg

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


For anything below 1.9

SpawnEgg egg = new SpawnEgg(EntityType.CREEPER);
ItemStack creeperEgg = egg.toItemStack(5);

For 1.9 and above

In versions 1.9 and higher, Spigot does not have an implementation for creating spawn eggs without using NMS. To accomplish this, you can use a small custom class/wrapper to make it happen:

public ItemStack toItemStack(int amount, EntityType type) {
    ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
    net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
    NBTTagCompound tagCompound = stack.getTag();
    if(tagCompound == null){
        tagCompound = new NBTTagCompound();
    NBTTagCompound id = new NBTTagCompound();
    id.setString("id", type.getName());
    tagCompound.set("EntityTag", id);
    return CraftItemStack.asBukkitCopy(stack);

Got any bukkit Question?