diff --git a/MinecraftClient/Mapping/DirectionExtensions.cs b/MinecraftClient/Mapping/DirectionExtensions.cs
index fe47f020..9a42368c 100644
--- a/MinecraftClient/Mapping/DirectionExtensions.cs
+++ b/MinecraftClient/Mapping/DirectionExtensions.cs
@@ -1,4 +1,6 @@
-namespace MinecraftClient.Mapping
+using System;
+
+namespace MinecraftClient.Mapping
{
public static class DirectionExtensions
{
@@ -35,5 +37,27 @@
}
}
+
+
+ public static Direction[] HORIZONTAL =
+ {
+ Direction.South,
+ Direction.West,
+ Direction.North,
+ Direction.East
+ };
+
+ public static Direction FromRotation(double rotation)
+ {
+ double floor = Math.Floor((rotation / 90.0) + 0.5);
+ int value = (int)floor & 3;
+
+ return FromHorizontal(value);
+ }
+
+ public static Direction FromHorizontal(int value)
+ {
+ return HORIZONTAL[Math.Abs(value % HORIZONTAL.Length)];
+ }
}
}
diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs
index b58e420e..4a8b6ab0 100644
--- a/MinecraftClient/McClient.cs
+++ b/MinecraftClient/McClient.cs
@@ -1036,6 +1036,15 @@ namespace MinecraftClient
#region Getters: Retrieve data for use in other methods or ChatBots
+ ///
+ /// Gets the horizontal direction of the takeoff.
+ ///
+ /// Return direction of view
+ public Direction GetHorizontalFacing()
+ {
+ return DirectionExtensions.FromRotation(GetYaw());
+ }
+
///
/// Get max length for chat messages
///
@@ -2260,6 +2269,7 @@ namespace MinecraftClient
return InvokeOnMainThread(() => handler.SendPlayerBlockPlacement((int)hand, location, blockFace, sequenceId++));
}
+
///
/// Attempt to dig a block at the specified location
///
diff --git a/MinecraftClient/Scripting/ChatBot.cs b/MinecraftClient/Scripting/ChatBot.cs
index ac77d935..8e8fc674 100644
--- a/MinecraftClient/Scripting/ChatBot.cs
+++ b/MinecraftClient/Scripting/ChatBot.cs
@@ -1631,6 +1631,15 @@ namespace MinecraftClient.Scripting
return Handler.GetProtocolVersion();
}
+ ///
+ /// Gets the horizontal direction of the takeoff.
+ ///
+ /// Return direction of view
+ protected Direction GetHorizontalFacing()
+ {
+ return Handler.GetHorizontalFacing();
+ }
+
///
/// Invoke a task on the main thread, wait for completion and retrieve return value.
///