From b0a2a809331b0f781517649857d31e0aec67d300 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 14 Dec 2025 15:34:03 +0930 Subject: fix mining delay being applied incorrectly --- azalea-client/src/plugins/mining.rs | 14 ++++++++---- azalea-client/tests/mine_block_timing_hand.rs | 33 ++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/azalea-client/src/plugins/mining.rs b/azalea-client/src/plugins/mining.rs index 869e7ac9..6f00c054 100644 --- a/azalea-client/src/plugins/mining.rs +++ b/azalea-client/src/plugins/mining.rs @@ -40,6 +40,7 @@ impl Plugin for MiningPlugin { update_mining_component, handle_auto_mine, handle_mining_queued, + decrement_mine_delay, continue_mining_block, ) .chain() @@ -594,6 +595,14 @@ pub fn handle_stop_mining_block_event( } } +pub fn decrement_mine_delay(mut query: Query<&mut MineDelay>) { + for mut mine_delay in &mut query { + if **mine_delay > 0 { + **mine_delay -= 1; + } + } +} + #[allow(clippy::too_many_arguments, clippy::type_complexity)] pub fn continue_mining_block( mut query: Query<( @@ -635,11 +644,6 @@ pub fn continue_mining_block( mut prediction_handler, ) in query.iter_mut() { - if **mine_delay > 0 { - **mine_delay -= 1; - continue; - } - if game_mode.current == GameMode::Creative { // TODO: worldborder check **mine_delay = 5; diff --git a/azalea-client/tests/mine_block_timing_hand.rs b/azalea-client/tests/mine_block_timing_hand.rs index 6f583e7b..d3dd9c30 100644 --- a/azalea-client/tests/mine_block_timing_hand.rs +++ b/azalea-client/tests/mine_block_timing_hand.rs @@ -29,10 +29,15 @@ fn test_mine_block_timing_hand() { simulation.tick(); let pos = BlockPos::new(0, 2, 0); + let pos2 = BlockPos::new(0, 1, 0); simulation.receive_packet(ClientboundBlockUpdate { pos, block_state: BlockKind::Stone.into(), }); + simulation.receive_packet(ClientboundBlockUpdate { + pos: pos2, + block_state: BlockKind::Stone.into(), + }); simulation.receive_packet(ClientboundPlayerPosition { id: 1, change: PositionMoveRotation { @@ -64,7 +69,7 @@ fn test_mine_block_timing_hand() { }); sent_packets.clear(); simulation.tick(); - sent_packets.expect("ServerboundPlayerAction", |p| { + sent_packets.expect("PlayerAction", |p| { p == &ServerboundPlayerAction { action: s_player_action::Action::StartDestroyBlock, pos, @@ -119,10 +124,32 @@ fn test_mine_block_timing_hand() { .into_variant() }); - for _ in 0..3 { - sent_packets.maybe_expect(|p| matches!(p, ServerboundGamePacket::MovePlayerPos(_))); + for _ in 0..5 { + sent_packets.expect("MovePlayerPos", |p| { + matches!(p, ServerboundGamePacket::MovePlayerPos(_)) + }); sent_packets.expect_tick_end(); sent_packets.expect_empty(); simulation.tick(); } + + // mine the block again to make sure that it takes the same number of ticks + simulation.write_message(StartMiningBlockEvent { + entity: simulation.entity, + position: pos2, + force: false, + }); + for _ in 0..150 { + simulation.tick(); + } + sent_packets.clear(); + simulation.tick(); + + sent_packets.expect("PlayerAction { action: StopDestroyBlock }", |p| { + matches!( + p, + ServerboundGamePacket::PlayerAction(p) + if p.action == s_player_action::Action::StopDestroyBlock + ) + }); } -- cgit v1.2.3