diff options
| author | mat <git@matdoes.dev> | 2025-04-04 16:05:06 -0430 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-04-04 16:05:06 -0430 |
| commit | 5fd57fd630bea256639332f117848d6f1fcfd132 (patch) | |
| tree | 83e21595e69e24b3b1e8790dc630b79cf14a1777 | |
| parent | e99ae608b67ad3ff105666e619d04ca9385488e1 (diff) | |
| download | azalea-drasl-5fd57fd630bea256639332f117848d6f1fcfd132.tar.xz | |
don't require mut for functions in Client and add some more convenience functions
| -rw-r--r-- | azalea-client/src/entity_query.rs | 6 | ||||
| -rw-r--r-- | azalea-client/src/plugins/interact.rs | 2 | ||||
| -rw-r--r-- | azalea-client/src/plugins/mining.rs | 2 | ||||
| -rw-r--r-- | azalea-client/src/plugins/movement.rs | 8 | ||||
| -rw-r--r-- | azalea-client/src/test_simulation.rs | 2 | ||||
| -rw-r--r-- | azalea/examples/steal.rs | 2 | ||||
| -rw-r--r-- | azalea/examples/testbot/commands/movement.rs | 18 | ||||
| -rw-r--r-- | azalea/examples/testbot/killaura.rs | 2 | ||||
| -rw-r--r-- | azalea/src/bot.rs | 12 | ||||
| -rw-r--r-- | azalea/src/container.rs | 8 | ||||
| -rw-r--r-- | azalea/src/swarm/mod.rs | 2 |
11 files changed, 32 insertions, 32 deletions
diff --git a/azalea-client/src/entity_query.rs b/azalea-client/src/entity_query.rs index c711253a..77be68a8 100644 --- a/azalea-client/src/entity_query.rs +++ b/azalea-client/src/entity_query.rs @@ -60,7 +60,7 @@ impl Client { /// /// [`Entity`]: bevy_ecs::entity::Entity pub fn entity_by<F: QueryFilter, Q: QueryData>( - &mut self, + &self, predicate: impl EntityPredicate<Q, F>, ) -> Option<Entity> { predicate.find(self.ecs.clone()) @@ -71,7 +71,7 @@ impl Client { /// /// If you're trying to get a component for this client, use /// [`Self::component`]. - pub fn entity_component<Q: Component + Clone>(&mut self, entity: Entity) -> Q { + pub fn entity_component<Q: Component + Clone>(&self, entity: Entity) -> Q { let mut ecs = self.ecs.lock(); let mut q = ecs.query::<&Q>(); let components = q.get(&ecs, entity).unwrap_or_else(|_| { @@ -86,7 +86,7 @@ impl Client { /// Get a component from an entity, if it exists. This is similar to /// [`Self::entity_component`] but returns an `Option` instead of panicking /// if the component isn't present. - pub fn get_entity_component<Q: Component + Clone>(&mut self, entity: Entity) -> Option<Q> { + pub fn get_entity_component<Q: Component + Clone>(&self, entity: Entity) -> Option<Q> { let mut ecs = self.ecs.lock(); let mut q = ecs.query::<&Q>(); let components = q.get(&ecs, entity).ok(); diff --git a/azalea-client/src/plugins/interact.rs b/azalea-client/src/plugins/interact.rs index a0dfa12a..f9513183 100644 --- a/azalea-client/src/plugins/interact.rs +++ b/azalea-client/src/plugins/interact.rs @@ -75,7 +75,7 @@ impl Client { /// /// Note that this may trigger anticheats as it doesn't take into account /// whether you're actually looking at the block. - pub fn block_interact(&mut self, position: BlockPos) { + pub fn block_interact(&self, position: BlockPos) { self.ecs.lock().send_event(BlockInteractEvent { entity: self.entity, position, diff --git a/azalea-client/src/plugins/mining.rs b/azalea-client/src/plugins/mining.rs index d4a6f2a0..2dd50700 100644 --- a/azalea-client/src/plugins/mining.rs +++ b/azalea-client/src/plugins/mining.rs @@ -64,7 +64,7 @@ impl Plugin for MiningPlugin { pub struct MiningSet; impl Client { - pub fn start_mining(&mut self, position: BlockPos) { + pub fn start_mining(&self, position: BlockPos) { self.ecs.lock().send_event(StartMiningBlockEvent { entity: self.entity, position, diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs index 54a46bcb..1a02fd21 100644 --- a/azalea-client/src/plugins/movement.rs +++ b/azalea-client/src/plugins/movement.rs @@ -86,7 +86,7 @@ impl Client { /// /// If you're making a realistic client, calling this function every tick is /// recommended. - pub fn set_jumping(&mut self, jumping: bool) { + pub fn set_jumping(&self, jumping: bool) { let mut ecs = self.ecs.lock(); let mut jumping_mut = self.query::<&mut Jumping>(&mut ecs); **jumping_mut = jumping; @@ -101,7 +101,7 @@ impl Client { /// side), `x_rot` is pitch (looking up and down). You can get these /// numbers from the vanilla f3 screen. /// `y_rot` goes from -180 to 180, and `x_rot` goes from -90 to 90. - pub fn set_direction(&mut self, y_rot: f32, x_rot: f32) { + pub fn set_direction(&self, y_rot: f32, x_rot: f32) { let mut ecs = self.ecs.lock(); let mut look_direction = self.query::<&mut LookDirection>(&mut ecs); @@ -406,7 +406,7 @@ impl Client { /// bot.walk(WalkDirection::None); /// # } /// ``` - pub fn walk(&mut self, direction: WalkDirection) { + pub fn walk(&self, direction: WalkDirection) { let mut ecs = self.ecs.lock(); ecs.send_event(StartWalkEvent { entity: self.entity, @@ -429,7 +429,7 @@ impl Client { /// bot.walk(WalkDirection::None); /// # } /// ``` - pub fn sprint(&mut self, direction: SprintDirection) { + pub fn sprint(&self, direction: SprintDirection) { let mut ecs = self.ecs.lock(); ecs.send_event(StartSprintEvent { entity: self.entity, diff --git a/azalea-client/src/test_simulation.rs b/azalea-client/src/test_simulation.rs index 7b422567..a09e5dae 100644 --- a/azalea-client/src/test_simulation.rs +++ b/azalea-client/src/test_simulation.rs @@ -95,7 +95,7 @@ impl Simulation { simulation } - pub fn receive_packet<P: ProtocolPacket + Debug>(&mut self, packet: impl Packet<P>) { + pub fn receive_packet<P: ProtocolPacket + Debug>(&self, packet: impl Packet<P>) { let buf = azalea_protocol::write::serialize_packet(&packet.into_variant()).unwrap(); self.incoming_packet_queue.lock().push(buf); } diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs index 21eea424..464d94f8 100644 --- a/azalea/examples/steal.rs +++ b/azalea/examples/steal.rs @@ -24,7 +24,7 @@ struct State { pub checked_chests: Arc<Mutex<Vec<BlockPos>>>, } -async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> { +async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { if let Event::Chat(m) = event { if m.sender() == Some(bot.profile.name.clone()) { return Ok(()); diff --git a/azalea/examples/testbot/commands/movement.rs b/azalea/examples/testbot/commands/movement.rs index a8511cc5..114c3c31 100644 --- a/azalea/examples/testbot/commands/movement.rs +++ b/azalea/examples/testbot/commands/movement.rs @@ -115,7 +115,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { get_integer(ctx, "z").unwrap(), ); println!("{:?}", pos); - let mut source = ctx.source.lock(); + let source = ctx.source.lock(); source.bot.look_at(pos.center()); 1 }), @@ -126,7 +126,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { literal("walk").then(argument("seconds", float()).executes(|ctx: &Ctx| { let mut seconds = get_float(ctx, "seconds").unwrap(); let source = ctx.source.lock(); - let mut bot = source.bot.clone(); + let bot = source.bot.clone(); if seconds < 0. { bot.walk(WalkDirection::Backward); @@ -147,7 +147,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { literal("sprint").then(argument("seconds", float()).executes(|ctx: &Ctx| { let seconds = get_float(ctx, "seconds").unwrap(); let source = ctx.source.lock(); - let mut bot = source.bot.clone(); + let bot = source.bot.clone(); bot.sprint(SprintDirection::Forward); tokio::spawn(async move { tokio::time::sleep(Duration::from_secs_f32(seconds)).await; @@ -159,25 +159,25 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { ); commands.register(literal("north").executes(|ctx: &Ctx| { - let mut source = ctx.source.lock(); + let source = ctx.source.lock(); source.bot.set_direction(180., 0.); source.reply("ok"); 1 })); commands.register(literal("south").executes(|ctx: &Ctx| { - let mut source = ctx.source.lock(); + let source = ctx.source.lock(); source.bot.set_direction(0., 0.); source.reply("ok"); 1 })); commands.register(literal("east").executes(|ctx: &Ctx| { - let mut source = ctx.source.lock(); + let source = ctx.source.lock(); source.bot.set_direction(-90., 0.); source.reply("ok"); 1 })); commands.register(literal("west").executes(|ctx: &Ctx| { - let mut source = ctx.source.lock(); + let source = ctx.source.lock(); source.bot.set_direction(90., 0.); source.reply("ok"); 1 @@ -185,14 +185,14 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { commands.register( literal("jump") .executes(|ctx: &Ctx| { - let mut source = ctx.source.lock(); + let source = ctx.source.lock(); source.bot.jump(); source.reply("ok"); 1 }) .then(argument("enabled", bool()).executes(|ctx: &Ctx| { let jumping = get_bool(ctx, "enabled").unwrap(); - let mut source = ctx.source.lock(); + let source = ctx.source.lock(); source.bot.set_jumping(jumping); 1 })), diff --git a/azalea/examples/testbot/killaura.rs b/azalea/examples/testbot/killaura.rs index e98fe6ec..b47ac0df 100644 --- a/azalea/examples/testbot/killaura.rs +++ b/azalea/examples/testbot/killaura.rs @@ -7,7 +7,7 @@ use azalea::{ use crate::State; -pub fn tick(mut bot: Client, state: State) -> anyhow::Result<()> { +pub fn tick(bot: Client, state: State) -> anyhow::Result<()> { if !state.killaura { return Ok(()); } 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<Output = ()> + Send; + fn mine(&self, position: BlockPos) -> impl Future<Output = ()> + 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<Output = Option<ContainerHandle>> + Send; - fn open_inventory(&mut self) -> Option<ContainerHandle>; + fn open_inventory(&self) -> Option<ContainerHandle>; fn get_open_container(&self) -> Option<ContainerHandleRef>; } @@ -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<ContainerHandle> { + async fn open_container_at(&self, pos: BlockPos) -> Option<ContainerHandle> { 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<ContainerHandle> { + fn open_inventory(&self) -> Option<ContainerHandle> { let ecs = self.ecs.lock(); let inventory = ecs.get::<Inventory>(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<S: Component + Clone>( - &mut self, + &self, account: &Account, state: S, ) -> Result<Client, JoinError> { |
