Minecraft-Console-Client/MinecraftClient/Pathing/Execution/Templates/WalkTemplate.cs
BruceChen 4b49135107 feat: add parkour moves and template-based path execution system
Phase 2.2: MoveParkour for sprint-jump across 1-2 block gaps (distance 2-3)
and ascending parkour (distance 2, +1Y). Registered in BuildDefaultMoves
with CalculationContext.AllowParkour gating.

Phase 3.1-3.2: Template execution engine replacing the waypoint queue system.
- IActionTemplate interface with per-tick state machine pattern
- Templates: Walk, Ascend, Descend, Climb, Fall, SprintJump
- ActionTemplateFactory maps MoveType to the correct template
- PathExecutor drives sequential template execution with logging
- PathSegmentManager handles replanning on failure (up to 5 retries)
- McClient integration: MoveToAStar now creates PathSegmentManager,
  UpdatePathfindingInput delegates to it, CancelMovement/ClientIsMoving
  updated for both old and new systems.

Tested on 1.21.11: straight walk, zigzag maze, stair ascent,
1-gap and 2-gap sprint jumps all pass.

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

51 lines
1.5 KiB
C#

using System;
using MinecraftClient.Mapping;
using MinecraftClient.Physics;
namespace MinecraftClient.Pathing.Execution.Templates
{
/// <summary>
/// Walk/sprint toward a destination on the same Y level.
/// Used for Traverse and Diagonal moves.
/// </summary>
public sealed class WalkTemplate : IActionTemplate
{
public Location ExpectedStart { get; }
public Location ExpectedEnd { get; }
private int _tickCount;
private Location _lastPos;
private int _stuckTicks;
public WalkTemplate(Location start, Location end)
{
ExpectedStart = start;
ExpectedEnd = end;
_lastPos = start;
}
public TemplateState Tick(Location pos, PlayerPhysics physics, MovementInput input)
{
_tickCount++;
if (TemplateHelper.IsNear(pos, ExpectedEnd, horizThresholdSq: 0.20))
return TemplateState.Complete;
double movedSq = TemplateHelper.HorizontalDistanceSq(pos, _lastPos);
_stuckTicks = movedSq < 0.0005 ? _stuckTicks + 1 : 0;
_lastPos = pos;
if (_stuckTicks > 40 || _tickCount > 100)
return TemplateState.Failed;
double dx = ExpectedEnd.X - pos.X;
double dz = ExpectedEnd.Z - pos.Z;
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
input.Forward = true;
input.Sprint = true;
return TemplateState.InProgress;
}
}
}