From 399c8cdc7950e12feed305a70fbd56502b208826 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Sun, 12 Apr 2026 00:57:38 +0800 Subject: [PATCH] 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 --- MinecraftClient/McClient.cs | 3 +++ .../Execution/Templates/AscendTemplate.cs | 1 + .../Execution/Templates/ClimbTemplate.cs | 2 ++ .../Execution/Templates/DescendTemplate.cs | 2 ++ .../Execution/Templates/SprintJumpTemplate.cs | 1 + .../Execution/Templates/TemplateHelper.cs | 12 ++++++++++++ .../Pathing/Execution/Templates/WalkTemplate.cs | 17 ++++------------- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 4f91d4a1..aada4a32 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -3285,6 +3285,9 @@ namespace MinecraftClient { pathSegmentManager.Tick(location, playerPhysics, physicsInput, world); playerYaw = playerPhysics.Yaw; + playerPitch = playerPhysics.Pitch; + _yaw = playerYaw; + _pitch = playerPitch; return; } diff --git a/MinecraftClient/Pathing/Execution/Templates/AscendTemplate.cs b/MinecraftClient/Pathing/Execution/Templates/AscendTemplate.cs index 8a96c041..16ad6b55 100644 --- a/MinecraftClient/Pathing/Execution/Templates/AscendTemplate.cs +++ b/MinecraftClient/Pathing/Execution/Templates/AscendTemplate.cs @@ -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; diff --git a/MinecraftClient/Pathing/Execution/Templates/ClimbTemplate.cs b/MinecraftClient/Pathing/Execution/Templates/ClimbTemplate.cs index 694b489b..0f562bbe 100644 --- a/MinecraftClient/Pathing/Execution/Templates/ClimbTemplate.cs +++ b/MinecraftClient/Pathing/Execution/Templates/ClimbTemplate.cs @@ -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) diff --git a/MinecraftClient/Pathing/Execution/Templates/DescendTemplate.cs b/MinecraftClient/Pathing/Execution/Templates/DescendTemplate.cs index 9659691a..31df4abd 100644 --- a/MinecraftClient/Pathing/Execution/Templates/DescendTemplate.cs +++ b/MinecraftClient/Pathing/Execution/Templates/DescendTemplate.cs @@ -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) diff --git a/MinecraftClient/Pathing/Execution/Templates/SprintJumpTemplate.cs b/MinecraftClient/Pathing/Execution/Templates/SprintJumpTemplate.cs index d17fb77c..96971656 100644 --- a/MinecraftClient/Pathing/Execution/Templates/SprintJumpTemplate.cs +++ b/MinecraftClient/Pathing/Execution/Templates/SprintJumpTemplate.cs @@ -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; diff --git a/MinecraftClient/Pathing/Execution/Templates/TemplateHelper.cs b/MinecraftClient/Pathing/Execution/Templates/TemplateHelper.cs index 18a67a66..0e888821 100644 --- a/MinecraftClient/Pathing/Execution/Templates/TemplateHelper.cs +++ b/MinecraftClient/Pathing/Execution/Templates/TemplateHelper.cs @@ -12,6 +12,18 @@ namespace MinecraftClient.Pathing.Execution.Templates return yaw; } + /// + /// 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). + /// + 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; diff --git a/MinecraftClient/Pathing/Execution/Templates/WalkTemplate.cs b/MinecraftClient/Pathing/Execution/Templates/WalkTemplate.cs index fd3a4063..55e0f73f 100644 --- a/MinecraftClient/Pathing/Execution/Templates/WalkTemplate.cs +++ b/MinecraftClient/Pathing/Execution/Templates/WalkTemplate.cs @@ -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;