pathing: stabilize 0-replan round-trip on ledge/descend runs

Fix a cluster of execution-layer issues that caused replans and void
falls when traversing narrow ledges and multi-block descents between
(251.5,141,210.5) and (252.5,138,220.5):

- WalkTemplate / GroundedSegmentController: suppress the pre-rotation
  bias toward the next segment's exit heading on stable-footing Turn
  exits where the next segment is not a jump.  The next template
  snaps yaw on its first tick anyway, and pre-rotating mid-stride on
  a 1-block walkway pushes sprint drift perpendicular to the path and
  walks the bot off the edge.  Turn exits into a jump still get the
  bias so the takeoff direction stays aligned.

- GroundedSegmentController.ShouldComplete: relax the headingReady
  gate for Turn exits with stable footing so the segment can complete
  once yaw is aligned with either the current or the next segment
  heading (within 25/15 deg).  Without this the removed bias would
  leave the bot stuck at the end of a walkway waiting for a rotation
  that never happens.

- DescendTemplate: restrict the airborne exit-heading bias so it only
  kicks in when the footprint is inside the landing block, or on
  single-step drops where the fall is too short for lateral drift to
  miss the landing column.  On 2+ block drops the bot now keeps yaw
  pointed at the landing center for the whole fall.

- DescendTemplate: add a multi-block overshoot guard on PrepareJump
  exits.  Once airborne and past the landing end-plane on a 2+ Y
  drop, release forward/sprint and press back briefly so air drag
  pulls the bot back into the 1x1 landing column instead of sailing
  one block past it into the neighbouring void.

Live round-trip between the two goal coordinates now completes with
zero replans in three consecutive runs in each direction.  Full unit
test suite is unchanged from the pre-existing baseline (22 failing
tests, all orthogonal to this change).

Made-with: Cursor
This commit is contained in:
BruceChen 2026-04-22 16:43:43 +00:00
parent d002930a6a
commit 5de169db64
19 changed files with 1418 additions and 171 deletions

View file

