diff options
| author | Ubuntu <github@matdoes.dev> | 2022-08-30 19:56:14 +0000 |
|---|---|---|
| committer | Ubuntu <github@matdoes.dev> | 2022-08-30 19:56:14 +0000 |
| commit | a6c5017e387954342a65358347cf89deead68944 (patch) | |
| tree | a1d92d6bb9da42262a2b64cd8e390c8c6e6cbbed /azalea-world/src | |
| parent | 5f0fe9f29ed8f56c4a62ff89605623b74d8ec87b (diff) | |
| download | azalea-drasl-a6c5017e387954342a65358347cf89deead68944.tar.xz | |
clippy
Diffstat (limited to 'azalea-world/src')
| -rw-r--r-- | azalea-world/src/entity/mod.rs | 64 | ||||
| -rw-r--r-- | azalea-world/src/entity_storage.rs | 2 | ||||
| -rw-r--r-- | azalea-world/src/lib.rs | 23 | ||||
| -rw-r--r-- | azalea-world/src/palette.rs | 11 |
4 files changed, 48 insertions, 52 deletions
diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs index 37321e0a..7c3e3873 100644 --- a/azalea-world/src/entity/mod.rs +++ b/azalea-world/src/entity/mod.rs @@ -2,6 +2,7 @@ mod data; mod dimensions; use crate::Dimension; +use azalea_block::BlockState; use azalea_core::{BlockPos, Vec3, AABB}; pub use data::*; pub use dimensions::*; @@ -36,7 +37,7 @@ impl<'d> EntityRef<'d> { } pub fn make_bounding_box(&self) -> AABB { - self.dimensions.make_bounding_box(&self.pos()) + self.dimensions.make_bounding_box(self.pos()) } /// Get the position of the block below the entity, but a little lower. @@ -63,20 +64,20 @@ impl<'d> EntityRef<'d> { let pos = BlockPos { x, y, z }; // TODO: check if block below is a fence, wall, or fence gate - // let block_pos = pos.below(); - // let block_state = dimension.get_block_state(&block_pos); - // if block_state == Some(BlockState::Air) { - // let block_pos_below = block_pos.below(); - // let block_state_below = dimension.get_block_state(&block_pos_below); - // if let Some(block_state_below) = block_state_below { - // if block_state_below.is_fence() - // || block_state_below.is_wall() - // || block_state_below.is_fence_gate() - // { - // return block_pos_below; - // } - // } - // } + let block_pos = pos.below(); + let block_state = self.dimension.get_block_state(&block_pos); + if block_state == Some(BlockState::Air) { + let block_pos_below = block_pos.below(); + let block_state_below = self.dimension.get_block_state(&block_pos_below); + if let Some(_block_state_below) = block_state_below { + // if block_state_below.is_fence() + // || block_state_below.is_wall() + // || block_state_below.is_fence_gate() + // { + // return block_pos_below; + // } + } + } pos } @@ -102,6 +103,9 @@ impl<'d> EntityMut<'d> { /// Sets the position of the entity. This doesn't update the cache in /// azalea-world, and should only be used within azalea-world! + /// + /// # Safety + /// Cached position in the dimension must be updated. pub unsafe fn move_unchecked(&mut self, new_pos: Vec3) { self.pos = new_pos; let bounding_box = self.make_bounding_box(); @@ -147,7 +151,7 @@ impl<'d> EntityMut<'d> { } pub fn make_bounding_box(&self) -> AABB { - self.dimensions.make_bounding_box(&self.pos()) + self.dimensions.make_bounding_box(self.pos()) } /// Get the position of the block below the entity, but a little lower. @@ -174,20 +178,20 @@ impl<'d> EntityMut<'d> { let pos = BlockPos { x, y, z }; // TODO: check if block below is a fence, wall, or fence gate - // let block_pos = pos.below(); - // let block_state = dimension.get_block_state(&block_pos); - // if block_state == Some(BlockState::Air) { - // let block_pos_below = block_pos.below(); - // let block_state_below = dimension.get_block_state(&block_pos_below); - // if let Some(block_state_below) = block_state_below { - // if block_state_below.is_fence() - // || block_state_below.is_wall() - // || block_state_below.is_fence_gate() - // { - // return block_pos_below; - // } - // } - // } + let block_pos = pos.below(); + let block_state = self.dimension.get_block_state(&block_pos); + if block_state == Some(BlockState::Air) { + let block_pos_below = block_pos.below(); + let block_state_below = self.dimension.get_block_state(&block_pos_below); + if let Some(_block_state_below) = block_state_below { + // if block_state_below.is_fence() + // || block_state_below.is_wall() + // || block_state_below.is_fence_gate() + // { + // return block_pos_below; + // } + } + } pos } diff --git a/azalea-world/src/entity_storage.rs b/azalea-world/src/entity_storage.rs index c7fd9c0b..4dd3ec12 100644 --- a/azalea-world/src/entity_storage.rs +++ b/azalea-world/src/entity_storage.rs @@ -63,7 +63,7 @@ impl EntityStorage { /// Get a mutable reference to an entity by its id. #[inline] - pub fn get_mut_by_id<'d>(&'d mut self, id: u32) -> Option<&'d mut EntityData> { + pub fn get_mut_by_id(&mut self, id: u32) -> Option<&mut EntityData> { self.data_by_id.get_mut(&id) } diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs index 77bb0f0f..93d2dcb2 100644 --- a/azalea-world/src/lib.rs +++ b/azalea-world/src/lib.rs @@ -123,23 +123,16 @@ impl Dimension { self.entity_storage.get_mut_by_id(id) } - pub fn entity<'d>(&'d self, id: u32) -> Option<EntityRef<'d>> { - let entity_data = self.entity_storage.get_by_id(id); - if let Some(entity_data) = entity_data { - Some(EntityRef::new(self, id, entity_data)) - } else { - None - } + pub fn entity(&self, id: u32) -> Option<EntityRef> { + let entity_data = self.entity_storage.get_by_id(id)?; + Some(EntityRef::new(self, id, entity_data)) } - pub fn entity_mut<'d>(&'d mut self, id: u32) -> Option<EntityMut<'d>> { - let entity_data = self.entity_storage.get_mut_by_id(id); - if let Some(entity_data) = entity_data { - let entity_ptr = unsafe { entity_data.as_ptr() }; - Some(EntityMut::new(self, id, entity_ptr)) - } else { - None - } + pub fn entity_mut(&mut self, id: u32) -> Option<EntityMut> { + let entity_data = self.entity_storage.get_mut_by_id(id)?; + + let entity_ptr = unsafe { entity_data.as_ptr() }; + Some(EntityMut::new(self, id, entity_ptr)) } pub fn entity_by_uuid(&self, uuid: &Uuid) -> Option<&EntityData> { diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs index 4e0f9a96..1b057e4f 100644 --- a/azalea-world/src/palette.rs +++ b/azalea-world/src/palette.rs @@ -112,8 +112,8 @@ impl PalettedContainer { // sanity check debug_assert_eq!(storage.size(), self.container_type.size()); - // let palette = new_palette_type.into_empty_palette(1usize << (bits_per_entry as usize)); - let palette = new_palette_type.into_empty_palette(); + // let palette = new_palette_type.as_empty_palette(1usize << (bits_per_entry as usize)); + let palette = new_palette_type.as_empty_palette(); PalettedContainer { bits_per_entry, palette, @@ -129,8 +129,7 @@ impl PalettedContainer { let mut new_data = self.create_or_reuse_data(bits_per_entry); new_data.copy_from(&self.palette, &self.storage); *self = new_data; - let id = self.id_for(value); - id + self.id_for(value) } fn copy_from(&mut self, palette: &Palette, storage: &BitStorage) { @@ -268,7 +267,7 @@ impl PaletteType { }) } - pub fn into_empty_palette(&self) -> Palette { + pub fn as_empty_palette(&self) -> Palette { match self { PaletteType::SingleValue => Palette::SingleValue(0), PaletteType::Linear => Palette::Linear(Vec::new()), @@ -298,7 +297,7 @@ impl PalettedContainerType { } fn size(&self) -> usize { - 1 << self.size_bits() * 3 + 1 << (self.size_bits() * 3) } } |
