using System; using MinecraftClient.Mapping; using MinecraftClient.Physics; namespace MinecraftClient.Pathing.Execution.Templates { /// /// 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. /// public sealed class ClimbTemplate : IActionTemplate { public Location ExpectedStart { get; } public Location ExpectedEnd { get; } private readonly bool _goingUp; private int _tickCount; public ClimbTemplate(PathSegment segment, PathSegment? nextSegment) { ExpectedStart = segment.Start; ExpectedEnd = segment.End; _goingUp = segment.End.Y > segment.Start.Y; } public TemplateState Tick(Location pos, PlayerPhysics physics, MovementInput input, World world) { _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; } } }