Get information dropped item

Discussion in 'Plugin Development' started by Ridan, Sep 16, 2015.

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

    Ridan

    So, i've researched this quite a lot and can't find anything; I've also tried alot, but nothing that actually works.
    I'm trying to get the ItemStack and if possible, also the MetaData of a dropped item. I know it's an entity, I'm using getChunk().getEntities() on a block to find the entities in that chunk. I know theres a EntityType DROPPED_ITEM But there doesn't seem to be a class for it like EntityDroppedItem Any help on this?
    Thanks!
     
  2. Offline

    Zombie_Striker

    @Ridan
    Sadly, there is no EntityDroppedItem. But there is the 'Item' class, which is what dropped items are. This class also stores the ItemStack instance, and as such, the ItemMeta.

    Are you sure you researched this?
     
  3. Offline

    teej107

  4. Offline

    Ridan

    I'm 100% sure.
    I'm also sure that you can't cast an entity to a item, And i've also tested that (using instanceof and casting, both proved that you can't)
    Can i have an actual working answer now?

    Wait.. ehh, The wiki-thing page sais it's an Entity tho

    Code:
    Entity[] entities = e.getClickedBlock().getChunk().getEntities();
                  
                    for(int i = 0; i < entities.length; i++){
                        if (entities[i].getType() == EntityType.DROPPED_ITEM){
                            if(entities[i] instanceof Item){
                                System.out.println(entities[i].getName() + " is a item");
                            }else{
                                System.out.println(entities[i].getName() + " isn't an item");
                            }
                        }
                    }
    Used this code and it simply said
    '[17:21:40 INFO]: item.tile.workbench isn't an item' in console,
    Using casting just made an error.
    What am i doing wrong here?

    EDIT: Found it! I was importing the server item class, And not the bukkit one.
    Thanks for your help.
    I guess i dind't use the right keywords while searching.
     
    Last edited: Sep 17, 2015
Thread Status:
Not open for further replies.

Share This Page