From 56afcb9dd8a6a08d084a642d64e7bef6e2051471 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 31 Aug 2022 22:39:38 -0500 Subject: make set_block_state return an Option --- azalea-world/src/chunk_storage.rs | 25 ++++++++++++------------- azalea-world/src/lib.rs | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index 4ceea347..9d81b28f 100644 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -80,22 +80,21 @@ impl ChunkStorage { pub fn get_block_state(&self, pos: &BlockPos, min_y: i32) -> Option { let chunk_pos = ChunkPos::from(pos); - let chunk = &self[&chunk_pos]; - chunk - .as_ref() - .map(|chunk| chunk.lock().unwrap().get(&ChunkBlockPos::from(pos), min_y)) + let chunk = self[&chunk_pos].as_ref()?; + let chunk = chunk.lock().unwrap(); + Some(chunk.get(&ChunkBlockPos::from(pos), min_y)) } - pub fn set_block_state(&self, pos: &BlockPos, state: BlockState, min_y: i32) -> BlockState { + pub fn set_block_state( + &self, + pos: &BlockPos, + state: BlockState, + min_y: i32, + ) -> Option { let chunk_pos = ChunkPos::from(pos); - let chunk = &self[&chunk_pos]; - if let Some(chunk) = chunk.as_ref() { - let mut chunk = chunk.lock().unwrap(); - chunk.get_and_set(&ChunkBlockPos::from(pos), state, min_y) - } else { - // nothing is in this chunk, just return air - BlockState::Air - } + let chunk = self[&chunk_pos].as_ref()?; + let mut chunk = chunk.lock().unwrap(); + Some(chunk.get_and_set(&ChunkBlockPos::from(pos), state, min_y)) } pub fn replace_with_packet_data( diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs index 93d2dcb2..32b4b82f 100644 --- a/azalea-world/src/lib.rs +++ b/azalea-world/src/lib.rs @@ -60,7 +60,7 @@ impl Dimension { self.chunk_storage.get_block_state(pos, self.min_y()) } - pub fn set_block_state(&mut self, pos: &BlockPos, state: BlockState) -> BlockState { + pub fn set_block_state(&mut self, pos: &BlockPos, state: BlockState) -> Option { self.chunk_storage.set_block_state(pos, state, self.min_y()) } -- cgit v1.2.3