2022-11-28 13:55:05 +08:00
|
|
|
|
using System;
|
2015-12-12 16:48:29 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using MinecraftClient.Mapping;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Move : Command
|
|
|
|
|
|
{
|
2020-10-17 19:41:31 +08:00
|
|
|
|
public override string CmdName { get { return "move"; } }
|
2022-07-25 18:11:10 +08:00
|
|
|
|
public override string CmdUsage { get { return "move <on|off|get|up|down|east|west|north|south|center|x y z|gravity [on|off]> [-f]"; } }
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public override string CmdDesc { get { return Translations.cmd_move_desc + " \"-f\": " + Translations.cmd_move_desc_force; } }
|
2015-12-12 16:48:29 +01:00
|
|
|
|
|
2022-10-02 18:31:08 +08:00
|
|
|
|
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
|
2015-12-12 16:48:29 +01:00
|
|
|
|
{
|
2022-10-02 18:31:08 +08:00
|
|
|
|
List<string> args = GetArgs(command.ToLower()).ToList();
|
2021-12-29 15:34:40 +01:00
|
|
|
|
bool takeRisk = false;
|
2019-04-28 21:32:03 +02:00
|
|
|
|
|
2022-01-23 21:31:44 +01:00
|
|
|
|
if (args.Count < 1)
|
2022-07-25 14:20:24 +08:00
|
|
|
|
{
|
2022-08-18 20:58:49 +02:00
|
|
|
|
string desc = GetCmdDescTranslated();
|
2022-07-25 14:20:24 +08:00
|
|
|
|
|
|
|
|
|
|
if (handler.GetTerrainEnabled())
|
2022-10-02 18:31:08 +08:00
|
|
|
|
handler.Log.Info(World.GetChunkLoadingStatus(handler.GetWorld()));
|
2022-07-25 14:20:24 +08:00
|
|
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
|
|
}
|
2022-01-23 21:31:44 +01:00
|
|
|
|
|
2021-12-29 15:34:40 +01:00
|
|
|
|
if (args.Contains("-f"))
|
|
|
|
|
|
{
|
|
|
|
|
|
takeRisk = true;
|
|
|
|
|
|
args.Remove("-f");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (args[0] == "on")
|
2019-04-28 21:32:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
handler.SetTerrainEnabled(true);
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return Translations.cmd_move_enable;
|
2019-04-28 21:32:03 +02:00
|
|
|
|
}
|
2021-12-29 15:34:40 +01:00
|
|
|
|
else if (args[0] == "off")
|
2019-04-28 21:32:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
handler.SetTerrainEnabled(false);
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return Translations.cmd_move_disable;
|
2019-04-28 21:32:03 +02:00
|
|
|
|
}
|
2022-03-06 19:37:27 +01:00
|
|
|
|
else if (args[0] == "gravity")
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Count >= 2)
|
2022-10-05 15:02:30 +08:00
|
|
|
|
Settings.InternalConfig.GravityEnabled = (args[1] == "on");
|
|
|
|
|
|
if (Settings.InternalConfig.GravityEnabled)
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return Translations.cmd_move_gravity_enabled;
|
|
|
|
|
|
else return Translations.cmd_move_gravity_disabled;
|
2022-03-06 19:37:27 +01:00
|
|
|
|
}
|
2019-04-28 21:32:03 +02:00
|
|
|
|
else if (handler.GetTerrainEnabled())
|
2015-12-12 16:48:29 +01:00
|
|
|
|
{
|
2021-12-29 15:34:40 +01:00
|
|
|
|
if (args.Count == 1)
|
2015-12-12 16:48:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
Direction direction;
|
2021-12-29 15:34:40 +01:00
|
|
|
|
switch (args[0])
|
2015-12-12 16:48:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
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-07-25 18:11:10 +08:00
|
|
|
|
case "center":
|
2022-08-18 20:58:49 +02:00
|
|
|
|
Location current = handler.GetCurrentLocation();
|
2022-10-02 18:31:08 +08:00
|
|
|
|
Location currentCenter = new(Math.Floor(current.X) + 0.5, current.Y, Math.Floor(current.Z) + 0.5);
|
2022-08-18 20:58:49 +02:00
|
|
|
|
handler.MoveTo(currentCenter, allowDirectTeleport: true);
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_move_walk, currentCenter, current);
|
2016-03-11 10:52:19 +01:00
|
|
|
|
case "get": return handler.GetCurrentLocation().ToString();
|
2022-10-28 11:13:20 +08:00
|
|
|
|
default: return string.Format(Translations.cmd_look_unknown, args[0]);
|
2015-12-12 16:48:29 +01:00
|
|
|
|
}
|
2022-08-24 18:16:16 +08:00
|
|
|
|
|
|
|
|
|
|
Location goal = Movement.Move(handler.GetCurrentLocation(), direction);
|
2022-08-25 14:36:15 +08:00
|
|
|
|
|
2022-09-12 16:27:37 +08:00
|
|
|
|
if (!Movement.CheckChunkLoading(handler.GetWorld(), handler.GetCurrentLocation(), goal))
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_move_chunk_not_loaded, goal.X, goal.Y, goal.Z);
|
2022-08-24 18:16:16 +08:00
|
|
|
|
|
2015-12-12 16:48:29 +01:00
|
|
|
|
if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
|
|
|
|
|
|
{
|
2022-08-25 14:36:15 +08:00
|
|
|
|
if (handler.MoveTo(goal, allowUnsafe: takeRisk))
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_move_moving, args[0]);
|
2022-10-02 18:31:08 +08:00
|
|
|
|
else
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return takeRisk ? Translations.cmd_move_dir_fail : Translations.cmd_move_suggestforce;
|
2015-12-12 16:48:29 +01:00
|
|
|
|
}
|
2022-10-28 11:13:20 +08:00
|
|
|
|
else return Translations.cmd_move_dir_fail;
|
2015-12-12 16:48:29 +01:00
|
|
|
|
}
|
2021-12-29 15:34:40 +01:00
|
|
|
|
else if (args.Count == 3)
|
2015-12-12 16:48:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-09-09 16:13:25 +08:00
|
|
|
|
Location current = handler.GetCurrentLocation(), currentCenter = current.ToCenter();
|
2022-09-29 22:49:07 +08:00
|
|
|
|
Location goal = Location.Parse(current, args[0], args[1], args[2]);
|
2021-12-29 15:34:40 +01:00
|
|
|
|
|
2022-09-12 16:27:37 +08:00
|
|
|
|
if (!Movement.CheckChunkLoading(handler.GetWorld(), current, goal))
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_move_chunk_not_loaded, goal.X, goal.Y, goal.Z);
|
2022-07-25 18:11:10 +08:00
|
|
|
|
|
2022-09-05 22:03:47 +08:00
|
|
|
|
if (takeRisk || Movement.PlayerFitsHere(handler.GetWorld(), goal))
|
|
|
|
|
|
{
|
2022-09-09 16:13:25 +08:00
|
|
|
|
if (current.ToFloor() == goal.ToFloor())
|
2022-09-05 22:03:47 +08:00
|
|
|
|
handler.MoveTo(goal, allowDirectTeleport: true);
|
|
|
|
|
|
else if (!handler.MoveTo(goal, allowUnsafe: takeRisk))
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return takeRisk ? string.Format(Translations.cmd_move_fail, goal) : string.Format(Translations.cmd_move_suggestforce, goal);
|
|
|
|
|
|
return string.Format(Translations.cmd_move_walk, goal, current);
|
2022-09-05 22:03:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2022-10-28 11:13:20 +08:00
|
|
|
|
return string.Format(Translations.cmd_move_suggestforce, goal);
|
2015-12-12 16:48:29 +01:00
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
|
catch (FormatException) { return GetCmdDescTranslated(); }
|
2015-12-12 16:48:29 +01:00
|
|
|
|
}
|
2020-10-17 19:41:31 +08:00
|
|
|
|
else return GetCmdDescTranslated();
|
2015-12-12 16:48:29 +01:00
|
|
|
|
}
|
2022-10-28 11:13:20 +08:00
|
|
|
|
else return Translations.extra_terrainandmovement_required;
|
2015-12-12 16:48:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|