From 2c8b7c5c2c9297273abfba8f7743f1bc25f166b1 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 28 Sep 2025 13:10:04 -0545 Subject: upgrade bevy to 0.17.0-rc.2 --- azalea-client/src/entity_query.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'azalea-client/src/entity_query.rs') diff --git a/azalea-client/src/entity_query.rs b/azalea-client/src/entity_query.rs index 55b86d6c..c21380fc 100644 --- a/azalea-client/src/entity_query.rs +++ b/azalea-client/src/entity_query.rs @@ -6,7 +6,7 @@ use azalea_world::InstanceName; use bevy_ecs::{ component::Component, entity::Entity, - query::{QueryData, QueryFilter, ROQueryItem}, + query::{QueryData, QueryFilter, QueryItem, ROQueryItem}, world::World, }; use parking_lot::Mutex; @@ -14,26 +14,29 @@ use parking_lot::Mutex; use crate::Client; impl Client { - /// A convenience function for getting components of our player's entity. + /// A convenience function for getting components from our client's entity. /// /// # Examples /// ``` /// # use azalea_world::InstanceName; /// # fn example(mut client: azalea_client::Client) { - /// let is_logged_in = client - /// .query::>(&mut client.ecs.lock()) - /// .is_some(); + /// let is_logged_in = client.query_self::, _>(|ins| ins.is_some()); /// # } /// ``` - pub fn query<'w, D: QueryData>(&self, ecs: &'w mut World) -> D::Item<'w> { - ecs.query::() - .get_mut(ecs, self.entity) - .unwrap_or_else(|_| { - panic!( - "Our client is missing a required component {:?}", - any::type_name::() - ) - }) + /// + /// # Panics + /// + /// This will panic if the component doesn't exist on the client. + pub fn query_self(&self, f: impl FnOnce(QueryItem) -> R) -> R { + let mut ecs = self.ecs.lock(); + let mut qs = ecs.query::(); + let res = qs.get_mut(&mut ecs, self.entity).unwrap_or_else(|_| { + panic!( + "Our client is missing a required component {:?}", + any::type_name::() + ) + }); + f(res) } /// Quickly returns a lightweight [`Entity`] for an arbitrary entity that -- cgit v1.2.3