Get location of dropped item

Discussion in 'Plugin Development' started by JazzaG, Jun 26, 2012.

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

    JazzaG

    I have done this:

    Code:java
    1.  
    2. @EventHandler
    3. public void onDrop(PlayerDropItemEvent event) {
    4. Location loc = event.getItemDrop().getLocation();
    5. }
    6.  


    ..but this gets the location the player dropped it from.

    Is there any way to actually get where the item dropped to?

    Thanks
     
  2. Offline

    SnRolls

    try this:
    @EventHandler
    public void onDrop(ItemSpawnEvent event) {
    Location loc = event.getLocation();
    }
     
  3. Offline

    EnvisionRed

    I dunno if that will work, because when you watch a player drop something, you can see that the items are actually spawned at the location of the player.

    JazzaG, you can probably do something along the lines of :
    1. Get the direction the player was facing
    2. move the x/z 1 or 2 blocks in that direction
    3. keep subtracting from the y until you find a block that isn't air.

    And you will probably find your items
     
  4. Offline

    SnRolls

    Kinda true ;)
     
  5. Offline

    JazzaG

    SnRolls
    Thanks for the reply.

    Isn't ItemSpawnEvent called on chunk generation as well? I just tried broadcasting the location so I can see what's going on, and everytime I moved, it spammed the console :S

    Sorry for my ignorance, but is there a way to do this with PlayerDropItemEvent?

    I was thinking of doing something like that, but won't it not find it as it is not a placed block?

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

Share This Page