Skip to content

Commit df94433

Browse files
committed
Done auxiliary methods for Direction
1 parent 91ef890 commit df94433

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

MinecraftClient/Mapping/DirectionExtensions.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace MinecraftClient.Mapping
1+
using System;
2+
3+
namespace MinecraftClient.Mapping
24
{
35
public static class DirectionExtensions
46
{
@@ -35,5 +37,27 @@ public static Direction GetOpposite(this Direction direction)
3537

3638
}
3739
}
40+
41+
42+
public static Direction[] HORIZONTAL =
43+
{
44+
Direction.South,
45+
Direction.West,
46+
Direction.North,
47+
Direction.East
48+
};
49+
50+
public static Direction FromRotation(double rotation)
51+
{
52+
double floor = Math.Floor((rotation / 90.0) + 0.5);
53+
int value = (int)floor & 3;
54+
55+
return FromHorizontal(value);
56+
}
57+
58+
public static Direction FromHorizontal(int value)
59+
{
60+
return HORIZONTAL[Math.Abs(value % HORIZONTAL.Length)];
61+
}
3862
}
3963
}

MinecraftClient/McClient.cs

+10
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,15 @@ public void SetNetworkPacketCaptureEnabled(bool enabled)
10361036

10371037
#region Getters: Retrieve data for use in other methods or ChatBots
10381038

1039+
/// <summary>
1040+
/// Gets the horizontal direction of the takeoff.
1041+
/// </summary>
1042+
/// <returns>Return direction of view</returns>
1043+
public Direction GetHorizontalFacing()
1044+
{
1045+
return DirectionExtensions.FromRotation(GetYaw());
1046+
}
1047+
10391048
/// <summary>
10401049
/// Get max length for chat messages
10411050
/// </summary>
@@ -2260,6 +2269,7 @@ public bool PlaceBlock(Location location, Direction blockFace, Hand hand = Hand.
22602269
return InvokeOnMainThread(() => handler.SendPlayerBlockPlacement((int)hand, location, blockFace, sequenceId++));
22612270
}
22622271

2272+
22632273
/// <summary>
22642274
/// Attempt to dig a block at the specified location
22652275
/// </summary>

MinecraftClient/Scripting/ChatBot.cs

+9
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,15 @@ protected int GetProtocolVersion()
16311631
return Handler.GetProtocolVersion();
16321632
}
16331633

1634+
/// <summary>
1635+
/// Gets the horizontal direction of the takeoff.
1636+
/// </summary>
1637+
/// <returns>Return direction of view</returns>
1638+
protected Direction GetHorizontalFacing()
1639+
{
1640+
return Handler.GetHorizontalFacing();
1641+
}
1642+
16341643
/// <summary>
16351644
/// Invoke a task on the main thread, wait for completion and retrieve return value.
16361645
/// </summary>

0 commit comments

Comments
 (0)