Discussion in 'Plugin Development' started by Darris, Aug 16, 2019.

  1. Offline


    Hello! I need to teleport player in the direction he's looking at the 10 blocks. In this case, consider the following:
    - if type, to which he looks is the air that's not to teleport.
    - if he looks at the other any other block except air, then teleport player end to end to the block.
  2. Offline


    1. use Player#getTargetBlock(10,null) to get the block the player is looking at (which is within 10 blocks)
    2. If that block is null/Air, do not teleport them.
    3. If it is not null/a block, check if the two blocks above it are solid (Block#isSolid()) If they are not solid, you can teleport the player without them suffocating.
    SloopyGames likes this.
  3. Offline


    There should be a rayTraceBlocks(distance) method that you can use to find the block that the user is looking at. I'm not looking at it right now so I might be incorrect, but this should return a RayTraceResult that you can find what block the user hit, or no block if they didn't hit air. From this, you can teleport the user to the result. If you want to, you can also store the player's initial position and end position to find a path, and then you can teleport the player to a safe position along that path.
  4. Offline


    I wrote the code, but I'm still being teleported into blocks.

    Block b = player.getTargetBlock((Set<Material>) null, 10);
     if (b.getType() == Material.AIR) return; 
    if (b.getType().isSolid()) player.teleport(b.getLocation());
  5. Offline

    timtower Moderator Moderator

    @Darris Use a relative location in that case, move 1 block up.

Share This Page