mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Explicit yawpitch, cardinal directions, and cleanup.
This commit is contained in:
parent
8bfdb2ab59
commit
4f54a4060a
2 changed files with 79 additions and 17 deletions
|
|
@ -18,25 +18,49 @@ namespace MinecraftClient.Commands
|
|||
string[] args = getArgs(command);
|
||||
if (args.Length == 1)
|
||||
{
|
||||
return "ok.";
|
||||
string dirStr = getArg(command).Trim().ToLower();
|
||||
Direction direction;
|
||||
switch (dirStr)
|
||||
{
|
||||
case "up": direction = Direction.Up; break;
|
||||
case "down": direction = Direction.Down; break;
|
||||
case "east": direction = Direction.East; break;
|
||||
case "west": direction = Direction.West; break;
|
||||
case "north": direction = Direction.North; break;
|
||||
case "south": direction = Direction.South; break;
|
||||
default: return "Unknown direction '" + dirStr + "'.";
|
||||
}
|
||||
|
||||
handler.LookAtDirection(direction);
|
||||
return "Looking " + dirStr;
|
||||
}
|
||||
else if (args.Length == 2)
|
||||
{
|
||||
float yaw = Single.Parse(args[0]),
|
||||
pitch = Single.Parse(args[1]);
|
||||
try
|
||||
{
|
||||
float yaw = Single.Parse(args[0]),
|
||||
pitch = Single.Parse(args[1]);
|
||||
|
||||
return $"Looking at YAW: {yaw} PITCH: {pitch}";
|
||||
handler.LookAtAngle(yaw, pitch);
|
||||
return $"Looking at YAW: {yaw} PITCH: {pitch}";
|
||||
}
|
||||
catch (FormatException) { return CMDDesc; }
|
||||
}
|
||||
else if (args.Length == 3)
|
||||
{
|
||||
int x = int.Parse(args[0]),
|
||||
y = int.Parse(args[1]),
|
||||
z = int.Parse(args[2]);
|
||||
try
|
||||
{
|
||||
int x = int.Parse(args[0]),
|
||||
y = int.Parse(args[1]),
|
||||
z = int.Parse(args[2]);
|
||||
|
||||
Location block = new Location(x, y, z);
|
||||
handler.LookAtBlock(block);
|
||||
Location block = new Location(x, y, z);
|
||||
handler.LookAtBlock(block);
|
||||
|
||||
return "Looking at " + block;
|
||||
}
|
||||
catch (FormatException) { return CMDDesc; }
|
||||
|
||||
return "Looking at " + block;
|
||||
}
|
||||
else return CMDDesc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -426,9 +426,9 @@ namespace MinecraftClient
|
|||
/// <param name="block">The block to look at</param>
|
||||
public void LookAtBlock(Location block)
|
||||
{
|
||||
double dx = block.X - location.X,
|
||||
dy = block.Y - location.Y,
|
||||
dz = block.Z - location.Z;
|
||||
double dx = block.X - (location.X - 0.5),
|
||||
dy = block.Y - (location.Y + 1),
|
||||
dz = block.Z - (location.Z - 0.5);
|
||||
|
||||
double r = Math.Sqrt(dx * dx + dy * dy + dz * dz);
|
||||
|
||||
|
|
@ -436,13 +436,51 @@ namespace MinecraftClient
|
|||
pitch = Convert.ToSingle(-Math.Asin(dy / r) / Math.PI * 180);
|
||||
if (yaw < 0) yaw += 360;
|
||||
|
||||
|
||||
ConsoleIO.WriteLineFormatted("YAW: " + yaw);
|
||||
ConsoleIO.WriteLineFormatted("PITCH: " + pitch);
|
||||
|
||||
UpdateLocation(location, yaw, pitch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Look at specified angle
|
||||
/// </summary>
|
||||
/// <param name="yaw">The yaw to look at</param>
|
||||
/// <param name="pitch">The pitch to look at</param>
|
||||
public void LookAtAngle(float yaw, float pitch)
|
||||
{
|
||||
UpdateLocation(location, yaw, pitch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Look in specified direction
|
||||
/// </summary>
|
||||
/// <param name="direction">The direction too look in</param>
|
||||
public void LookAtDirection(Direction direction)
|
||||
{
|
||||
float yaw = 0,
|
||||
pitch = 0;
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
pitch = -90;
|
||||
break;
|
||||
case Direction.Down:
|
||||
pitch = 90;
|
||||
break;
|
||||
case Direction.East:
|
||||
yaw = 270;
|
||||
break;
|
||||
case Direction.West:
|
||||
yaw = 90;
|
||||
break;
|
||||
case Direction.North:
|
||||
yaw = 90;
|
||||
break;
|
||||
case Direction.South:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unknown direction", "direction");
|
||||
}
|
||||
UpdateLocation(location, yaw, pitch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move to the specified location
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue