aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins/brand.rs
blob: cf179e71dfdf89fd9959810351bc763b69a0e86a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use azalea_buf::AzaleaWrite;
use azalea_core::resource_location::ResourceLocation;
use azalea_protocol::{
    common::client_information::ClientInformation,
    packets::config::{
        s_client_information::ServerboundClientInformation,
        s_custom_payload::ServerboundCustomPayload,
    },
};
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use tracing::{debug, warn};

use super::packet::config::SendConfigPacketEvent;
use crate::packet::login::InLoginState;

pub struct BrandPlugin;
impl Plugin for BrandPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Update, handle_end_login_state);
    }
}

pub fn handle_end_login_state(
    mut commands: Commands,
    mut removed: RemovedComponents<InLoginState>,
    query: Query<&ClientInformation>,
) {
    for entity in removed.read() {
        let mut brand_data = Vec::new();
        // azalea pretends to be vanilla everywhere else so it makes sense to lie here
        // too
        "vanilla".azalea_write(&mut brand_data).unwrap();
        commands.trigger(SendConfigPacketEvent::new(
            entity,
            ServerboundCustomPayload {
                identifier: ResourceLocation::new("brand"),
                data: brand_data.into(),
            },
        ));

        let client_information = match query.get(entity).ok() {
            Some(i) => i,
            None => {
                warn!(
                    "ClientInformation component was not set before leaving login state, using a default"
                );
                &ClientInformation::default()
            }
        };

        debug!("Writing ClientInformation while in config state: {client_information:?}");
        commands.trigger(SendConfigPacketEvent::new(
            entity,
            ServerboundClientInformation {
                information: client_information.clone(),
            },
        ));
    }
}