diff options
| author | mat <git@matdoes.dev> | 2025-09-21 22:43:55 +0400 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-09-21 22:43:55 +0400 |
| commit | f049eee0496083fe6347e2f4a4f7b8e4512883ee (patch) | |
| tree | b45a9301a9c0225f3a8663f7c0eee0c9c90fb010 /azalea-client/tests | |
| parent | 585b51e91a5335eae37bc5af7c0111bb2092b156 (diff) | |
| download | azalea-drasl-f049eee0496083fe6347e2f4a4f7b8e4512883ee.tar.xz | |
fix packet order for ServerboundSetCarriedItem
Diffstat (limited to 'azalea-client/tests')
| -rw-r--r-- | azalea-client/tests/mine_block_timing.rs | 21 | ||||
| -rw-r--r-- | azalea-client/tests/packet_order_set_carried_item.rs | 110 |
2 files changed, 121 insertions, 10 deletions
diff --git a/azalea-client/tests/mine_block_timing.rs b/azalea-client/tests/mine_block_timing.rs index 1216f178..45648a83 100644 --- a/azalea-client/tests/mine_block_timing.rs +++ b/azalea-client/tests/mine_block_timing.rs @@ -65,23 +65,24 @@ fn test_mine_block_timing() { sent_packets.clear(); simulation.tick(); sent_packets.expect("ServerboundPlayerAction", |p| { - p == &ServerboundGamePacket::PlayerAction(ServerboundPlayerAction { + p == &ServerboundPlayerAction { action: s_player_action::Action::StartDestroyBlock, pos, direction: Direction::Up, seq: 1, - }) + } + .into_variant() }); sent_packets.expect("Swing 1", |p| { - p == &ServerboundGamePacket::Swing(ServerboundSwing { + p == &ServerboundSwing { hand: InteractionHand::MainHand, - }) + } .into_variant() }); sent_packets.expect("Swing 2", |p| { - p == &ServerboundGamePacket::Swing(ServerboundSwing { + p == &ServerboundSwing { hand: InteractionHand::MainHand, - }) + } .into_variant() }); sent_packets.expect_tick_end(); @@ -90,9 +91,9 @@ fn test_mine_block_timing() { for i in 3..=151 { simulation.tick(); sent_packets.expect(&format!("Swing {i}"), |p| { - p == &ServerboundGamePacket::Swing(ServerboundSwing { + p == &ServerboundSwing { hand: InteractionHand::MainHand, - }) + } .into_variant() }); sent_packets.maybe_expect(|p| matches!(p, ServerboundGamePacket::MovePlayerPos(_))); @@ -112,9 +113,9 @@ fn test_mine_block_timing() { }, ); sent_packets.expect("Last swing", |p| { - p == &ServerboundGamePacket::Swing(ServerboundSwing { + p == &ServerboundSwing { hand: InteractionHand::MainHand, - }) + } .into_variant() }); diff --git a/azalea-client/tests/packet_order_set_carried_item.rs b/azalea-client/tests/packet_order_set_carried_item.rs new file mode 100644 index 00000000..358b7b73 --- /dev/null +++ b/azalea-client/tests/packet_order_set_carried_item.rs @@ -0,0 +1,110 @@ +use azalea_client::{ + inventory::SetSelectedHotbarSlotEvent, mining::StartMiningBlockEvent, test_utils::prelude::*, +}; +use azalea_core::{ + direction::Direction, + position::{BlockPos, ChunkPos, Vec3}, + resource_location::ResourceLocation, +}; +use azalea_entity::LookDirection; +use azalea_protocol::{ + common::movements::{PositionMoveRotation, RelativeMovements}, + packets::{ + ConnectionProtocol, Packet, + game::{ + ClientboundBlockUpdate, ClientboundPlayerPosition, ServerboundPlayerAction, + ServerboundSetCarriedItem, ServerboundSwing, s_interact::InteractionHand, + s_player_action, + }, + }, +}; +use azalea_registry::{Block, DataRegistry, DimensionType}; + +#[test] +fn test_packet_order_set_carried_item() { + init_tracing(); + + let mut simulation = Simulation::new(ConnectionProtocol::Game); + let sent_packets = SentPackets::new(&mut simulation); + simulation.receive_packet(make_basic_login_packet( + DimensionType::new_raw(0), + ResourceLocation::new("azalea:overworld"), + )); + + simulation.receive_packet(make_basic_empty_chunk(ChunkPos::new(0, 0), (384 + 64) / 16)); + simulation.tick(); + + let pos = BlockPos::new(0, 2, 0); + simulation.receive_packet(ClientboundBlockUpdate { + pos, + block_state: Block::Stone.into(), + }); + simulation.receive_packet(ClientboundPlayerPosition { + id: 1, + change: PositionMoveRotation { + pos: pos.up(1).center_bottom(), + delta: Vec3::ZERO, + look_direction: LookDirection::default(), + }, + relative: RelativeMovements::all_absolute(), + }); + simulation.tick(); + assert_eq!(simulation.get_block_state(pos), Some(Block::Stone.into())); + simulation.with_component_mut::<LookDirection>(|look| { + // look down + look.update_x_rot(90.); + }); + + simulation.tick(); + simulation.tick(); + simulation.tick(); + + simulation.send_event(SetSelectedHotbarSlotEvent { + entity: simulation.entity, + slot: 1, + }); + simulation.send_event(StartMiningBlockEvent { + entity: simulation.entity, + position: pos, + }); + + sent_packets.clear(); + simulation.tick(); + sent_packets.expect("ServerboundPlayerAction", |p| { + p == &ServerboundPlayerAction { + action: s_player_action::Action::StartDestroyBlock, + pos, + direction: Direction::Up, + seq: 1, + } + .into_variant() + }); + sent_packets.expect("Swing 1", |p| { + p == &ServerboundSwing { + hand: InteractionHand::MainHand, + } + .into_variant() + }); + sent_packets.expect("SetCarriedItem", |p| { + p == &ServerboundSetCarriedItem { slot: 1 }.into_variant() + }); + sent_packets.expect("Swing 2", |p| { + p == &ServerboundSwing { + hand: InteractionHand::MainHand, + } + .into_variant() + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + simulation.tick(); + + sent_packets.expect("Swing", |p| { + p == &ServerboundSwing { + hand: InteractionHand::MainHand, + } + .into_variant() + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); +} |
