From d98ee9a7603f9220239cbcb059664311e12526c3 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:44:57 -0400 Subject: [PATCH] Route mouse-bound hotbar keys through container swaps --- crates/horizon-client/src/game.rs | 12 +++++++ crates/horizon-client/src/keybinds.rs | 49 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 5ffcd9124..3d17c0f74 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -9363,6 +9363,18 @@ impl ApplicationHandler for Game<'_> { } WindowEvent::MouseInput { state, button, .. } => { let pressed = state == ElementState::Pressed; + if matches!(self.screen, Screen::Inventory | Screen::Creative) + && let Some(key) = self + .settings + .keys + .container_mouse_key(button, self.creative) + { + if pressed && self.carried.is_none() { + self.inventory_hotkey(key); + } + // Neither edge of a bound button is an ordinary slot click. + return Ok(()); + } match self.screen { Screen::Playing => { if pressed && !self.captured { diff --git a/crates/horizon-client/src/keybinds.rs b/crates/horizon-client/src/keybinds.rs index 155ffcc24..5f8c0876b 100644 --- a/crates/horizon-client/src/keybinds.rs +++ b/crates/horizon-client/src/keybinds.rs @@ -373,11 +373,60 @@ impl KeyBinds { } Some(Err(button)) } + /// `AbstractContainerScreen.checkHotbarMouseClicked`: off hand, then hotbar. + pub fn container_mouse_key(&self, button: MouseButton, creative: bool) -> Option { + let name = mouse_name(button); + if matches!(button, MouseButton::Left | MouseButton::Right) + || (creative && self.get("key.pickItem") == name) + { + return None; + } + std::iter::once("key.swapOffhand") + .chain( + MAPPINGS + .iter() + .map(|m| m.0) + .filter(|n| n.starts_with("key.hotbar.")), + ) + .find(|mapping| self.get(mapping) == name) + .and_then(|mapping| key_code(Self::default_of(mapping))) + } } #[cfg(test)] mod tests { use super::*; + #[test] + fn container_mouse_hotkeys_follow_slot_bindings_and_pick_item_priority() { + for button in [MouseButton::Back, MouseButton::Forward, MouseButton::Middle] { + for (mapping, default, _) in MAPPINGS.iter().filter(|m| m.0.starts_with("key.hotbar.")) + { + let mut keys = KeyBinds::default(); + keys.set(mapping, &mouse_name(button)); + assert_eq!(keys.container_mouse_key(button, false), key_code(default)); + assert_eq!( + keys.container_mouse_key(button, true), + if button == MouseButton::Middle { + None + } else { + key_code(default) + } + ); + } + } + let mut keys = KeyBinds::default(); + keys.set("key.hotbar.1", "key.mouse.4"); + keys.set("key.swapOffhand", "key.mouse.4"); + assert_eq!( + keys.container_mouse_key(MouseButton::Back, false), + Some(KeyCode::KeyF) + ); + keys.set("key.hotbar.2", "key.mouse.left"); + assert_eq!(keys.container_mouse_key(MouseButton::Left, false), None); + assert_eq!(keys.container_mouse_key(MouseButton::Right, false), None); + assert_eq!(keys.container_mouse_key(MouseButton::Forward, false), None); + } + #[test] fn rebinding_translates_to_defaults() { let mut k = KeyBinds::default();