From f12589ab809ece7dfd34c58b2ddc67dd5801ccb3 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 26 Jun 2025 15:24:41 +0930 Subject: fix invalid look directions on teleport --- azalea-client/src/test_utils/simulation.rs | 69 ++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'azalea-client/src') diff --git a/azalea-client/src/test_utils/simulation.rs b/azalea-client/src/test_utils/simulation.rs index e7ac8d5b..d898293c 100644 --- a/azalea-client/src/test_utils/simulation.rs +++ b/azalea-client/src/test_utils/simulation.rs @@ -1,4 +1,4 @@ -use std::{fmt::Debug, sync::Arc}; +use std::{collections::VecDeque, fmt::Debug, sync::Arc}; use azalea_auth::game_profile::GameProfile; use azalea_block::BlockState; @@ -19,7 +19,8 @@ use azalea_protocol::{ config::{ClientboundFinishConfiguration, ClientboundRegistryData}, game::{ ClientboundAddEntity, ClientboundLevelChunkWithLight, ClientboundLogin, - ClientboundRespawn, c_level_chunk_with_light::ClientboundLevelChunkPacketData, + ClientboundRespawn, ServerboundGamePacket, + c_level_chunk_with_light::ClientboundLevelChunkPacketData, c_light_update::ClientboundLightUpdatePacketData, }, }, @@ -28,13 +29,13 @@ use azalea_registry::{Biome, DimensionType, EntityKind}; use azalea_world::{Chunk, Instance, MinecraftEntityId, Section, palette::PalettedContainer}; use bevy_app::App; use bevy_ecs::{component::Mutable, prelude::*, schedule::ExecutorKind}; -use parking_lot::RwLock; +use parking_lot::{Mutex, RwLock}; use simdnbt::owned::{NbtCompound, NbtTag}; use uuid::Uuid; use crate::{ InConfigState, LocalPlayerBundle, connection::RawConnection, disconnect::DisconnectEvent, - local_player::InstanceHolder, player::GameProfileComponent, + local_player::InstanceHolder, packet::game::SendPacketEvent, player::GameProfileComponent, }; /// A way to simulate a client in a server, used for some internal tests. @@ -170,6 +171,66 @@ impl Simulation { } } +#[derive(Clone)] +pub struct SentPackets { + pub list: Arc>>, +} +impl SentPackets { + pub fn new(simulation: &mut Simulation) -> Self { + let sent_packets = SentPackets { + list: Default::default(), + }; + + let simulation_entity = simulation.entity; + let sent_packets_clone = sent_packets.clone(); + simulation + .app + .add_observer(move |trigger: Trigger| { + if trigger.sent_by == simulation_entity { + sent_packets_clone + .list + .lock() + .push_back(trigger.event().packet.clone()) + } + }); + + sent_packets + } + + pub fn clear(&self) { + self.list.lock().clear(); + } + + pub fn expect_tick_end(&self) { + self.expect("TickEnd", |p| { + matches!(p, ServerboundGamePacket::ClientTickEnd(_)) + }); + } + pub fn expect_empty(&self) { + let sent_packet = self.next(); + if sent_packet.is_some() { + panic!("Expected no packet, got {sent_packet:?}"); + } + } + pub fn expect( + &self, + expected_formatted: &str, + check: impl FnOnce(&ServerboundGamePacket) -> bool, + ) { + let sent_packet = self.next(); + if let Some(sent_packet) = sent_packet { + if !check(&sent_packet) { + panic!("Expected {expected_formatted}, got {sent_packet:?}"); + } + } else { + panic!("Expected {expected_formatted}, got nothing"); + } + } + pub fn next(&self) -> Option { + self.list.lock().pop_front() + } +} + #[allow(clippy::type_complexity)] fn create_local_player_bundle( entity: Entity, -- cgit v1.2.3