Check if a player bumped into a wall

Discussion in 'Plugin Development' started by bramhaag, Aug 22, 2014.

Thread Status:
Not open for further replies.
  1. Hi,

    I want to run a piece of code when a player touches a wall(with his body, not with the cross hair!) So, I think that this is possible with a PlayerMoveEvent. The question is, how.
    A few notes:
    • If the player looks at an other direction and he walks into a wall, I want to run the same code
    • The player has to touch the wall with his body, not with his cross hair
    I really can't figure this out and I couldn't find this on the web. You guys are my last hope ;)
    Thanks in advance,
    Bram
     
  2. Offline

    megasaad44

    Get the player's location, add +1/-1 to both the x and z, do it in a for loop. then compare it to the wall's loc. if wallloc.equals(newLoc) { code }
     
  3. megasaad44
    And what if I don't have the location of the wall?
     
  4. Offline

    megasaad44

    bramhaag ok. Here is another way. BlockFace. if (player.getlocation.getdirection(blockface.(here))) { stuff }
    I might have wrote that wrong, but basically what blockface is it checks the block adjacent to a location. You could try that.

    EDIT: got proper code: p.getLocation().getBlock().getRelative(BlockFace.DOWN)
     
  5. Offline

    fireblast709

    bramhaag use their velocity to determine their direction, then use the player's Location, add (a part of) the velocity (depending on how precise you want to be) to their Location, and call getBlock() to get the Block. Then check if that Block is part of a wall.
     
  6. megasaad44
    Can I just put the code from the edit in an if statement that is inside of a PlayerMoveEvent and should it work than?
     
  7. Offline

    megasaad44

    bramhaag I wont spoon feed. Change the BlockFace to South/West/East/North/South-East/South-West/etc... in if statements, after each BlockFace check, you can simply do .isSolid to check if the block is a solid block, or you can check for a material instead with .getType. REMEMBER. Use || to check each block face so that if one of them is true, the if statement continues. And you have your wall.
     
  8. megasaad44
    Well, the problem is that I don't know in what direction the player is heading, so I have to store 2 locations and compare them to each other?
     
  9. Offline

    megasaad44

    bramhaag OH I thought you didn't care where the player looks. I mis-read that.

     
Thread Status:
Not open for further replies.

Share This Page