diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-06 14:05:01 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-06 14:05:01 -0600 |
| commit | d112856ff6353592a50658b0ddd316f54dd97b87 (patch) | |
| tree | 6c408ecab96012e3bffaf15843fad5b9b6817796 /azalea-world/src/entity/mod.rs | |
| parent | 9bc517511663193f3166320db4cb5ca02701b039 (diff) | |
| download | azalea-drasl-d112856ff6353592a50658b0ddd316f54dd97b87.tar.xz | |
Entity metadata (#37)
* add example generated metadata.rs
* metadata.rs codegen
* add the files
* add comment to top of metadata.rs
* avoid clone
* metadata
* defaults
* defaults
* fix metadata readers and writers
* fix bad bitmasks and ignore some clippy warnings in generated code
* add set_index function to entity metadatas
* applying metadata
Diffstat (limited to 'azalea-world/src/entity/mod.rs')
| -rw-r--r-- | azalea-world/src/entity/mod.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs index 37474d1d..e537e7e0 100644 --- a/azalea-world/src/entity/mod.rs +++ b/azalea-world/src/entity/mod.rs @@ -1,6 +1,8 @@ mod data; mod dimensions; +pub mod metadata; +pub use self::metadata::EntityMetadata; use crate::Dimension; use azalea_block::BlockState; use azalea_core::{BlockPos, Vec3, AABB}; @@ -142,6 +144,18 @@ impl<'d> EntityMut<'d> { z: acceleration.z * (x_rot as f64) + acceleration.x * (y_rot as f64), } } + + /// Apply the given metadata items to the entity. Everything that isn't + /// included in items will be left unchanged. If an error occured, None + /// will be returned. + /// + /// TODO: this should be changed to have a proper error. + pub fn apply_metadata(&mut self, items: &Vec<EntityDataItem>) -> Option<()> { + for item in items { + self.metadata.set_index(item.index, item.value.clone())?; + } + Some(()) + } } impl<'d> EntityMut<'d> { @@ -264,10 +278,13 @@ pub struct EntityData { /// Whether the entity will try to jump every tick /// (equivalent to the space key being held down in vanilla). pub jumping: bool, + + /// Stores some extra data about the entity, including the entity type. + pub metadata: EntityMetadata, } impl EntityData { - pub fn new(uuid: Uuid, pos: Vec3) -> Self { + pub fn new(uuid: Uuid, pos: Vec3, metadata: EntityMetadata) -> Self { let dimensions = EntityDimensions { width: 0.6, height: 1.8, @@ -297,6 +314,8 @@ impl EntityData { dimensions, jumping: false, + + metadata, } } @@ -318,7 +337,14 @@ mod tests { fn from_mut_entity_to_ref_entity() { let mut dim = Dimension::default(); let uuid = Uuid::from_u128(100); - dim.add_entity(0, EntityData::new(uuid, Vec3::default())); + dim.add_entity( + 0, + EntityData::new( + uuid, + Vec3::default(), + EntityMetadata::Player(metadata::Player::default()), + ), + ); let entity: EntityMut = dim.entity_mut(0).unwrap(); let entity_ref: EntityRef = entity.into(); assert_eq!(entity_ref.uuid, uuid); |
