aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins/brand.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-02-22 21:45:26 -0600
committerGitHub <noreply@github.com>2025-02-22 21:45:26 -0600
commite21e1b97bf9337e9f4747cd1b545b1b3a03e2ce7 (patch)
treeadd6f8bfce40d0c07845d8aa4c9945a0b918444c /azalea-client/src/plugins/brand.rs
parentf8130c3c92946d2293634ba4e252d6bc93026c3c (diff)
downloadazalea-drasl-e21e1b97bf9337e9f4747cd1b545b1b3a03e2ce7.tar.xz
Refactor azalea-client (#205)
* start organizing packet_handling more by moving packet handlers into their own functions * finish writing all the handler functions for packets * use macro for generating match statement for packet handler functions * fix set_entity_data * update config state to also use handler functions * organize az-client file structure by moving things into plugins directory * fix merge issues
Diffstat (limited to 'azalea-client/src/plugins/brand.rs')
-rw-r--r--azalea-client/src/plugins/brand.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/azalea-client/src/plugins/brand.rs b/azalea-client/src/plugins/brand.rs
new file mode 100644
index 00000000..e15a6c67
--- /dev/null
+++ b/azalea-client/src/plugins/brand.rs
@@ -0,0 +1,63 @@
+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.before(crate::packet::config::handle_send_packet_event),
+ );
+ }
+}
+
+fn handle_end_login_state(
+ mut removed: RemovedComponents<InLoginState>,
+ query: Query<&ClientInformation>,
+ mut send_packet_events: EventWriter<SendConfigPacketEvent>,
+) {
+ 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();
+ send_packet_events.send(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:?}");
+ send_packet_events.send(SendConfigPacketEvent::new(
+ entity,
+ ServerboundClientInformation {
+ information: client_information.clone(),
+ },
+ ));
+ }
+}