mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Implements the new Baritone-inspired A* pathfinding system: - Core types: PathNode, PathResult, MoveResult, MoveType, ActionCosts - BinaryHeapOpenSet min-heap for A* open set - AStarPathFinder with timeout, cancellation, partial path support - CalculationContext for thread-safe world state snapshots - MoveHelper for block passability checks - IGoal interface + GoalBlock, GoalXZ, GoalNear, GoalComposite - IMove interface + MoveTraverse, MoveDiagonal, MoveAscend, MoveDescend, MoveClimb - /pathfind command for testing the new pathfinder Made-with: Cursor
67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using MinecraftClient.Mapping;
|
|
using MinecraftClient.Pathing.Moves;
|
|
|
|
namespace MinecraftClient.Pathing.Core
|
|
{
|
|
/// <summary>
|
|
/// Thread-safe snapshot of world state and player capabilities for path planning.
|
|
/// Created once at the start of a search; all move calculations read from this.
|
|
/// </summary>
|
|
public sealed class CalculationContext
|
|
{
|
|
public World World { get; }
|
|
public bool CanSprint { get; }
|
|
public bool AllowParkour { get; }
|
|
public bool AllowParkourAscend { get; }
|
|
public bool AllowDiagonalDescend { get; }
|
|
public int MaxFallHeight { get; }
|
|
public double JumpPenalty { get; }
|
|
public double WalkCost { get; }
|
|
public double SprintCost { get; }
|
|
public double SneakCost { get; }
|
|
|
|
public CalculationContext(
|
|
World world,
|
|
bool canSprint = true,
|
|
bool allowParkour = false,
|
|
bool allowParkourAscend = false,
|
|
bool allowDiagonalDescend = true,
|
|
int maxFallHeight = 3,
|
|
double jumpPenalty = ActionCosts.JumpPenalty)
|
|
{
|
|
World = world;
|
|
CanSprint = canSprint;
|
|
AllowParkour = allowParkour;
|
|
AllowParkourAscend = allowParkourAscend;
|
|
AllowDiagonalDescend = allowDiagonalDescend;
|
|
MaxFallHeight = maxFallHeight;
|
|
JumpPenalty = jumpPenalty;
|
|
WalkCost = ActionCosts.WalkOneBlock;
|
|
SprintCost = CanSprint ? ActionCosts.SprintOneBlock : ActionCosts.WalkOneBlock;
|
|
SneakCost = ActionCosts.SneakOneBlock;
|
|
}
|
|
|
|
public Block GetBlock(int x, int y, int z)
|
|
=> World.GetBlock(new Location(x, y, z));
|
|
|
|
public Material GetMaterial(int x, int y, int z)
|
|
=> GetBlock(x, y, z).Type;
|
|
|
|
public bool CanWalkThrough(int x, int y, int z)
|
|
=> MoveHelper.CanWalkThrough(this, x, y, z);
|
|
|
|
public bool CanWalkOn(int x, int y, int z)
|
|
=> MoveHelper.CanWalkOn(this, x, y, z);
|
|
|
|
public bool IsFullyPassable(int x, int y, int z)
|
|
=> MoveHelper.IsFullyPassable(this, x, y, z);
|
|
|
|
public bool IsChunkLoaded(int x, int z)
|
|
{
|
|
int cx = x >> 4;
|
|
int cz = z >> 4;
|
|
var col = World[cx, cz];
|
|
return col is not null && col.FullyLoaded;
|
|
}
|
|
}
|
|
}
|