From 1fc3f6724e11a5a9f7fcd4660151d7243b85ac78 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 19:59:23 -0400 Subject: [PATCH] Cancel block mining immediately when opening screens --- crates/horizon-client/src/game.rs | 3 +++ crates/horizon-client/src/game/hand.rs | 12 ++++++++++++ crates/horizon-client/src/game/remote.rs | 20 ++++++++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index e552eb118..5ffcd9124 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -3648,6 +3648,9 @@ impl Game<'_> { ) || self.book.is_some()) } fn capture(&mut self, capture: bool) { + if !capture { + self.stop_mining(); + } // The real pointer takes over from an agent's. self.agent_pointer = false; let Some(window) = &self.window else { return }; diff --git a/crates/horizon-client/src/game/hand.rs b/crates/horizon-client/src/game/hand.rs index 76d626716..431e6661a 100644 --- a/crates/horizon-client/src/game/hand.rs +++ b/crates/horizon-client/src/game/hand.rs @@ -30,6 +30,18 @@ fn attack_range_contains(range: &serde_json::Value, distance: f64, creative: boo } impl Game<'_> { + /// Opening a screen stops breaking before the next game tick (which may pause). + pub(super) fn stop_mining(&mut self) { + let mut destroying = std::mem::take(&mut self.clicks.destroying); + destroying.stop(&mut GameHands { + game: self, + error: None, + }); + self.clicks.destroying = destroying; + self.attack_clicks = 0; + self.stop_remote_mining(); + self.mining = None; + } /// `LivingEntity.swing` with `getModifiedSwingDuration`. pub(super) fn swing_hand(&mut self, hand: Hand, animation: SwingAnimation) { let effects = &self.potions.effects; diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index aa88896e8..525d6d2bb 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -2071,6 +2071,17 @@ impl Game<'_> { } } + 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 { + action: 2, + pos, + direction: 0, + sequence: 0, + })); + } + } + /// MultiPlayerGameMode.startDestroyBlock / continueDestroyBlock. fn remote_mining(&mut self) { let Some(r) = self.remote.as_mut() else { @@ -2081,14 +2092,7 @@ impl Game<'_> { } let chatting = r.chat_input.is_some(); if !self.left || self.screen != Screen::Playing || chatting { - if let Some((pos, _, _)) = r.destroying.take() { - self.send(S::PlayerAction(play::PlayerAction { - action: 2, - pos, - direction: 0, - sequence: 0, - })); - } + self.stop_remote_mining(); self.mining = None; return; }