From 29ab66935e357a547da200a59af3162e36dbef93 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 06:17:48 +0100 Subject: [PATCH 1/2] Restart a break when the held item changes and reset the attack strength when it stops --- crates/horizon-client/src/game/hand.rs | 9 ++++++--- crates/horizon-client/src/game/remote.rs | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game/hand.rs b/crates/horizon-client/src/game/hand.rs index d91d3b979..7c12223c9 100644 --- a/crates/horizon-client/src/game/hand.rs +++ b/crates/horizon-client/src/game/hand.rs @@ -144,6 +144,11 @@ impl Game<'_> { let harvest = !facts.requires_tool || self.res.items().correct_for_drops(held, &facts.name); speed / facts.hardness / if harvest { 30.0 } else { 100.0 } } + /// A key for the main-hand stack (`destroyingItem`): its item and components. + pub(super) fn main_hand_key(&self) -> String { + self.held() + .map_or(String::new(), |s| format!("{} {:?}", s.item, s.extra)) + } /// Whether an attack would hit an entity rather than the block behind /// it: the crosshair's `EntityHitResult`. pub(super) fn entity_targeted(&self) -> bool { @@ -445,9 +450,7 @@ impl HandWorld for GameHands<'_, '_> { true } fn main_hand_key(&mut self) -> String { - self.game - .held() - .map_or(String::new(), |s| format!("{} {:?}", s.item, s.extra)) + self.game.main_hand_key() } fn destroy_stage(&mut self, _: [i32; 3], _: Option) {} fn swing(&mut self, hand: Hand, animation: SwingAnimation) { diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 77e143f9a..d128602c1 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -187,6 +187,8 @@ pub(super) struct Remote { /// The local player's profile name: its score holder and team member. pub(super) profile_name: String, destroying: Option<([i32; 3], u8, f32)>, + /// `MultiPlayerGameMode.destroyingItem`: the held item key the break began with. + destroying_item: String, destroy_delay: u32, input: horizon_client::interaction_input::InteractionInput, stop_mining: bool, @@ -471,6 +473,7 @@ impl Game<'_> { profile: 0, profile_name: String::new(), destroying: None, + destroying_item: String::new(), destroy_delay: 0, input: Default::default(), stop_mining: false, @@ -3837,6 +3840,8 @@ impl Game<'_> { } } + /// `MultiPlayerGameMode.stopDestroyBlock`: aborts the break and starts + /// the attack strength again. pub(super) fn stop_remote_mining(&mut self) { if let Some((pos, _, _)) = self.remote.as_mut().and_then(|r| r.destroying.take()) { self.send(S::PlayerAction(play::PlayerAction { @@ -3845,6 +3850,7 @@ impl Game<'_> { direction: 0, sequence: 0, })); + self.reset_attack_strength(); } } @@ -3898,11 +3904,11 @@ impl Game<'_> { } else { self.destroy_progress(hit.pos) }; - let same = self - .remote - .as_ref() - .and_then(|r| r.destroying) - .is_some_and(|(p, _, _)| p == hit.pos); + // sameDestroyTarget: the same block and still the item the break began with. + let held = self.main_hand_key(); + let same = self.remote.as_ref().is_some_and(|r| { + r.destroying.is_some_and(|(p, _, _)| p == hit.pos) && r.destroying_item == held + }); if start && same { return; } @@ -3929,6 +3935,7 @@ impl Game<'_> { } if let Some(r) = self.remote.as_mut() { r.destroying = Some((hit.pos, face, 0.0)); + r.destroying_item = held; } self.mining = Some(Mining { pos: hit.pos, From 6d69bba15ee6630c2bb88e48b0c34deb9e317508 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 06:24:05 +0100 Subject: [PATCH 2/2] Remote mining test fixture: the held-item key and the attack strength reset --- tests/test_remote_mining.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_remote_mining.py b/tests/test_remote_mining.py index 9feb255fa..b940eefb5 100644 --- a/tests/test_remote_mining.py +++ b/tests/test_remote_mining.py @@ -26,7 +26,7 @@ class RemoteMiningTests(unittest.TestCase): struct Hit { pos: [i32; 3], face: u8 } struct Mining { pos: [i32; 3], progress: f32, ticks: u32 } #[derive(Default)] -struct Remote { destroy_delay: u32, destroying: Option<([i32; 3], u8, f32)> } +struct Remote { destroy_delay: u32, destroying: Option<([i32; 3], u8, f32)>, destroying_item: String } struct Ground { on_ground: bool } struct Player { ground: Ground } #[derive(Clone)] @@ -70,6 +70,8 @@ struct Game { hit: Hit, sequence: i32, packets: Vec, } impl Game { + fn main_hand_key(&self) -> String { String::new() } + fn reset_attack_strength(&mut self) {} fn new(hardness: f32, speed: f32, creative: bool) -> Self { Self { remote: Some(Remote::default()), mining: None, creative,