aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/client_impl/mod.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-12-28 09:06:47 -0330
committermat <git@matdoes.dev>2025-12-28 09:06:47 -0330
commit839d536e8020b291bc1d213a5e8e823dc513a940 (patch)
tree60cab8b908ad53af0126e2cb1dec670d073936a3 /azalea/src/client_impl/mod.rs
parent5b1a78baf757897532be8c308a37c99fb2ca3352 (diff)
downloadazalea-drasl-839d536e8020b291bc1d213a5e8e823dc513a940.tar.xz
add a few more functions for getting common components to Client
Diffstat (limited to 'azalea/src/client_impl/mod.rs')
-rw-r--r--azalea/src/client_impl/mod.rs24
1 files changed, 19 insertions, 5 deletions
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::<Option<&InstanceName>, _>(|ins| ins.is_some())
}
-}
-impl Client {
/// Get the position of this client.
///
/// This is a shortcut for `Vec3::from(&bot.component::<Position>())`.
@@ -395,10 +393,26 @@ impl Client {
(**self.component::<GameProfileComponent>()).clone()
}
+ /// Returns the [`Account`] for our client.
+ pub fn account(&self) -> Account {
+ self.component::<Account>().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::<Attributes>()
+ 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::<Attributes>().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::<InstanceName>()).clone()
}
/// A convenience function to get the Minecraft Uuid of a player by their