Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Gets the Yaw from one location to another in relation to North.
- *
- */
- public double getYawTo(Location from, Location to) {
- final int distX = to.getBlockX() - from.getBlockX();
- final int distZ = to.getBlockZ() - from.getBlockZ();
- double degrees = Math.toDegrees(Math.atan2(-distX, distZ));
- degrees += 180;
- return degrees;
- }
- /**
- * Converts a rotation to a cardinal direction name.
- * Author: sk89q - Original function from CommandBook plugin
- * @param rot
- * @return
- */
- private static String getDirection(double rot) {
- if (0 <= rot && rot < 22.5) {
- return "North";
- } else if (22.5 <= rot && rot < 67.5) {
- return "Northeast";
- } else if (67.5 <= rot && rot < 112.5) {
- return "East";
- } else if (112.5 <= rot && rot < 157.5) {
- return "Southeast";
- } else if (157.5 <= rot && rot < 202.5) {
- return "South";
- } else if (202.5 <= rot && rot < 247.5) {
- return "Southwest";
- } else if (247.5 <= rot && rot < 292.5) {
- return "West";
- } else if (292.5 <= rot && rot < 337.5) {
- return "Northwest";
- } else if (337.5 <= rot && rot < 360.0) {
- return "North";
- } else {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement