Minecraft-Console-Client/MinecraftClient/Pathing/Execution/Templates/ClimbTemplate.cs
BruceChen 285c3000c3 feat: add diagonal ascend/descend moves, fix pitch, smooth look angles
- Add MoveDiagonalAscend and MoveDiagonalDescend for "corner" moves:
  step diagonally around a wall edge while ascending/descending 1 block.
  Requires at least one intermediate cardinal direction to be passable.

- Fix pitch calculation: look toward target's eye level (same height
  delta as feet delta) instead of subtracting eye height, which caused
  the player to stare at the ground during flat walks.

- Add Yaw/Pitch smoothing via SmoothYaw/SmoothPitch in TemplateHelper.
  Max 35 deg/tick for yaw, 25 deg/tick for pitch. Prevents instant
  camera snaps between path segments while still being responsive
  enough for sprint-jumps and tight maneuvers.

- Apply smoothing to all five action templates (Walk, Ascend, Descend,
  Climb, SprintJump).

Made-with: Cursor
2026-04-12 18:43:32 +00:00

84 lines
2.9 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;
float targetPitch = _goingUp ? -70f : 70f;
physics.Pitch = TemplateHelper.SmoothPitch(physics.Pitch, targetPitch);
if (physics.OnClimbable)
{
if (_goingUp)
{
input.Jump = true;
input.Forward = true;
if (horizDistSq > 0.01)
{
float targetYaw = TemplateHelper.CalculateYaw(dx, dz);
physics.Yaw = TemplateHelper.SmoothYaw(physics.Yaw, targetYaw);
}
}
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)
{
float targetYaw = TemplateHelper.CalculateYaw(dx, dz);
physics.Yaw = TemplateHelper.SmoothYaw(physics.Yaw, targetYaw);
input.Forward = true;
}
}
}
else
{
if (horizDistSq > 0.01)
{
float targetYaw = TemplateHelper.CalculateYaw(dx, dz);
physics.Yaw = TemplateHelper.SmoothYaw(physics.Yaw, targetYaw);
input.Forward = true;
}
}
return TemplateState.InProgress;
}
}
}