aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder/moves
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-01-05 17:47:46 +0500
committermat <git@matdoes.dev>2026-01-05 17:47:46 +0500
commit8c9b3c98cb6afd7484cc44c35965e6d2436e6d37 (patch)
tree68f5a0f6d84bbd3a255ac654ee38da987fcd90ea /azalea/src/pathfinder/moves
parentdb9a9e53ca18911fb2045b7d6af4ed6df388eaaa (diff)
downloadazalea-drasl-8c9b3c98cb6afd7484cc44c35965e6d2436e6d37.tar.xz
pathfinder swimming
Diffstat (limited to 'azalea/src/pathfinder/moves')
-rw-r--r--azalea/src/pathfinder/moves/basic.rs20
-rw-r--r--azalea/src/pathfinder/moves/parkour.rs12
2 files changed, 23 insertions, 9 deletions
diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs
index 539d989d..128a6daf 100644
--- a/azalea/src/pathfinder/moves/basic.rs
+++ b/azalea/src/pathfinder/moves/basic.rs
@@ -20,10 +20,17 @@ pub fn basic_move(ctx: &mut PathfinderCtx, node: RelBlockPos) {
}
fn forward_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) {
+ let mut base_cost = SPRINT_ONE_BLOCK_COST;
+ // it's for us cheaper to have the water cost be applied when leaving the water
+ // rather than when entering
+ if ctx.world.is_block_water(pos.down(1)) {
+ base_cost = WALK_ONE_IN_WATER_COST;
+ }
+
for dir in CardinalDirection::iter() {
let offset = RelBlockPos::new(dir.x(), 0, dir.z());
- let mut cost = SPRINT_ONE_BLOCK_COST;
+ let mut cost = base_cost;
let break_cost = ctx.world.cost_for_standing(pos + offset, ctx.mining_cache);
if break_cost == f32::INFINITY {
@@ -407,14 +414,21 @@ fn descend_forward_1_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) {
}
fn diagonal_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) {
+ let mut base_cost = SPRINT_ONE_BLOCK_COST;
+ if ctx.world.is_block_water(pos.down(1)) {
+ base_cost = WALK_ONE_IN_WATER_COST;
+ }
+
+ // add 0.001 as a tie-breaker to avoid unnecessarily going diagonal
+ base_cost = base_cost.mul_add(SQRT_2, 0.001);
+
for dir in CardinalDirection::iter() {
let right = dir.right();
let offset = RelBlockPos::new(dir.x() + right.x(), 0, dir.z() + right.z());
let left_pos = RelBlockPos::new(pos.x + dir.x(), pos.y, pos.z + dir.z());
let right_pos = RelBlockPos::new(pos.x + right.x(), pos.y, pos.z + right.z());
- // +0.001 so it doesn't unnecessarily go diagonal sometimes
- let mut cost = SPRINT_ONE_BLOCK_COST * SQRT_2 + 0.001;
+ let mut cost = base_cost;
let left_passable = ctx.world.is_passable(left_pos);
let right_passable = ctx.world.is_passable(right_pos);
diff --git a/azalea/src/pathfinder/moves/parkour.rs b/azalea/src/pathfinder/moves/parkour.rs
index b4a03732..9ff10417 100644
--- a/azalea/src/pathfinder/moves/parkour.rs
+++ b/azalea/src/pathfinder/moves/parkour.rs
@@ -22,7 +22,7 @@ fn parkour_forward_1_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) {
let offset = RelBlockPos::new(dir.x() * 2, 0, dir.z() * 2);
// make sure we actually have to jump
- if ctx.world.is_block_solid((pos + gap_offset).down(1)) {
+ if ctx.world.is_block_standable((pos + gap_offset).down(1)) {
continue;
}
if !ctx.world.is_passable(pos + gap_offset) {
@@ -75,8 +75,8 @@ fn parkour_forward_2_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) {
let offset = RelBlockPos::new(dir.x() * 3, 0, dir.z() * 3);
// make sure we actually have to jump
- if ctx.world.is_block_solid((pos + gap_1_offset).down(1))
- || ctx.world.is_block_solid((pos + gap_2_offset).down(1))
+ if ctx.world.is_block_standable((pos + gap_1_offset).down(1))
+ || ctx.world.is_block_standable((pos + gap_2_offset).down(1))
{
continue;
}
@@ -134,9 +134,9 @@ fn parkour_forward_3_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) {
let offset = RelBlockPos::new(dir.x() * 4, 0, dir.z() * 4);
// make sure we actually have to jump
- if ctx.world.is_block_solid((pos + gap_1_offset).down(1))
- || ctx.world.is_block_solid((pos + gap_2_offset).down(1))
- || ctx.world.is_block_solid((pos + gap_3_offset).down(1))
+ if ctx.world.is_block_standable((pos + gap_1_offset).down(1))
+ || ctx.world.is_block_standable((pos + gap_2_offset).down(1))
+ || ctx.world.is_block_standable((pos + gap_3_offset).down(1))
{
continue;
}