Auxiliary class for Direction, preparation for autodetection of the broken side of the block

This commit is contained in:
Roman Danilov 2024-03-05 20:30:58 +05:00
parent fde50c1728
commit 91ef890bb6
4 changed files with 43 additions and 3 deletions

View file

@ -651,7 +651,7 @@ public class WebSocketBot : ChatBot
var result = cmd.Parameters.Length switch
{
// TODO Get Direction from the arguments
// TODO Get blockFace direction from arguments
3 => DigBlock(location, Direction.Down),
4 => DigBlock(location, Direction.Down, (bool)cmd.Parameters[3]),
5 => DigBlock(location, Direction.Down, (bool)cmd.Parameters[3], (bool)cmd.Parameters[4]),

View file

@ -22,6 +22,7 @@ namespace MinecraftClient.Commands
);
dispatcher.Register(l => l.Literal(CmdName)
// TODO Get blockFace direction from arguments
.Executes(r => DigLookAt(r.Source))
.Then(l => l.Argument("Duration", Arguments.Double())
.Executes(r => DigLookAt(r.Source, Arguments.GetDouble(r, "Duration"))))

View file

@ -0,0 +1,39 @@
namespace MinecraftClient.Mapping
{
public static class DirectionExtensions
{
public static Direction GetOpposite(this Direction direction)
{
switch (direction)
{
case Direction.SouthEast:
return Direction.NorthEast;
case Direction.SouthWest:
return Direction.NorthWest;
case Direction.NorthEast:
return Direction.SouthEast;
case Direction.NorthWest:
return Direction.SouthWest;
case Direction.West:
return Direction.East;
case Direction.East:
return Direction.West;
case Direction.North:
return Direction.South;
case Direction.South:
return Direction.North;
case Direction.Down:
return Direction.Up;
case Direction.Up:
return Direction.Down;
default:
return Direction.Up;
}
}
}
}

View file

@ -2268,14 +2268,14 @@ namespace MinecraftClient
/// <param name="lookAtBlock">Also look at the block before digging</param>
public bool DigBlock(Location location, Direction blockFace, bool swingArms = true, bool lookAtBlock = true, double duration = 0)
{
// TODO select best face from current player location
if (!GetTerrainEnabled())
return false;
if (InvokeRequired)
return InvokeOnMainThread(() => DigBlock(location, blockFace, swingArms, lookAtBlock, duration));
// TODO select best face from current player location
lock (DigLock)
{
if (RemainingDiggingTime > 0 && LastDigPosition != null)