2019-04-09 18:01:00 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-10-04 11:53:07 +08:00
|
|
|
|
using System.Globalization;
|
2022-10-26 08:54:54 +08:00
|
|
|
|
using Brigadier.NET;
|
2019-04-09 18:01:00 -07:00
|
|
|
|
using MinecraftClient.Mapping;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Look : Command
|
|
|
|
|
|
{
|
2020-10-17 19:41:31 +08:00
|
|
|
|
public override string CmdName { get { return "look"; } }
|
|
|
|
|
|
public override string CmdUsage { get { return "look <x y z|yaw pitch|up|down|east|west|north|south>"; } }
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public override string CmdDesc { get { return Translations.cmd_look_desc; } }
|
2019-04-09 18:01:00 -07:00
|
|
|
|
|
2022-10-26 08:54:54 +08:00
|
|
|
|
public override void RegisterCommand(McClient handler, CommandDispatcher<CommandSource> dispatcher)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-02 18:31:08 +08:00
|
|
|
|
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
|
2019-04-09 18:01:00 -07:00
|
|
|
|
{
|
2019-04-28 21:32:03 +02:00
|
|
|
|
if (handler.GetTerrainEnabled())
|
2019-04-09 18:01:00 -07:00
|
|
|
|
{
|
2022-10-02 18:31:08 +08:00
|
|
|
|
string[] args = GetArgs(command);
|
2022-10-02 13:49:36 +08:00
|
|
|
|
if (args.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
const double maxDistance = 8.0;
|
|
|
|
|
|
(bool hasBlock, Location target, Block block) = RaycastHelper.RaycastBlock(handler, maxDistance, false);
|
|
|
|
|
|
if (!hasBlock)
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_look_noinspection, maxDistance);
|
2022-10-02 13:49:36 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Location current = handler.GetCurrentLocation(), target_center = target.ToCenter();
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_look_inspection, block.Type, target.X, target.Y, target.Z,
|
2022-10-02 13:49:36 +08:00
|
|
|
|
current.Distance(target_center), current.EyesLocation().Distance(target_center));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (args.Length == 1)
|
2019-04-09 18:01:00 -07:00
|
|
|
|
{
|
2022-10-02 18:31:08 +08:00
|
|
|
|
string dirStr = GetArg(command).Trim().ToLower();
|
2019-04-09 20:19:27 -07:00
|
|
|
|
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;
|
2022-10-28 11:13:20 +08:00
|
|
|
|
default: return string.Format(Translations.cmd_look_unknown, dirStr);
|
2019-04-09 20:19:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-12 17:08:30 +02:00
|
|
|
|
handler.UpdateLocation(handler.GetCurrentLocation(), direction);
|
2019-04-09 20:19:27 -07:00
|
|
|
|
return "Looking " + dirStr;
|
2019-04-09 18:01:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (args.Length == 2)
|
|
|
|
|
|
{
|
2019-04-09 20:19:27 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-10-04 11:53:07 +08:00
|
|
|
|
float yaw = float.Parse(args[0], NumberStyles.Any, CultureInfo.CurrentCulture);
|
|
|
|
|
|
float pitch = float.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture);
|
2019-04-09 18:01:00 -07:00
|
|
|
|
|
2019-04-12 17:08:30 +02:00
|
|
|
|
handler.UpdateLocation(handler.GetCurrentLocation(), yaw, pitch);
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_look_at, yaw.ToString("0.00"), pitch.ToString("0.00"));
|
2019-04-09 20:19:27 -07:00
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
|
catch (FormatException) { return GetCmdDescTranslated(); }
|
2019-04-09 18:01:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (args.Length == 3)
|
|
|
|
|
|
{
|
2019-04-09 20:19:27 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-09-29 23:11:30 +08:00
|
|
|
|
Location current = handler.GetCurrentLocation();
|
|
|
|
|
|
Location block = Location.Parse(current, args[0], args[1], args[2]);
|
|
|
|
|
|
handler.UpdateLocation(current, block);
|
2019-04-09 18:01:00 -07:00
|
|
|
|
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_look_block, block);
|
2019-04-09 20:19:27 -07:00
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
|
catch (FormatException) { return CmdUsage; }
|
2019-04-09 20:19:27 -07:00
|
|
|
|
|
2019-04-09 18:01:00 -07:00
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
|
else return GetCmdDescTranslated();
|
2019-04-09 18:01:00 -07:00
|
|
|
|
}
|
2022-10-28 11:13:20 +08:00
|
|
|
|
else return Translations.extra_terrainandmovement_required;
|
2019-04-09 18:01:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|