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-11 12:46:38 +08:00
|
|
|
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; }
|
|
|
|
|
|
2026-04-12 18:46:42 +08:00
|
|
|
private readonly PathSegment _segment;
|
|
|
|
|
private readonly PathSegment? _nextSegment;
|
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-11 12:46:38 +08:00
|
|
|
private int _tickCount;
|
|
|
|
|
private Location _lastPos;
|
|
|
|
|
private int _stuckTicks;
|
2026-04-22 16:43:43 +00:00
|
|
|
private int _airborneTicks;
|
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-11 12:46:38 +08:00
|
|
|
|
2026-04-12 18:46:42 +08:00
|
|
|
public WalkTemplate(PathSegment segment, PathSegment? nextSegment)
|
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-11 12:46:38 +08:00
|
|
|
{
|
2026-04-12 18:46:42 +08:00
|
|
|
_segment = segment;
|
|
|
|
|
_nextSegment = nextSegment;
|
|
|
|
|
ExpectedStart = segment.Start;
|
|
|
|
|
ExpectedEnd = segment.End;
|
|
|
|
|
_lastPos = segment.Start;
|
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-11 12:46:38 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-12 18:46:42 +08:00
|
|
|
public TemplateState Tick(Location pos, PlayerPhysics physics, MovementInput input, World world)
|
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-11 12:46:38 +08:00
|
|
|
{
|
|
|
|
|
_tickCount++;
|
|
|
|
|
|
2026-04-11 14:03:50 +08:00
|
|
|
double dx = ExpectedEnd.X - pos.X;
|
|
|
|
|
double dz = ExpectedEnd.Z - pos.Z;
|
2026-04-12 00:57:38 +08:00
|
|
|
double dy = ExpectedEnd.Y - pos.Y;
|
2026-04-22 16:43:43 +00:00
|
|
|
// While approaching the end, steer via pos->end so lateral drift self-
|
|
|
|
|
// corrects. Once the center has entered the target block the pos->end
|
|
|
|
|
// vector becomes tiny/negative and flips yaw by ~180 degrees, which
|
|
|
|
|
// fights GroundedSegmentController's exit-heading rotation and locks
|
|
|
|
|
// yaw at a local equilibrium (e.g. 333 deg on a 1,1 diagonal) where
|
|
|
|
|
// HeadingPenalty never drops below the 8 deg ShouldComplete gate.
|
|
|
|
|
// Fall back to the stable quantized segment heading once inside the
|
|
|
|
|
// target block so the completion check and exit rotation converge.
|
|
|
|
|
// Skip the exit-heading bias on stable-footing Turn exits: it
|
|
|
|
|
// rotates yaw mid-segment while the bot still has along-segment
|
|
|
|
|
// momentum, which on a 1-block walkway drifts the bot
|
|
|
|
|
// perpendicular and walks it off the edge. The next segment's
|
|
|
|
|
// template snaps yaw on its first tick, so nothing is lost by
|
|
|
|
|
// deferring the rotation. Keep the bias when the next segment
|
|
|
|
|
// is a jump (RequireJumpReady): we need yaw aligned before
|
|
|
|
|
// takeoff or the jump direction will be off.
|
|
|
|
|
bool suppressBiasForSafeTurn = _segment.ExitTransition == PathTransitionType.Turn
|
|
|
|
|
&& _segment.ExitHints.RequireStableFooting
|
|
|
|
|
&& !_segment.ExitHints.RequireJumpReady;
|
|
|
|
|
float targetYaw;
|
|
|
|
|
if (!suppressBiasForSafeTurn
|
|
|
|
|
&& TemplateHelper.ShouldBiasTowardExitHeading(pos, _segment))
|
|
|
|
|
targetYaw = TemplateHelper.GetExitHeadingYaw(_segment);
|
|
|
|
|
else if (TemplateFootingHelper.IsCenterInsideTargetBlock(pos, _segment.End))
|
|
|
|
|
targetYaw = TemplateHelper.CalculateYaw(_segment.HeadingX, _segment.HeadingZ);
|
|
|
|
|
else
|
|
|
|
|
targetYaw = TemplateHelper.CalculateYaw(dx, dz);
|
2026-04-12 01:15:17 +08:00
|
|
|
float targetPitch = TemplateHelper.CalculatePitch(dx, dy, dz);
|
2026-04-22 16:43:43 +00:00
|
|
|
// Snap yaw on the first tick so we don't push forward input while the
|
|
|
|
|
// bot is still rotating from whatever yaw it had before this segment
|
|
|
|
|
// started (e.g. a random post-teleport orientation). Baritone-style:
|
|
|
|
|
// the server accepts instant yaw updates and the narrow 1-block lanes
|
|
|
|
|
// in parkour courses don't tolerate 3 ticks of sideways drift.
|
|
|
|
|
physics.Yaw = _tickCount == 1
|
|
|
|
|
? targetYaw
|
|
|
|
|
: TemplateHelper.SmoothYaw(physics.Yaw, targetYaw);
|
2026-04-12 01:15:17 +08:00
|
|
|
physics.Pitch = TemplateHelper.SmoothPitch(physics.Pitch, targetPitch);
|
2026-04-11 14:03:50 +08:00
|
|
|
|
2026-04-12 21:33:24 +08:00
|
|
|
GroundedSegmentController.Apply(_segment, _nextSegment, pos, physics, input, world);
|
2026-04-12 18:46:42 +08:00
|
|
|
|
2026-04-12 21:33:24 +08:00
|
|
|
if (GroundedSegmentController.ShouldComplete(_segment, pos, physics))
|
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-11 12:46:38 +08:00
|
|
|
return TemplateState.Complete;
|
|
|
|
|
|
|
|
|
|
double movedSq = TemplateHelper.HorizontalDistanceSq(pos, _lastPos);
|
|
|
|
|
_stuckTicks = movedSq < 0.0005 ? _stuckTicks + 1 : 0;
|
|
|
|
|
_lastPos = pos;
|
|
|
|
|
|
2026-04-22 16:43:43 +00:00
|
|
|
// Walk/Diagonal is a grounded move: if the bot is airborne for more
|
|
|
|
|
// than a handful of ticks the platform is gone beneath us (e.g. we
|
|
|
|
|
// rotated toward an exit heading on a narrow 1-block walkway and
|
|
|
|
|
// stepped off the edge). Fail fast so the replanner can recover
|
|
|
|
|
// before gravity carries the bot 10+ blocks out of position.
|
|
|
|
|
_airborneTicks = physics.OnGround ? 0 : _airborneTicks + 1;
|
|
|
|
|
if (_airborneTicks > 8)
|
|
|
|
|
return TemplateState.Failed;
|
|
|
|
|
|
2026-04-12 21:33:24 +08:00
|
|
|
int maxTicks = _segment.ExitTransition switch
|
|
|
|
|
{
|
|
|
|
|
PathTransitionType.ContinueStraight => 100,
|
|
|
|
|
PathTransitionType.PrepareJump => 80,
|
|
|
|
|
_ => 140
|
|
|
|
|
};
|
2026-04-12 18:46:42 +08:00
|
|
|
if (_stuckTicks > 40 || _tickCount > maxTicks)
|
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-11 12:46:38 +08:00
|
|
|
return TemplateState.Failed;
|
|
|
|
|
|
|
|
|
|
return TemplateState.InProgress;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|