fix: brake landing recovery before turns

This commit is contained in:
BruceChen 2026-04-12 23:42:25 +08:00
parent 0e0fc06b72
commit 4b92781d10
3 changed files with 88 additions and 1 deletions

View file

@ -0,0 +1,45 @@
using MinecraftClient.Mapping;
using MinecraftClient.Pathing.Core;
using MinecraftClient.Pathing.Execution;
using MinecraftClient.Pathing.Execution.Templates;
using Xunit;
namespace MinecraftClient.Tests.Pathing.Execution;
public sealed class LivePathingRegressionTests
{
[Fact]
public void SprintJumpTemplate_LandingRecoveryIntoTurn_CompletesInsideLandingBlock()
{
World world = FlatWorldTestBuilder.CreateStoneFloor(min: 108, max: 126);
FlatWorldTestBuilder.ClearBox(world, 118, 79, 108, 126, 90, 112);
FlatWorldTestBuilder.SetSolid(world, 120, 79, 110);
FlatWorldTestBuilder.SetSolid(world, 122, 79, 110);
FlatWorldTestBuilder.SetSolid(world, 122, 79, 111);
FlatWorldTestBuilder.SetSolid(world, 120, 80, 111);
FlatWorldTestBuilder.SetSolid(world, 120, 81, 111);
var segment = new PathSegment
{
Start = new Location(120.5, 80, 110.5),
End = new Location(122.5, 80, 110.5),
MoveType = MoveType.Parkour,
ExitTransition = PathTransitionType.LandingRecovery
};
var next = new PathSegment
{
Start = new Location(122.5, 80, 110.5),
End = new Location(122.5, 80, 111.5),
MoveType = MoveType.Traverse,
ExitTransition = PathTransitionType.FinalStop
};
var template = new SprintJumpTemplate(segment, next);
var physics = TemplateSimulationRunner.CreateGroundedPhysics(segment.Start, yaw: 270f);
TemplateState state = TemplateSimulationRunner.Run(template, physics, world, maxTicks: 140, out Location finalPos);
Assert.True(state == TemplateState.Complete, $"state={state} finalPos={finalPos} vel={physics.DeltaMovement}");
Assert.True(TemplateFootingHelper.IsFootprintInsideTargetBlock(finalPos, segment.End), $"finalPos={finalPos} vel={physics.DeltaMovement}");
}
}

View file

@ -96,6 +96,39 @@ public sealed class TransitionBrakingPlannerTests
Assert.True(release);
}
[Fact]
public void Plan_BackBrakes_ForLandingRecovery_WhenNextSegmentTurns()
{
World world = FlatWorldTestBuilder.CreateStoneFloor(min: 108, max: 126);
FlatWorldTestBuilder.ClearBox(world, 118, 79, 108, 126, 90, 112);
FlatWorldTestBuilder.SetSolid(world, 120, 79, 110);
FlatWorldTestBuilder.SetSolid(world, 122, 79, 110);
FlatWorldTestBuilder.SetSolid(world, 122, 79, 111);
var physics = CreatePhysics(0.118, 0.018, onGround: true);
var current = new PathSegment
{
Start = new Location(120.5, 80, 110.5),
End = new Location(122.5, 80, 110.5),
MoveType = MoveType.Parkour,
ExitTransition = PathTransitionType.LandingRecovery,
PreserveSprint = false
};
var next = new PathSegment
{
Start = new Location(122.5, 80, 110.5),
End = new Location(122.5, 80, 111.5),
MoveType = MoveType.Traverse,
ExitTransition = PathTransitionType.FinalStop
};
TransitionBrakingDecision decision = TransitionBrakingPlanner.Plan(current, next, new Location(122.56, 80, 110.68), physics, world);
Assert.False(decision.HoldForward);
Assert.False(decision.HoldSprint);
Assert.True(decision.HoldBack);
}
private static PlayerPhysics CreatePhysics(double deltaX, double deltaZ, bool onGround)
{
return new PlayerPhysics