diff options
| author | mat <github@matdoes.dev> | 2022-08-31 22:39:38 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-08-31 22:39:38 -0500 |
| commit | 56afcb9dd8a6a08d084a642d64e7bef6e2051471 (patch) | |
| tree | d517f1bec1d0ae9dabc02d4cea5ec32fbda1b528 | |
| parent | 7a159bdee50146ced2a0026124e4d5b62356b0f7 (diff) | |
| download | azalea-drasl-56afcb9dd8a6a08d084a642d64e7bef6e2051471.tar.xz | |
make set_block_state return an Option
| -rw-r--r-- | azalea-world/src/chunk_storage.rs | 25 | ||||
| -rw-r--r-- | 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<BlockState> { 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<BlockState> { 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<BlockState> { self.chunk_storage.set_block_state(pos, state, self.min_y()) } |
