player.getInventory().setItemInHand(item) crashing client

Discussion in 'Plugin Development' started by Jonbas, Feb 28, 2011.

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

    Jonbas

    I'm having a little trouble with my plugin today:

    I'm trying to remove the item a player is currently holding so I'm doing this:

    PHP:
    ItemStack item player.getItemInHand();
    item.setAmount(0);
    item.setTypeId(0);
    player.getInventory().setItemInHand(item);
    But every time it runs it crashes my client. Is this a known bug, or am i doing something wrong?

    Server linux with RB 440.
    Client winxp x86 mc 1.3_01
    --- merged: Feb 28, 2011 9:08 PM ---
    Hmm... but it does what I want when I use

    PHP:
    player.setItemInHand(null);
     
  2. Offline

    Plague

    Yes, I don't really think getInventory.setItemInHand() is to be used anymore.
     
  3. Offline

    Edward Hand

    Well, you seem to have fixed it, but FYI it was the item.setTypeId(0) that was doing it. (The client has no idea what kind of item that corresponds to)
     
  4. Offline

    Jonbas

    Isn't item type 0 air?
    --- merged: Feb 28, 2011 10:30 PM ---
    What should I be doing instead? I haven't seen a note in the javadocs about this being depreciated yet.
     
  5. I found out, through much pain, that armour slots (but not inventory slots) cannot take itemstacks with values of 0 for either the Id or the Amount. So I guess the problem also lies with the setItemInHand.

    It really annoyed me because when you save an empty slot (with get) the Id is 0, but when you try to set that itemstack it just causes a client NPE.

    i.e player.setHelmet(player.getHelmet()); would cause an NPE if the helmet slot was blank...

    I also had to check the id of itemstacks and, if they were 0, set the values as null.


    I don't know of a problem with the function. I'd continue to use it...
     
Thread Status:
Not open for further replies.

Share This Page