aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea-world/src/chunk_storage.rs25
-rw-r--r--azalea-world/src/lib.rs2
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())
}