From a2389a7830c3de0fc1d3c25cd67ea592b1200c2b Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 11 Apr 2025 17:07:06 -1100 Subject: [PATCH] fix tests --- azalea-buf/azalea-buf-macros/src/read.rs | 12 ++++-------- azalea-client/src/client.rs | 2 +- azalea-client/src/plugins/connection.rs | 4 ---- azalea-client/src/plugins/packet/config/mod.rs | 4 ++-- azalea-client/src/plugins/packet/game/events.rs | 6 +++--- azalea-client/src/test_simulation.rs | 15 ++++++++++++--- .../tests/change_dimension_to_nether_and_back.rs | 8 ++++++++ azalea/examples/echo.rs | 2 +- azalea/examples/steal.rs | 2 +- azalea/examples/todo/craft_dig_straight_down.rs | 2 +- 10 files changed, 33 insertions(+), 24 deletions(-) diff --git a/azalea-buf/azalea-buf-macros/src/read.rs b/azalea-buf/azalea-buf-macros/src/read.rs index 5f75ad4d..5b4518bb 100644 --- a/azalea-buf/azalea-buf-macros/src/read.rs +++ b/azalea-buf/azalea-buf-macros/src/read.rs @@ -175,15 +175,13 @@ fn read_named_fields( } fn read_unnamed_fields(unnamed: &Punctuated) -> Vec { - let read_fields = unnamed + unnamed .iter() .map(|f| { let reader_call = get_reader_call(f); quote! { #reader_call } }) - .collect::>(); - - read_fields + .collect::>() } fn get_reader_call(f: &Field) -> proc_macro2::TokenStream { @@ -210,7 +208,7 @@ fn get_reader_call(f: &Field) -> proc_macro2::TokenStream { // do a different buf.write_* for each field depending on the type // if it's a string, use buf.write_string - let reader_call = match field_type { + match field_type { syn::Type::Path(_) | syn::Type::Array(_) => { if is_variable_length { quote! { @@ -231,7 +229,5 @@ fn get_reader_call(f: &Field) -> proc_macro2::TokenStream { f.ident.clone(), field_type.to_token_stream() ), - }; - - reader_call + } } diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index d12582f9..d3fe2989 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -507,7 +507,7 @@ impl Client { /// view_distance: 2, /// ..Default::default() /// }) - /// .await?; + /// .await; /// # Ok(()) /// # } /// ``` diff --git a/azalea-client/src/plugins/connection.rs b/azalea-client/src/plugins/connection.rs index b9c695bb..3e5eec1e 100644 --- a/azalea-client/src/plugins/connection.rs +++ b/azalea-client/src/plugins/connection.rs @@ -67,10 +67,6 @@ pub fn read_packets(ecs: &mut World) { trace!("Received injected packet with bytes: {raw_packet:?}"); handle_raw_packet(ecs, &raw_packet, entity, state, &mut queued_packet_events).unwrap(); - - // update the state and for the client - let (_, mut raw_conn_component) = entity_and_conn_query.get_mut(ecs, entity).unwrap(); - raw_conn_component.state = state; } } diff --git a/azalea-client/src/plugins/packet/config/mod.rs b/azalea-client/src/plugins/packet/config/mod.rs index e944d45a..910019a6 100644 --- a/azalea-client/src/plugins/packet/config/mod.rs +++ b/azalea-client/src/plugins/packet/config/mod.rs @@ -89,8 +89,8 @@ impl ConfigPacketHandler<'_> { }); } - pub fn finish_configuration(&mut self, p: &ClientboundFinishConfiguration) { - debug!("got FinishConfiguration packet: {p:?}"); + pub fn finish_configuration(&mut self, _p: &ClientboundFinishConfiguration) { + debug!("got FinishConfiguration packet"); as_system::<(Commands, Query<&mut RawConnection>)>( self.ecs, diff --git a/azalea-client/src/plugins/packet/game/events.rs b/azalea-client/src/plugins/packet/game/events.rs index 3367f02c..68bfb4b3 100644 --- a/azalea-client/src/plugins/packet/game/events.rs +++ b/azalea-client/src/plugins/packet/game/events.rs @@ -16,12 +16,12 @@ use crate::{PlayerInfo, client::InGameState, connection::RawConnection}; /// An event that's sent when we receive a packet. /// ``` -/// # use azalea_client::packet::game::ReceivePacketEvent; +/// # use azalea_client::packet::game::ReceiveGamePacketEvent; /// # use azalea_protocol::packets::game::ClientboundGamePacket; /// # use bevy_ecs::event::EventReader; /// -/// fn handle_packets(mut events: EventReader) { -/// for ReceivePacketEvent { +/// fn handle_packets(mut events: EventReader) { +/// for ReceiveGamePacketEvent { /// entity, /// packet, /// } in events.read() { diff --git a/azalea-client/src/test_simulation.rs b/azalea-client/src/test_simulation.rs index 3e4dd99a..4dec01b4 100644 --- a/azalea-client/src/test_simulation.rs +++ b/azalea-client/src/test_simulation.rs @@ -1,5 +1,6 @@ use std::{fmt::Debug, sync::Arc}; +use azalea_auth::game_profile::GameProfile; use azalea_buf::AzaleaWrite; use azalea_core::delta::PositionDelta8; use azalea_core::game_type::{GameMode, OptionalGameType}; @@ -26,7 +27,9 @@ use uuid::Uuid; use crate::connection::RawConnection; use crate::disconnect::DisconnectEvent; -use crate::{ClientInformation, InConfigState, InstanceHolder, LocalPlayerBundle}; +use crate::{ + ClientInformation, GameProfileComponent, InConfigState, InstanceHolder, LocalPlayerBundle, +}; /// A way to simulate a client in a server, used for some internal tests. pub struct Simulation { @@ -50,7 +53,13 @@ impl Simulation { tick_app(&mut app); // start in the config state - app.world_mut().entity_mut(entity).insert(InConfigState); + app.world_mut().entity_mut(entity).insert(( + InConfigState, + GameProfileComponent(GameProfile::new( + Uuid::from_u128(1234), + "azalea".to_string(), + )), + )); tick_app(&mut app); let mut simulation = Self { app, entity, rt }; @@ -84,7 +93,7 @@ impl Simulation { pub fn receive_packet(&mut self, packet: impl Packet

) { let buf = azalea_protocol::write::serialize_packet(&packet.into_variant()).unwrap(); self.with_component_mut::(|raw_conn| { - raw_conn.injected_clientbound_packets.push(buf.clone()); + raw_conn.injected_clientbound_packets.push(buf); }); } diff --git a/azalea-client/tests/change_dimension_to_nether_and_back.rs b/azalea-client/tests/change_dimension_to_nether_and_back.rs index cc1fcb14..dcc64908 100644 --- a/azalea-client/tests/change_dimension_to_nether_and_back.rs +++ b/azalea-client/tests/change_dimension_to_nether_and_back.rs @@ -12,6 +12,8 @@ use simdnbt::owned::{NbtCompound, NbtTag}; #[test] fn test_change_dimension_to_nether_and_back() { + let _ = tracing_subscriber::fmt().try_init(); + generic_test_change_dimension_to_nether_and_back(true); generic_test_change_dimension_to_nether_and_back(false); } @@ -33,6 +35,8 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { assert!(simulation.has_component::()); assert!(!simulation.has_component::()); + println!("meow 1"); + simulation.receive_packet(ClientboundRegistryData { registry_id: ResourceLocation::new("minecraft:dimension_type"), entries: vec![ @@ -67,6 +71,8 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { simulation.receive_packet(ClientboundFinishConfiguration); simulation.tick(); + println!("meow 2"); + assert!(!simulation.has_component::()); assert!(simulation.has_component::()); assert!(simulation.has_component::()); @@ -81,6 +87,8 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { )); simulation.tick(); + println!("meow 3"); + assert_eq!( *simulation.component::(), ResourceLocation::new("azalea:a"), diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs index 01390982..1e773b7d 100644 --- a/azalea/examples/echo.rs +++ b/azalea/examples/echo.rs @@ -20,7 +20,7 @@ pub struct State {} async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> { if let Event::Chat(m) = event { if let (Some(sender), content) = m.split_sender_and_content() { - if sender == bot.profile.name { + if sender == bot.username() { return Ok(()); // ignore our own messages } bot.chat(&content); diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs index 45d54d27..84f69e55 100644 --- a/azalea/examples/steal.rs +++ b/azalea/examples/steal.rs @@ -26,7 +26,7 @@ struct State { async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { if let Event::Chat(m) = event { - if m.sender() == Some(bot.profile().name.clone()) { + if m.sender() == Some(bot.username()) { return Ok(()); }; if m.content() != "go" { diff --git a/azalea/examples/todo/craft_dig_straight_down.rs b/azalea/examples/todo/craft_dig_straight_down.rs index 4f613adf..0dc8e16d 100644 --- a/azalea/examples/todo/craft_dig_straight_down.rs +++ b/azalea/examples/todo/craft_dig_straight_down.rs @@ -24,7 +24,7 @@ async fn main() { async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { match event { Event::Chat(m) => { - if m.sender() == Some(bot.profile.name) { + if m.sender() == Some(bot.username()) { return Ok(()); }; if m.content() == "go" {