Skip to content

Instantly share code, notes, and snippets.

@jonathonw
Created August 25, 2010 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathonw/548619 to your computer and use it in GitHub Desktop.
Save jonathonw/548619 to your computer and use it in GitHub Desktop.
:100644 100644 1010a25... 0000000... M etc.java
:100644 100644 a6cb6c9... 0000000... M ia.java
diff --git a/etc.java b/etc.java
index 1010a25..41670dd 100644
--- a/etc.java
+++ b/etc.java
@@ -1045,4 +1045,28 @@ public class etc {
return true;
return false;
}
+
+ public static String getCompassPointForDirection(double degrees) {
+ if(0 <= degrees && degrees < 22.5) {
+ return "N";
+ } else if(22.5 <= degrees && degrees < 67.5) {
+ return "NE";
+ } else if(67.5 <= degrees && degrees < 112.5) {
+ return "E";
+ } else if(112.5 <= degrees && degrees < 157.5) {
+ return "SE";
+ } else if(157.5 <= degrees && degrees < 202.5) {
+ return "S";
+ } else if(202.5 <= degrees && degrees < 247.5) {
+ return "SW";
+ } else if(247.5 <= degrees && degrees < 292.5) {
+ return "W";
+ } else if(292.5 <= degrees && degrees < 337.5) {
+ return "NW";
+ } else if(337.5 <= degrees && degrees < 360.0) {
+ return "N";
+ } else {
+ return "ERR";
+ }
+ }
}
diff --git a/ia.java b/ia.java
index a6cb6c9..f9cb2f1 100644
--- a/ia.java
+++ b/ia.java
@@ -801,6 +801,11 @@ public class ia extends eh implements ed {
} else if (split[0].equalsIgnoreCase("/getpos")) {
msg("Pos X: " + e.k + " Y: " + e.l + " Z " + e.m);
msg("Rotation X: " + e.q + " Y: " + e.r);
+ double degreeRotation = ((e.q - 90) % 360);
+ if(degreeRotation < 0) {
+ degreeRotation += 360.0;
+ }
+ msg("Compass: " + etc.getCompassPointForDirection(degreeRotation) + " (" + (Math.round(degreeRotation * 10) / 10.0) + ")");
} else if (split[0].equalsIgnoreCase("/motd")) {
for (String str : etc.getInstance(d).motd)
msg(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment