Entity Pickup Item event?

Discussion in 'Plugin Development' started by netherfoam, Dec 9, 2012.

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

    netherfoam

    Hi guys,

    I want to stop mobs picking up certain items. How can I detect when a mob picks an item up?

    Thanks.
     
  2. Offline

    JazzaG

    If you're talking about Endermen picking up blocks, you can use EntityChangeBlockEvent.

    Code:
    @EventHandler
    public void onEntityChangeBlock(EntityChangeBlockEvent e) {
        Entity entity = e.getEntity();
        Block from    = e.getBlock();
        Material to    = e.getTo();
     
        if(entity instanceof Enderman) {
            // I think you know where to go from here ;)
        }
    }
     
  3. Or are talking about Zombies picking up swords etc?
     
  4. Offline

    KeybordPiano459

    TfT_02
    I'm pretty sure that's what he meant. netherfoam if so, Bukkit hasn't added support for that yet, and if you want to stop it, you might have to try out some NBT stuff.
     
  5. Offline

    netherfoam

    Yeah, I had a look at the NBT tags, there is one for allowPickup or something. Unfortunately, I only want a certain set of items not to be picked up :/ And mobs disregard ItemPickupDelay too... https://bukkit.atlassian.net/browse/BUKKIT-3132

    I'll be waiting eagerly on this api :/
     
  6. Offline

    netherfoam

    API had nothing useful in it (A few builds ago it was added).

    How can I set an item entity to have 0 items? Would I have to use NMS?

    Found it.
    Code:java
    1.  
    2. //Fetch the NMS item
    3. net.minecraft.server.v1_4_5.ItemStack nmsI = CraftItemStack.createNMSItemStack(iStack);
    4. //Force the count to 0, don't notify anything though.
    5. nmsI.count = 0;
    6. //Get the itemstack back as a bukkit stack
    7. iStack = CraftItemStack.asBukkitStack(nmsI);
    8. //Set the display item to the stack.
    9. this.item.setItemStack(iStack);
    10.  


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

    Badeye

    How would you implement this into the code? I am not sure where to put this, i just want to cancel all item pickups for entitys, players should still be able to pick items up.
     
Thread Status:
Not open for further replies.

Share This Page