fix: set movement input before completion check to maintain sprint momentum

Templates now set Forward/Sprint input before checking completion
conditions. This prevents a 1-tick input gap during template transitions
that caused the player to lose sprint speed, making parkour jumps fail
due to insufficient horizontal velocity.

Made-with: Cursor
This commit is contained in:
BruceChen 2026-04-11 14:03:50 +08:00
parent 034c5d0cab
commit a9c9a6a669
3 changed files with 13 additions and 22 deletions

View file

@ -33,8 +33,13 @@ namespace MinecraftClient.Pathing.Execution.Templates
double dy = ExpectedEnd.Y - pos.Y;
double horizDistSq = dx * dx + dz * dz;
// Complete when close to destination. Sprint bouncing can leave the player
// slightly above ground, so we don't require OnGround here.
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
input.Forward = true;
input.Sprint = true;
if (physics.OnGround && dy > 0.1)
input.Jump = true;
if (horizDistSq < 0.25 && Math.Abs(dy) < 0.8)
return TemplateState.Complete;
@ -46,13 +51,6 @@ namespace MinecraftClient.Pathing.Execution.Templates
if (_stuckTicks > 40 || _tickCount > 80)
return TemplateState.Failed;
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
input.Forward = true;
input.Sprint = true;
if (physics.OnGround && dy > 0.1)
input.Jump = true;
return TemplateState.InProgress;
}
}

View file

@ -17,16 +17,11 @@ namespace MinecraftClient.Pathing.Execution.Templates
private int _tickCount;
private Phase _phase = Phase.Approach;
private readonly int _distance;
public SprintJumpTemplate(Location start, Location end)
{
ExpectedStart = start;
ExpectedEnd = end;
double dx = Math.Abs(end.X - start.X);
double dz = Math.Abs(end.Z - start.Z);
_distance = (int)Math.Round(Math.Max(dx, dz));
}
public TemplateState Tick(Location pos, PlayerPhysics physics, MovementInput input)
@ -57,7 +52,6 @@ namespace MinecraftClient.Pathing.Execution.Templates
case Phase.Airborne:
if (!physics.OnGround)
break;
// Landed
_phase = Phase.Landing;
goto case Phase.Landing;

View file

@ -28,6 +28,12 @@ namespace MinecraftClient.Pathing.Execution.Templates
{
_tickCount++;
double dx = ExpectedEnd.X - pos.X;
double dz = ExpectedEnd.Z - pos.Z;
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
input.Forward = true;
input.Sprint = true;
if (TemplateHelper.IsNear(pos, ExpectedEnd, horizThresholdSq: 0.20))
return TemplateState.Complete;
@ -38,13 +44,6 @@ namespace MinecraftClient.Pathing.Execution.Templates
if (_stuckTicks > 40 || _tickCount > 100)
return TemplateState.Failed;
double dx = ExpectedEnd.X - pos.X;
double dz = ExpectedEnd.Z - pos.Z;
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
input.Forward = true;
input.Sprint = true;
return TemplateState.InProgress;
}
}