From 67b6e75c0b4361c9aa2fb04ea020410cf0fe5167 Mon Sep 17 00:00:00 2001 From: levzzz <86072227+levzzz5154@users.noreply.github.com> Date: Tue, 27 Oct 2026 04:01:42 +0500 Subject: [PATCH] The container screen's press state does not survive the screen AbstractContainerScreen keeps `isQuickCrafting` and the drag it belongs to on the screen, so every screen starts with its own state. Horizon keeps both on `Game`, and #2052 only dropped them when the pointer was grabbed again, so a press whose release never arrived (the pointer left the window) kept the drag running on the next screen: `Clicks::press` answers `None` for every later press, so the Shift quick move and the clicks on the inventory went dead. The press state now goes with the pointer: `Game::capture` drops it whichever way the pointer changes hands (a screen opens or closes, the window loses focus), and `Clicks::cancel_drag` names the drop. Fixes #1737 Co-Authored-By: minimax-m3.1-flash (Claude Code) --- crates/horizon-client/src/container_screen.rs | 43 +++++++++++++++++++ crates/horizon-client/src/game.rs | 21 +++++---- crates/horizon-client/src/menu.rs | 27 ++++++++++++ 3 files changed, 83 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/container_screen.rs b/crates/horizon-client/src/container_screen.rs index 77c7ad8aa..a7b1794c5 100644 --- a/crates/horizon-client/src/container_screen.rs +++ b/crates/horizon-client/src/container_screen.rs @@ -124,6 +124,18 @@ impl Clicks { self.skip_next_release = true; } + /// The screen that takes the pointer over starts with its own state: + /// `AbstractContainerScreen` holds `isQuickCrafting` and the drag it + /// belongs to on the screen, so a screen that opens (or closes) drops + /// them. A press whose release never arrived -- the pointer left the + /// window -- would otherwise keep the drag running, and `press` answers + /// `None` for every later press, so the quick move and the clicks go + /// dead on every screen after it. + pub fn cancel_drag(&mut self) { + self.quick_crafting = None; + self.skip_next_release = false; + } + /// `mouseClicked` (no double click): the `slotClicked` input it sends on /// `target`, if any. A press holding a stack starts a quick craft drag /// instead. `cloning` is `keyPickItem` with infinite materials. @@ -301,4 +313,35 @@ mod tests { Some(Input::Pickup) ); } + + /// #1737: a press whose release never arrives (the pointer left the + /// window) leaves `isQuickCrafting` set, and `press` answers `None` for + /// every later press, so the Shift quick move and the clicks on the + /// inventory go dead. The drag belongs to the screen that has it + /// (`AbstractContainerScreen` holds `isQuickCrafting`), so the screen + /// that takes the pointer over drops it and the quick move works again. + #[test] + fn a_lost_release_does_not_wedge_the_quick_move() { + let mut clicks = Clicks::default(); + let slot = Target::::Slot(3); + // Pressed with a stack carried: a quick craft drag starts, and its + // release never arrives. + assert_eq!(clicks.press(&slot, Button::Left, false, false, false), None); + assert!(clicks.quick_crafting().is_some()); + // The stuck drag swallows the next press: the Shift quick move stops + // working and the inventory stops answering. + assert_eq!(clicks.press(&slot, Button::Right, true, true, false), None); + // The screen that takes the pointer over starts with its own state. + clicks.cancel_drag(); + assert!(clicks.quick_crafting().is_none()); + // The quick move works again. + assert_eq!( + clicks.press(&slot, Button::Right, true, true, false), + Some(Input::QuickMove) + ); + assert_eq!( + clicks.press(&slot, Button::Left, true, false, false), + Some(Input::Pickup) + ); + } } diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 807a1d2cf..60c857785 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4941,10 +4941,13 @@ impl Game<'_> { if capture && !self.focused { return; } - if capture { - // The inventory's screens are behind us: no drag survives them. - self.reset_inventory_clicks(); - } else { + // The container screen's press state belongs to the screen: a screen + // that takes the pointer over starts with its own state, as + // `AbstractContainerScreen` does, so a press whose release never + // arrived (the pointer left the window) cannot wedge the next + // screen's quick move and clicks. + self.reset_inventory_clicks(); + if !capture { self.stop_mining(); } // The real pointer takes over from an agent's. @@ -5788,12 +5791,14 @@ impl Game<'_> { } } /// `AbstractContainerScreen` keeps `isQuickCrafting` and the drag it - /// belongs to on the screen; Horizon keeps them on the game, so they are - /// dropped when a screen closes. A press whose release never reaches the - /// screen (the pointer left the window, or the screen closed first) would + /// belongs to on the screen. Horizon keeps both on `Game` (`inv_clicks`, + /// `inv_drag`, `last_inv_click`), so they are dropped when the pointer + /// changes hands: a screen that opens or closes starts with its own + /// state, and a press whose release never reached the screen -- the + /// pointer left the window, or the screen closed first -- would /// otherwise leave every later press on every later screen swallowed. pub(super) fn reset_inventory_clicks(&mut self) { - self.inv_clicks = Default::default(); + self.inv_clicks.cancel_drag(); self.inv_drag = None; self.last_inv_click = None; } diff --git a/crates/horizon-client/src/menu.rs b/crates/horizon-client/src/menu.rs index 3b2b8fd31..56c8a3b55 100644 --- a/crates/horizon-client/src/menu.rs +++ b/crates/horizon-client/src/menu.rs @@ -3211,4 +3211,31 @@ pub(crate) mod tests { assert_eq!(menu.slot(0), stack("dirt", 1).as_ref()); }); } + + /// #1737: a Shift+Right-Click quick move in a chest (a double chest's + /// 54 slots) moves the stack and leaves the menu's state clean, so the + /// next quick move still moves its stack and the inventory still + /// answers. + #[test] + fn a_chest_quick_move_keeps_the_next_one_working() { + with_menu(Kind::Chest(6), |env, menu| { + menu.creative = false; + // The hotbar holds two stacks; the chest is empty. + menu.set_slot(env, 81, stack("cobblestone", 64)); + menu.set_slot(env, 82, stack("dirt", 32)); + // Shift+Right-Click on the hotbar: the stack goes into the chest. + menu.click(env, 81, 1, Input::QuickMove).unwrap(); + assert_eq!(menu.slot(81), None); + assert_eq!(menu.slot(0).map(|s| s.count), Some(64)); + // Nothing is left on the cursor and no quick craft is running. + assert_eq!(menu.carried, None); + assert_eq!(menu.quick_status, 0); + // The next quick move still works. + menu.click(env, 82, 1, Input::QuickMove).unwrap(); + assert_eq!(menu.slot(82), None); + assert_eq!(menu.slot(1).map(|s| s.count), Some(32)); + assert_eq!(menu.carried, None); + assert_eq!(menu.quick_status, 0); + }); + } }