azalea_client/plugins/
brand.rs

1use azalea_buf::AzaleaWrite;
2use azalea_core::resource_location::ResourceLocation;
3use azalea_protocol::{
4    common::client_information::ClientInformation,
5    packets::config::{
6        s_client_information::ServerboundClientInformation,
7        s_custom_payload::ServerboundCustomPayload,
8    },
9};
10use bevy_app::prelude::*;
11use bevy_ecs::prelude::*;
12use tracing::{debug, warn};
13
14use super::packet::config::SendConfigPacketEvent;
15use crate::packet::login::InLoginState;
16
17pub struct BrandPlugin;
18impl Plugin for BrandPlugin {
19    fn build(&self, app: &mut App) {
20        app.add_systems(
21            Update,
22            handle_end_login_state.before(crate::packet::config::handle_outgoing_packets),
23        );
24    }
25}
26
27pub fn handle_end_login_state(
28    mut removed: RemovedComponents<InLoginState>,
29    query: Query<&ClientInformation>,
30    mut send_packet_events: EventWriter<SendConfigPacketEvent>,
31) {
32    for entity in removed.read() {
33        let mut brand_data = Vec::new();
34        // azalea pretends to be vanilla everywhere else so it makes sense to lie here
35        // too
36        "vanilla".azalea_write(&mut brand_data).unwrap();
37        send_packet_events.send(SendConfigPacketEvent::new(
38            entity,
39            ServerboundCustomPayload {
40                identifier: ResourceLocation::new("brand"),
41                data: brand_data.into(),
42            },
43        ));
44
45        let client_information = match query.get(entity).ok() {
46            Some(i) => i,
47            None => {
48                warn!(
49                    "ClientInformation component was not set before leaving login state, using a default"
50                );
51                &ClientInformation::default()
52            }
53        };
54
55        debug!("Writing ClientInformation while in config state: {client_information:?}");
56        send_packet_events.send(SendConfigPacketEvent::new(
57            entity,
58            ServerboundClientInformation {
59                information: client_information.clone(),
60            },
61        ));
62    }
63}