Solved Removing items from current stack in hand (2+ stacks of same item)

Discussion in 'Plugin Development' started by Shzylo, Jul 30, 2013.

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

    Shzylo

    I'm having problems that when I have multiple stacks of items in my inventory and/or hot bar, and say I have the item in slot 1 and slot 2, if I were to right click with that item that is in slot 2, it is supposed to remove one from that stack, but instead it removes it from the stack in slot 1, but doesn't update it until I go back to stack one. How will I fix this? I have been running with this code:
    Code:
    p.getInventory().removeItem(new ItemStack(Material.SULPHUR, 1));
    I tried to fix it with this, but it just throws an EventException at this line:
    Code:
    ((Inventory) p.getInventory().getItemInHand()).removeItem(new ItemStack(Material.SULPHUR, 1)); //I have tried it without the '.getInventory()'
    Thank you for the help.
     
  2. Offline

    xmarinusx

    Shzylo
    Try
    Code:java
    1.  
    2. p.getItemInHand().setType(Material.AIR);


    You may need to update the inventory after it. (p.updateInventory(); )

    EDIT:
    Got ninja'ed by Chiller ;)
     
  3. Offline

    Shzylo

    Well, the player will more than likely have more than one piece of sulphur (gunpowder) so I don't think I want to set it to air when they first use it :/
     
  4. Offline

    xmarinusx

    Yes, you're right. I've misread your post. Use .setAmount(p.getItemInHand().getAmount() - 1); instead.
     
    Shzylo likes this.
  5. Offline

    Shzylo

    Solved :D
     
Thread Status:
Not open for further replies.

Share This Page