aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/tests
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-09-20 20:35:16 -1200
committermat <git@matdoes.dev>2025-09-20 20:35:16 -1200
commit585b51e91a5335eae37bc5af7c0111bb2092b156 (patch)
treec1559014df9db20dd625d9fe972d4e9f88317008 /azalea-client/tests
parentdb793448ff8e656ad80859835edc3b89cb547dd2 (diff)
downloadazalea-drasl-585b51e91a5335eae37bc5af7c0111bb2092b156.tar.xz
more accurate mining and impl PartialEq for packets
Diffstat (limited to 'azalea-client/tests')
-rw-r--r--azalea-client/tests/correct_sneak_movement.rs20
-rw-r--r--azalea-client/tests/mine_block_timing.rs127
2 files changed, 128 insertions, 19 deletions
diff --git a/azalea-client/tests/correct_sneak_movement.rs b/azalea-client/tests/correct_sneak_movement.rs
index cf1d17b5..9a9e8f4f 100644
--- a/azalea-client/tests/correct_sneak_movement.rs
+++ b/azalea-client/tests/correct_sneak_movement.rs
@@ -8,7 +8,6 @@ use azalea_protocol::{
common::movements::{PositionMoveRotation, RelativeMovements},
packets::{
ConnectionProtocol,
- config::{ClientboundFinishConfiguration, ClientboundRegistryData},
game::{
ClientboundBlockUpdate, ClientboundPlayerPosition, ServerboundGamePacket,
ServerboundPlayerInput,
@@ -16,31 +15,14 @@ use azalea_protocol::{
},
};
use azalea_registry::{Block, DataRegistry, DimensionType};
-use simdnbt::owned::{NbtCompound, NbtTag};
#[test]
fn test_correct_sneak_movement() {
init_tracing();
- let mut simulation = Simulation::new(ConnectionProtocol::Configuration);
+ let mut simulation = Simulation::new(ConnectionProtocol::Game);
let sent_packets = SentPackets::new(&mut simulation);
- simulation.receive_packet(ClientboundRegistryData {
- registry_id: ResourceLocation::new("minecraft:dimension_type"),
- entries: vec![(
- ResourceLocation::new("minecraft:overworld"),
- Some(NbtCompound::from_values(vec![
- ("height".into(), NbtTag::Int(384)),
- ("min_y".into(), NbtTag::Int(-64)),
- ])),
- )]
- .into_iter()
- .collect(),
- });
- simulation.tick();
- simulation.receive_packet(ClientboundFinishConfiguration);
- simulation.tick();
-
simulation.receive_packet(make_basic_login_packet(
DimensionType::new_raw(0), // overworld
ResourceLocation::new("minecraft:overworld"),
diff --git a/azalea-client/tests/mine_block_timing.rs b/azalea-client/tests/mine_block_timing.rs
new file mode 100644
index 00000000..1216f178
--- /dev/null
+++ b/azalea-client/tests/mine_block_timing.rs
@@ -0,0 +1,127 @@
+use azalea_client::{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, ServerboundGamePacket,
+ ServerboundPlayerAction, ServerboundSwing, s_interact::InteractionHand,
+ s_player_action,
+ },
+ },
+};
+use azalea_registry::{Block, DataRegistry, DimensionType};
+
+#[test]
+fn test_mine_block_timing() {
+ 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()));
+ println!("set serverside stone");
+ simulation.with_component_mut::<LookDirection>(|look| {
+ // look down
+ look.update_x_rot(90.);
+ });
+
+ simulation.tick();
+ simulation.tick();
+ simulation.tick();
+
+ simulation.send_event(StartMiningBlockEvent {
+ entity: simulation.entity,
+ position: pos,
+ });
+ sent_packets.clear();
+ simulation.tick();
+ sent_packets.expect("ServerboundPlayerAction", |p| {
+ p == &ServerboundGamePacket::PlayerAction(ServerboundPlayerAction {
+ action: s_player_action::Action::StartDestroyBlock,
+ pos,
+ direction: Direction::Up,
+ seq: 1,
+ })
+ });
+ sent_packets.expect("Swing 1", |p| {
+ p == &ServerboundGamePacket::Swing(ServerboundSwing {
+ hand: InteractionHand::MainHand,
+ })
+ .into_variant()
+ });
+ sent_packets.expect("Swing 2", |p| {
+ p == &ServerboundGamePacket::Swing(ServerboundSwing {
+ hand: InteractionHand::MainHand,
+ })
+ .into_variant()
+ });
+ sent_packets.expect_tick_end();
+ sent_packets.expect_empty();
+
+ for i in 3..=151 {
+ simulation.tick();
+ sent_packets.expect(&format!("Swing {i}"), |p| {
+ p == &ServerboundGamePacket::Swing(ServerboundSwing {
+ hand: InteractionHand::MainHand,
+ })
+ .into_variant()
+ });
+ sent_packets.maybe_expect(|p| matches!(p, ServerboundGamePacket::MovePlayerPos(_)));
+ sent_packets.expect_tick_end();
+ sent_packets.expect_empty();
+ }
+
+ simulation.tick();
+ sent_packets.expect(
+ "ServerboundPlayerAction { action: StopDestroyBlock }",
+ |p| {
+ matches!(
+ p,
+ ServerboundGamePacket::PlayerAction(p)
+ if p.action == s_player_action::Action::StopDestroyBlock
+ )
+ },
+ );
+ sent_packets.expect("Last swing", |p| {
+ p == &ServerboundGamePacket::Swing(ServerboundSwing {
+ hand: InteractionHand::MainHand,
+ })
+ .into_variant()
+ });
+
+ for _ in 0..3 {
+ sent_packets.maybe_expect(|p| matches!(p, ServerboundGamePacket::MovePlayerPos(_)));
+ sent_packets.expect_tick_end();
+ sent_packets.expect_empty();
+ simulation.tick();
+ }
+}