Skip to main content

azalea/client_impl/
client_information.rs

1use azalea_client::ClientInformation;
2use azalea_protocol::packets::game;
3use tracing::debug;
4
5use crate::{Client, client_impl::error::AzaleaResult};
6
7impl Client {
8    /// Tell the server we changed our game options (i.e. render distance, main
9    /// hand).
10    ///
11    /// If this is not set before the login packet, the default will be sent.
12    ///
13    /// ```rust,no_run
14    /// # use azalea::{Client, ClientInformation};
15    /// # async fn example(bot: Client) -> Result<(), Box<dyn std::error::Error>> {
16    /// bot.set_client_information(ClientInformation {
17    ///     view_distance: 2,
18    ///     ..Default::default()
19    /// });
20    /// # Ok(())
21    /// # }
22    /// ```
23    pub fn set_client_information(
24        &self,
25        client_information: ClientInformation,
26    ) -> AzaleaResult<()> {
27        self.query_self::<&mut ClientInformation, _>(|mut ci| {
28            *ci = client_information.clone();
29        })?;
30
31        if self.logged_in() {
32            debug!(
33                "Sending client information (already logged in): {:?}",
34                client_information
35            );
36            self.write_packet(game::s_client_information::ServerboundClientInformation {
37                client_information,
38            });
39        }
40
41        Ok(())
42    }
43}