From 5fd57fd630bea256639332f117848d6f1fcfd132 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 4 Apr 2025 16:05:06 -0430 Subject: don't require mut for functions in Client and add some more convenience functions --- azalea/src/bot.rs | 12 ++++++------ azalea/src/container.rs | 8 ++++---- azalea/src/swarm/mod.rs | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'azalea/src') diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index aae8af05..514cea1e 100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -81,27 +81,27 @@ fn stop_jumping(mut query: Query<(&mut Jumping, &mut Bot)>) { pub trait BotClientExt { /// Queue a jump for the next tick. - fn jump(&mut self); + fn jump(&self); /// Turn the bot's head to look at the coordinate in the world. - fn look_at(&mut self, pos: Vec3); + fn look_at(&self, pos: Vec3); /// Get a receiver that will receive a message every tick. fn get_tick_broadcaster(&self) -> tokio::sync::broadcast::Receiver<()>; /// Mine a block. This won't turn the bot's head towards the block, so if /// that's necessary you'll have to do that yourself with [`look_at`]. /// /// [`look_at`]: crate::prelude::BotClientExt::look_at - fn mine(&mut self, position: BlockPos) -> impl Future + Send; + fn mine(&self, position: BlockPos) -> impl Future + Send; } impl BotClientExt for azalea_client::Client { - fn jump(&mut self) { + fn jump(&self) { let mut ecs = self.ecs.lock(); ecs.send_event(JumpEvent { entity: self.entity, }); } - fn look_at(&mut self, position: Vec3) { + fn look_at(&self, position: Vec3) { let mut ecs = self.ecs.lock(); ecs.send_event(LookAtEvent { entity: self.entity, @@ -133,7 +133,7 @@ impl BotClientExt for azalea_client::Client { tick_broadcast.subscribe() } - async fn mine(&mut self, position: BlockPos) { + async fn mine(&self, position: BlockPos) { self.start_mining(position); // vanilla sends an extra swing arm packet when we start mining self.ecs.lock().send_event(SwingArmEvent { diff --git a/azalea/src/container.rs b/azalea/src/container.rs index b5ed74cc..0ce0fc44 100644 --- a/azalea/src/container.rs +++ b/azalea/src/container.rs @@ -24,10 +24,10 @@ impl Plugin for ContainerPlugin { pub trait ContainerClientExt { fn open_container_at( - &mut self, + &self, pos: BlockPos, ) -> impl Future> + Send; - fn open_inventory(&mut self) -> Option; + fn open_inventory(&self) -> Option; fn get_open_container(&self) -> Option; } @@ -49,7 +49,7 @@ impl ContainerClientExt for Client { /// let container = bot.open_container_at(target_pos).await; /// # } /// ``` - async fn open_container_at(&mut self, pos: BlockPos) -> Option { + async fn open_container_at(&self, pos: BlockPos) -> Option { self.ecs .lock() .entity_mut(self.entity) @@ -83,7 +83,7 @@ impl ContainerClientExt for Client { /// If you just want to get the items in the player's inventory without /// sending any packets, use [`Client::menu`], [`Menu::player_slots_range`], /// and [`Menu::slots`]. - fn open_inventory(&mut self) -> Option { + fn open_inventory(&self) -> Option { let ecs = self.ecs.lock(); let inventory = ecs.get::(self.entity).expect("no inventory"); diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index 2062446a..eb56ae2d 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -627,7 +627,7 @@ impl Swarm { /// /// Returns an `Err` if the bot could not do a handshake successfully. pub async fn add( - &mut self, + &self, account: &Account, state: S, ) -> Result { -- cgit v1.2.3