Check if a player is at the edge of a block

Discussion in 'Plugin Development' started by someguyonthestreet, May 27, 2015.

Thread Status:
Not open for further replies.
  1. I'm trying to check if a player is at the edge of a block but not crouching. I have tested it, but when you go and crouch and then go out of a block and then let go of the crouch button, you are still in the same position but underneath you is air. If somebody could help me out, I don't really have an idea of checking this since i'm not good with vectors and velocities.
     
  2. Offline

    Agentleader1

    Most effective way I know of is to grab:
    Code:
    double x = player.getLocation().getX();
    double z = player.getLocation().getZ();
    And boolean check it, if any of those 2 values are at the edge.
     
    Last edited: May 27, 2015
  3. @Agentleader1
    Ok, but I don't know what the if statement should include for checking if the 2 values are at the edge.
     
  4. Offline

    Agentleader1

  5. @Agentleader1
    So I checked out some other posts and I found this:
    Code:
    if(event.getTo().getZ() - event.getTo().getBlockZ() > 0.5 || event.getTo().getBlockZ() - event.getTo().getZ() > 0.5) {
                    
    And this works but it works when I jump in the air and it says that i'm at the edge of a block, i'm guessing that i'm at the edge of the air block but how would I check that? I have used player.getLocation().getBlock().getType() == Material.AIR and cancelled it and did that the other way around but it was just not working.
     
  6. Offline

    Agentleader1

  7. Ok, i'm having problems again, i'm trying to check if they ARE NOT at the edge of a block that isn't air or water.
    My Code:
    Code:
    if(!(event.getTo().getBlockZ() - event.getTo().getZ() > 0.5 || event.getTo().getZ() - event.getTo().getBlockZ() > 0.5) || !(event.getTo().getBlockX() - event.getTo().getX() > 0.5 || event.getTo().getX() - event.getTo().getBlockX() > 0.5)) {
                        
     
Thread Status:
Not open for further replies.

Share This Page