1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

fix tests

This commit is contained in:
mat 2025-04-11 17:07:06 -11:00
parent 7a3246dc1a
commit a2389a7830
10 changed files with 33 additions and 24 deletions

View file

@ -175,15 +175,13 @@ fn read_named_fields(
} }
fn read_unnamed_fields(unnamed: &Punctuated<Field, Comma>) -> Vec<proc_macro2::TokenStream> { fn read_unnamed_fields(unnamed: &Punctuated<Field, Comma>) -> Vec<proc_macro2::TokenStream> {
let read_fields = unnamed unnamed
.iter() .iter()
.map(|f| { .map(|f| {
let reader_call = get_reader_call(f); let reader_call = get_reader_call(f);
quote! { #reader_call } quote! { #reader_call }
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>()
read_fields
} }
fn get_reader_call(f: &Field) -> proc_macro2::TokenStream { 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 // do a different buf.write_* for each field depending on the type
// if it's a string, use buf.write_string // if it's a string, use buf.write_string
let reader_call = match field_type { match field_type {
syn::Type::Path(_) | syn::Type::Array(_) => { syn::Type::Path(_) | syn::Type::Array(_) => {
if is_variable_length { if is_variable_length {
quote! { quote! {
@ -231,7 +229,5 @@ fn get_reader_call(f: &Field) -> proc_macro2::TokenStream {
f.ident.clone(), f.ident.clone(),
field_type.to_token_stream() field_type.to_token_stream()
), ),
}; }
reader_call
} }

View file

@ -507,7 +507,7 @@ impl Client {
/// view_distance: 2, /// view_distance: 2,
/// ..Default::default() /// ..Default::default()
/// }) /// })
/// .await?; /// .await;
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```

View file

@ -67,10 +67,6 @@ pub fn read_packets(ecs: &mut World) {
trace!("Received injected packet with bytes: {raw_packet:?}"); trace!("Received injected packet with bytes: {raw_packet:?}");
handle_raw_packet(ecs, &raw_packet, entity, state, &mut queued_packet_events).unwrap(); 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;
} }
} }

View file

@ -89,8 +89,8 @@ impl ConfigPacketHandler<'_> {
}); });
} }
pub fn finish_configuration(&mut self, p: &ClientboundFinishConfiguration) { pub fn finish_configuration(&mut self, _p: &ClientboundFinishConfiguration) {
debug!("got FinishConfiguration packet: {p:?}"); debug!("got FinishConfiguration packet");
as_system::<(Commands, Query<&mut RawConnection>)>( as_system::<(Commands, Query<&mut RawConnection>)>(
self.ecs, self.ecs,

View file

@ -16,12 +16,12 @@ use crate::{PlayerInfo, client::InGameState, connection::RawConnection};
/// An event that's sent when we receive a packet. /// 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 azalea_protocol::packets::game::ClientboundGamePacket;
/// # use bevy_ecs::event::EventReader; /// # use bevy_ecs::event::EventReader;
/// ///
/// fn handle_packets(mut events: EventReader<ReceivePacketEvent>) { /// fn handle_packets(mut events: EventReader<ReceiveGamePacketEvent>) {
/// for ReceivePacketEvent { /// for ReceiveGamePacketEvent {
/// entity, /// entity,
/// packet, /// packet,
/// } in events.read() { /// } in events.read() {

View file

@ -1,5 +1,6 @@
use std::{fmt::Debug, sync::Arc}; use std::{fmt::Debug, sync::Arc};
use azalea_auth::game_profile::GameProfile;
use azalea_buf::AzaleaWrite; use azalea_buf::AzaleaWrite;
use azalea_core::delta::PositionDelta8; use azalea_core::delta::PositionDelta8;
use azalea_core::game_type::{GameMode, OptionalGameType}; use azalea_core::game_type::{GameMode, OptionalGameType};
@ -26,7 +27,9 @@ use uuid::Uuid;
use crate::connection::RawConnection; use crate::connection::RawConnection;
use crate::disconnect::DisconnectEvent; 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. /// A way to simulate a client in a server, used for some internal tests.
pub struct Simulation { pub struct Simulation {
@ -50,7 +53,13 @@ impl Simulation {
tick_app(&mut app); tick_app(&mut app);
// start in the config state // 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); tick_app(&mut app);
let mut simulation = Self { app, entity, rt }; let mut simulation = Self { app, entity, rt };
@ -84,7 +93,7 @@ impl Simulation {
pub fn receive_packet<P: ProtocolPacket + Debug>(&mut self, packet: impl Packet<P>) { pub fn receive_packet<P: ProtocolPacket + Debug>(&mut self, packet: impl Packet<P>) {
let buf = azalea_protocol::write::serialize_packet(&packet.into_variant()).unwrap(); let buf = azalea_protocol::write::serialize_packet(&packet.into_variant()).unwrap();
self.with_component_mut::<RawConnection>(|raw_conn| { self.with_component_mut::<RawConnection>(|raw_conn| {
raw_conn.injected_clientbound_packets.push(buf.clone()); raw_conn.injected_clientbound_packets.push(buf);
}); });
} }

View file

@ -12,6 +12,8 @@ use simdnbt::owned::{NbtCompound, NbtTag};
#[test] #[test]
fn test_change_dimension_to_nether_and_back() { 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(true);
generic_test_change_dimension_to_nether_and_back(false); 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::<InConfigState>()); assert!(simulation.has_component::<InConfigState>());
assert!(!simulation.has_component::<InGameState>()); assert!(!simulation.has_component::<InGameState>());
println!("meow 1");
simulation.receive_packet(ClientboundRegistryData { simulation.receive_packet(ClientboundRegistryData {
registry_id: ResourceLocation::new("minecraft:dimension_type"), registry_id: ResourceLocation::new("minecraft:dimension_type"),
entries: vec![ entries: vec![
@ -67,6 +71,8 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) {
simulation.receive_packet(ClientboundFinishConfiguration); simulation.receive_packet(ClientboundFinishConfiguration);
simulation.tick(); simulation.tick();
println!("meow 2");
assert!(!simulation.has_component::<InConfigState>()); assert!(!simulation.has_component::<InConfigState>());
assert!(simulation.has_component::<InGameState>()); assert!(simulation.has_component::<InGameState>());
assert!(simulation.has_component::<LocalEntity>()); assert!(simulation.has_component::<LocalEntity>());
@ -81,6 +87,8 @@ fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) {
)); ));
simulation.tick(); simulation.tick();
println!("meow 3");
assert_eq!( assert_eq!(
*simulation.component::<InstanceName>(), *simulation.component::<InstanceName>(),
ResourceLocation::new("azalea:a"), ResourceLocation::new("azalea:a"),

View file

@ -20,7 +20,7 @@ pub struct State {}
async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> { async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
if let Event::Chat(m) = event { if let Event::Chat(m) = event {
if let (Some(sender), content) = m.split_sender_and_content() { 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 return Ok(()); // ignore our own messages
} }
bot.chat(&content); bot.chat(&content);

View file

@ -26,7 +26,7 @@ struct State {
async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
if let Event::Chat(m) = event { if let Event::Chat(m) = event {
if m.sender() == Some(bot.profile().name.clone()) { if m.sender() == Some(bot.username()) {
return Ok(()); return Ok(());
}; };
if m.content() != "go" { if m.content() != "go" {

View file

@ -24,7 +24,7 @@ async fn main() {
async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
match event { match event {
Event::Chat(m) => { Event::Chat(m) => {
if m.sender() == Some(bot.profile.name) { if m.sender() == Some(bot.username()) {
return Ok(()); return Ok(());
}; };
if m.content() == "go" { if m.content() == "go" {