PlayerPickupItem event

Discussion in 'Plugin Development' started by raGan., Aug 4, 2012.

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

    raGan.

    Hello, I was trying to make player not pickup anything on pickup event, effectively erasing picked up item, but I was not able to do that. I tried event.getItem().setItemStack(), but it always throws NPE when I modify item in any way, and player connected to the event with Internal server error message. Is this even possible ?
     
  2. Offline

    davejavu

    evt.setCancelled(true) maybe?
     
  3. Offline

    raGan.

    I don't want to cancel event. I want player to pick up item and not give him anything.
     
  4. Offline

    anthonyc39

    so you want him to be able to remove it from the ground but instead of going into his inventory, it vanishes?
     
  5. Offline

    raGan.

    Exactly. It seems to be harder than I first thought.
     
  6. Offline

    Taco

    Just cancel the event and remove the entity from the world?
     
    WarmakerT likes this.
  7. Offline

    raGan.

    I will try that, but it needs to meet few conditions. I will post again if something goes wrong.

    I have run into a problem. How to change entity involved in the event ? This does not work:
    Code:
    int rem = event.getRemaining();
    if(rem > 0) {
      ItemStack newit = item.clone();
      newit.setAmount(rem);
      event.getItem().setItemStack(newit);
    } else {
      event.getItem().remove();
    }
    event.setCancelled(true);
    What I am trying to do here is partially remove items from dropped item but changing amount does not work. How can it be changed ?
    edit: item is item from getItemStack(), so it represents item on the ground (it really does)

    I found solution I am fine with. Whenever only part of the stack is picked up, it removes it completely and spawns new item_drop with remaining amount at the same location. Item also jumps a little, which looks like ripping part of it away.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page