mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
- 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
50 lines
1.8 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|