Getting the block a player is standing on?

Discussion in 'Plugin Development' started by xxCoderForLifexx, Jan 12, 2013.

Thread Status:
Not open for further replies.
  1. Code:java
    1. if(player.getLoaction().getBlock == Material.ICE){}

    That's not working :'(
     
  2. Offline

    Jogy34

    first, the player's location is the location of their bottom half of their body

    second, you are looking for getBlock().getType() to compare it with a material
     
  3. Since player.getLocation() gives you the block the feet are in instead of the block that are under the feet, you have to take one block below.

    Code:
    if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.ICE))
    {
    //do something
    }
     
  4. Offline

    mcat95

    Another way:
    Code:
    Location loc = player.getLocation();
    loc.setY(loc.getY-1)
    if(loc.getBlock().getType.equals(Material.ICE){
    //CODE HERE
    }
     
    
     
  5. Offline

    gomeow

    And lastly, a 1 line way:
    Code:
    if(player.getLocation().subtract(0,1,0).getBlock().getType() == Material.ICE)
     
    PongoHD and Ne0nx3r0 like this.
Thread Status:
Not open for further replies.

Share This Page