The uncraftable SpawnEgg!

Discussion in 'Plugin Development' started by nathanaelps, Sep 13, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    nathanaelps

    In short:
    Creating plugin: Craftable spawn eggs! (I know it's been done before)

    I successfully create recipes for spawn eggs. Let's try one that uses stone:

    Code:
    Material xpBottle = Material.getMaterial(384); //<-Bottle O' Enchanting
    Material stone= Material.getMaterial(1); //Stone
    int count = 1;
     
    //set up the egg itself
    SpawnEgg theEgg = new SpawnEgg();
    String output = ZOMBIE;
    theEgg.setSpawnedType(EntityType.fromName(output));
    ItemStack eggType = theEgg.toItemStack();
     
    //And, create the recipe!
    ShapelessRecipe eggRecipe = new ShapelessRecipe(eggType);
    eggRecipe.addIngredient(xpBottle);
    eggRecipe.addIngredient(count,  stone);
    server.addRecipe(eggRecipe);
    
    Lay 1 stone and 1 Bottle O' Enchanting on a crafting table, viola! a Zombie Spawn Egg pops up on the output!
    Wonderful. Perfect. Delightful.
    Now, try to pick up said egg...
    "Disconnected by Server" and "Internal server error"
    The server is busy crying:
    Code:
    14:47:50 [WARNING] Failed to handle packet: java.lang.NullPointerException
    java.lang.NullPointerException
            at net.minecraft.server.SlotResult.c(SourceFile:41)
            at net.minecraft.server.SlotResult.b(SourceFile:58)
            at net.minecraft.server.Container.clickItem(Container.java:201)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:1116)
            at net.minecraft.server.Packet102WindowClick.handle(SourceFile:29)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:281)
            at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
            at net.minecraft.server.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:583)
            at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
            at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    
    What the heck am I doing wrong?!
     
  2. Offline

    MM1990d

    Is it whole error?
     
  3. Offline

    nathanaelps

    Yeah, that's everything.
     
  4. Offline

    Seadragon91

    I can confirm that error too. It looks like that the spawner egg in the result slot cause the error, other items like golden apple works without any problems.
     
  5. Offline

    nathanaelps

    Fun fact:
    Code:
    ItemStack eggType = theEgg.toItemStack();
    
    has the problem, while

    Code:
    ItemStack eggType = new ItemStack(383, 1, (short) 120);
    
    does not. Guess I'll tinker some more.
    (Am I using SpawnEgg.toItemStack() wrong?)[/CODE]

    Yep. Did some more tinkering:

    Code:
    ItemStack eggType = theEgg.toItemStack(1);
    
    fixes it. You need the amount.
    Which isn't what jd.bukkit.org says, so I should probably figure out how to turn in a bug report...
    Anyone know how to do that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  6. Offline

    skore87

    It's in the javadocs

    ItemStack toItemStack (int amount)
    Creates a new ItemStack based on this MaterialData.
     
  7. Offline

    nathanaelps


    Yes, but so is

    ItemStack org.bukkit.material.MaterialData.toItemStack ( )
    Creates a new ItemStack based on this MaterialData.

    which doesn't work. I just figure that the toItemStack() without a parameter should be removed from the jd.
     
  8. Offline

    skore87

  9. Offline

    nathanaelps

    Yep. That would do it.
    Is it standard to make the default stack size be 0? I would think that it would default to 1, so that it doesn't crash the client.
     
  10. Offline

    skore87

    I believe you can still use it, just not actually give it to the user. As for the specifics, I can only speculate but it is always annoying when you work on a problem for a while just to find out that if you RTM then the solution is staring right back at you lol.
     
Thread Status:
Not open for further replies.

Share This Page