aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/configuration.rs
blob: bfaa36f01ee3be7f34e074ac8d1e258bcc3003bc (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
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 crate::{client::InConfigurationState, packet_handling::configuration::SendConfigurationEvent};

pub struct ConfigurationPlugin;
impl Plugin for ConfigurationPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(
            Update,
            handle_in_configuration_state
                .after(crate::packet_handling::configuration::handle_send_packet_event),
        );
    }
}

fn handle_in_configuration_state(
    query: Query<(Entity, &ClientInformation), Added<InConfigurationState>>,
    mut send_packet_events: EventWriter<SendConfigurationEvent>,
) {
    for (entity, client_information) in query.iter() {
        let mut brand_data = Vec::new();
        // they don't have to know :)
        "vanilla".azalea_write(&mut brand_data).unwrap();
        send_packet_events.send(SendConfigurationEvent::new(
            entity,
            ServerboundCustomPayload {
                identifier: ResourceLocation::new("brand"),
                data: brand_data.into(),
            },
        ));

        send_packet_events.send(SendConfigurationEvent::new(
            entity,
            ServerboundClientInformation {
                information: client_information.clone(),
            },
        ));
    }
}