Is this the fastest way to get the block x away from where the player is looking?

Discussion in 'Bukkit Help' started by orange451, Aug 1, 2012.

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

    orange451

    Code:
        public static double lengthdir_x(double len, double dir) {
            return len * Math.cos(Math.toRadians(dir));
        }
     
        public static double lengthdir_y(double len, double dir) {
            return -len * Math.sin(Math.toRadians(dir));
        }
     
        public Block getBlockXAway(Player p, double distance) {
            Location ploc = p.getLocation().add(0,2,0);
            double pitch = -ploc.getPitch();
            double direction = -ploc.getYaw()-90;
            System.out.println(pitch);
            System.out.println(direction);
            int xx = (int) (ploc.getBlockX() + ( lengthdir_x(distance, direction) * lengthdir_x(1, pitch)));
            int yy = (int) (ploc.getBlockY() + (-lengthdir_y(distance, pitch)));
            int zz = (int) (ploc.getBlockZ() + ( lengthdir_y(distance, direction) * lengthdir_x(1, pitch)));
            Location nloc = new Location(ploc.getWorld(), xx, yy, zz);
            Block b = nloc.getBlock();
            return b;
        }
    Would this be the fastest way to get a block that is "x" away from the player (in the direction he is looking)?

    [EDIT]
    wrong forum, my bad.
     
Thread Status:
Not open for further replies.

Share This Page