Minecraft-Console-Client/MinecraftClient/Pathing/Execution/Templates/ClimbTemplate.cs
BruceChen 399c8cdc79 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
2026-04-12 18:43:32 +00:00

78 lines
2.5 KiB
C#

using System;
using MinecraftClient.Mapping;
using MinecraftClient.Physics;
namespace MinecraftClient.Pathing.Execution.Templates
{
/// <summary>
/// Climb up or down a ladder/vine by 1 block.
/// Up: pushes against the wall (Forward + face center) and jumps.
/// Down: releases all input to let gravity + climbable friction handle descent.
/// </summary>
public sealed class ClimbTemplate : IActionTemplate
{
public Location ExpectedStart { get; }
public Location ExpectedEnd { get; }
private readonly bool _goingUp;
private int _tickCount;
public ClimbTemplate(Location start, Location end)
{
ExpectedStart = start;
ExpectedEnd = end;
_goingUp = end.Y > start.Y;
}
public TemplateState Tick(Location pos, PlayerPhysics physics, MovementInput input)
{
_tickCount++;
double dy = ExpectedEnd.Y - pos.Y;
double dx = ExpectedEnd.X - pos.X;
double dz = ExpectedEnd.Z - pos.Z;
double horizDistSq = dx * dx + dz * dz;
if (Math.Abs(dy) < 0.4 && horizDistSq < 0.5)
return TemplateState.Complete;
if (_tickCount > 120)
return TemplateState.Failed;
physics.Pitch = _goingUp ? -70f : 70f;
if (physics.OnClimbable)
{
if (_goingUp)
{
input.Jump = true;
input.Forward = true;
if (horizDistSq > 0.01)
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
}
else
{
// Descending: release all input, gravity pulls down at clamped speed.
// Do NOT press Sneak (that would freeze position on ladders).
// Do NOT press Jump (that would push upward).
// Keep centered horizontally by gently steering if drifting.
if (horizDistSq > 0.15)
{
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
input.Forward = true;
}
}
}
else
{
if (horizDistSq > 0.01)
{
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
input.Forward = true;
}
}
return TemplateState.InProgress;
}
}
}