diff options
| author | mat <git@matdoes.dev> | 2026-01-17 22:53:06 +0200 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-17 22:53:06 +0200 |
| commit | a49c8d0b53fed223bab127704c604291ee77f921 (patch) | |
| tree | 228f9317401decf77d16b1ec6358184d8c3fb241 | |
| parent | 4d125a7ae042183d177af5070b6d2b1555f65456 (diff) | |
| download | azalea-drasl-a49c8d0b53fed223bab127704c604291ee77f921.tar.xz | |
add 'uncommon' pathfinder move category
| -rw-r--r-- | azalea/src/pathfinder/moves/basic.rs | 56 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/mod.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/uncommon.rs | 72 |
3 files changed, 75 insertions, 55 deletions
diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs index e5081964..69c949d7 100644 --- a/azalea/src/pathfinder/moves/basic.rs +++ b/azalea/src/pathfinder/moves/basic.rs @@ -330,7 +330,7 @@ fn descend_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) { }) } } -fn execute_descend_move(mut ctx: ExecuteCtx) { +pub fn execute_descend_move(mut ctx: ExecuteCtx) { let ExecuteCtx { target, start, @@ -401,60 +401,6 @@ pub fn descend_is_reached( false } -// TODO: disabled for now (for performance), this should probably be moved into -// its own category of moves -fn _descend_forward_1_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) { - for dir in CardinalDirection::iter() { - let dir_delta = RelBlockPos::new(dir.x(), 0, dir.z()); - let gap_horizontal_position = pos + dir_delta; - let new_horizontal_position = pos + dir_delta * 2; - - let gap_fall_distance = ctx.world.fall_distance(gap_horizontal_position); - let fall_distance = ctx.world.fall_distance(new_horizontal_position); - - if fall_distance == 0 || fall_distance > 3 || gap_fall_distance < fall_distance { - continue; - } - - let new_position = new_horizontal_position.down(fall_distance as i32); - - // check whether 2 blocks vertically forward are passable - if !ctx.world.is_passable(new_horizontal_position) { - continue; - } - if !ctx.world.is_passable(gap_horizontal_position) { - continue; - } - // check whether we can stand on the target position - if !ctx.world.is_standable(new_position) { - continue; - } - - let cost = WALK_OFF_BLOCK_COST - + WALK_ONE_BLOCK_COST - + f32::max( - FALL_N_BLOCKS_COST - .get(fall_distance as usize) - .copied() - // avoid panicking if we fall more than the size of FALL_N_BLOCKS_COST - // probably not possible but just in case - .unwrap_or(f32::INFINITY), - CENTER_AFTER_FALL_COST, - ); - - ctx.edges.push(Edge { - movement: astar::Movement { - target: new_position, - data: MoveData { - execute: &execute_descend_move, - is_reached: &descend_is_reached, - }, - }, - cost, - }) - } -} - fn diagonal_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) { let mut base_cost = SPRINT_ONE_BLOCK_COST; diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs index 1d16d42e..e62ae516 100644 --- a/azalea/src/pathfinder/moves/mod.rs +++ b/azalea/src/pathfinder/moves/mod.rs @@ -1,5 +1,6 @@ pub mod basic; pub mod parkour; +pub mod uncommon; use std::{ fmt::{self, Debug}, @@ -44,6 +45,7 @@ pub const BARITONE_COMPAT: bool = false; pub fn default_move(ctx: &mut PathfinderCtx, node: RelBlockPos) { basic::basic_move(ctx, node); parkour::parkour_move(ctx, node); + uncommon::uncommon_move(ctx, node); } #[derive(Clone)] diff --git a/azalea/src/pathfinder/moves/uncommon.rs b/azalea/src/pathfinder/moves/uncommon.rs new file mode 100644 index 00000000..43df3334 --- /dev/null +++ b/azalea/src/pathfinder/moves/uncommon.rs @@ -0,0 +1,72 @@ +//! Some moves which aren't used often but make execution slightly cleaner. + +use azalea_core::direction::CardinalDirection; + +use crate::pathfinder::{ + astar::{self, Edge}, + costs::{CENTER_AFTER_FALL_COST, FALL_N_BLOCKS_COST, WALK_OFF_BLOCK_COST, WALK_ONE_BLOCK_COST}, + moves::{ + BARITONE_COMPAT, MoveData, PathfinderCtx, + basic::{descend_is_reached, execute_descend_move}, + }, + rel_block_pos::RelBlockPos, +}; + +pub fn uncommon_move(ctx: &mut PathfinderCtx, node: RelBlockPos) { + if BARITONE_COMPAT { + return; + } + descend_forward_1_move(ctx, node); +} + +pub fn descend_forward_1_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) { + for dir in CardinalDirection::iter() { + let dir_delta = RelBlockPos::new(dir.x(), 0, dir.z()); + let gap_horizontal_position = pos + dir_delta; + let new_horizontal_position = pos + dir_delta * 2; + + let gap_fall_distance = ctx.world.fall_distance(gap_horizontal_position); + let fall_distance = ctx.world.fall_distance(new_horizontal_position); + + if fall_distance == 0 || fall_distance > 3 || gap_fall_distance < fall_distance { + continue; + } + + let new_position = new_horizontal_position.down(fall_distance as i32); + + // check whether 2 blocks vertically forward are passable + if !ctx.world.is_passable(new_horizontal_position) { + continue; + } + if !ctx.world.is_passable(gap_horizontal_position) { + continue; + } + // check whether we can stand on the target position + if !ctx.world.is_standable(new_position) { + continue; + } + + let cost = WALK_OFF_BLOCK_COST + + WALK_ONE_BLOCK_COST + + f32::max( + FALL_N_BLOCKS_COST + .get(fall_distance as usize) + .copied() + // avoid panicking if we fall more than the size of FALL_N_BLOCKS_COST + // probably not possible but just in case + .unwrap_or(f32::INFINITY), + CENTER_AFTER_FALL_COST, + ); + + ctx.edges.push(Edge { + movement: astar::Movement { + target: new_position, + data: MoveData { + execute: &execute_descend_move, + is_reached: &descend_is_reached, + }, + }, + cost, + }) + } +} |
