aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/test_utils
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-26 15:24:41 +0930
committermat <git@matdoes.dev>2025-06-25 16:10:15 -1345
commitf12589ab809ece7dfd34c58b2ddc67dd5801ccb3 (patch)
tree7ffef4672378715c92d82749d3ef1a82cc7f9f24 /azalea-client/src/test_utils
parent08c409d04896e7057c31250f2d6f99c75b8af5b5 (diff)
downloadazalea-drasl-f12589ab809ece7dfd34c58b2ddc67dd5801ccb3.tar.xz
fix invalid look directions on teleport
Diffstat (limited to 'azalea-client/src/test_utils')
-rw-r--r--azalea-client/src/test_utils/simulation.rs69
1 files changed, 65 insertions, 4 deletions
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<Mutex<VecDeque<ServerboundGamePacket>>>,
+}
+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<SendPacketEvent>| {
+ 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<ServerboundGamePacket> {
+ self.list.lock().pop_front()
+ }
+}
+
#[allow(clippy::type_complexity)]
fn create_local_player_bundle(
entity: Entity,