Minecraft-Console-Client/MinecraftClient/Pathing/Moves/MoveHelper.cs
BruceChen 8ece75acc3 feat: complete Phase 4 McClient integration for A* pathfinding
- Fix MoveHelper.IsOpenGate: MangroveWood -> MangroveFenceGate
- Fix ResetStateForTransfer to cancel and clear pathSegmentManager
- Fix GetCurrentMovementGoal to return correct goal during A* navigation
- Fix SetMovementSpeed(Sneak) speed value consistency (2 -> 1)
- Migrate /pathfind command to use MoveToAStar + PathSegmentManager
- Add NavigateToGoal(IGoal) to McClient for flexible goal navigation
- Refactor MoveToAStar to delegate to NavigateToGoal
- Add ChatBot API: NavigateTo, CancelMovement, GetCurrentMovementGoal
- Expose PathSegmentManager.Goal property for external goal inspection

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

114 lines
4.2 KiB
C#

using MinecraftClient.Mapping;
using MinecraftClient.Pathing.Core;
namespace MinecraftClient.Pathing.Moves
{
/// <summary>
/// Block passability checks for path planning.
/// Uses Material-level checks initially; designed to allow future BlockShapes upgrade.
/// </summary>
public static class MoveHelper
{
/// <summary>
/// Can a player's body/head occupy this block position? (air, open door, tall grass, etc.)
/// </summary>
public static bool CanWalkThrough(CalculationContext ctx, int x, int y, int z)
{
Material mat = ctx.GetMaterial(x, y, z);
if (mat == Material.Air || mat == Material.CaveAir || mat == Material.VoidAir)
return true;
if (mat.IsLiquid())
return false;
if (mat.CanBeClimbedOn())
return true;
if (IsOpenGate(mat))
return true;
if (mat.IsSolid())
return false;
if (mat.CanHarmPlayers())
return false;
return true;
}
/// <summary>
/// Can a player stand on top of this block? (solid upper surface)
/// </summary>
public static bool CanWalkOn(CalculationContext ctx, int x, int y, int z)
{
Material mat = ctx.GetMaterial(x, y, z);
if (mat == Material.Air || mat == Material.CaveAir || mat == Material.VoidAir)
return false;
if (mat.IsLiquid())
return false;
if (mat.CanHarmPlayers())
return false;
if (mat.CanBeClimbedOn())
return false;
if (IsOpenGate(mat))
return false;
return mat.IsSolid();
}
/// <summary>
/// Is this block completely passable with no slowdown or interaction?
/// Stricter than CanWalkThrough -- excludes water, cobwebs, etc.
/// </summary>
public static bool IsFullyPassable(CalculationContext ctx, int x, int y, int z)
{
Material mat = ctx.GetMaterial(x, y, z);
return mat == Material.Air || mat == Material.CaveAir || mat == Material.VoidAir;
}
public static bool IsClimbable(Material mat)
{
return mat.CanBeClimbedOn();
}
public static bool IsHazardous(Material mat)
{
return mat.CanHarmPlayers();
}
public static bool IsWater(Material mat)
{
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>
/// Conservative check for gate-type blocks. Since we cannot read block state
/// (open/closed) during planning, treat all fence gates as passable.
/// </summary>
private static bool IsOpenGate(Material mat)
{
return mat is Material.AcaciaFenceGate or Material.BirchFenceGate
or Material.CrimsonFenceGate or Material.DarkOakFenceGate
or Material.JungleFenceGate or Material.MangroveFenceGate
or Material.OakFenceGate or Material.SpruceFenceGate
or Material.WarpedFenceGate or Material.CherryFenceGate
or Material.BambooFenceGate or Material.PaleOakFenceGate;
}
}
}