diff options
| author | mat <git@matdoes.dev> | 2025-08-18 08:27:00 +0600 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-08-18 08:27:00 +0600 |
| commit | 89564da6b1ed2b424a4649d230a694b425e015cb (patch) | |
| tree | 506e70486842dae3f40799e8794cfdb5e8288284 /azalea-inventory/src | |
| parent | 9c6e40051dadeaa67df0acabee003e4a0286f5f1 (diff) | |
| download | azalea-drasl-89564da6b1ed2b424a4649d230a694b425e015cb.tar.xz | |
fix DataComponentPatch::get
Diffstat (limited to 'azalea-inventory/src')
| -rw-r--r-- | azalea-inventory/src/slot.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/azalea-inventory/src/slot.rs b/azalea-inventory/src/slot.rs index 444e0b2b..e9da4856 100644 --- a/azalea-inventory/src/slot.rs +++ b/azalea-inventory/src/slot.rs @@ -298,7 +298,7 @@ impl DataComponentPatch { /// # } /// ``` pub fn get<T: components::DataComponentTrait>(&self) -> Option<&T> { - let component = self.components.get(&T::KIND)?; + let component = self.get_kind(T::KIND)?; let component_any = component as &dyn Any; component_any.downcast_ref::<T>() } @@ -487,3 +487,16 @@ impl Serialize for DataComponentPatch { s.end() } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::components::MapId; + + #[test] + fn test_get_component() { + let item = ItemStack::from(Item::Map).with_component(MapId { id: 1 }); + let map_id = item.get_component::<MapId>().unwrap(); + assert_eq!(map_id.id, 1); + } +} |
