[SOLVED] checking and disabling drops?

Discussion in 'Plugin Development' started by Jakeob22, Dec 6, 2011.

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

    Jakeob22

    If I wanted to stop a zombie from dropping flesh, what would I do? I really HATE posting here. It makes me feel dumb. xD

    Anyway, I'm thinking of having it check for a zombie death and cancelling the drop so I can add a custom drop. Any suggestions?
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    @Jakeob22
    What you want to do is on the on death event get the drops and remove the rotten flesh

    This one will make no sense to you unless you have an understanding of objects. Although I have not tested if this actually works.
    Show Spoiler
    Code:
    public class ZombieListener extends EntityListener {
    
        @Override
        public void onEntityDeath(EntityDeathEvent event) {
            if (event.getEntity() instanceof Zombie) {
                final Iterator<ItemStack> iter = event.getDrops().iterator();
                while (iter.hasNext()){
                    if (iter.next().getType().equals(Material.ROTTEN_FLESH)){
                        iter.remove();
                    }
                }
            } else {
                return;
            }
        }
    }
     
  3. Offline

    Jakeob22

    What if I just wanted to cancel anything that any mob drops? Is there a way to just say:
    "onDrop (DropEvent event) {
    event.setCancelled(true);
    }"
    And then replace what it drops what I set somehow? I'm sure there's an easier way to cancel a drop than the one you gave me, but I'll try it.

    I still need help. :(

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

    Jakeob22

    Actually, I think I can get it to stop spawning. Lets just say I wanted them to drop a stone block, rather than flesh.(ID = 1), how would I do that?
     
  5. Offline

    Sagacious_Zed Bukkit Docs

  6. Offline

    coldandtired

    Check the Mob Drops plugin in my sig if you want to see some more code, but basically in the onEntityDeath method you do this:
    Code:
    event.getDrops().clear();
    event.getDrops().add(new ItemStack(Material.STONE));
     
  7. Offline

    Jakeob22

    Thanks!!! :D That solved it.
     
Thread Status:
Not open for further replies.

Share This Page