diff options
| author | mat <git@matdoes.dev> | 2025-05-06 10:58:48 -1000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-05-07 06:59:22 +1000 |
| commit | f7c9419045470495fe76b0167d09d17c3cf4cc56 (patch) | |
| tree | b8bb1c4cc19fa9a6887224a57c43af9334ef285d /azalea/src/pathfinder/moves | |
| parent | af3affb467c01ee2880fbbc366ea0420c0580ab8 (diff) | |
| download | azalea-drasl-f7c9419045470495fe76b0167d09d17c3cf4cc56.tar.xz | |
pathfinder can now handle slabs, stairs, and dirt paths
Diffstat (limited to 'azalea/src/pathfinder/moves')
| -rw-r--r-- | azalea/src/pathfinder/moves/basic.rs | 5 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/mod.rs | 13 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/parkour.rs | 18 |
3 files changed, 31 insertions, 5 deletions
diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs index 4955ed08..d23bb894 100644 --- a/azalea/src/pathfinder/moves/basic.rs +++ b/azalea/src/pathfinder/moves/basic.rs @@ -135,7 +135,10 @@ fn execute_ascend_move(mut ctx: ExecuteCtx) { } if BlockPos::from(position) == start { - ctx.jump(); + // only jump if the target is more than 0.5 blocks above us + if target.y as f64 - position.y > 0.5 { + ctx.jump(); + } } } #[must_use] diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs index 150dad52..f79f7249 100644 --- a/azalea/src/pathfinder/moves/mod.rs +++ b/azalea/src/pathfinder/moves/mod.rs @@ -191,10 +191,19 @@ pub struct IsReachedCtx<'a> { #[must_use] pub fn default_is_reached( IsReachedCtx { - position, target, .. + position, + target, + physics, + .. }: IsReachedCtx, ) -> bool { - BlockPos::from(position) == target + if BlockPos::from(position) == target { + return true; + } + + // this is to make it handle things like slabs correctly, if we're on the block + // below the target but on_ground + BlockPos::from(position).up(1) == target && physics.on_ground() } pub struct PathfinderCtx<'a> { diff --git a/azalea/src/pathfinder/moves/parkour.rs b/azalea/src/pathfinder/moves/parkour.rs index 1816a5e1..d4f136be 100644 --- a/azalea/src/pathfinder/moves/parkour.rs +++ b/azalea/src/pathfinder/moves/parkour.rs @@ -6,6 +6,11 @@ use super::{Edge, ExecuteCtx, IsReachedCtx, MoveData, PathfinderCtx}; use crate::pathfinder::{astar, costs::*, rel_block_pos::RelBlockPos}; pub fn parkour_move(ctx: &mut PathfinderCtx, node: RelBlockPos) { + if !ctx.world.is_block_solid(node.down(1)) { + // we can only parkour from solid blocks (not just standable blocks like slabs) + return; + } + parkour_forward_1_move(ctx, node); parkour_forward_2_move(ctx, node); parkour_forward_3_move(ctx, node); @@ -232,9 +237,18 @@ fn execute_parkour_move(mut ctx: ExecuteCtx) { #[must_use] pub fn parkour_is_reached( IsReachedCtx { - position, target, .. + position, + target, + physics, + .. }: IsReachedCtx, ) -> bool { // 0.094 and not 0 for lilypads - BlockPos::from(position) == target && (position.y - target.y as f64) < 0.094 + if BlockPos::from(position) == target && (position.y - target.y as f64) < 0.094 { + return true; + } + + // this is to make it handle things like slabs correctly, if we're on the block + // below the target but on_ground + BlockPos::from(position).up(1) == target && physics.on_ground() } |
