diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-15 14:52:26 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-15 14:52:26 -0600 |
| commit | 0d004b72ac22641978c6ef93ca8641eb621e2f48 (patch) | |
| tree | 61eca3b0bd0339b36b947afd76724b2b6447572c /azalea-world/src | |
| parent | b9da6f74756abb8daf7253765fdc5f5521381090 (diff) | |
| download | azalea-drasl-0d004b72ac22641978c6ef93ca8641eb621e2f48.tar.xz | |
Rename "dimension" to "world" (#39)
* rename "dimension" to "world"
* Update mod.rs
Diffstat (limited to 'azalea-world/src')
| -rwxr-xr-x | azalea-world/src/chunk_storage.rs | 4 | ||||
| -rw-r--r-- | azalea-world/src/entity/mod.rs | 46 | ||||
| -rwxr-xr-x | azalea-world/src/lib.rs | 17 |
3 files changed, 33 insertions, 34 deletions
diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index 85f0ebb3..a03cbe7b 100755 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -1,6 +1,6 @@ use crate::palette::PalettedContainer; use crate::palette::PalettedContainerType; -use crate::Dimension; +use crate::World; use azalea_block::BlockState; use azalea_buf::BufReadError; use azalea_buf::{McBufReadable, McBufWritable}; @@ -143,7 +143,7 @@ impl IndexMut<&ChunkPos> for ChunkStorage { impl Chunk { pub fn read_with_dimension( buf: &mut Cursor<&[u8]>, - data: &Dimension, + data: &World, ) -> Result<Self, BufReadError> { Self::read_with_dimension_height(buf, data.height()) } diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs index 540bfeed..4611f215 100644 --- a/azalea-world/src/entity/mod.rs +++ b/azalea-world/src/entity/mod.rs @@ -5,7 +5,7 @@ pub mod metadata; use self::attributes::{AttributeInstance, AttributeModifiers}; pub use self::metadata::EntityMetadata; -use crate::Dimension; +use crate::World; use azalea_block::BlockState; use azalea_core::{BlockPos, Vec3, AABB}; pub use data::*; @@ -15,22 +15,22 @@ use std::ops::{Deref, DerefMut}; use std::ptr::NonNull; use uuid::Uuid; -/// A reference to an entity in a dimension. +/// A reference to an entity in a world. #[derive(Debug)] -pub struct Entity<'d, D = &'d mut Dimension> { - /// The dimension this entity is in. - pub dimension: D, +pub struct Entity<'d, D = &'d mut World> { + /// The world this entity is in. + pub world: D, /// The incrementing numerical id of the entity. pub id: u32, pub data: NonNull<EntityData>, _marker: PhantomData<&'d ()>, } -impl<'d, D: Deref<Target = Dimension>> Entity<'d, D> { - pub fn new(dimension: D, id: u32, data: NonNull<EntityData>) -> Self { +impl<'d, D: Deref<Target = World>> Entity<'d, D> { + pub fn new(world: D, id: u32, data: NonNull<EntityData>) -> Self { // TODO: have this be based on the entity type Self { - dimension, + world, id, data, _marker: PhantomData, @@ -38,12 +38,12 @@ impl<'d, D: Deref<Target = Dimension>> Entity<'d, D> { } } -impl<'d, D: DerefMut<Target = Dimension>> Entity<'d, D> { +impl<'d, D: DerefMut<Target = World>> Entity<'d, 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. + /// Cached position in the world must be updated. pub unsafe fn move_unchecked(&mut self, new_pos: Vec3) { self.pos = new_pos; let bounding_box = self.make_bounding_box(); @@ -94,7 +94,7 @@ impl<'d, D: DerefMut<Target = Dimension>> Entity<'d, D> { } } -impl<'d, D: Deref<Target = Dimension>> Entity<'d, D> { +impl<'d, D: Deref<Target = World>> Entity<'d, D> { #[inline] pub fn pos(&self) -> &Vec3 { &self.pos @@ -129,10 +129,10 @@ impl<'d, D: Deref<Target = Dimension>> Entity<'d, D> { // TODO: check if block below is a fence, wall, or fence gate let block_pos = pos.down(1); - let block_state = self.dimension.get_block_state(&block_pos); + let block_state = self.world.get_block_state(&block_pos); if block_state == Some(BlockState::Air) { let block_pos_below = block_pos.down(1); - let block_state_below = self.dimension.get_block_state(&block_pos_below); + let block_state_below = self.world.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() @@ -149,13 +149,13 @@ impl<'d, D: Deref<Target = Dimension>> Entity<'d, D> { // impl< // 'd, -// D: DerefMut<Target = Dimension> + Deref<Target = Dimension>, -// D2: Deref<Target = Dimension>, +// D: DerefMut<Target = World> + Deref<Target = World>, +// D2: Deref<Target = World>, // > From<Entity<'d, D>> for Entity<'d, D2> // { // fn from(entity: Entity<'d, D>) -> Entity<'d, D> { // Entity { -// dimension: entity.dimension, +// world: entity.world, // id: entity.id, // data: entity.data, // _marker: PhantomData, @@ -163,13 +163,13 @@ impl<'d, D: Deref<Target = Dimension>> Entity<'d, D> { // } // } -impl<D: DerefMut<Target = Dimension>> DerefMut for Entity<'_, D> { +impl<D: DerefMut<Target = World>> DerefMut for Entity<'_, D> { fn deref_mut(&mut self) -> &mut Self::Target { unsafe { self.data.as_mut() } } } -impl<D: Deref<Target = Dimension>> Deref for Entity<'_, D> { +impl<D: Deref<Target = World>> Deref for Entity<'_, D> { type Target = EntityData; fn deref(&self) -> &Self::Target { @@ -181,7 +181,7 @@ impl<D: Deref<Target = Dimension>> Deref for Entity<'_, D> { pub struct EntityData { pub uuid: Uuid, /// The position of the entity right now. - /// This can be changde with unsafe_move, but the correct way is with dimension.move_entity + /// This can be changde with unsafe_move, but the correct way is with world.move_entity pos: Vec3, /// The position of the entity last tick. pub last_pos: Vec3, @@ -264,7 +264,7 @@ impl EntityData { } } - /// Get the position of the entity in the dimension. + /// Get the position of the entity in the world. #[inline] pub fn pos(&self) -> &Vec3 { &self.pos @@ -295,9 +295,9 @@ mod tests { #[test] fn from_mut_entity_to_ref_entity() { - let mut dim = Dimension::default(); + let mut world = World::default(); let uuid = Uuid::from_u128(100); - dim.add_entity( + world.add_entity( 0, EntityData::new( uuid, @@ -305,7 +305,7 @@ mod tests { EntityMetadata::Player(metadata::Player::default()), ), ); - let entity: Entity = dim.entity_mut(0).unwrap(); + let entity: Entity = world.entity_mut(0).unwrap(); let entity_ref = Entity::from(entity); assert_eq!(entity_ref.uuid, uuid); } diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs index 30e09fe9..a802f4c3 100755 --- a/azalea-world/src/lib.rs +++ b/azalea-world/src/lib.rs @@ -22,10 +22,9 @@ use std::{ use thiserror::Error; use uuid::Uuid; -/// A dimension is a collection of chunks and entities. -/// Minecraft calls these "Levels", Fabric calls them "Worlds", Minestom calls them "Instances". +/// A world is a collection of chunks and entities. They're called "levels" in Minecraft's source code. #[derive(Debug, Default)] -pub struct Dimension { +pub struct World { pub chunk_storage: ChunkStorage, pub entity_storage: EntityStorage, } @@ -36,9 +35,9 @@ pub enum MoveEntityError { EntityDoesNotExist, } -impl Dimension { +impl World { pub fn new(chunk_radius: u32, height: u32, min_y: i32) -> Self { - Dimension { + World { chunk_storage: ChunkStorage::new(chunk_radius, height, min_y), entity_storage: EntityStorage::new(), } @@ -127,13 +126,13 @@ impl Dimension { self.entity_storage.get_mut_by_id(id) } - pub fn entity(&self, id: u32) -> Option<Entity<&Dimension>> { + pub fn entity(&self, id: u32) -> Option<Entity<&World>> { let entity_data = self.entity_storage.get_by_id(id)?; let entity_ptr = unsafe { entity_data.as_const_ptr() }; Some(Entity::new(self, id, entity_ptr)) } - pub fn entity_mut(&mut self, id: u32) -> Option<Entity<'_, &mut Dimension>> { + pub fn entity_mut(&mut self, id: u32) -> Option<Entity<'_, &mut World>> { let entity_data = self.entity_storage.get_mut_by_id(id)?; let entity_ptr = unsafe { entity_data.as_ptr() }; Some(Entity::new(self, id, entity_ptr)) @@ -157,14 +156,14 @@ impl Dimension { } } -impl Index<&ChunkPos> for Dimension { +impl Index<&ChunkPos> for World { type Output = Option<Arc<Mutex<Chunk>>>; fn index(&self, pos: &ChunkPos) -> &Self::Output { &self.chunk_storage[pos] } } -impl IndexMut<&ChunkPos> for Dimension { +impl IndexMut<&ChunkPos> for World { fn index_mut<'a>(&'a mut self, pos: &ChunkPos) -> &'a mut Self::Output { &mut self.chunk_storage[pos] } |
