diff options
| author | mat <git@matdoes.dev> | 2026-01-17 08:50:46 -1345 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-17 08:50:46 -1345 |
| commit | be4f2df7be4963a863d6fd96f64275dd7028e9d4 (patch) | |
| tree | ef3bcec160eb11207f08435b864fafde2f17030e | |
| parent | 74ef7d19b2bc4453f5368cc39c838582f2f3bafd (diff) | |
| download | azalea-drasl-be4f2df7be4963a863d6fd96f64275dd7028e9d4.tar.xz | |
clippy
| -rw-r--r-- | azalea/src/pathfinder/moves/basic.rs | 40 | ||||
| -rw-r--r-- | azalea/src/pathfinder/positions.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/world.rs | 29 |
3 files changed, 33 insertions, 38 deletions
diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs index 1e8b7c64..be0f3b99 100644 --- a/azalea/src/pathfinder/moves/basic.rs +++ b/azalea/src/pathfinder/moves/basic.rs @@ -40,19 +40,17 @@ fn forward_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) { let new_position = pos + offset; - let break_cost; - if currently_in_water { + let break_cost = if currently_in_water { let dest_in_water = ctx.world.is_block_water(new_position); if !dest_in_water { continue; } - break_cost = ctx - .world - .cost_for_breaking_block(new_position.up(1), ctx.mining_cache); + ctx.world + .cost_for_breaking_block(new_position.up(1), ctx.mining_cache) } else { - break_cost = ctx.world.cost_for_standing(new_position, ctx.mining_cache); - } + ctx.world.cost_for_standing(new_position, ctx.mining_cache) + }; if break_cost == f32::INFINITY { continue; } @@ -96,20 +94,18 @@ fn ascend_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) { let is_unusual_shape = !ctx.world.is_block_solid(pos.down(1)); let mut stair_facing = None; - if is_unusual_shape { - if !ctx.world.is_block_water(pos) { - // this is potentially expensive but it's rare enough that it shouldn't matter - // much - let block_below = ctx.world.get_block_state(pos.down(1)); + if is_unusual_shape && !ctx.world.is_block_water(pos) { + // this is potentially expensive but it's rare enough that it shouldn't matter + // much + let block_below = ctx.world.get_block_state(pos.down(1)); - let Some(found_stair_facing) = validate_stair_and_get_facing(block_below) else { - // return if it's not a stair or it's not facing the right way (like, if it's - // upside down or something) - return; - }; + let Some(found_stair_facing) = validate_stair_and_get_facing(block_below) else { + // return if it's not a stair or it's not facing the right way (like, if it's + // upside down or something) + return; + }; - stair_facing = Some(found_stair_facing); - } + stair_facing = Some(found_stair_facing); } let break_cost_1 = ctx @@ -454,10 +450,8 @@ fn diagonal_move(ctx: &mut PathfinderCtx, pos: RelBlockPos) { { continue; } - } else { - if !ctx.world.is_standable(new_position) { - continue; - } + } else if !ctx.world.is_standable(new_position) { + continue; } if !left_passable || !right_passable { diff --git a/azalea/src/pathfinder/positions.rs b/azalea/src/pathfinder/positions.rs index ca2768b2..eb915242 100644 --- a/azalea/src/pathfinder/positions.rs +++ b/azalea/src/pathfinder/positions.rs @@ -160,7 +160,7 @@ impl From<BlockPos> for SmallChunkSectionPos { } impl PartialOrd for SmallChunkSectionPos { fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { - self.as_u64().partial_cmp(&other.as_u64()) + Some(self.cmp(other)) } } impl Ord for SmallChunkSectionPos { diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs index ec8aa259..be264889 100644 --- a/azalea/src/pathfinder/world.rs +++ b/azalea/src/pathfinder/world.rs @@ -1,14 +1,13 @@ use core::f32; use std::{ cell::{RefCell, UnsafeCell}, - cmp, mem, sync::Arc, }; use azalea_block::{BlockState, properties}; use azalea_core::{ bitset::FastFixedBitSet, - position::{BlockPos, ChunkPos, ChunkSectionBlockPos, ChunkSectionPos}, + position::{BlockPos, ChunkPos, ChunkSectionBlockPos}, }; use azalea_physics::collision::BlockWithShape; use azalea_registry::{builtin::BlockKind, tags}; @@ -29,9 +28,7 @@ pub struct CachedWorld { min_y: i32, world_lock: Arc<RwLock<World>>, - // we store `PalettedContainer`s instead of `Chunk`s or `Section`s because it doesn't contain - // any unnecessary data like heightmaps or biomes. - cached_chunks: RefCell<Vec<(ChunkPos, Box<[PalettedContainer<BlockState>]>)>>, + cached_chunks: RefCell<Vec<(ChunkPos, CachedChunk)>>, last_chunk_cache_index: RefCell<Option<usize>>, cached_blocks: UnsafeCell<CachedSections>, @@ -39,6 +36,10 @@ pub struct CachedWorld { cached_mining_costs: UnsafeCell<Box<[(RelBlockPos, f32)]>>, } +// we store `PalettedContainer`s instead of `Chunk`s or `Section`s because it +// doesn't contain any unnecessary data like heightmaps or biomes. +type CachedChunk = Box<[PalettedContainer<BlockState>]>; + #[derive(Default)] pub struct CachedSections { pub last_index: usize, @@ -452,33 +453,33 @@ impl CachedWorld { } // check the adjacent blocks that weren't in the same section - if !up_is_in_same_section { - if check_should_avoid_this_block(&self, pos.up(1), |b| { + if !up_is_in_same_section + && check_should_avoid_this_block(self, pos.up(1), |b| { if mining_cache.is_falling_block(b) { is_falling_block_above = true; } mining_cache.is_liquid(b) - }) { - return f32::INFINITY; - } + }) + { + return f32::INFINITY; } if !north_is_in_same_section - && check_should_avoid_this_block(&self, pos.north(1), &|b| mining_cache.is_liquid(b)) + && check_should_avoid_this_block(self, pos.north(1), |b| mining_cache.is_liquid(b)) { return f32::INFINITY; } if !east_is_in_same_section - && check_should_avoid_this_block(&self, pos.east(1), |b| mining_cache.is_liquid(b)) + && check_should_avoid_this_block(self, pos.east(1), |b| mining_cache.is_liquid(b)) { return f32::INFINITY; } if !south_is_in_same_section - && check_should_avoid_this_block(&self, pos.south(1), |b| mining_cache.is_liquid(b)) + && check_should_avoid_this_block(self, pos.south(1), |b| mining_cache.is_liquid(b)) { return f32::INFINITY; } if !west_is_in_same_section - && check_should_avoid_this_block(&self, pos.west(1), |b| mining_cache.is_liquid(b)) + && check_should_avoid_this_block(self, pos.west(1), |b| mining_cache.is_liquid(b)) { return f32::INFINITY; } |
