Skip to content

Commit

Permalink
fix get_block_collisions panicking when starting in a non existent chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Apr 19, 2024
1 parent b66b5b6 commit 8808ece
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions azalea-physics/src/collision/world_collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub fn get_block_collisions(world: &Instance, aabb: AABB) -> Vec<VoxelShape> {
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 {
Expand All @@ -25,9 +25,13 @@ pub fn get_block_collisions(world: &Instance, aabb: AABB) -> Vec<VoxelShape> {

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)
};
Expand Down

0 comments on commit 8808ece

Please sign in to comment.