fix: remove spurious jump on vines in WalkTemplate and add pitch tracking

- WalkTemplate: remove OnClimbable jump/sprint logic that caused the
  player to jump when walking past vine blocks during flat traversal
- TemplateHelper: add CalculatePitch() for computing the look angle
  toward a 3D target relative to eye height
- All templates (Walk, Ascend, Descend, Climb, SprintJump): set
  physics.Pitch each tick so the player visually looks toward the
  current path target direction
- McClient: sync playerPitch and set _yaw/_pitch after pathfinding
  ticks so rotation is included in position update packets sent to
  the server

Made-with: Cursor
This commit is contained in:
BruceChen 2026-04-12 00:57:38 +08:00
parent 9046c61f95
commit 399c8cdc79
7 changed files with 25 additions and 13 deletions

View file

@ -3285,6 +3285,9 @@ namespace MinecraftClient
{
pathSegmentManager.Tick(location, playerPhysics, physicsInput, world);
playerYaw = playerPhysics.Yaw;
playerPitch = playerPhysics.Pitch;
_yaw = playerYaw;
_pitch = playerPitch;
return;
}

View file

@ -34,6 +34,7 @@ namespace MinecraftClient.Pathing.Execution.Templates
double horizDistSq = dx * dx + dz * dz;
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
physics.Pitch = TemplateHelper.CalculatePitch(dx, dy - 1.62, dz);
input.Forward = true;
input.Sprint = true;

View file

@ -39,6 +39,8 @@ namespace MinecraftClient.Pathing.Execution.Templates
if (_tickCount > 120)
return TemplateState.Failed;
physics.Pitch = _goingUp ? -70f : 70f;
if (physics.OnClimbable)
{
if (_goingUp)

View file

@ -54,6 +54,8 @@ namespace MinecraftClient.Pathing.Execution.Templates
if (_tickCount > 200)
return TemplateState.Failed;
physics.Pitch = TemplateHelper.CalculatePitch(dx, dy - 1.62, dz);
if (physics.OnClimbable)
{
if (horizDistSq > 0.25)

View file

@ -40,6 +40,7 @@ namespace MinecraftClient.Pathing.Execution.Templates
double horizDistSq = dx * dx + dz * dz;
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
physics.Pitch = TemplateHelper.CalculatePitch(dx, dy - 1.62, dz);
input.Forward = true;
input.Sprint = true;

View file

@ -12,6 +12,18 @@ namespace MinecraftClient.Pathing.Execution.Templates
return yaw;
}
/// <summary>
/// Calculate the pitch angle (in degrees) to look toward a 3D offset.
/// Negative = look up, positive = look down. Clamped to [-90, 90].
/// The dy is relative to eye height (~1.62 blocks above feet).
/// </summary>
internal static float CalculatePitch(double dx, double dy, double dz)
{
double horizDist = Math.Sqrt(dx * dx + dz * dz);
float pitch = (float)(-Math.Atan2(dy, horizDist) / Math.PI * 180.0);
return Math.Clamp(pitch, -90f, 90f);
}
internal static double HorizontalDistanceSq(Location a, Location b)
{
double dx = a.X - b.X;

View file

@ -30,29 +30,20 @@ namespace MinecraftClient.Pathing.Execution.Templates
double dx = ExpectedEnd.X - pos.X;
double dz = ExpectedEnd.Z - pos.Z;
double dy = ExpectedEnd.Y - pos.Y;
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
physics.Pitch = TemplateHelper.CalculatePitch(dx, dy - 1.62, dz);
input.Forward = true;
if (physics.OnClimbable)
{
input.Jump = true;
input.Sprint = false;
}
else
{
input.Sprint = true;
}
input.Sprint = true;
if (TemplateHelper.IsNear(pos, ExpectedEnd, horizThresholdSq: 0.20))
return TemplateState.Complete;
double movedSq = TemplateHelper.HorizontalDistanceSq(pos, _lastPos);
int stuckThreshold = physics.OnClimbable ? 80 : 40;
_stuckTicks = movedSq < 0.0005 ? _stuckTicks + 1 : 0;
_lastPos = pos;
int tickLimit = physics.OnClimbable ? 160 : 100;
if (_stuckTicks > stuckThreshold || _tickCount > tickLimit)
if (_stuckTicks > 40 || _tickCount > 100)
return TemplateState.Failed;
return TemplateState.InProgress;