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:
parent
7a3246dc1a
commit
a2389a7830
10 changed files with 33 additions and 24 deletions
|
@ -175,15 +175,13 @@ fn read_named_fields(
|
|||
}
|
||||
|
||||
fn read_unnamed_fields(unnamed: &Punctuated<Field, Comma>) -> Vec<proc_macro2::TokenStream> {
|
||||
let read_fields = unnamed
|
||||
unnamed
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let reader_call = get_reader_call(f);
|
||||
quote! { #reader_call }
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
read_fields
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -507,7 +507,7 @@ impl Client {
|
|||
/// view_distance: 2,
|
||||
/// ..Default::default()
|
||||
/// })
|
||||
/// .await?;
|
||||
/// .await;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<ReceivePacketEvent>) {
|
||||
/// for ReceivePacketEvent {
|
||||
/// fn handle_packets(mut events: EventReader<ReceiveGamePacketEvent>) {
|
||||
/// for ReceiveGamePacketEvent {
|
||||
/// entity,
|
||||
/// packet,
|
||||
/// } in events.read() {
|
||||
|
|
|
@ -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<P: ProtocolPacket + Debug>(&mut self, packet: impl Packet<P>) {
|
||||
let buf = azalea_protocol::write::serialize_packet(&packet.into_variant()).unwrap();
|
||||
self.with_component_mut::<RawConnection>(|raw_conn| {
|
||||
raw_conn.injected_clientbound_packets.push(buf.clone());
|
||||
raw_conn.injected_clientbound_packets.push(buf);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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::<InConfigState>());
|
||||
assert!(!simulation.has_component::<InGameState>());
|
||||
|
||||
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::<InConfigState>());
|
||||
assert!(simulation.has_component::<InGameState>());
|
||||
assert!(simulation.has_component::<LocalEntity>());
|
||||
|
@ -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::<InstanceName>(),
|
||||
ResourceLocation::new("azalea:a"),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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" {
|
||||
|
|
|
@ -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" {
|
||||
|
|
Loading…
Add table
Reference in a new issue