get block drop is on

Discussion in 'Plugin Development' started by matter123, May 15, 2011.

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

    matter123

    how would i get a block that the block lands on when a onplayer drop event is fired
     
  2. Offline

    cjc343

    It's unclear exactly what you're asking, but you likely want to use block.blockFace(face) in order to get a block adjacent to a block or location given by an event.
     
  3. Offline

    matter123

    what i want is when a player drops a item i want to get the block that the item is hovering over
     
  4. Code:
    //create the item variable yourself in the event
    Location loc = item.getLocation()
    loc.setY(loc.getY() - 1);
    Block hover = loc.getWorld().getBlockAt(loc);
    
    I maybe made some typo's, but thats basicly how you get the block under it.
     
  5. Offline

    Jayjay110

    Ty very helpful :)
     
  6. oh but note that if you call it in the event, you'll probably get the same location as your player, since you throw blocks from the players location, and not from the location you throw it to :)
     
  7. Offline

    Jayjay110

    yeah I just realised that after an hour of trying to figure out whats wrong Lols :p

    how would I get the block once it lands?

    Edit: all I need is this now to finish my plugin lol
     
  8. @Jayjay110 you need to track the item until the velocity stops (xfrom = xfor, yfrom = yfor, zfrom = zfor etc)
    The best thing to do that (i think) is make a class (TrackedItem for example) and every 200ms or something you check the velocity
     
  9. Offline

    Jayjay110

    I thought of that but I dont understand how to check something ever 200ms
     
  10. Offline

    DreadKyller

    you use the Scheduler class, I don't get it too much either, but I haven't ever used it so that's probably why...
     
  11. Code:
    new Timer().schedule(new TimerTask() {
        public void run() {
            //check if item velocity is zero, if so call a method and then
            //this.cancel
        }
    }, 0, 200)
    
    where the 0, 200 is for startup-delay, delay

    HOWEVER, People always use aSyncTask or something, i never used that one before but i suppose its better for it.
     
  12. Offline

    Jayjay110

    very nice thankyou :D
     
  13. Offline

    Shamebot

    I think it's:

    Code:
    getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
    {
       @Override
       public void run()
       {
            //do stuff
       }
    },0,200);
    But I don't know how to cancel it.
    Edit: try:
    Code:
    int id = getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
    {
       @Override
       public void run()
       {
             //do stuff
            getServer().getScheduler().cancelTask(id);
       }
    },0,200);
     
  14. Offline

    Jayjay110

    perfect, so If Im getting this right I just place my code to check if the drop is on a block in do stuff?

    p.s: How can I pass my dropped item into the run class?
     
  15. Offline

    Shamebot

    If it's defined somewhere in the outer class you should be able to access it,
    I doubt you'll be able to access getServer(), maybe try to do outerclass.this.getServer() where outerclass is the name of the class your task is within or do something like Outerclass out = this in the outerclass.
     
Thread Status:
Not open for further replies.

Share This Page