From 37b9f10b3bcc74b48df2c6843a5286a7d41e2414 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 11 Dec 2022 00:15:37 -0600 Subject: make entities have a reference to WeakWorlds instead ... and other exciting bug fixes --- azalea-world/src/entity/mod.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'azalea-world/src/entity') diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs index 814ef6d2..94362f2f 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::World; +use crate::WeakWorld; use azalea_block::BlockState; use azalea_core::{BlockPos, Vec3, AABB}; pub use data::*; @@ -17,7 +17,7 @@ use uuid::Uuid; /// A reference to an entity in a world. #[derive(Debug)] -pub struct Entity<'d, D = &'d mut World> { +pub struct Entity<'d, D = &'d WeakWorld> { /// The world this entity is in. pub world: D, /// The incrementing numerical id of the entity. @@ -26,7 +26,7 @@ pub struct Entity<'d, D = &'d mut World> { _marker: PhantomData<&'d ()>, } -impl<'d, D: Deref> Entity<'d, D> { +impl<'d, D: Deref> Entity<'d, D> { pub fn new(world: D, id: u32, data: NonNull) -> Self { // TODO: have this be based on the entity type Self { @@ -38,7 +38,7 @@ impl<'d, D: Deref> Entity<'d, D> { } } -impl<'d, D: DerefMut> Entity<'d, D> { +impl<'d, D: Deref> 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! /// @@ -95,7 +95,7 @@ impl<'d, D: DerefMut> Entity<'d, D> { } } -impl<'d, D: Deref> Entity<'d, D> { +impl<'d, D: Deref> Entity<'d, D> { #[inline] pub fn pos(&self) -> &Vec3 { &self.pos @@ -150,8 +150,8 @@ impl<'d, D: Deref> Entity<'d, D> { // impl< // 'd, -// D: DerefMut + Deref, -// D2: Deref, +// D: Deref + Deref, +// D2: Deref, // > From> for Entity<'d, D2> // { // fn from(entity: Entity<'d, D>) -> Entity<'d, D> { @@ -164,13 +164,13 @@ impl<'d, D: Deref> Entity<'d, D> { // } // } -impl> DerefMut for Entity<'_, D> { +impl> DerefMut for Entity<'_, D> { fn deref_mut(&mut self) -> &mut Self::Target { unsafe { self.data.as_mut() } } } -impl> Deref for Entity<'_, D> { +impl> Deref for Entity<'_, D> { type Target = EntityData; fn deref(&self) -> &Self::Target { @@ -287,10 +287,11 @@ impl EntityData { #[cfg(test)] mod tests { use super::*; + use crate::PartialWorld; #[test] fn from_mut_entity_to_ref_entity() { - let mut world = World::default(); + let mut world = PartialWorld::default(); let uuid = Uuid::from_u128(100); world.add_entity( 0, @@ -301,7 +302,6 @@ mod tests { ), ); let entity: Entity = world.entity_mut(0).unwrap(); - let entity_ref = Entity::from(entity); - assert_eq!(entity_ref.uuid, uuid); + assert_eq!(entity.uuid, uuid); } } -- cgit v1.2.3