diff options
| -rw-r--r-- | azalea-client/src/entity_query.rs | 10 | ||||
| -rw-r--r-- | azalea-inventory/src/slot.rs | 15 | ||||
| -rw-r--r-- | azalea/examples/testbot/commands/debug.rs | 9 |
3 files changed, 29 insertions, 5 deletions
diff --git a/azalea-client/src/entity_query.rs b/azalea-client/src/entity_query.rs index 84fcf9e7..55b86d6c 100644 --- a/azalea-client/src/entity_query.rs +++ b/azalea-client/src/entity_query.rs @@ -84,7 +84,6 @@ impl Client { /// efficient to use [`Self::any_entity_by`] instead. You can also use /// [`Self::nearest_entities_by`] to get all nearby entities. /// - /// # Example /// ``` /// use azalea_entity::{LocalEntity, Position, metadata::Player}; /// use bevy_ecs::query::{With, Without}; @@ -112,6 +111,15 @@ impl Client { /// all entities in our instance that match the predicate. /// /// The first entity is the nearest one. + /// + /// ``` + /// # use azalea_entity::{LocalEntity, Position, metadata::Player}; + /// # use bevy_ecs::query::{With, Without}; + /// # fn example(mut bot: azalea_client::Client, sender_name: String) { + /// let nearby_players = + /// bot.nearest_entities_by::<(With<Player>, Without<LocalEntity>), ()>(|_: &()| true); + /// # } + /// ``` pub fn nearest_entities_by<F: QueryFilter, Q: QueryData>( &self, predicate: impl EntityPredicate<Q, F>, 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); + } +} diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs index b3a8b419..8d24794d 100644 --- a/azalea/examples/testbot/commands/debug.rs +++ b/azalea/examples/testbot/commands/debug.rs @@ -14,10 +14,13 @@ use azalea::{ world::MinecraftEntityId, }; use azalea_core::hit_result::HitResult; -use azalea_entity::EntityKindComponent; -use azalea_inventory::components::MaxStackSize; +use azalea_entity::{ + EntityKindComponent, + metadata::{ItemFrame, ItemFrameItem}, +}; +use azalea_inventory::components::{MapId, MaxStackSize}; use azalea_world::InstanceContainer; -use bevy_ecs::event::Events; +use bevy_ecs::{event::Events, query::With}; use parking_lot::Mutex; use super::{CommandSource, Ctx}; |
