From 839d536e8020b291bc1d213a5e8e823dc513a940 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 28 Dec 2025 09:06:47 -0330 Subject: add a few more functions for getting common components to Client --- azalea/src/client_impl/mod.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'azalea/src/client_impl/mod.rs') diff --git a/azalea/src/client_impl/mod.rs b/azalea/src/client_impl/mod.rs index bbbe23e0..419fc27e 100644 --- a/azalea/src/client_impl/mod.rs +++ b/azalea/src/client_impl/mod.rs @@ -35,7 +35,7 @@ use bevy_ecs::{ resource::Resource, world::{Mut, World}, }; -use parking_lot::{MappedRwLockReadGuard, RwLock}; +use parking_lot::RwLock; use tokio::sync::mpsc; use uuid::Uuid; @@ -308,9 +308,7 @@ impl Client { // the login packet tells us the world name self.query_self::, _>(|ins| ins.is_some()) } -} -impl Client { /// Get the position of this client. /// /// This is a shortcut for `Vec3::from(&bot.component::())`. @@ -395,10 +393,26 @@ impl Client { (**self.component::()).clone() } + /// Returns the [`Account`] for our client. + pub fn account(&self) -> Account { + self.component::().clone() + } + /// Returns the attribute values of our player, which can be used to /// determine things like our movement speed. - pub fn attributes(&self) -> MappedRwLockReadGuard<'_, Attributes> { - self.component::() + pub fn attributes(&self) -> Attributes { + // this *could* return a mapped read guard for performance but that rarely + // matters and it's just easier for the user if it doesn't. + self.component::().clone() + } + + /// Get the name of the instance (world) that the bot is in. + /// + /// This can be used to check if the client is in the same world as another + /// entity. + #[doc(alias("world_name", "dimension_name"))] + pub fn instance_name(&self) -> InstanceName { + (*self.component::()).clone() } /// A convenience function to get the Minecraft Uuid of a player by their -- cgit v1.2.3