Check if item is on ground doesn't work?!

Discussion in 'Plugin Development' started by Regenwurm97, Jun 27, 2015.

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

    Regenwurm97

    Hey there!

    I'm using a PlayerDropItemEvent to get any items dropped. I want to check the type of block they lie on after they are on the ground. So my idea was the following:

    I create a runnable task timer every second and the run() checks for whether the item is on the ground (method: item.isOnGround()) or not. If it is, the runnable is cancelled and the block below the item is recieved.
    However, I discovered that some items are stuck in the status "not on ground" even though they are already on the ground.
    I made this little debug method you can implement in any of your plugins to try it out yourself:

    Code:
        @EventHandler
        private void onDropTest(final PlayerDropItemEvent e) {
          
            BukkitRunnable runnable = new BukkitRunnable() {
              
                @Override
                public void run() {
                  
                    if(!e.getItemDrop().isOnGround()) {
                      
                        System.out.println("Item not on ground!");
                      
                    }
                  
                    else this.cancel();
                  
                }
              
            };
          
            runnable.runTaskTimer(plugin, 0L, 20L);
          
        }
    If you drop like 30 items with the q-button quite fast (like spamming the items) from a certain height above ground then you will recognize that the console starts printing "Item not on ground!" for ever...

    How can I solve this problem?

    EDIT I found out that the problem only occurs if you spam the items from the same location. Dropping the items while moving into a direction doesn't cause the bug. Seems like the stacking / merging of itemstacks is causing the problem but I don't know how to proceed then
     
  2. Offline

    tytwining

    @Regenwurm97 It may be because the item gets a little upward velocity and if it gets to a point it may "confuse" that for some reason. Maybe try checking if the block under the location of the item is not air and see if you get the same result
     
  3. Offline

    Cycryl

    cancelling the event this late is something bukkit no longer cares about.
    also you are checking if it is NOT on the ground.
    @tytwining @Regenwurm97
     
Thread Status:
Not open for further replies.

Share This Page