Minecraft-Console-Client/MinecraftClient/Pathing/Moves/Impl/MoveParkour.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

113 lines
3.3 KiB
C#

using MinecraftClient.Pathing.Core;
namespace MinecraftClient.Pathing.Moves.Impl
{
/// <summary>
/// Sprint jump across a gap of 1-3 blocks (total distance 2-4 blocks forward).
/// Optionally ascends 1 block during the jump (distance 2 only).
/// Requires AllowParkour in context; the first block forward must lack ground.
/// </summary>
public sealed class MoveParkour : IMove
{
public MoveType Type => MoveType.Parkour;
public int XOffset { get; }
public int ZOffset { get; }
public bool DynamicY => false;
private readonly int _distance;
private readonly int _yDelta;
private readonly int _xDir;
private readonly int _zDir;
public MoveParkour(int xDir, int zDir, int distance, int yDelta = 0)
{
_xDir = xDir;
_zDir = zDir;
_distance = distance;
_yDelta = yDelta;
XOffset = xDir * distance;
ZOffset = zDir * distance;
}
public void Calculate(CalculationContext ctx, int x, int y, int z, ref MoveResult result)
{
if (!ctx.AllowParkour)
{
result.SetImpossible();
return;
}
if (_yDelta > 0 && !ctx.AllowParkourAscend)
{
result.SetImpossible();
return;
}
if (!ctx.CanSprint)
{
result.SetImpossible();
return;
}
int destX = x + _xDir * _distance;
int destZ = z + _zDir * _distance;
int destY = y + _yDelta;
if (!ctx.CanWalkThrough(x, y + 2, z))
{
result.SetImpossible();
return;
}
if (!ctx.CanWalkOn(destX, destY - 1, destZ))
{
result.SetImpossible();
return;
}
if (!ctx.CanWalkThrough(destX, destY, destZ) ||
!ctx.CanWalkThrough(destX, destY + 1, destZ))
{
result.SetImpossible();
return;
}
for (int i = 1; i < _distance; i++)
{
int gx = x + _xDir * i;
int gz = z + _zDir * i;
if (!ctx.CanWalkThrough(gx, y, gz) ||
!ctx.CanWalkThrough(gx, y + 1, gz) ||
!ctx.CanWalkThrough(gx, y + 2, gz))
{
result.SetImpossible();
return;
}
if (_yDelta > 0 && !ctx.CanWalkThrough(gx, y + 3, gz))
{
result.SetImpossible();
return;
}
}
int firstGapX = x + _xDir;
int firstGapZ = z + _zDir;
if (ctx.CanWalkOn(firstGapX, y - 1, firstGapZ))
{
result.SetImpossible();
return;
}
double cost = _distance * ctx.SprintCost + ctx.JumpPenalty;
if (_yDelta > 0)
cost += ctx.JumpPenalty;
result.Set(destX, destY, destZ, cost);
}
public override string ToString() =>
$"MoveParkour(dir=({_xDir},{_zDir}), dist={_distance}, dy={_yDelta})";
}
}