Solved GetBlockFace.Down never registers when you are on the edge of a block.

Discussion in 'Plugin Development' started by megasaad44, Aug 20, 2014.

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


    This is a bukkit bug, I will probably issue this to the bug tracker here. In the mean time, if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR) does not register when you are on the edge of the block. it registers when you are standing on the actual pixels of the block, so standing on the far edge of the block doesn't register it. Any workarounds? I really need a better way.

    You mean, as expected?
    Since the player location is over air, of course it would return air. A player can stand over a total of 4 blocks at a time. Scan the blocks that a player can stand on, and take the one that the player location is closest to and is not air.

    Necrodoom What? Could you rephrase your solution please? I will not scan for every block in the game if that's what you're implying.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Aug 25, 2018
  2. Offline


    I'll explain it in more detail.

    Basically, he means this:

    A player can stand on a total of 4 blocks at a time. For this to happen a player would have to stand dead center of four blocks in a 2x2 square. What you need to do is get the blocks that could possibly be under the player, then get the player's location. Then compare their location to all the locations of the block's you've checked underneath them. Whichever block they are the closest to is the block they are standing on. That's how you can bypass the issue.
  3. Offline


    DevSock That wouldn't fix a double jump feature though. Basically, if player is not on air, they can double jump. Which brings this issue.
  4. Offline


    First of all, you never said anything about a double jump feature in your initial post, I would've attempted to figure out a solution for it right then. If I'm going to help you out, I'm going to require an explanation of how your double jump feature works along with the code you're using for it please.
  5. Offline


    DevSock Sorry, I assumed that information was not required.
    All i need to do is check if the player is standing on a block and NOT air. Because if you fall on the edge of the block, the blockface will not register and thus rendering the player deprived from doublejumping as long as they do not move off of the edge which is not favored at all.

    I have a repeating task every tick that checks the method to allow a player to doublejump after checking if the player is not on air:
    1. public static void dj(Player p) {
    2. if (p.hasPermission("saad.doublejump")) {
    3. if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR) {
  6. Offline


    Can you explain why you can't get the blocks beneath a player in a 2x2 square and then compare their location to the block locations and whichever one is closest is the one they're standing on? I mean that's seriously all you need to do. Make a method using some simple maths to get the blocks beneath the player that compares the locations and returns the closest block to the player that isn't air. Then in your conditional instead of using GetBlockFace.DOWN just use your method. It seems pretty straight forward to me.
  7. Offline


  8. Offline


    DevSock I was thinking of using BlockFaces. If under-right contains a block, if under-front co- etc...
    would that possible work?
    SparrowMaxx Depracated, and it returns exactly what i was doing in the first place.
  9. Offline


    Get the player's position. Check +- 0.3 in the X and Z directions. If those checks cross over into new blocks then the player is also standing on those blocks.
    NathanWolf and megasaad44 like this.
  10. Offline


    1. Location playerLoc = p.getLocation(); // This is the starting location;
    2. Block topBlock = null;
    3. while(topBlock == null && playerLoc.getY() > 0){
    4. playerLoc.subtract(0, 1, 0);
    5. if(playerLoc.getBlock().getType() != Material.AIR)
    6. topBlock = playerLoc.getBlock();
    7. }
    8. // topBlock will be the block under the player, if it's valid.

    1. Block currentBlock = p.getLocation().getBlock();
    2. while(currentBlock.getType() == Material.AIR && currentBlock.getLocation().getY() > 1)
    3. currentBlock = currentBlock.getRelative(BlockFace.DOWN);
    4. // Same solution, simplier code.
  11. Offline


    Jogy34 BRILLIANT! I'll try that.

    Worked like a charm. Thanks ^_^ Thread solved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page