diff options
| -rw-r--r-- | azalea-physics/src/lib.rs | 13 | ||||
| -rw-r--r-- | azalea-world/src/lib.rs | 5 |
2 files changed, 15 insertions, 3 deletions
diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index c2aa607a..7202a3b8 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -140,7 +140,8 @@ fn get_speed(entity: &EntityData, friction: f32) -> f32 { #[cfg(test)] mod tests { use super::*; - use azalea_world::Dimension; + use azalea_core::ChunkPos; + use azalea_world::{Chunk, Dimension}; use uuid::Uuid; #[test] @@ -176,7 +177,8 @@ mod tests { #[test] fn test_collision() { let mut dim = Dimension::default(); - + dim.set_chunk(&ChunkPos { x: 0, z: 0 }, Some(Chunk::default())) + .unwrap(); dim.add_entity( 0, EntityData::new( @@ -188,7 +190,12 @@ mod tests { }, ), ); - dim.set_block_state(&BlockPos { x: 0, y: 68, z: 0 }, BlockState::Stone); + let old_block_state = + dim.set_block_state(&BlockPos { x: 0, y: 70, z: 0 }, BlockState::Stone); + assert!( + old_block_state.is_some(), + "Old block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" + ); let mut entity = dim.entity_mut(0).unwrap(); entity.ai_step(); // delta will change, but it won't move until next tick diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs index 32b4b82f..2d65ebc8 100644 --- a/azalea-world/src/lib.rs +++ b/azalea-world/src/lib.rs @@ -52,6 +52,11 @@ impl Dimension { self.chunk_storage.replace_with_packet_data(pos, data) } + pub fn set_chunk(&mut self, pos: &ChunkPos, chunk: Option<Chunk>) -> Result<(), BufReadError> { + self[pos] = chunk.map(|c| Arc::new(Mutex::new(c))); + Ok(()) + } + pub fn update_view_center(&mut self, pos: &ChunkPos) { self.chunk_storage.view_center = *pos; } |
