From 89564da6b1ed2b424a4649d230a694b425e015cb Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 18 Aug 2025 08:27:00 +0600 Subject: fix DataComponentPatch::get --- azalea-inventory/src/slot.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'azalea-inventory/src') 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(&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::() } @@ -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::().unwrap(); + assert_eq!(map_id.id, 1); + } +} -- cgit v1.2.3