Get Nearest Block Under Player.

Discussion in 'Plugin Development' started by hubeb, Jul 2, 2013.

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

    hubeb

    Hello, Ive created a plugin that teleports a player to a random location. How would I go about getting the nearest groundlevel block? (The plugin can spawn a player 300 blocks in air).

    Thanks,
    Hubeb
     
  2. Offline

    CubieX

    There is a method ".getHighestBlockAt()" in the "World" class.
    This returns the highest non-empty block at a given location (or x + z).

    But be aware: This may also return blocks like lava and cactus.
    So better check the returned block for unwanted materials. ;)
     
  3. Offline

    hubeb

    CubieX
    My code is
    Code:java
    1. player.teleport(new Location(player.getWorld(),rand.nextInt(1000),150,rand.nextInt(1000));
    2.  

    I need to get the closest ground level block for my Y so it does not cause the player fall damage. (Or is there a way to negate the fall damage?)
     
  4. Offline

    CubieX

    This will get the closest ground level block for your given locations x and z coords. ;)
    It looks which block on the Y coordinate of the given location has only air above it, and returns this highest non-empty block.
    I don't know if there are blocks that are not recognized by this method. But try it and judge yourself.
     
Thread Status:
Not open for further replies.

Share This Page