Minecraft-Console-Client/MinecraftClient/Commands/Pathfind.cs
BruceChen 8ece75acc3 feat: complete Phase 4 McClient integration for A* pathfinding
- Fix MoveHelper.IsOpenGate: MangroveWood -> MangroveFenceGate
- Fix ResetStateForTransfer to cancel and clear pathSegmentManager
- Fix GetCurrentMovementGoal to return correct goal during A* navigation
- Fix SetMovementSpeed(Sneak) speed value consistency (2 -> 1)
- Migrate /pathfind command to use MoveToAStar + PathSegmentManager
- Add NavigateToGoal(IGoal) to McClient for flexible goal navigation
- Refactor MoveToAStar to delegate to NavigateToGoal
- Add ChatBot API: NavigateTo, CancelMovement, GetCurrentMovementGoal
- Expose PathSegmentManager.Goal property for external goal inspection

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 Pathfind : Command
{
public override string CmdName => "pathfind";
public override string CmdUsage => "pathfind <x y z>";
public override string CmdDesc => Translations.cmd_pathfind_desc;
public override void RegisterCommand(CommandDispatcher<CmdResult> dispatcher)
{
dispatcher.Register(l => l.Literal("help")
.Then(l => l.Literal(CmdName)
.Executes(r => GetUsage(r.Source)))
);
dispatcher.Register(l => l.Literal(CmdName)
.Then(l => l.Argument("location", MccArguments.Location())
.Executes(r => DoPathfind(r.Source, MccArguments.GetLocation(r, "location"))))
.Then(l => l.Literal("_help")
.Executes(r => GetUsage(r.Source))
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
);
}
private int GetUsage(CmdResult r)
{
return r.SetAndReturn(GetCmdDescTranslated());
}
private static int DoPathfind(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, timeoutMs: 10000);
return r.SetAndReturn(success ? Status.Done : Status.Fail, message);
}
}
}