From 8808ecef9416edca9c77296742a533e848fba075 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 18 Apr 2024 19:52:13 -0500 Subject: [PATCH] fix get_block_collisions panicking when starting in a non existent chunk --- azalea-physics/src/collision/world_collisions.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/azalea-physics/src/collision/world_collisions.rs b/azalea-physics/src/collision/world_collisions.rs index 54493d622..4a3c2c3b3 100644 --- a/azalea-physics/src/collision/world_collisions.rs +++ b/azalea-physics/src/collision/world_collisions.rs @@ -15,8 +15,8 @@ pub fn get_block_collisions(world: &Instance, aabb: AABB) -> Vec { let mut block_collisions = Vec::new(); let initial_chunk_pos = ChunkPos::from(state.cursor.origin()); - let initial_chunk = world.chunks.get(&initial_chunk_pos).unwrap(); - let initial_chunk = initial_chunk.read(); + let initial_chunk = world.chunks.get(&initial_chunk_pos); + let initial_chunk = initial_chunk.as_deref().map(RwLock::read); while let Some(item) = state.cursor.next() { if item.iteration_type == CursorIterationType::Corner { @@ -25,9 +25,13 @@ pub fn get_block_collisions(world: &Instance, aabb: AABB) -> Vec { let item_chunk_pos = ChunkPos::from(item.pos); let block_state: BlockState = if item_chunk_pos == initial_chunk_pos { - initial_chunk - .get(&ChunkBlockPos::from(item.pos), state.world.chunks.min_y) - .unwrap_or(BlockState::AIR) + if let Some(initial_chunk) = &initial_chunk { + initial_chunk + .get(&ChunkBlockPos::from(item.pos), state.world.chunks.min_y) + .unwrap_or(BlockState::AIR) + } else { + BlockState::AIR + } } else { state.get_block_state(item.pos) };