aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-10-05 08:43:52 +0330
committermat <git@matdoes.dev>2025-10-05 08:43:52 +0330
commit682f3c0e95966c39b3d135fc6364f891f3dfb30a (patch)
treee13407411cecbada972284109d978460cc10cf8e
parent2b9c453ade60bf4a37e2d77059641dc81b011be0 (diff)
downloadazalea-drasl-682f3c0e95966c39b3d135fc6364f891f3dfb30a.tar.xz
add Client::query_entity
-rw-r--r--CHANGELOG.md2
-rw-r--r--azalea-client/src/entity_query.rs25
-rw-r--r--azalea-world/src/chunk_storage.rs1
3 files changed, 28 insertions, 0 deletions
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<D: QueryData, R>(
+ &self,
+ entity: Entity,
+ f: impl FnOnce(QueryItem<D>) -> R,
+ ) -> R {
+ let mut ecs = self.ecs.lock();
+ let mut qs = ecs.query::<D>();
+ let res = qs.get_mut(&mut ecs, entity).unwrap_or_else(|_| {
+ panic!(
+ "Entity is missing a required component {:?}",
+ any::type_name::<D>()
+ )
+ });
+ 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<Biome> {
if pos.y < min_y {
// y position is out of bounds