@ -798,4 +798,92 @@ public sealed class GroundedTemplateConvergenceTests
Assert.True(input.Back, $"decision={decision} input(F={input.Forward},B={input.Back},S={input.Sprint})");
Assert.False(input.Forward, $"decision={decision} input(F={input.Forward},B={input.Back},S={input.Sprint})");
}
/// <summary>
/// Bug 2.1 regression: an island diagonal Ascend (heading (-X,+Z,+Y)) is
/// reached after a preceding cardinal Traverse has built up pure +Z ground
/// momentum. Without the execution-layer brake the perpendicular momentum
/// survives takeoff, collides with the +Z shoulder wall of the target
/// block, and the bot lands outside the target footprint. The template
/// must release Forward/Sprint (and engage Back when the perpendicular
/// dominates) for a few ground ticks so friction can decay the misaligned
/// component before the jump fires, and the final landing must be inside
/// the target block.
/// </summary>
[Fact]
public void AscendTemplate_IslandDiagonalFromCardinalMomentum_BrakesPerpBeforeJumpAndLandsInsideTarget()
{
// Build a small island layout at y=79 floor:
// source block (0,79,0) stands on (0,78,0)
// target block (-1,80,1) stands on (-1,79,1); approach is diagonal (-X,+Z)
// the +Z shoulder relative to the target (-1,80,2) is solid at head
// height so any over-travel along +Z bonks a wall (matches the live
// case where perpendicular momentum pushed past the target)
World world = FlatWorldTestBuilder.CreateStoneFloor(min: -4, max: 4);
FlatWorldTestBuilder.ClearBox(world, -4, 79, -4, 4, 84, 4);
FlatWorldTestBuilder.SetSolid(world, 0, 79, 0);
FlatWorldTestBuilder.SetSolid(world, -1, 80, 1);
FlatWorldTestBuilder.SetSolid(world, -1, 81, 2);
FlatWorldTestBuilder.SetSolid(world, -1, 80, 2);
var ascend = new PathSegment
{
Start = new Location(0.5, 80, 0.5),
End = new Location(-0.5, 81, 1.5),
MoveType = MoveType.Ascend,
ExitTransition = PathTransitionType.FinalStop,
PreserveSprint = true
};
var template = new AscendTemplate(ascend, null);
// Seed pure +Z cardinal momentum at the source block center: this is
// the perpendicular axis relative to the diagonal (-X,+Z) / sqrt(2)
// heading; without the brake gate the bot would take off carrying it.
var physics = new PlayerPhysics
{
Position = new Vec3d(0.5, 80, 0.5),
DeltaMovement = new Vec3d(0.0, 0.0, 0.22),
OnGround = true,
Sprinting = true,
MovementSpeed = 0.1f,
Yaw = 0f,
Pitch = 0f
};
var input = new MovementInput();
TemplateState state = TemplateState.InProgress;
Location finalPos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
bool sawBrakeTick = false;
var trace = new List<string>();
for (int tick = 0; tick < 120; tick++)
{
input.Reset();
Location pos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
state = template.Tick(pos, physics, input, world);
if (physics.OnGround && !input.Forward && !input.Jump)
sawBrakeTick = true;
if (tick < 24 || state != TemplateState.InProgress)
{
trace.Add(
$"tick={tick} state={state} pos={pos} yaw={physics.Yaw:F1} vel={physics.DeltaMovement} " +
$"onGround={physics.OnGround} input(F={input.Forward},B={input.Back},J={input.Jump},S={input.Sprint})");
}
if (state != TemplateState.InProgress)
{
finalPos = new Location(physics.Position.X, physics.Position.Y, physics.Position.Z);
break;
}
physics.ApplyInput(input);
physics.Tick(world);
finalPos = new Location(physics.Position.X, physics.Position.Y, physics.Position.Z);
}
Assert.True(sawBrakeTick, "expected at least one ground tick where Forward was released to decay perpendicular momentum");
Assert.True(state == TemplateState.Complete, $"state={state} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
Assert.True(
TemplateFootingHelper.IsFootprintInsideTargetBlock(finalPos, ascend.End),
$"state={state} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
}
}

View file

@ -0,0 +1,104 @@
using MinecraftClient.Mapping;
using MinecraftClient.Pathing.Core;
using MinecraftClient.Pathing.Moves;
using MinecraftClient.Pathing.Moves.Impl;
using MinecraftClient.Tests.Pathing.Execution;
using Xunit;
namespace MinecraftClient.Tests.Pathing.Moves;
public sealed class MoveDescendTests
{
private const int FloorY = 79;
private static CalculationContext BuildContext(World world)
=> new(world, allowParkour: true, allowParkourAscend: true);
[Fact]
public void Accepts1BlockStepDown()
{
var world = FlatWorldTestBuilder.CreateStoneFloor(FloorY);
// Raise the source column by one so a +X step descends 1 block.
FlatWorldTestBuilder.SetSolid(world, 0, FloorY + 1, 0);
var ctx = BuildContext(world);
var move = new MoveDescend(1, 0);
var result = default(MoveResult);
// Source feet block is FloorY+2, destination feet block is FloorY+1.
move.Calculate(ctx, 0, FloorY + 2, 0, ref result);
Assert.False(result.IsImpossible);
Assert.Equal(1, result.DestX);
Assert.Equal(FloorY + 1, result.DestY);
}
/// <summary>
/// Regression: when the landing column is itself solid at y-1 (e.g. a
/// 2-block-thick platform top), MoveDescend must reject the move.
/// Previously the simple 1-block branch only checked the y-2 floor and the
/// y / y+1 body-clearance at the destination, so A* emitted a Descend that
/// the bot could never execute (it just walked onto the solid y-1 block at
/// the same feet level), producing an infinite replan loop in live play.
/// </summary>
[Fact]
public void Rejects1BlockDescendIntoSolidLandingColumn()
{
var world = FlatWorldTestBuilder.CreateStoneFloor(FloorY);
// Bot stands on source pillar (0, FloorY+1), feet at FloorY+2.
FlatWorldTestBuilder.SetSolid(world, 0, FloorY + 1, 0);
// Destination column is ALSO solid at the feet-landing level (y-1 of source).
// Concretely: (1, FloorY+1) is stone, (1, FloorY) is stone, and the flat
// floor under that is still there too. There is no valid 1-block drop.
FlatWorldTestBuilder.SetSolid(world, 1, FloorY + 1, 0);
var ctx = BuildContext(world);
var move = new MoveDescend(1, 0);
var result = default(MoveResult);
move.Calculate(ctx, 0, FloorY + 2, 0, ref result);
Assert.True(result.IsImpossible);
}
[Fact]
public void Accepts2BlockDrop()
{
// Two-tier setup: source pillar at y=FloorY+2, destination floor at y=FloorY.
var world = FlatWorldTestBuilder.CreateStoneFloor(FloorY);
FlatWorldTestBuilder.SetSolid(world, 0, FloorY + 1, 0);
FlatWorldTestBuilder.SetSolid(world, 0, FloorY + 2, 0);
var ctx = BuildContext(world);
var move = new MoveDescend(1, 0);
var result = default(MoveResult);
// Source feet block is FloorY+3, destination column drops to FloorY+1 floor.
move.Calculate(ctx, 0, FloorY + 3, 0, ref result);
Assert.False(result.IsImpossible);
Assert.Equal(1, result.DestX);
Assert.Equal(FloorY + 1, result.DestY);
}
[Fact]
public void RejectsMultiBlockDropWhenFlightColumnIsBlocked()
{
// Source pillar at y=FloorY+2, but destination column has a solid
// block at y-1 that blocks the fall path entirely. The bot cannot
// enter the destination column at all.
var world = FlatWorldTestBuilder.CreateStoneFloor(FloorY);
FlatWorldTestBuilder.SetSolid(world, 0, FloorY + 1, 0);
FlatWorldTestBuilder.SetSolid(world, 0, FloorY + 2, 0);
// Blocker: (1, FloorY+2) is solid -- this is the y-1 of the source feet.
FlatWorldTestBuilder.SetSolid(world, 1, FloorY + 2, 0);
var ctx = BuildContext(world);
var move = new MoveDescend(1, 0);
var result = default(MoveResult);
move.Calculate(ctx, 0, FloorY + 3, 0, ref result);
Assert.True(result.IsImpossible);
}
}

View file

@ -0,0 +1,109 @@
using MinecraftClient.Mapping;
using MinecraftClient.Pathing.Core;
using MinecraftClient.Pathing.Moves;
using MinecraftClient.Pathing.Moves.Impl;
using MinecraftClient.Tests.Pathing.Execution;
using Xunit;
namespace MinecraftClient.Tests.Pathing.Moves;
/// <summary>
/// Regression tests for the Baritone-parity cardinal-split gate in
/// <see cref="JumpFeasibility"/>'s diagonal Ascend branch. When a cardinal
/// fallback (cardinal Walk into the dx or dz shoulder + a cardinal Ascend
/// from there) exists, the diagonal Ascend must be rejected: it has no
/// physical way to redirect the preceding segment's axis-aligned ground
/// momentum into the diagonal in 2 handoff ticks, so executing it
/// overshoots the target and loops on replan.
/// </summary>
public sealed class MoveJumpDiagonalAscendTests
{
private const int FloorY = 79;
private static CalculationContext BuildContext(World world)
=> new(world, allowParkour: true, allowParkourAscend: true);
[Fact]
public void RejectsDiagonalAscendWhenCardinalSplitIsWalkable()
{
// Flat floor at FloorY, so the cardinal shoulders at (1, FloorY, 0)
// and (0, FloorY, 1) both have solid ground. The ascend target is a
// 1-block riser on the diagonal corner at (1, FloorY+1, 1). Either
// "walk +X first, then cardinal Ascend +Z+Y" or "walk +Z first, then
// cardinal Ascend +X+Y" produces a stable 2-step plan, so the direct
// diagonal Ascend must be rejected.
var world = FlatWorldTestBuilder.CreateStoneFloor(FloorY);
FlatWorldTestBuilder.SetSolid(world, 1, FloorY + 1, 1);
var ctx = BuildContext(world);
var move = MoveJump.DiagonalAscend(1, 1);
var result = default(MoveResult);
move.Calculate(ctx, 0, FloorY + 1, 0, ref result);
Assert.True(result.IsImpossible);
}
[Fact]
public void AcceptsDiagonalAscendWhenBothCardinalShouldersLackFloor()
{
// Island configuration: the source pillar and the diagonal ascend
// riser are the only walk-on surfaces near the bot. The cardinal
// shoulders are open air, so no cardinal Walk + cardinal Ascend
// split exists and the diagonal Ascend is the genuine only option.
var world = FlatWorldTestBuilder.CreateStoneFloor(FloorY);
world.SetBlock(new Location(1, FloorY, 0), Block.Air);
world.SetBlock(new Location(0, FloorY, 1), Block.Air);
FlatWorldTestBuilder.SetSolid(world, 1, FloorY + 1, 1);
var ctx = BuildContext(world);
var move = MoveJump.DiagonalAscend(1, 1);
var result = default(MoveResult);
move.Calculate(ctx, 0, FloorY + 1, 0, ref result);
Assert.False(result.IsImpossible);
Assert.Equal(1, result.DestX);
Assert.Equal(FloorY + 2, result.DestY);
Assert.Equal(1, result.DestZ);
}
[Fact]
public void RejectsDiagonalAscendWhenOnlyOneCardinalShoulderHasFloor()
{
// Only the +X shoulder has floor support; the +Z shoulder is open
// air. Even a single viable cardinal split is enough for Baritone's
// gate to forbid the diagonal Ascend, because A* can simply take
// "walk +X then cardinal Ascend +Z+Y" instead.
var world = FlatWorldTestBuilder.CreateStoneFloor(FloorY);
world.SetBlock(new Location(0, FloorY, 1), Block.Air);
FlatWorldTestBuilder.SetSolid(world, 1, FloorY + 1, 1);
var ctx = BuildContext(world);
var move = MoveJump.DiagonalAscend(1, 1);
var result = default(MoveResult);
move.Calculate(ctx, 0, FloorY + 1, 0, ref result);
Assert.True(result.IsImpossible);
}
[Fact]
public void CardinalAscendStillAcceptedOnFlatFloor()
{
// Sanity: the gate must not touch cardinal Ascend. A plain +X Ascend
// onto a 1-block riser on flat floor should still plan as before.
var world = FlatWorldTestBuilder.CreateStoneFloor(FloorY);
FlatWorldTestBuilder.SetSolid(world, 1, FloorY + 1, 0);
var ctx = BuildContext(world);
var move = MoveJump.Ascend(1, 0);
var result = default(MoveResult);
move.Calculate(ctx, 0, FloorY + 1, 0, ref result);
Assert.False(result.IsImpossible);
Assert.Equal(1, result.DestX);
Assert.Equal(FloorY + 2, result.DestY);
}
}