Get block relative to players location and direction.

Discussion in 'Plugin Development' started by Paxination, Dec 18, 2013.

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

    Paxination

    I've tried several ways and non have worked. I googled the forums and I fount some that reference vectors, but im having issues with it. What I need is the block y-1 and in front of the player. Just the 1 block.
     
  2. Offline

    xTrollxDudex

    Paxination
    PHP:
    public Location behindPlayer(Player player) {
            
    double rotation = (player.getLocation().getYaw() - 90) % 360;
            
    Block b player.getLocation().clone().subtract(010).getBlock();
            if (
    rotation 0) {
                
    rotation += 360.0;
            }
            if (
    <= rotation && rotation 22.5) {
                return 
    b.getRelative(BlockFace.NORTH).getLocation();
            } else if (
    22.5 <= rotation && rotation 67.5) {
                return 
    b.getRelative(BlockFace.NORTH_EAST).getLocation()
            } else if (
    67.5 <= rotation && rotation 112.5) {
                return 
    b.getRelative(BlockFace.EAST).getLocation();
            } else if (
    112.5 <= rotation && rotation 157.5) {
                return 
    b.getRelative(BlockFace.SOUTH_EAST).getLocation();
            } else if (
    157.5 <= rotation && rotation 202.5) {
                return 
    b.getRelative(BlockFace.SOUTH).getLocation();
            } else if (
    202.5 <= rotation && rotation 247.5) {
                return 
    b.getRelative(BlockFace._SOUTH_WEST).getLocation();
            } else if (
    247.5 <= rotation && rotation 292.5) {
                return 
    b.getRelative(BlockFace.WEST).getLocation();
            } else if (
    292.5 <= rotation && rotation 337.5) {
               return 
    b.getRelative(BlockFace.NORTH_WEST).getLocation() ;
            } else if (
    337.5 <= rotation && rotation 360.0) {
                return 
    b.getRelative(BlockFace.NORTH).getLocation();
            } else {
                return 
    null;
            }
        }
    }
     
    evilLamer likes this.
  3. Offline

    Paxination

    Whats the point in .clone()? Other than its name sake "clone", why are you using it? Is it so the subtract(0,1,0) doesnt modify the actual location?
     
Thread Status:
Not open for further replies.

Share This Page