Minecraft-Console-Client/MinecraftClient/Commands/Goto.cs
BruceChen 77c5f88168 feat: add /goto command with A* pathfinder integration and MoveFall
- Add MoveFall move for straight-down falls beyond MoveDescend range
- Register MoveFall in default move set
- Create /goto command using new A* pathfinder
- Add MoveToAStar() method to McClient bridging A* results to existing
  path execution system (Queue<Location> + UpdatePathfindingInput)
- Add translation entries for goto command

Made-with: Cursor
2026-04-12 18:43:32 +00:00

50 lines
1.8 KiB
C#

using Brigadier.NET;
using Brigadier.NET.Builder;
using MinecraftClient.CommandHandler;
using MinecraftClient.Mapping;
using static MinecraftClient.CommandHandler.CmdResult;
namespace MinecraftClient.Commands
{
public class Goto : Command
{
public override string CmdName => "goto";
public override string CmdUsage => "goto <x y z>";
public override string CmdDesc => Translations.cmd_goto_desc;
public override void RegisterCommand(CommandDispatcher<CmdResult> dispatcher)
{
dispatcher.Register(l => l.Literal("help")
.Then(l => l.Literal(CmdName)
.Executes(r => GetUsage(r.Source, string.Empty)))
);
dispatcher.Register(l => l.Literal(CmdName)
.Then(l => l.Argument("location", MccArguments.Location())
.Executes(r => DoGoto(r.Source, MccArguments.GetLocation(r, "location"))))
.Then(l => l.Literal("_help")
.Executes(r => GetUsage(r.Source, string.Empty))
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
);
}
private int GetUsage(CmdResult r, string? cmd)
{
return r.SetAndReturn(GetCmdDescTranslated());
}
private static int DoGoto(CmdResult r, Location goal)
{
McClient handler = CmdResult.currentHandler!;
if (!handler.GetTerrainEnabled())
return r.SetAndReturn(Status.FailNeedTerrain);
Location current = handler.GetCurrentLocation();
goal.ToAbsolute(current);
var (success, message) = handler.MoveToAStar(goal);
return r.SetAndReturn(success ? Status.Done : Status.Fail, message);
}
}
}