mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
make set_block_state return an Option
This commit is contained in:
parent
7a159bdee5
commit
56afcb9dd8
2 changed files with 13 additions and 14 deletions
|
@ -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(
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue