Solved Remove all drops from location?

Discussion in 'Plugin Development' started by Goty_Metal, Dec 31, 2012.

Thread Status:
Not open for further replies.
  1. Hi guys, i've been trying to delete all drops in a location, but i don't want to specify the itemstack, just delete ALL drops, is there anyway? thanks!

    location.getBlock().getDrops().removeAll(???);
     
  2. Offline

    tommycake50

    location.getBlock().getDrops().clear();
    maybe.
     
  3. That should works, but if the drop is not in the exact, pitch yaw etc it doesn't work, there's any way to check the entire block location?

    Well i made a little test:

    location.getBlock().getDrops().clear();
    Bukkit.broadcastMessage("block = " + l.getBlock());
    Bukkit.broadcastMessage("drop = " + l.getBlock().getDrops());

    It gives me the block (air) but doesn't matter if i drop or spawn 500 items in this block, the itemstack finded is [] (nothing).

    I found this in the documentation:

    Collection< ItemStack > getDrops ()

    Returns a list of items which would drop by destroying this block.

    So the getDrops DON'T get the current "drops" in this block, but the items that will drop the block.


    I think when an item is droped is an entity right? so i should get the entity in this location... but can't do it :/

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

    tommycake50

    ok well.
    Location().getChunk().getEntities();
    iterate through that
    if they are on the specific location and they are a drop save their index to an int array and then loop through the int array and for every int in it call Location().getChunk().getEntities().remove(int);
     
  5. Offline

    fireblast709

    Code:
    for(Entity e : location.getChunk().getEntities())
    {
        if(e instanceof Item)
        {
            e.remove();
        }
    }
     
  6. Offline

    tommycake50

    he wants to get at a specific location.
     
  7. Offline

    fireblast709

    then check if the block coordinates are the same
     
  8. Done thanks guys :) the location had too much decimals but i get the exact block location and compared them, thanks!
     
  9. Offline

    Gungsu

    Guys,
    I use this:
    Code:
    @EventHandler
        public void onMyMobDead(EntityDeathEvent dev){
            EntityType ET = (EntityType) dev.getEntityType();
            Entity Ent = (Entity) dev.getEntity();
            if (ET == EntityType.ZOMBIE) {
                Creature nnZom = (Creature) Ent;
                if (nnZom == nZom) {
                        for(Entity e1 : nZom.getLocation().getChunk().getEntities())
                        {
                            if(e1 instanceof Item || e1 instanceof ExperienceOrb)
                                {
                                    e1.remove();
                                }
                        }
                }
            }
        }
    But this remove old itens don't new drop itens, I need a idea for when he death don't drop itens or xp.
    sorry my english.

    obs. nZom is one Zombie create by me.
     
  10. Offline

    Gungsu

    sorry guys,
    The solution is easy:
    Code:
    @EventHandler
        public void onMyMobDead(EntityDeathEvent dev){
            if (dev.getEntity() == nZom){
                dev.setDroppedExp(0);
                dev.getDrops().clear();
            }
        }
     
  11. Offline

    fireblast709

    Gungsu note that this would only work for that one specific mob you spawned ;3 (though it seems like you want that)
     
  12. Offline

    juampi_92

    Gungsu , thanks for the help. I wanted just that.
     
Thread Status:
Not open for further replies.

Share This Page