mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-29 13:04:59 +00:00
pathing: snap yaw for jump-ready grounded handoffs
This commit is contained in:
parent
2be9b287a3
commit
8408a41398
3 changed files with 519 additions and 8 deletions
|
|
@ -115,6 +115,452 @@ public sealed class GroundedTemplateConvergenceTests
|
|||
Assert.True(physics.DeltaMovement.X > 0.02);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WalkTemplate_PrepareJump_WithPlannerHints_CompletesOnRunUpBlock()
|
||||
{
|
||||
World world = FlatWorldTestBuilder.CreateStoneFloor();
|
||||
var current = new PathSegment
|
||||
{
|
||||
Start = new Location(0.5, 80, 0.5),
|
||||
End = new Location(1.5, 80, 0.5),
|
||||
MoveType = MoveType.Traverse,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 0, 0.10, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var next = new PathSegment
|
||||
{
|
||||
Start = new Location(1.5, 80, 0.5),
|
||||
End = new Location(3.5, 80, 0.5),
|
||||
MoveType = MoveType.Parkour,
|
||||
ExitTransition = PathTransitionType.FinalStop
|
||||
};
|
||||
|
||||
var template = new WalkTemplate(current, next);
|
||||
var physics = TemplateSimulationRunner.CreateGroundedPhysics(current.Start, yaw: 270f);
|
||||
|
||||
TemplateState state = TemplateSimulationRunner.Run(template, physics, world, maxTicks: 120, out Location finalPos);
|
||||
|
||||
Assert.Equal(TemplateState.Complete, state);
|
||||
Assert.True(
|
||||
TemplateFootingHelper.IsCenterInsideTargetBlock(finalPos, current.End),
|
||||
$"state={state} finalPos={finalPos} vel={physics.DeltaMovement}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AscendTemplate_DiagonalPrepareJump_WithPlannerHints_CompletesOnRunUpBlock()
|
||||
{
|
||||
World world = FlatWorldTestBuilder.CreateStoneFloor(min: -1, max: 6);
|
||||
FlatWorldTestBuilder.ClearBox(world, -1, 79, -1, 6, 84, 6);
|
||||
FlatWorldTestBuilder.SetSolid(world, 0, 79, 0);
|
||||
FlatWorldTestBuilder.SetSolid(world, 1, 80, 1);
|
||||
FlatWorldTestBuilder.SetSolid(world, 3, 80, 3);
|
||||
|
||||
var current = new PathSegment
|
||||
{
|
||||
Start = new Location(0.5, 80, 0.5),
|
||||
End = new Location(1.5, 81, 1.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 1, 0.10, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var next = new PathSegment
|
||||
{
|
||||
Start = new Location(1.5, 81, 1.5),
|
||||
End = new Location(3.5, 81, 3.5),
|
||||
MoveType = MoveType.Parkour,
|
||||
ExitTransition = PathTransitionType.FinalStop
|
||||
};
|
||||
|
||||
var template = new AscendTemplate(current, next);
|
||||
var physics = TemplateSimulationRunner.CreateGroundedPhysics(current.Start, yaw: 315f);
|
||||
var input = new MovementInput();
|
||||
var trace = new List<string>();
|
||||
TemplateState state = TemplateState.InProgress;
|
||||
Location finalPos = current.Start;
|
||||
for (int tick = 0; tick < 140; tick++)
|
||||
{
|
||||
input.Reset();
|
||||
Location pos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
|
||||
state = template.Tick(pos, physics, input, world);
|
||||
if (tick < 20 || 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},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(
|
||||
state == TemplateState.Complete,
|
||||
$"state={state} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
|
||||
Assert.True(
|
||||
TemplateFootingHelper.IsCenterInsideTargetBlock(finalPos, current.End),
|
||||
$"state={state} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AscendTemplate_AfterTraversePrepareJump_CompletesWithinTwentyTicks()
|
||||
{
|
||||
World world = FlatWorldTestBuilder.CreateStoneFloor(min: -1, max: 6);
|
||||
FlatWorldTestBuilder.ClearBox(world, -1, 79, -1, 6, 84, 2);
|
||||
FlatWorldTestBuilder.SetSolid(world, 0, 79, 0);
|
||||
FlatWorldTestBuilder.SetSolid(world, 1, 79, 0);
|
||||
FlatWorldTestBuilder.SetSolid(world, 2, 80, 0);
|
||||
FlatWorldTestBuilder.SetSolid(world, 3, 81, 0);
|
||||
|
||||
var traverse = new PathSegment
|
||||
{
|
||||
Start = new Location(0.5, 80, 0.5),
|
||||
End = new Location(1.5, 80, 0.5),
|
||||
MoveType = MoveType.Traverse,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 0, 0.0, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var ascend = new PathSegment
|
||||
{
|
||||
Start = new Location(1.5, 80, 0.5),
|
||||
End = new Location(2.5, 81, 0.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 0, 0.10, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var next = new PathSegment
|
||||
{
|
||||
Start = new Location(2.5, 81, 0.5),
|
||||
End = new Location(3.5, 82, 0.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.FinalStop
|
||||
};
|
||||
|
||||
var physics = TemplateSimulationRunner.CreateGroundedPhysics(traverse.Start, yaw: 270f);
|
||||
|
||||
TemplateState traverseState = TemplateSimulationRunner.Run(new WalkTemplate(traverse, ascend), physics, world, maxTicks: 80, out _);
|
||||
|
||||
var template = new AscendTemplate(ascend, next);
|
||||
var input = new MovementInput();
|
||||
TemplateState state = TemplateState.InProgress;
|
||||
int elapsedTicks = 0;
|
||||
Location finalPos = ascend.Start;
|
||||
for (; elapsedTicks < 80; elapsedTicks++)
|
||||
{
|
||||
input.Reset();
|
||||
Location pos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
|
||||
state = template.Tick(pos, physics, input, world);
|
||||
if (state != TemplateState.InProgress)
|
||||
{
|
||||
finalPos = new Location(physics.Position.X, physics.Position.Y, physics.Position.Z);
|
||||
break;
|
||||
}
|
||||
|
||||
physics.ApplyInput(input);
|
||||
physics.Tick(world);
|
||||
}
|
||||
|
||||
Assert.Equal(TemplateState.Complete, traverseState);
|
||||
Assert.Equal(TemplateState.Complete, state);
|
||||
Assert.True(elapsedTicks <= 20, $"elapsedTicks={elapsedTicks} finalPos={finalPos} vel={physics.DeltaMovement}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AscendTemplate_PrepareJump_CompletesFromOppositeYawWithinTwentyTicks()
|
||||
{
|
||||
World world = FlatWorldTestBuilder.CreateStoneFloor(min: 338, max: 344);
|
||||
FlatWorldTestBuilder.ClearBox(world, 340, 80, 338, 344, 84, 342);
|
||||
FlatWorldTestBuilder.FillSolid(world, 341, 80, 339, 341, 80, 341);
|
||||
FlatWorldTestBuilder.FillSolid(world, 342, 81, 339, 342, 81, 341);
|
||||
|
||||
var segment = new PathSegment
|
||||
{
|
||||
Start = new Location(340.5, 80, 340.5),
|
||||
End = new Location(341.5, 81, 340.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 0, 0.10, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var next = new PathSegment
|
||||
{
|
||||
Start = new Location(341.5, 81, 340.5),
|
||||
End = new Location(342.5, 82, 340.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.FinalStop
|
||||
};
|
||||
|
||||
var template = new AscendTemplate(segment, next);
|
||||
var physics = TemplateSimulationRunner.CreateGroundedPhysics(segment.Start, yaw: 90f);
|
||||
var input = new MovementInput();
|
||||
TemplateState state = TemplateState.InProgress;
|
||||
int elapsedTicks = 0;
|
||||
Location finalPos = segment.Start;
|
||||
var trace = new List<string>();
|
||||
for (; elapsedTicks < 80; elapsedTicks++)
|
||||
{
|
||||
input.Reset();
|
||||
Location pos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
|
||||
state = template.Tick(pos, physics, input, world);
|
||||
if (elapsedTicks < 20 || state != TemplateState.InProgress)
|
||||
{
|
||||
trace.Add(
|
||||
$"tick={elapsedTicks} state={state} pos={pos} yaw={physics.Yaw:F1} vel={physics.DeltaMovement} " +
|
||||
$"onGround={physics.OnGround} input(F={input.Forward},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.Equal(TemplateState.Complete, state);
|
||||
Assert.True(elapsedTicks <= 20, $"elapsedTicks={elapsedTicks} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
|
||||
Assert.True(
|
||||
TemplateFootingHelper.IsCenterInsideTargetBlock(finalPos, segment.End),
|
||||
$"elapsedTicks={elapsedTicks} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AscendTemplate_PrepareJump_SnapsYawImmediatelyFromOppositeYaw()
|
||||
{
|
||||
World world = FlatWorldTestBuilder.CreateStoneFloor(min: 338, max: 344);
|
||||
FlatWorldTestBuilder.ClearBox(world, 340, 80, 338, 344, 84, 342);
|
||||
FlatWorldTestBuilder.FillSolid(world, 341, 80, 339, 341, 80, 341);
|
||||
FlatWorldTestBuilder.FillSolid(world, 342, 81, 339, 342, 81, 341);
|
||||
|
||||
var segment = new PathSegment
|
||||
{
|
||||
Start = new Location(340.5, 80, 340.5),
|
||||
End = new Location(341.5, 81, 340.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 0, 0.10, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var next = new PathSegment
|
||||
{
|
||||
Start = new Location(341.5, 81, 340.5),
|
||||
End = new Location(342.5, 82, 340.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.FinalStop
|
||||
};
|
||||
|
||||
var template = new AscendTemplate(segment, next);
|
||||
var physics = TemplateSimulationRunner.CreateGroundedPhysics(segment.Start, yaw: 90f);
|
||||
var input = new MovementInput();
|
||||
|
||||
TemplateState state = template.Tick(segment.Start, physics, input, world);
|
||||
|
||||
Assert.Equal(TemplateState.InProgress, state);
|
||||
Assert.InRange(physics.Yaw, 269.9f, 270.1f);
|
||||
Assert.True(input.Forward);
|
||||
Assert.True(input.Sprint);
|
||||
Assert.True(input.Jump);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WalkTemplate_PrepareJump_FreezeForTurn_SnapsExitHeadingImmediately()
|
||||
{
|
||||
World world = FlatWorldTestBuilder.CreateStoneFloor();
|
||||
var current = new PathSegment
|
||||
{
|
||||
Start = new Location(0.5, 80, 0.5),
|
||||
End = new Location(1.5, 80, 0.5),
|
||||
MoveType = MoveType.Traverse,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(0, 1, 0.10, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var next = new PathSegment
|
||||
{
|
||||
Start = new Location(1.5, 80, 0.5),
|
||||
End = new Location(1.5, 80, 1.5),
|
||||
MoveType = MoveType.Parkour,
|
||||
ExitTransition = PathTransitionType.FinalStop
|
||||
};
|
||||
|
||||
var template = new WalkTemplate(current, next);
|
||||
var physics = new PlayerPhysics
|
||||
{
|
||||
Position = new Vec3d(1.5, 80.0, 0.5),
|
||||
DeltaMovement = Vec3d.Zero,
|
||||
OnGround = true,
|
||||
MovementSpeed = 0.1f,
|
||||
Yaw = 180f,
|
||||
Pitch = 0f
|
||||
};
|
||||
var input = new MovementInput();
|
||||
|
||||
TemplateState state = template.Tick(new Location(1.5, 80, 0.5), physics, input, world);
|
||||
|
||||
Assert.Equal(TemplateState.Complete, state);
|
||||
Assert.InRange(physics.Yaw, -0.1f, 0.1f);
|
||||
Assert.False(input.Forward);
|
||||
Assert.False(input.Sprint);
|
||||
Assert.False(input.Back);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AscendTemplate_PrepareJump_CompletesFromOffCenterRunUpState()
|
||||
{
|
||||
World world = FlatWorldTestBuilder.CreateStoneFloor(min: 338, max: 344);
|
||||
FlatWorldTestBuilder.ClearBox(world, 340, 80, 338, 344, 84, 342);
|
||||
FlatWorldTestBuilder.FillSolid(world, 341, 80, 339, 341, 80, 341);
|
||||
FlatWorldTestBuilder.FillSolid(world, 342, 81, 339, 342, 81, 341);
|
||||
|
||||
var segment = new PathSegment
|
||||
{
|
||||
Start = new Location(340.5, 80, 340.5),
|
||||
End = new Location(341.5, 81, 340.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 0, 0.10, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var next = new PathSegment
|
||||
{
|
||||
Start = new Location(341.5, 81, 340.5),
|
||||
End = new Location(342.5, 82, 340.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.FinalStop
|
||||
};
|
||||
|
||||
var template = new AscendTemplate(segment, next);
|
||||
var physics = new PlayerPhysics
|
||||
{
|
||||
Position = new Vec3d(340.25, 80.0, 340.25),
|
||||
DeltaMovement = Vec3d.Zero,
|
||||
OnGround = true,
|
||||
MovementSpeed = 0.1f,
|
||||
Yaw = 270f,
|
||||
Pitch = 0f
|
||||
};
|
||||
var input = new MovementInput();
|
||||
TemplateState state = TemplateState.InProgress;
|
||||
Location finalPos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
|
||||
var trace = new List<string>();
|
||||
for (int tick = 0; tick < 80; tick++)
|
||||
{
|
||||
input.Reset();
|
||||
Location pos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
|
||||
state = template.Tick(pos, physics, input, world);
|
||||
if (tick < 20 || 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},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(
|
||||
state == TemplateState.Complete,
|
||||
$"state={state} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
|
||||
Assert.True(
|
||||
TemplateFootingHelper.IsCenterInsideTargetBlock(finalPos, segment.End),
|
||||
$"state={state} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WalkTemplate_DiagonalPrepareJumpIntoAscend_CompletesFromTargetBlockEntry()
|
||||
{
|
||||
World world = FlatWorldTestBuilder.CreateStoneFloor(min: 418, max: 426);
|
||||
FlatWorldTestBuilder.ClearBox(world, 418, 79, 418, 426, 84, 424);
|
||||
FlatWorldTestBuilder.SetSolid(world, 420, 79, 420);
|
||||
FlatWorldTestBuilder.SetSolid(world, 421, 79, 421);
|
||||
FlatWorldTestBuilder.SetSolid(world, 422, 79, 422);
|
||||
FlatWorldTestBuilder.SetSolid(world, 423, 80, 422);
|
||||
FlatWorldTestBuilder.SetSolid(world, 424, 81, 422);
|
||||
|
||||
var current = new PathSegment
|
||||
{
|
||||
Start = new Location(421.5, 80, 421.5),
|
||||
End = new Location(422.5, 80, 422.5),
|
||||
MoveType = MoveType.Diagonal,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 0, 0.0, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
var next = new PathSegment
|
||||
{
|
||||
Start = new Location(422.5, 80, 422.5),
|
||||
End = new Location(423.5, 81, 422.5),
|
||||
MoveType = MoveType.Ascend,
|
||||
ExitTransition = PathTransitionType.PrepareJump,
|
||||
ExitHints = new PathTransitionHints(1, 0, 0.0, double.PositiveInfinity, false, true, true, false, 10),
|
||||
PreserveSprint = true
|
||||
};
|
||||
|
||||
var template = new WalkTemplate(current, next);
|
||||
var physics = new PlayerPhysics
|
||||
{
|
||||
Position = new Vec3d(422.25, 80.0, 422.25),
|
||||
DeltaMovement = Vec3d.Zero,
|
||||
OnGround = true,
|
||||
MovementSpeed = 0.1f,
|
||||
Yaw = 315f,
|
||||
Pitch = 0f
|
||||
};
|
||||
var input = new MovementInput();
|
||||
TemplateState state = TemplateState.InProgress;
|
||||
Location finalPos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
|
||||
var trace = new List<string>();
|
||||
for (int tick = 0; tick < 80; tick++)
|
||||
{
|
||||
input.Reset();
|
||||
Location pos = new(physics.Position.X, physics.Position.Y, physics.Position.Z);
|
||||
state = template.Tick(pos, physics, input, world);
|
||||
if (tick < 20 || 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},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(
|
||||
state == TemplateState.Complete,
|
||||
$"state={state} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
|
||||
Assert.True(
|
||||
TemplateFootingHelper.IsCenterInsideTargetBlock(finalPos, current.End),
|
||||
$"state={state} finalPos={finalPos} vel={physics.DeltaMovement}\n{string.Join('\n', trace)}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WalkTemplate_TurnIntoParkour_CompletesOnlyWhenTurnEntryIsSlowAndJumpReady()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue