From 682f3c0e95966c39b3d135fc6364f891f3dfb30a Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 5 Oct 2025 08:43:52 +0330 Subject: add Client::query_entity --- CHANGELOG.md | 2 ++ azalea-client/src/entity_query.rs | 25 +++++++++++++++++++++++++ azalea-world/src/chunk_storage.rs | 1 + 3 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 541ba2ce..c425e178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ is breaking anyways, semantic versioning is not followed. ### Added +- Add `Client::query_entity` to complement `query_self`. + ### Changed - Update to Minecraft 1.21.9. diff --git a/azalea-client/src/entity_query.rs b/azalea-client/src/entity_query.rs index c21380fc..43e99c55 100644 --- a/azalea-client/src/entity_query.rs +++ b/azalea-client/src/entity_query.rs @@ -16,6 +16,8 @@ use crate::Client; impl Client { /// A convenience function for getting components from our client's entity. /// + /// To query another entity, you can use [`Self::query_entity`]. + /// /// # Examples /// ``` /// # use azalea_world::InstanceName; @@ -39,6 +41,29 @@ impl Client { f(res) } + /// A convenience function for getting components from any entity. + /// + /// If you're querying the client, you should use [`Self::query_self`]. + /// + /// # Panics + /// + /// This will panic if the component doesn't exist on the entity. + pub fn query_entity( + &self, + entity: Entity, + f: impl FnOnce(QueryItem) -> R, + ) -> R { + let mut ecs = self.ecs.lock(); + let mut qs = ecs.query::(); + let res = qs.get_mut(&mut ecs, entity).unwrap_or_else(|_| { + panic!( + "Entity is missing a required component {:?}", + any::type_name::() + ) + }); + f(res) + } + /// Quickly returns a lightweight [`Entity`] for an arbitrary entity that /// matches the given predicate function that is in the same /// [`Instance`] as the client. diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index 2efd002d..d38c5ef9 100644 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -404,6 +404,7 @@ impl Chunk { } } + /// Get the biome at the given position, or `None` if it's out of bounds. pub fn get_biome(&self, pos: ChunkBiomePos, min_y: i32) -> Option { if pos.y < min_y { // y position is out of bounds -- cgit v1.2.3