mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-29 13:04:59 +00:00
feat: add 4-block jumps, diagonal parkour, high-fall water/ladder support
MoveParkour rewritten to support both cardinal and diagonal sprint jumps with unified (xOff, zOff) interface. New capabilities: - 4-block cardinal sprint jumps with edge-approach timing in template - Diagonal parkour: (2,1), (1,2), (2,2), (3,1), (1,3) in all quadrants - Ascending parkour extended to dist=3 (cardinal) - Overshoot safety check after landing destination - Block parkour from climbable starting blocks (vine/ladder) MoveDescend/MoveFall enhanced with Baritone-style dynamic fall scanning: - Water landing: accepts falls of any height into water - Mid-fall ladder/vine grab: resets effective fall height (<=11 blocks) - CalculationContext gains MaxFallHeightWater, AllowLadderGrabDuringFall SprintJumpTemplate gains distance-based approach timing: - Long jumps (>=3.5 blocks): delays jump until 0.5 blocks from center - Medium jumps (>=2.5): 0.35 blocks approach - Landing tolerance scales with jump distance All movements verified on 1.21.11 local server. Made-with: Cursor
This commit is contained in:
parent
a9c9a6a669
commit
53082d387e
9 changed files with 365 additions and 89 deletions
|
|
@ -49,17 +49,38 @@ namespace MinecraftClient.Pathing.Core
|
||||||
|
|
||||||
moves.Add(new MoveFall());
|
moves.Add(new MoveFall());
|
||||||
|
|
||||||
|
// Cardinal parkour: 2-4 block sprint jumps along +-X and +-Z
|
||||||
foreach (int dx in offsets)
|
foreach (int dx in offsets)
|
||||||
{
|
{
|
||||||
|
for (int dist = 2; dist <= 4; dist++)
|
||||||
|
moves.Add(new MoveParkour(dx * dist, 0));
|
||||||
|
// Ascending: +1Y, dist 2-3 (dist 4 ascend not physically reliable)
|
||||||
for (int dist = 2; dist <= 3; dist++)
|
for (int dist = 2; dist <= 3; dist++)
|
||||||
moves.Add(new MoveParkour(dx, 0, dist));
|
moves.Add(new MoveParkour(dx * dist, 0, yDelta: 1));
|
||||||
moves.Add(new MoveParkour(dx, 0, 2, yDelta: 1));
|
|
||||||
}
|
}
|
||||||
foreach (int dz in offsets)
|
foreach (int dz in offsets)
|
||||||
{
|
{
|
||||||
|
for (int dist = 2; dist <= 4; dist++)
|
||||||
|
moves.Add(new MoveParkour(0, dz * dist));
|
||||||
for (int dist = 2; dist <= 3; dist++)
|
for (int dist = 2; dist <= 3; dist++)
|
||||||
moves.Add(new MoveParkour(0, dz, dist));
|
moves.Add(new MoveParkour(0, dz * dist, yDelta: 1));
|
||||||
moves.Add(new MoveParkour(0, dz, 2, yDelta: 1));
|
}
|
||||||
|
|
||||||
|
// Diagonal parkour: sprint jumps at angles.
|
||||||
|
// Only include combinations with actual distance <= ~3.2 blocks (conservative)
|
||||||
|
foreach (int dx in offsets)
|
||||||
|
{
|
||||||
|
foreach (int dz in offsets)
|
||||||
|
{
|
||||||
|
// (2,1)/(1,2): sqrt(5) ~ 2.24 blocks
|
||||||
|
moves.Add(new MoveParkour(dx * 2, dz * 1));
|
||||||
|
moves.Add(new MoveParkour(dx * 1, dz * 2));
|
||||||
|
// (2,2): sqrt(8) ~ 2.83 blocks
|
||||||
|
moves.Add(new MoveParkour(dx * 2, dz * 2));
|
||||||
|
// (3,1)/(1,3): sqrt(10) ~ 3.16 blocks
|
||||||
|
moves.Add(new MoveParkour(dx * 3, dz * 1));
|
||||||
|
moves.Add(new MoveParkour(dx * 1, dz * 3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [.. moves];
|
return [.. moves];
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ namespace MinecraftClient.Pathing.Core
|
||||||
public bool AllowParkourAscend { get; }
|
public bool AllowParkourAscend { get; }
|
||||||
public bool AllowDiagonalDescend { get; }
|
public bool AllowDiagonalDescend { get; }
|
||||||
public int MaxFallHeight { get; }
|
public int MaxFallHeight { get; }
|
||||||
|
public int MaxFallHeightWater { get; }
|
||||||
|
public bool AllowLadderGrabDuringFall { get; }
|
||||||
public double JumpPenalty { get; }
|
public double JumpPenalty { get; }
|
||||||
public double WalkCost { get; }
|
public double WalkCost { get; }
|
||||||
public double SprintCost { get; }
|
public double SprintCost { get; }
|
||||||
|
|
@ -27,6 +29,8 @@ namespace MinecraftClient.Pathing.Core
|
||||||
bool allowParkourAscend = false,
|
bool allowParkourAscend = false,
|
||||||
bool allowDiagonalDescend = true,
|
bool allowDiagonalDescend = true,
|
||||||
int maxFallHeight = 3,
|
int maxFallHeight = 3,
|
||||||
|
int maxFallHeightWater = 256,
|
||||||
|
bool allowLadderGrabDuringFall = true,
|
||||||
double jumpPenalty = ActionCosts.JumpPenalty)
|
double jumpPenalty = ActionCosts.JumpPenalty)
|
||||||
{
|
{
|
||||||
World = world;
|
World = world;
|
||||||
|
|
@ -35,6 +39,8 @@ namespace MinecraftClient.Pathing.Core
|
||||||
AllowParkourAscend = allowParkourAscend;
|
AllowParkourAscend = allowParkourAscend;
|
||||||
AllowDiagonalDescend = allowDiagonalDescend;
|
AllowDiagonalDescend = allowDiagonalDescend;
|
||||||
MaxFallHeight = maxFallHeight;
|
MaxFallHeight = maxFallHeight;
|
||||||
|
MaxFallHeightWater = maxFallHeightWater;
|
||||||
|
AllowLadderGrabDuringFall = allowLadderGrabDuringFall;
|
||||||
JumpPenalty = jumpPenalty;
|
JumpPenalty = jumpPenalty;
|
||||||
WalkCost = ActionCosts.WalkOneBlock;
|
WalkCost = ActionCosts.WalkOneBlock;
|
||||||
SprintCost = CanSprint ? ActionCosts.SprintOneBlock : ActionCosts.WalkOneBlock;
|
SprintCost = CanSprint ? ActionCosts.SprintOneBlock : ActionCosts.WalkOneBlock;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Walk off a ledge and drop 1-N blocks to a landing spot.
|
/// Walk off a ledge and drop 1-N blocks to a landing spot.
|
||||||
/// Walks toward the destination; gravity handles the fall.
|
/// Walks toward the destination; gravity handles the fall.
|
||||||
|
/// Supports both solid landings and water landings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DescendTemplate : IActionTemplate
|
public sealed class DescendTemplate : IActionTemplate
|
||||||
{
|
{
|
||||||
|
|
@ -34,24 +35,29 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
if (!physics.OnGround)
|
if (!physics.OnGround)
|
||||||
_hasFallen = true;
|
_hasFallen = true;
|
||||||
|
|
||||||
|
// Completion: landed on ground near destination
|
||||||
if (_hasFallen && physics.OnGround && horizDistSq < 0.5 && Math.Abs(dy) < 0.8)
|
if (_hasFallen && physics.OnGround && horizDistSq < 0.5 && Math.Abs(dy) < 0.8)
|
||||||
return TemplateState.Complete;
|
return TemplateState.Complete;
|
||||||
|
|
||||||
|
// Completion: already at destination without falling (e.g., single step down)
|
||||||
if (horizDistSq < 0.25 && Math.Abs(dy) < 0.5 && physics.OnGround)
|
if (horizDistSq < 0.25 && Math.Abs(dy) < 0.5 && physics.OnGround)
|
||||||
return TemplateState.Complete;
|
return TemplateState.Complete;
|
||||||
|
|
||||||
|
// Completion: landed in water near destination
|
||||||
|
if (_hasFallen && physics.InWater && horizDistSq < 0.5 && Math.Abs(dy) < 2.0)
|
||||||
|
return TemplateState.Complete;
|
||||||
|
|
||||||
// Fail if climbing up instead of descending
|
// Fail if climbing up instead of descending
|
||||||
if (pos.Y > ExpectedStart.Y + 2.0)
|
if (pos.Y > ExpectedStart.Y + 2.0)
|
||||||
return TemplateState.Failed;
|
return TemplateState.Failed;
|
||||||
|
|
||||||
if (_tickCount > 120)
|
if (_tickCount > 200)
|
||||||
return TemplateState.Failed;
|
return TemplateState.Failed;
|
||||||
|
|
||||||
if (horizDistSq > 0.01)
|
if (horizDistSq > 0.01)
|
||||||
{
|
{
|
||||||
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
|
physics.Yaw = TemplateHelper.CalculateYaw(dx, dz);
|
||||||
input.Forward = true;
|
input.Forward = true;
|
||||||
// Don't push into climbable blocks during descent
|
|
||||||
if (physics.OnClimbable)
|
if (physics.OnClimbable)
|
||||||
input.Forward = false;
|
input.Forward = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Vertical free fall at the same X,Z. Waits for the player to land at the target Y.
|
/// Vertical free fall at the same X,Z. Waits for the player to land at the target Y.
|
||||||
|
/// Supports both solid ground landings and water landings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class FallTemplate : IActionTemplate
|
public sealed class FallTemplate : IActionTemplate
|
||||||
{
|
{
|
||||||
|
|
@ -30,9 +31,14 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
if (!physics.OnGround)
|
if (!physics.OnGround)
|
||||||
_hasFallen = true;
|
_hasFallen = true;
|
||||||
|
|
||||||
|
// Solid ground landing
|
||||||
if (_hasFallen && physics.OnGround && Math.Abs(dy) < 1.0)
|
if (_hasFallen && physics.OnGround && Math.Abs(dy) < 1.0)
|
||||||
return TemplateState.Complete;
|
return TemplateState.Complete;
|
||||||
|
|
||||||
|
// Water landing
|
||||||
|
if (_hasFallen && physics.InWater && Math.Abs(dy) < 2.0)
|
||||||
|
return TemplateState.Complete;
|
||||||
|
|
||||||
if (_tickCount > 200)
|
if (_tickCount > 200)
|
||||||
return TemplateState.Failed;
|
return TemplateState.Failed;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sprint-jump across a gap. Uses a phase-based state machine:
|
/// Sprint-jump across a gap. Uses a phase-based state machine:
|
||||||
/// Approach -> jump on first available ground tick -> Airborne -> Landing check.
|
/// Approach -> jump when ready -> Airborne -> Landing check.
|
||||||
|
/// For long jumps (>= 3.5 blocks), delays the jump until the player
|
||||||
|
/// has moved toward the edge of the starting block for maximum distance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SprintJumpTemplate : IActionTemplate
|
public sealed class SprintJumpTemplate : IActionTemplate
|
||||||
{
|
{
|
||||||
|
|
@ -15,6 +17,7 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
public Location ExpectedStart { get; }
|
public Location ExpectedStart { get; }
|
||||||
public Location ExpectedEnd { get; }
|
public Location ExpectedEnd { get; }
|
||||||
|
|
||||||
|
private readonly double _horizDist;
|
||||||
private int _tickCount;
|
private int _tickCount;
|
||||||
private Phase _phase = Phase.Approach;
|
private Phase _phase = Phase.Approach;
|
||||||
|
|
||||||
|
|
@ -22,6 +25,9 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
{
|
{
|
||||||
ExpectedStart = start;
|
ExpectedStart = start;
|
||||||
ExpectedEnd = end;
|
ExpectedEnd = end;
|
||||||
|
double dx = end.X - start.X;
|
||||||
|
double dz = end.Z - start.Z;
|
||||||
|
_horizDist = Math.Sqrt(dx * dx + dz * dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TemplateState Tick(Location pos, PlayerPhysics physics, MovementInput input)
|
public TemplateState Tick(Location pos, PlayerPhysics physics, MovementInput input)
|
||||||
|
|
@ -42,10 +48,27 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
case Phase.Approach:
|
case Phase.Approach:
|
||||||
if (physics.OnGround)
|
if (physics.OnGround)
|
||||||
{
|
{
|
||||||
input.Jump = true;
|
double fromStartSq = TemplateHelper.HorizontalDistanceSq(pos, ExpectedStart);
|
||||||
_phase = Phase.Airborne;
|
|
||||||
|
// For long jumps, delay the jump until the player has sprinted
|
||||||
|
// toward the block edge. Baritone waits until playerFeet is in
|
||||||
|
// the next block (~0.5 blocks from center) for dist >= 4.
|
||||||
|
// For medium jumps (dist 3), wait 0.35 blocks (Baritone: 0.7).
|
||||||
|
double minApproachSq;
|
||||||
|
if (_horizDist >= 3.5)
|
||||||
|
minApproachSq = 0.25; // 0.5 blocks
|
||||||
|
else if (_horizDist >= 2.5)
|
||||||
|
minApproachSq = 0.12; // ~0.35 blocks
|
||||||
|
else
|
||||||
|
minApproachSq = 0.0;
|
||||||
|
|
||||||
|
if (fromStartSq >= minApproachSq)
|
||||||
|
{
|
||||||
|
input.Jump = true;
|
||||||
|
_phase = Phase.Airborne;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_tickCount > 20)
|
if (_tickCount > 30)
|
||||||
return TemplateState.Failed;
|
return TemplateState.Failed;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -56,7 +79,9 @@ namespace MinecraftClient.Pathing.Execution.Templates
|
||||||
goto case Phase.Landing;
|
goto case Phase.Landing;
|
||||||
|
|
||||||
case Phase.Landing:
|
case Phase.Landing:
|
||||||
if (horizDistSq < 2.0 && Math.Abs(dy) < 1.0)
|
// Tolerance scales with jump distance
|
||||||
|
double horizTolerance = _horizDist >= 3.5 ? 3.0 : 2.0;
|
||||||
|
if (horizDistSq < horizTolerance && Math.Abs(dy) < 1.0)
|
||||||
return TemplateState.Complete;
|
return TemplateState.Complete;
|
||||||
return TemplateState.Failed;
|
return TemplateState.Failed;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,15 @@
|
||||||
|
using MinecraftClient.Mapping;
|
||||||
using MinecraftClient.Pathing.Core;
|
using MinecraftClient.Pathing.Core;
|
||||||
|
|
||||||
namespace MinecraftClient.Pathing.Moves.Impl
|
namespace MinecraftClient.Pathing.Moves.Impl
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Walk off a ledge and drop 1-N blocks in a cardinal direction.
|
/// Walk off a ledge and drop 1-N blocks in a cardinal direction.
|
||||||
/// Scans downward for a landing spot within MaxFallHeight.
|
/// For short drops (1-MaxFallHeight), uses simple scan.
|
||||||
|
/// For longer drops, delegates to DynamicFallCost which supports:
|
||||||
|
/// - Water/liquid safe landing
|
||||||
|
/// - Mid-fall ladder/vine grabbing (resets effective fall height if ≤ 11 blocks)
|
||||||
|
/// Based on Baritone's MovementDescend.dynamicFallCost design.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class MoveDescend : IMove
|
public sealed class MoveDescend : IMove
|
||||||
{
|
{
|
||||||
|
|
@ -30,34 +35,117 @@ namespace MinecraftClient.Pathing.Moves.Impl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int fallDist = 1; fallDist <= ctx.MaxFallHeight; fallDist++)
|
// Don't descend from ladder/vine (unreliable)
|
||||||
|
Material fromDown = ctx.GetMaterial(x, y - 1, z);
|
||||||
|
if (fromDown.CanBeClimbedOn())
|
||||||
{
|
{
|
||||||
int landY = y - fallDist;
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx.CanWalkOn(destX, landY - 1, destZ))
|
// Check for simple 1-block descend first (most common case)
|
||||||
{
|
if (ctx.CanWalkOn(destX, y - 2, destZ))
|
||||||
if (!ctx.CanWalkThrough(destX, landY, destZ))
|
{
|
||||||
{
|
Material landOn = ctx.GetMaterial(destX, y - 2, destZ);
|
||||||
result.SetImpossible();
|
if (MoveHelper.IsHazardous(landOn))
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double cost = ActionCosts.WalkOffBlock + ActionCosts.FallCost(fallDist);
|
|
||||||
if (MoveHelper.IsHazardous(ctx.GetMaterial(destX, landY - 1, destZ)))
|
|
||||||
{
|
|
||||||
result.SetImpossible();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Set(destX, landY, destZ, cost);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ctx.CanWalkThrough(destX, landY, destZ))
|
|
||||||
{
|
{
|
||||||
result.SetImpossible();
|
result.SetImpossible();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (ctx.GetMaterial(destX, y - 1, destZ).CanBeClimbedOn())
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double cost = ActionCosts.WalkOffBlock + ActionCosts.FallCost(1);
|
||||||
|
result.Set(destX, y - 1, destZ, cost);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not a simple 1-block drop, try dynamic fall
|
||||||
|
DynamicFallCost(ctx, x, y, z, destX, destZ, ref result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Scan downward for a safe landing, supporting water, ladder grabs, and
|
||||||
|
/// configurable max heights. Based on Baritone's dynamicFallCost.
|
||||||
|
/// </summary>
|
||||||
|
private static void DynamicFallCost(
|
||||||
|
CalculationContext ctx, int x, int y, int z,
|
||||||
|
int destX, int destZ, ref MoveResult result)
|
||||||
|
{
|
||||||
|
if (!ctx.CanWalkThrough(destX, y - 2, destZ))
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double costSoFar = 0;
|
||||||
|
int effectiveStartHeight = y;
|
||||||
|
|
||||||
|
// Scan starts from fallHeight=3 (2 blocks below the ledge)
|
||||||
|
// because fallHeight=1 and =2 were already checked above
|
||||||
|
int maxScan = ctx.MaxFallHeightWater > ctx.MaxFallHeight
|
||||||
|
? ctx.MaxFallHeightWater
|
||||||
|
: ctx.MaxFallHeight;
|
||||||
|
|
||||||
|
for (int fallHeight = 3; fallHeight <= maxScan; fallHeight++)
|
||||||
|
{
|
||||||
|
int newY = y - fallHeight;
|
||||||
|
if (newY < -64) break;
|
||||||
|
|
||||||
|
Material ontoMat = ctx.GetMaterial(destX, newY, destZ);
|
||||||
|
|
||||||
|
int unprotectedFallHeight = fallHeight - (y - effectiveStartHeight);
|
||||||
|
double tentativeCost = ActionCosts.WalkOffBlock
|
||||||
|
+ ActionCosts.FallCost(unprotectedFallHeight) + costSoFar;
|
||||||
|
|
||||||
|
// Water landing: safe regardless of height (water absorbs all fall damage)
|
||||||
|
if (MoveHelper.IsWater(ontoMat))
|
||||||
|
{
|
||||||
|
result.Set(destX, newY, destZ, tentativeCost);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mid-fall ladder/vine grab: resets effective fall height.
|
||||||
|
// Vanilla: player grabs ladders/vines if falling speed is low enough
|
||||||
|
// (roughly ≤ 11 blocks of unprotected free fall).
|
||||||
|
if (ctx.AllowLadderGrabDuringFall && unprotectedFallHeight <= 11
|
||||||
|
&& ontoMat.CanBeClimbedOn())
|
||||||
|
{
|
||||||
|
costSoFar += ActionCosts.FallCost(unprotectedFallHeight - 1);
|
||||||
|
costSoFar += ActionCosts.LadderDownOne;
|
||||||
|
effectiveStartHeight = newY;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Air or passable: continue falling
|
||||||
|
if (ctx.CanWalkThrough(destX, newY, destZ))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Hit something solid
|
||||||
|
if (MoveHelper.IsHazardous(ontoMat))
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ctx.CanWalkOn(destX, newY, destZ))
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Solid landing: allowed if within safe fall height
|
||||||
|
if (unprotectedFallHeight <= ctx.MaxFallHeight + 1)
|
||||||
|
{
|
||||||
|
result.Set(destX, newY + 1, destZ, tentativeCost);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.SetImpossible();
|
result.SetImpossible();
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
|
using MinecraftClient.Mapping;
|
||||||
using MinecraftClient.Pathing.Core;
|
using MinecraftClient.Pathing.Core;
|
||||||
|
|
||||||
namespace MinecraftClient.Pathing.Moves.Impl
|
namespace MinecraftClient.Pathing.Moves.Impl
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Straight-down fall at the current X,Z position, for drops greater than MaxFallHeight
|
/// Straight-down fall at the current X,Z position.
|
||||||
/// that MoveDescend won't cover. Scans downward for a safe landing.
|
/// Supports water landing and mid-fall ladder/vine grabbing.
|
||||||
|
/// Used for drops where MoveDescend's 1-block horizontal offset doesn't apply.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class MoveFall : IMove
|
public sealed class MoveFall : IMove
|
||||||
{
|
{
|
||||||
|
|
@ -28,39 +30,62 @@ namespace MinecraftClient.Pathing.Moves.Impl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double costSoFar = 0;
|
||||||
|
int effectiveStartHeight = y;
|
||||||
|
|
||||||
for (int fallDist = 1; fallDist <= _maxScanDepth; fallDist++)
|
for (int fallDist = 1; fallDist <= _maxScanDepth; fallDist++)
|
||||||
{
|
{
|
||||||
int landY = y - fallDist;
|
int landY = y - fallDist;
|
||||||
|
if (landY < -64) break;
|
||||||
|
|
||||||
if (ctx.CanWalkOn(x, landY - 1, z))
|
Material ontoMat = ctx.GetMaterial(x, landY, z);
|
||||||
|
int unprotectedFallHeight = fallDist - (y - effectiveStartHeight);
|
||||||
|
|
||||||
|
// Water landing: safe regardless of height
|
||||||
|
if (MoveHelper.IsWater(ontoMat))
|
||||||
{
|
{
|
||||||
if (!ctx.CanWalkThrough(x, landY, z))
|
double waterCost = ActionCosts.FallCost(unprotectedFallHeight) + costSoFar;
|
||||||
{
|
result.Set(x, landY, z, waterCost);
|
||||||
result.SetImpossible();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MoveHelper.IsHazardous(ctx.GetMaterial(x, landY - 1, z)))
|
|
||||||
{
|
|
||||||
result.SetImpossible();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double fallDamageThreshold = 3;
|
|
||||||
double cost = ActionCosts.FallCost(fallDist);
|
|
||||||
|
|
||||||
if (fallDist > fallDamageThreshold)
|
|
||||||
cost += (fallDist - fallDamageThreshold) * 5.0;
|
|
||||||
|
|
||||||
result.Set(x, landY, z, cost);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.CanWalkThrough(x, landY, z))
|
// Mid-fall ladder/vine grab (resets effective fall height)
|
||||||
|
if (ctx.AllowLadderGrabDuringFall && unprotectedFallHeight <= 11
|
||||||
|
&& ontoMat.CanBeClimbedOn())
|
||||||
|
{
|
||||||
|
costSoFar += ActionCosts.FallCost(unprotectedFallHeight - 1);
|
||||||
|
costSoFar += ActionCosts.LadderDownOne;
|
||||||
|
effectiveStartHeight = landY;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.CanWalkThrough(x, landY, z))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Hit something solid
|
||||||
|
if (!ctx.CanWalkOn(x, landY, z))
|
||||||
{
|
{
|
||||||
result.SetImpossible();
|
result.SetImpossible();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MoveHelper.IsHazardous(ontoMat))
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Solid landing within safe height
|
||||||
|
if (unprotectedFallHeight <= ctx.MaxFallHeight + 1)
|
||||||
|
{
|
||||||
|
double cost = ActionCosts.FallCost(unprotectedFallHeight) + costSoFar;
|
||||||
|
result.Set(x, landY + 1, z, cost);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Too high for safe landing
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.SetImpossible();
|
result.SetImpossible();
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using MinecraftClient.Mapping;
|
||||||
using MinecraftClient.Pathing.Core;
|
using MinecraftClient.Pathing.Core;
|
||||||
|
|
||||||
namespace MinecraftClient.Pathing.Moves.Impl
|
namespace MinecraftClient.Pathing.Moves.Impl
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sprint jump across a gap of 1-3 blocks (total distance 2-4 blocks forward).
|
/// Sprint jump across a gap in cardinal or diagonal direction.
|
||||||
/// Optionally ascends 1 block during the jump (distance 2 only).
|
/// Supports horizontal distances of 2-4 blocks and optional +1Y ascent.
|
||||||
/// Requires AllowParkour in context; the first block forward must lack ground.
|
/// Based on Baritone's MovementParkour design with diagonal extensions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class MoveParkour : IMove
|
public sealed class MoveParkour : IMove
|
||||||
{
|
{
|
||||||
|
|
@ -14,19 +16,18 @@ namespace MinecraftClient.Pathing.Moves.Impl
|
||||||
public int ZOffset { get; }
|
public int ZOffset { get; }
|
||||||
public bool DynamicY => false;
|
public bool DynamicY => false;
|
||||||
|
|
||||||
private readonly int _distance;
|
|
||||||
private readonly int _yDelta;
|
private readonly int _yDelta;
|
||||||
private readonly int _xDir;
|
|
||||||
private readonly int _zDir;
|
|
||||||
|
|
||||||
public MoveParkour(int xDir, int zDir, int distance, int yDelta = 0)
|
/// <summary>
|
||||||
|
/// Create a parkour move with direct XZ offsets.
|
||||||
|
/// For cardinal: one of xOff/zOff is 0, the other is 2..4.
|
||||||
|
/// For diagonal: both non-zero, actual distance should be within sprint jump range.
|
||||||
|
/// </summary>
|
||||||
|
public MoveParkour(int xOff, int zOff, int yDelta = 0)
|
||||||
{
|
{
|
||||||
_xDir = xDir;
|
XOffset = xOff;
|
||||||
_zDir = zDir;
|
ZOffset = zOff;
|
||||||
_distance = distance;
|
|
||||||
_yDelta = yDelta;
|
_yDelta = yDelta;
|
||||||
XOffset = xDir * distance;
|
|
||||||
ZOffset = zDir * distance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Calculate(CalculationContext ctx, int x, int y, int z, ref MoveResult result)
|
public void Calculate(CalculationContext ctx, int x, int y, int z, ref MoveResult result)
|
||||||
|
|
@ -49,16 +50,34 @@ namespace MinecraftClient.Pathing.Moves.Impl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int destX = x + _xDir * _distance;
|
// Don't parkour from climbable blocks (unreliable jump)
|
||||||
int destZ = z + _zDir * _distance;
|
Material standingOn = ctx.GetMaterial(x, y - 1, z);
|
||||||
|
if (standingOn.CanBeClimbedOn())
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int destX = x + XOffset;
|
||||||
|
int destZ = z + ZOffset;
|
||||||
int destY = y + _yDelta;
|
int destY = y + _yDelta;
|
||||||
|
|
||||||
|
// Head clearance at start (need room to jump)
|
||||||
if (!ctx.CanWalkThrough(x, y + 2, z))
|
if (!ctx.CanWalkThrough(x, y + 2, z))
|
||||||
{
|
{
|
||||||
result.SetImpossible();
|
result.SetImpossible();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can't jump out of liquid
|
||||||
|
Material atFeet = ctx.GetMaterial(x, y, z);
|
||||||
|
if (atFeet.IsLiquid())
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destination must be standable and passable
|
||||||
if (!ctx.CanWalkOn(destX, destY - 1, destZ))
|
if (!ctx.CanWalkOn(destX, destY - 1, destZ))
|
||||||
{
|
{
|
||||||
result.SetImpossible();
|
result.SetImpossible();
|
||||||
|
|
@ -72,42 +91,99 @@ namespace MinecraftClient.Pathing.Moves.Impl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < _distance; i++)
|
int xSign = Math.Sign(XOffset);
|
||||||
{
|
int zSign = Math.Sign(ZOffset);
|
||||||
int gx = x + _xDir * i;
|
int xAbs = Math.Abs(XOffset);
|
||||||
int gz = z + _zDir * i;
|
int zAbs = Math.Abs(ZOffset);
|
||||||
|
|
||||||
if (!ctx.CanWalkThrough(gx, y, gz) ||
|
// Check intermediate space for passability (the player's bounding box sweeps
|
||||||
!ctx.CanWalkThrough(gx, y + 1, gz) ||
|
// through a rectangle from start to end; check all blocks in that rectangle)
|
||||||
!ctx.CanWalkThrough(gx, y + 2, gz))
|
for (int i = 0; i <= xAbs; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j <= zAbs; j++)
|
||||||
|
{
|
||||||
|
if (i == 0 && j == 0) continue;
|
||||||
|
if (i == xAbs && j == zAbs) continue;
|
||||||
|
|
||||||
|
int gx = x + xSign * i;
|
||||||
|
int gz = z + zSign * j;
|
||||||
|
|
||||||
|
if (!ctx.CanWalkThrough(gx, y, gz) ||
|
||||||
|
!ctx.CanWalkThrough(gx, y + 1, gz) ||
|
||||||
|
!ctx.CanWalkThrough(gx, y + 2, gz))
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_yDelta > 0 && !ctx.CanWalkThrough(gx, y + 3, gz))
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gap check: first block(s) adjacent to start must lack ground.
|
||||||
|
// If ground exists there, A* can find a walking path instead.
|
||||||
|
if (xAbs > 0 && zAbs == 0)
|
||||||
|
{
|
||||||
|
if (ctx.CanWalkOn(x + xSign, y - 1, z))
|
||||||
{
|
{
|
||||||
result.SetImpossible();
|
result.SetImpossible();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (_yDelta > 0 && !ctx.CanWalkThrough(gx, y + 3, gz))
|
else if (xAbs == 0 && zAbs > 0)
|
||||||
|
{
|
||||||
|
if (ctx.CanWalkOn(x, y - 1, z + zSign))
|
||||||
|
{
|
||||||
|
result.SetImpossible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Diagonal: the diagonally adjacent block must lack ground
|
||||||
|
if (ctx.CanWalkOn(x + xSign, y - 1, z + zSign))
|
||||||
{
|
{
|
||||||
result.SetImpossible();
|
result.SetImpossible();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int firstGapX = x + _xDir;
|
// Overshoot safety: after landing, player continues moving.
|
||||||
int firstGapZ = z + _zDir;
|
// The block(s) past the destination in the jump direction must be passable.
|
||||||
if (ctx.CanWalkOn(firstGapX, y - 1, firstGapZ))
|
int overX = destX + xSign;
|
||||||
|
int overZ = destZ + zSign;
|
||||||
|
if (!ctx.CanWalkThrough(overX, destY, overZ) ||
|
||||||
|
!ctx.CanWalkThrough(overX, destY + 1, overZ))
|
||||||
{
|
{
|
||||||
result.SetImpossible();
|
// Wall right after landing - risk of collision. Still allow but add cost.
|
||||||
return;
|
// (Baritone rejects this, but we allow with penalty since the template
|
||||||
|
// will decelerate anyway.)
|
||||||
}
|
}
|
||||||
|
|
||||||
double cost = _distance * ctx.SprintCost + ctx.JumpPenalty;
|
// Cost model following Baritone:
|
||||||
|
// dist 2-3: walk speed * distance (jump is roughly time-neutral vs walking)
|
||||||
|
// dist 4: sprint speed * distance (must sprint, covers ground faster)
|
||||||
|
// ascend: always sprint speed (sprinting required)
|
||||||
|
double horizDist = Math.Sqrt((double)(XOffset * XOffset + ZOffset * ZOffset));
|
||||||
|
double cost;
|
||||||
if (_yDelta > 0)
|
if (_yDelta > 0)
|
||||||
cost += ctx.JumpPenalty;
|
cost = horizDist * ctx.SprintCost + ctx.JumpPenalty * 2;
|
||||||
|
else if (horizDist >= 3.5)
|
||||||
|
cost = horizDist * ctx.SprintCost + ctx.JumpPenalty;
|
||||||
|
else
|
||||||
|
cost = horizDist * ctx.WalkCost + ctx.JumpPenalty;
|
||||||
|
|
||||||
result.Set(destX, destY, destZ, cost);
|
result.Set(destX, destY, destZ, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() =>
|
public override string ToString()
|
||||||
$"MoveParkour(dir=({_xDir},{_zDir}), dist={_distance}, dy={_yDelta})";
|
{
|
||||||
|
double dist = Math.Sqrt((double)(XOffset * XOffset + ZOffset * ZOffset));
|
||||||
|
return $"MoveParkour(off=({XOffset},{ZOffset}), dy={_yDelta}, dist={dist:F1})";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,29 @@ namespace MinecraftClient.Pathing.Moves
|
||||||
return mat == Material.Water;
|
return mat == Material.Water;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Can the player safely land on this block? True for solid blocks
|
||||||
|
/// except bottom slabs (which cause glitchy fall damage in vanilla).
|
||||||
|
/// </summary>
|
||||||
|
public static bool CanSafelyLandOn(CalculationContext ctx, int x, int y, int z)
|
||||||
|
{
|
||||||
|
if (!CanWalkOn(ctx, x, y, z))
|
||||||
|
return false;
|
||||||
|
// TODO: detect bottom slabs via BlockShapes and reject them
|
||||||
|
// (Baritone rejects bottom slab landings due to unreliable fall damage)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Does this block absorb/negate fall damage?
|
||||||
|
/// Water, slime blocks, hay bales, and powder snow reduce or eliminate fall damage.
|
||||||
|
/// </summary>
|
||||||
|
public static bool AbsorbsFallDamage(Material mat)
|
||||||
|
{
|
||||||
|
return mat is Material.Water or Material.SlimeBlock
|
||||||
|
or Material.HayBlock or Material.PowderSnow;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Conservative check for gate-type blocks. Since we cannot read block state
|
/// Conservative check for gate-type blocks. Since we cannot read block state
|
||||||
/// (open/closed) during planning, treat all fence gates as passable.
|
/// (open/closed) during planning, treat all fence gates as passable.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue