Merge pull request #396 from ludovic111/feat/mouse-tweaks

Mouse Tweaks-style inventory controls (extra, off by default)
This commit is contained in:
Ludovic Marie
2026-10-15 21:08:44 +02:00
committed by GitHub
8 changed files with 464 additions and 23 deletions
@@ -298,6 +298,10 @@ pub const COMMANDS: &[Cmd] = &[
&[p("label", Ty::Rest, "button label")], mcp: true, local: false),
cmd!("click-at", Screens, "click-at X Y [right]", "click at GUI pixel X Y of the window (screen gives button rectangles)", "",
["horizon-ctl click-at 200 120"], &[p("x", Ty::Num, "GUI x"), p("y", Ty::Num, "GUI y"), opt("right", Ty::Bool, "right-click")], mcp: true, local: false),
cmd!("drag-at", Screens, "drag-at [right] X Y X Y...", "press at the first GUI point, move through the others, release at the last", "",
["horizon-ctl drag-at 130 100 148 100 166 100", "horizon-ctl drag-at right 130 100 148 100"], &[p("points", Ty::Rest, "right, then GUI x y pairs")], mcp: true, local: false),
cmd!("scroll-at", Screens, "scroll-at X Y STEPS", "turn the mouse wheel at GUI pixel X Y (positive scrolls up)", "",
["horizon-ctl scroll-at 130 100 -1"], &[p("x", Ty::Num, "GUI x"), p("y", Ty::Num, "GUI y"), p("steps", Ty::Num, "wheel steps")], mcp: true, local: false),
cmd!("type", Screens, "type [--field name|seed] [--replace] TEXT", "type into the focused text field (chat box, world name, anvil, sign...)",
"On the title's create-world screen, --field name|seed picks the field and --replace clears it first; type \\b deletes one character.",
["horizon-ctl type hello everyone", "horizon-ctl type --field name --replace Agent World", "horizon-ctl type --field seed 12345"], &[flag("field", Ty::Enum(&["name", "seed"]), "create-world field to type into"), flag("replace", Ty::Bool, "clear the field first"), p("text", Ty::Rest, "text to type")], mcp: true, local: false),
+32 -2
View File
@@ -94,6 +94,10 @@ pub struct Extras {
pub minimap_rotate: bool,
/// Retry lost multiplayer connections (`reconnect`).
pub auto_reconnect: bool,
/// Mouse Tweaks-style drags in the inventory and storage containers.
pub mouse_tweaks: bool,
/// With them, the wheel over a slot moves its items one at a time.
pub mouse_tweaks_wheel: bool,
}
impl Default for Extras {
fn default() -> Self {
@@ -116,6 +120,8 @@ impl Default for Extras {
minimap_zoom: 1.0,
minimap_rotate: false,
auto_reconnect: false,
mouse_tweaks: false,
mouse_tweaks_wheel: true,
}
}
}
@@ -173,6 +179,8 @@ impl Extras {
}
"minimapRotate" => e.minimap_rotate = flag(e.minimap_rotate),
"autoReconnect" => e.auto_reconnect = flag(e.auto_reconnect),
"mouseTweaks" => e.mouse_tweaks = flag(e.mouse_tweaks),
"mouseTweaksWheel" => e.mouse_tweaks_wheel = flag(e.mouse_tweaks_wheel),
_ => {}
}
}
@@ -180,7 +188,7 @@ impl Extras {
}
pub fn serialize(&self) -> String {
format!(
"zoom:{}\nzoomKey:{}\nzoomLevel:{}\nzoomSmooth:{}\nzoomSensitivity:{}\nfps:{}\nfpsCorner:{}\nfpsLows:{}\nkeystrokes:{}\nkeystrokesCorner:{}\nkeystrokesCps:{}\nminimap:{}\nminimapCorner:{}\nminimapSize:{}\nminimapShape:{}\nminimapZoom:{}\nminimapRotate:{}\nautoReconnect:{}\n",
"zoom:{}\nzoomKey:{}\nzoomLevel:{}\nzoomSmooth:{}\nzoomSensitivity:{}\nfps:{}\nfpsCorner:{}\nfpsLows:{}\nkeystrokes:{}\nkeystrokesCorner:{}\nkeystrokesCps:{}\nminimap:{}\nminimapCorner:{}\nminimapSize:{}\nminimapShape:{}\nminimapZoom:{}\nminimapRotate:{}\nautoReconnect:{}\nmouseTweaks:{}\nmouseTweaksWheel:{}\n",
bool_text(self.zoom),
self.zoom_key,
self.zoom_level,
@@ -203,6 +211,8 @@ impl Extras {
self.minimap_zoom,
bool_text(self.minimap_rotate),
bool_text(self.auto_reconnect),
bool_text(self.mouse_tweaks),
bool_text(self.mouse_tweaks_wheel),
)
}
/// Written only once something differs from the defaults, so a vanilla
@@ -404,6 +414,8 @@ pub enum Item {
MinimapZoom,
MinimapRotate,
AutoReconnect,
MouseTweaks,
MouseTweaksWheel,
}
/// The Extras page: headers and items.
pub fn rows() -> Vec<Result<Item, &'static str>> {
@@ -430,6 +442,9 @@ pub fn rows() -> Vec<Result<Item, &'static str>> {
Ok(Keystrokes),
Ok(KeystrokesCorner),
Ok(KeystrokesCps),
Err("Inventory"),
Ok(MouseTweaks),
Ok(MouseTweaksWheel),
Err("Multiplayer"),
Ok(AutoReconnect),
]
@@ -465,6 +480,8 @@ impl Item {
Item::MinimapZoom => "Zoom",
Item::MinimapRotate => "Turn with the player",
Item::AutoReconnect => "Auto-reconnect",
Item::MouseTweaks => "Mouse Tweaks controls",
Item::MouseTweaksWheel => "Scroll wheel moves items",
Item::FpsLows => "Minimum and 1% low",
Item::Keystrokes => "Keystrokes",
Item::KeystrokesCps => "Clicks per second",
@@ -491,6 +508,12 @@ impl Item {
"Rejoins a server after a lost connection or a restart, never after a kick or ban."
}
Item::FpsLows => "The slowest frame and the 1% low of the last 5 seconds.",
Item::MouseTweaks => {
"Right-drag places one per slot, left-drag gathers the held item, Shift + left-drag moves every slot."
}
Item::MouseTweaksWheel => {
"Down sends one item of the slot to the other side, up brings one back."
}
Item::Keystrokes => "Movement keys, jump and mouse buttons as you press them.",
Item::KeystrokesCps => "Clicks in the last second under each mouse button.",
}
@@ -501,7 +524,7 @@ impl Item {
match self {
Item::Zoom | Item::Fps | Item::Keystrokes => Some(Cost::None),
Item::Minimap => Some(Cost::Low),
Item::AutoReconnect => Some(Cost::None),
Item::AutoReconnect | Item::MouseTweaks => Some(Cost::None),
_ => None,
}
}
@@ -518,6 +541,8 @@ impl Item {
Item::Minimap => e.minimap,
Item::MinimapRotate => e.minimap_rotate,
Item::AutoReconnect => e.auto_reconnect,
Item::MouseTweaks => e.mouse_tweaks,
Item::MouseTweaksWheel => e.mouse_tweaks_wheel,
_ => return None,
})
}
@@ -560,6 +585,8 @@ impl Item {
Item::Minimap => e.minimap = !e.minimap,
Item::MinimapRotate => e.minimap_rotate = !e.minimap_rotate,
Item::AutoReconnect => e.auto_reconnect = !e.auto_reconnect,
Item::MouseTweaks => e.mouse_tweaks = !e.mouse_tweaks,
Item::MouseTweaksWheel => e.mouse_tweaks_wheel = !e.mouse_tweaks_wheel,
Item::MinimapCorner => e.minimap_corner = next(&Corner::ALL, e.minimap_corner, back),
Item::MinimapSize => {
let sizes: Vec<u8> = MINIMAP_SIZES.iter().map(|s| s.0).collect();
@@ -580,6 +607,7 @@ mod tests {
fn everything_is_off_by_default_and_round_trips() {
let d = Extras::default();
assert!(!d.zoom && !d.fps && !d.keystrokes && !d.minimap && !d.auto_reconnect);
assert!(!d.mouse_tweaks);
assert_eq!(Extras::parse(""), d);
assert_eq!(Extras::parse(&d.serialize()), d);
let mut e = d.clone();
@@ -596,6 +624,8 @@ mod tests {
e.minimap_rotate = true;
e.minimap_corner = Corner::BottomLeft;
e.auto_reconnect = true;
e.mouse_tweaks = true;
e.mouse_tweaks_wheel = false;
assert_eq!(Extras::parse(&e.serialize()), e);
}
+15 -1
View File
@@ -119,6 +119,7 @@ mod totem;
mod trading;
mod trial_spawner;
mod trident;
mod tweaks;
mod ui_control;
mod villagers;
mod wandering_trader;
@@ -692,6 +693,8 @@ struct Game<'a> {
inv_drag: Option<(i32, Vec<usize>)>,
/// `AbstractContainerScreen`'s quick craft and skip-release state.
inv_clicks: horizon_client::container_screen::Clicks,
/// The Mouse Tweaks extra's drag and wheel (`tweaks`).
tweaks: tweaks::Tweaks,
/// The last inventory click, for the double click that gathers a stack.
last_inv_click: Option<(std::time::Instant, usize, bool)>,
/// `lastQuickMoved`: what the last Shift click moved, which a Shift
@@ -4803,6 +4806,9 @@ impl Game<'_> {
}
return;
}
if self.tweak_press(slot, right, shift) {
return;
}
if let Some(slot) = slot
&& shift
&& slot != 200
@@ -4887,6 +4893,9 @@ impl Game<'_> {
}
/// Mouse movement while a quick craft drag is running.
fn inventory_drag_move(&mut self) {
if self.tweaks_on() && self.tweak_drag_move(self.inventory_target().0) {
return;
}
let Some((ty, slots)) = self.inv_drag.clone() else {
return;
};
@@ -5005,6 +5014,7 @@ impl Game<'_> {
/// cancels the drag, drops a stack released outside, or clicks.
fn inventory_mouse_release(&mut self, right: bool) {
use horizon_client::container_screen::{Release, Target};
self.tweak_release();
let (slot, outside) = self.inventory_target();
let dragged = self.inv_drag.as_ref().is_some_and(|(_, s)| !s.is_empty());
let release = self.inv_clicks.release(
@@ -9110,7 +9120,10 @@ impl ApplicationHandler for Game<'_> {
if self.screen == Screen::Creative && d != 0.0 {
self.creative_screen.wheel(f64::from(d), &self.res.names);
}
if self.screen == Screen::Inventory && d != 0.0 {
if self.screen == Screen::Inventory
&& d != 0.0
&& !self.tweak_scroll(d, self.inventory_target().0)
{
self.station_scroll(d);
}
if self.screen == Screen::Stats && d != 0.0 {
@@ -9828,6 +9841,7 @@ pub fn run() -> Result<()> {
craft_grid: vec![None; 9],
craft_size: 2,
inv_drag: None,
tweaks: Default::default(),
inv_clicks: Default::default(),
last_inv_click: None,
last_quick_moved: None,
+92 -14
View File
@@ -16,7 +16,7 @@ use std::{
use winit::{
application::ApplicationHandler,
dpi::PhysicalPosition,
event::{DeviceId, ElementState, MouseButton, WindowEvent},
event::{DeviceId, ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent},
event_loop::ActiveEventLoop,
keyboard::KeyCode,
};
@@ -47,6 +47,8 @@ pub(super) const HELP: &[&str] = &[
"open-inventory open the inventory screen",
"click-button LABEL click a button of the open screen or menu by its label",
"click-at X Y [right] click at GUI pixel X Y of the window",
"drag-at [right] X Y X Y... press at the first GUI point, move through the others, release",
"scroll-at X Y STEPS turn the wheel at GUI pixel X Y (positive scrolls up)",
"command TEXT run a /command",
"pause open the pause menu",
"wait TICKS wait for game ticks to pass",
@@ -788,6 +790,16 @@ impl Game<'_> {
x: f32,
y: f32,
button: MouseButton,
) -> Result<()> {
self.synth_drag(event_loop, &[(x, y)], button)
}
/// The window events of a press at the first GUI point, moves through
/// the others and a release at the last (one point is a click).
fn synth_drag(
&mut self,
event_loop: &ActiveEventLoop,
points: &[(f32, f32)],
button: MouseButton,
) -> Result<()> {
let id = self.window.as_ref().ok_or("no window yet")?.id();
let scale = self
@@ -796,26 +808,37 @@ impl Game<'_> {
.map(|r| horizon_client::hud::HudBatch::new([r.config.width, r.config.height]).scale)
.ok_or("no renderer yet")?;
let device_id = DeviceId::dummy();
let position = PhysicalPosition::new(f64::from(x * scale), f64::from(y * scale));
self.window_event(
event_loop,
id,
WindowEvent::CursorMoved {
device_id,
position,
},
);
for state in [ElementState::Pressed, ElementState::Released] {
for (i, &(x, y)) in points.iter().enumerate() {
let position = PhysicalPosition::new(f64::from(x * scale), f64::from(y * scale));
self.window_event(
event_loop,
id,
WindowEvent::MouseInput {
WindowEvent::CursorMoved {
device_id,
state,
button,
position,
},
);
if i == 0 {
self.window_event(
event_loop,
id,
WindowEvent::MouseInput {
device_id,
state: ElementState::Pressed,
button,
},
);
}
}
self.window_event(
event_loop,
id,
WindowEvent::MouseInput {
device_id,
state: ElementState::Released,
button,
},
);
Ok(())
}
@@ -1294,6 +1317,61 @@ impl Game<'_> {
)?;
ok(json!({ "ok": true, "clicked": w.label, "screen": self.screen_label() }))
}
"drag-at" => {
let right = a.pos.first() == Some(&"right");
let numbers = &a.pos[usize::from(right)..];
let points = numbers
.chunks(2)
.map(|c| match c {
[x, y] => Ok((x.parse::<f32>()?, y.parse::<f32>()?)),
_ => Err("drag-at needs X Y pairs".into()),
})
.collect::<Result<Vec<_>>>()?;
if points.is_empty() {
return Err("drag-at needs X Y pairs".into());
}
let button = if right {
MouseButton::Right
} else {
MouseButton::Left
};
self.synth_drag(event_loop, &points, button)?;
ok(json!({ "ok": true, "screen": self.screen_label() }))
}
"scroll-at" => {
let (x, y) = (a.f64(0, "X")? as f32, a.f64(1, "Y")? as f32);
let steps = a.f64(2, "STEPS")? as f32;
let id = self.window.as_ref().ok_or("no window yet")?.id();
let scale = self
.renderer
.as_ref()
.map(|r| {
horizon_client::hud::HudBatch::new([r.config.width, r.config.height]).scale
})
.ok_or("no renderer yet")?;
let device_id = DeviceId::dummy();
let position = PhysicalPosition::new(f64::from(x * scale), f64::from(y * scale));
self.window_event(
event_loop,
id,
WindowEvent::CursorMoved {
device_id,
position,
},
);
for _ in 0..steps.abs() as u32 {
self.window_event(
event_loop,
id,
WindowEvent::MouseWheel {
device_id,
delta: MouseScrollDelta::LineDelta(0.0, steps.signum()),
phase: TouchPhase::Moved,
},
);
}
ok(json!({ "ok": true, "screen": self.screen_label() }))
}
"click-at" => {
let (x, y) = (a.f64(0, "X")? as f32, a.f64(1, "Y")? as f32);
let button = if a.pos.get(2) == Some(&"right") {
+23 -4
View File
@@ -2419,24 +2419,43 @@ impl Game<'_> {
let Some(internal) = self.slot_at(&batch, self.cursor.0, self.cursor.1) else {
return;
};
let input = if self.has_shift_down() { 1 } else { 0 };
self.remote_slot_click(internal, i8::from(right), input);
}
/// A `ContainerClick` on game slot `internal` of the server's open menu
/// (`input` is the ContainerInput ordinal). False when the menu has no
/// such slot.
pub(super) fn remote_slot_click(&mut self, internal: usize, button: i8, input: i32) -> bool {
let (container, menu) = match self.remote.as_ref().and_then(|r| r.menu.clone()) {
Some((id, name)) => (id, name),
None => (0, "inventory".to_owned()),
};
let slot = (0..64).find(|&s| Self::menu_slot(&menu, s) == Some(internal));
let Some(slot) = slot else { return };
let shift = self.has_shift_down();
let Some(slot) = slot else { return false };
let carried = self.to_network(&self.carried).map(|s| Hashed::of(&s));
let state = self.remote.as_ref().map_or(0, |r| r.state_id);
self.send(S::ContainerClick(play::ContainerClick {
container,
state,
slot: slot as i16,
button: i8::from(right),
input: if shift { 1 } else { 0 },
button,
input,
changed: Vec::new(),
carried,
}));
true
}
/// The server's open menu is the inventory or a chest-like container
/// (chests, barrels, ender chests: `generic_9xN`; shulker boxes).
pub(super) fn remote_storage_open(&self) -> bool {
match self.remote.as_ref().and_then(|r| r.menu.as_ref()) {
None => true,
Some((_, name)) => {
name == "inventory"
|| name.starts_with("minecraft:generic_9x")
|| name == "minecraft:shulker_box"
}
}
}
/// A click outside a server's window (slot -999): predicted like
/// `MultiPlayerGameMode.handleContainerInput` (the carried stack after
+1 -1
View File
@@ -493,7 +493,7 @@ impl Game<'_> {
}
self.station = Some(s);
}
fn max_stack(&self, stack: &ItemStack) -> u32 {
pub(super) fn max_stack(&self, stack: &ItemStack) -> u32 {
self.res.items.get(&stack.item).map_or(64, |i| i.max_stack)
}
/// `Slot.mayPlace` and `getMaxStackSize` for station and brewing slots.
+274
View File
@@ -0,0 +1,274 @@
//! Horizon's Mouse Tweaks-style controls (#332, `docs/extras.md`), off by
//! default: while the extra is off every hook returns false and the screen
//! clicks exactly as vanilla's. Each action is made of ordinary slot clicks
//! (the menu engine's, or `ContainerClick`s on a server), so it works
//! wherever vanilla's clicks do. They run in the player inventory and the
//! chest-like containers (chests, barrels, ender chests, shulker boxes,
//! hoppers, dispensers).
//!
//! - Right-drag holding a stack: one item into each slot entered, at once.
//! - Left-drag holding a stack, before vanilla's drag has spread over a
//! second slot: each slot entered holding the same item is gathered into
//! the hand (when it all fits); with Shift, those slots are quick-moved.
//! - Shift + left-drag with an empty hand: every slot entered is quick-moved.
//! - The wheel over a slot, with an empty hand: down moves one of its items
//! to the other side (container and inventory, or hotbar and inventory),
//! up brings one of the same item back.
use super::{Creative, Game, Screen};
use horizon_client::{containers::BlockEntity, items::ItemStack, menu::Input};
#[derive(Default)]
pub(super) struct Tweaks {
drag: Option<Drag>,
/// Wheel steps not yet acted on (a trackpad scrolls in fractions).
wheel: f32,
}
/// A drag the tweaks follow.
#[derive(Clone, Debug)]
struct Drag {
right: bool,
/// The stack in hand at the press and its count since, as the drag's
/// own clicks change it (a server answers them later).
held: Option<ItemStack>,
/// The drag replaced vanilla's: its release clicks nothing.
active: bool,
visited: Vec<usize>,
}
impl Game<'_> {
/// The open screen is one the tweaks run in, with the extra on.
pub(super) fn tweaks_on(&self) -> bool {
if !self.settings.extras.mouse_tweaks
|| self.screen != Screen::Inventory
|| self.station.is_some()
|| self.mount_active()
{
return false;
}
if self.remote.is_some() {
self.remote_storage_open()
} else {
matches!(self.container_kind(), None | Some(BlockEntity::Chest(_)))
}
}
/// One ordinary click on a game slot. False when nothing took it.
pub(super) fn tweak_click(&mut self, slot: usize, button: i32, input: Input) -> bool {
if self.remote.is_some() {
let ordinal = match input {
Input::Pickup => 0,
Input::QuickMove => 1,
Input::Swap => 2,
Input::Clone => 3,
Input::Throw => 4,
Input::QuickCraft => 5,
Input::PickupAll => 6,
};
return self.remote_slot_click(slot, button as i8, ordinal);
}
if !self.menu_click(Some(slot), button, input) {
return false;
}
if let Some(key) = self.container {
self.container_changed(key);
}
true
}
/// A press on `slot`: true when the tweaks took it (a right-drag
/// placing), else vanilla's press runs and the tweaks watch the drag.
pub(super) fn tweak_press(&mut self, slot: Option<usize>, right: bool, shift: bool) -> bool {
self.tweaks.drag = None;
let Some(slot) = slot.filter(|&s| s != 200 && s < Creative::DISPLAY) else {
return false;
};
if !self.tweaks_on() {
return false;
}
let held = self.carried.clone();
if right {
if shift || held.is_none() {
return false;
}
// RMB: the press places at once, then the drag goes on.
let mut drag = Drag {
right,
held,
active: true,
visited: vec![slot],
};
self.tweak_place(&mut drag, slot);
self.inv_drag = None;
self.inv_clicks.skip_release();
self.tweaks.drag = Some(drag);
return true;
}
if held.is_some() || shift {
self.tweaks.drag = Some(Drag {
right,
held,
active: false,
visited: vec![slot],
});
}
false
}
/// Places one held item in `slot` when it takes it.
fn tweak_place(&mut self, drag: &mut Drag, slot: usize) {
let Some(held) = drag.held.clone() else {
return;
};
let accepts = match self.slot_view(slot) {
None => true,
Some(s) => s.same_item_same_components(&held) && s.count < self.max_stack(&s),
};
if accepts && self.tweak_click(slot, 1, Input::Pickup) {
drag.held = (held.count > 1).then(|| ItemStack {
count: held.count - 1,
..held
});
}
}
/// The cursor moved while a button is held: true when the tweaks own
/// the drag (vanilla's quick craft drag doesn't grow).
pub(super) fn tweak_drag_move(&mut self, slot: Option<usize>) -> bool {
let Some(mut drag) = self.tweaks.drag.take() else {
return false;
};
let active = drag.active;
let entered =
slot.filter(|s| *s != 200 && *s < Creative::DISPLAY && !drag.visited.contains(s));
if let Some(slot) = entered {
drag.visited.push(slot);
let stack = self.slot_view(slot);
let shift = self.has_shift_down();
if drag.right {
self.tweak_place(&mut drag, slot);
} else if let Some(held) = drag.held.clone() {
// Holding a stack: only slots of the same item, and only
// while vanilla's drag hasn't spread.
let spread = self.inv_drag.as_ref().is_some_and(|(_, s)| s.len() > 1);
if let Some(s) = stack.filter(|s| s.same_item_same_components(&held))
&& (drag.active || !spread)
{
if !drag.active {
drag.active = true;
self.inv_drag = None;
self.inv_clicks.skip_release();
}
if shift {
self.tweak_click(slot, 0, Input::QuickMove);
} else if held.count + s.count <= self.max_stack(&s)
&& self.tweak_click(slot, 0, Input::Pickup)
&& self.tweak_click(slot, 0, Input::Pickup)
{
// Put the hand's stack in the slot, then take it all.
drag.held = Some(ItemStack {
count: held.count + s.count,
..held
});
}
}
} else if shift && stack.is_some() {
drag.active = true;
self.tweak_click(slot, 0, Input::QuickMove);
}
}
let owned = drag.active || active;
self.tweaks.drag = Some(drag);
owned
}
/// The button went up: the drag ends.
pub(super) fn tweak_release(&mut self) {
self.tweaks.drag = None;
}
/// The wheel over an inventory screen: true when the tweaks used it.
pub(super) fn tweak_scroll(&mut self, delta: f32, slot: Option<usize>) -> bool {
if !self.settings.extras.mouse_tweaks_wheel || !self.tweaks_on() || self.carried.is_some() {
return false;
}
let Some(slot) = slot.filter(|&s| s != 200) else {
self.tweaks.wheel = 0.0;
return false;
};
self.tweaks.wheel += delta;
let steps = self.tweaks.wheel.trunc();
self.tweaks.wheel -= steps;
for _ in 0..steps.abs() as u32 {
if steps < 0.0 {
self.tweak_push(slot);
} else {
self.tweak_pull(slot);
}
}
true
}
/// The slots across from `slot`, in quick-move order: a container's
/// go to the inventory (hotbar first, from the right), the inventory's
/// to the container; without one, hotbar and main inventory trade.
fn other_side(&self, slot: usize) -> Vec<usize> {
let container: Vec<usize> = self
.slots()
.into_iter()
.filter(|s| (300..500).contains(s))
.collect();
let player = || (0..9).rev().chain((9..36).rev());
match slot {
300..500 => player().collect(),
0..36 if !container.is_empty() => container,
0..9 => (9..36).collect(),
9..36 => (0..9).collect(),
_ => Vec::new(),
}
}
/// Wheel down: one item of `slot` to the other side, where a stack of
/// it has room, else to the first empty slot (`moveItemStackTo`).
fn tweak_push(&mut self, slot: usize) {
let Some(stack) = self.slot_view(slot) else {
return;
};
let max = self.max_stack(&stack);
let side = self.other_side(slot);
let views: Vec<(usize, Option<ItemStack>)> =
side.iter().map(|&s| (s, self.slot_view(s))).collect();
let target = views
.iter()
.find(|(_, v)| {
v.as_ref()
.is_some_and(|v| v.same_item_same_components(&stack) && v.count < max)
})
.or_else(|| views.iter().find(|(_, v)| v.is_none()))
.map(|(s, _)| *s);
let Some(target) = target else {
return;
};
if self.tweak_click(slot, 0, Input::Pickup) {
self.tweak_click(target, 1, Input::Pickup);
if stack.count > 1 {
self.tweak_click(slot, 0, Input::Pickup);
}
}
}
/// Wheel up: one item of the same kind from the other side into `slot`.
fn tweak_pull(&mut self, slot: usize) {
let Some(stack) = self.slot_view(slot) else {
return;
};
if stack.count >= self.max_stack(&stack) {
return;
}
let side = self.other_side(slot);
let source = side.into_iter().find_map(|s| {
self.slot_view(s)
.filter(|v| v.same_item_same_components(&stack))
.map(|v| (s, v.count))
});
let Some((source, count)) = source else {
return;
};
if self.tweak_click(source, 0, Input::Pickup) {
self.tweak_click(slot, 1, Input::Pickup);
if count > 1 {
self.tweak_click(source, 0, Input::Pickup);
}
}
}
}
+23 -1
View File
@@ -1,7 +1,7 @@
# Horizon extras
Optional conveniences built into the client: zoom, a minimap, an FPS counter, a
keystroke overlay and auto-reconnect. **Every one is off by default**: a fresh
keystroke overlay, auto-reconnect and Mouse Tweaks-style inventory controls. **Every one is off by default**: a fresh
install looks and behaves exactly like vanilla 26.3, and turning an extra off
again restores vanilla's behaviour completely.
@@ -15,6 +15,7 @@ again restores vanilla's behaviour completely.
| Minimap colours, tiles and image | `crates/horizon-client/src/minimap.rs` |
| Reconnect policy and backoff | `crates/horizon-client/src/reconnect.rs` |
| Game glue (input hooks, per-frame update) | `crates/horizon-client/src/game/extras.rs` |
| Mouse Tweaks-style controls | `crates/horizon-client/src/game/tweaks.rs` |
| The settings page | `options_horizon.rs`: the **Extras** section of Horizon's Options |
`game.rs` only gets one-line hooks (key, wheel, mouse, frame, HUD), so the
@@ -94,6 +95,27 @@ Horizon category in Controls, and adding one would put a non-vanilla mapping int
with, held in memory for the whole run (`auth::current()`); nothing is
written to disk.
### Mouse Tweaks controls (`mouseTweaks`, default off; `mouseTweaksWheel`, default on)
In the player inventory and chest-like containers (chests, barrels, ender
chests, shulker boxes, hoppers, dispensers), in singleplayer and on servers:
- Right-drag holding a stack: one item goes into each slot entered, at once
(slots holding another item, or full, are skipped).
- Left-drag holding a stack: each slot entered that holds the same item is
gathered into the hand, when it all fits. This takes over only while
vanilla's drag covers one slot, so a left-drag across empty slots still
splits the stack as vanilla does.
- Shift + left-drag: every slot entered is quick-moved (with a stack in hand,
only the slots of its item).
- The wheel over a slot, with an empty hand (`mouseTweaksWheel`): down moves
one item to the other side (container and inventory, or hotbar and main
inventory: to a stack of it with room, else the first empty slot, as
quick-move picks), up brings one of the same item back.
Every action is ordinary slot clicks (`ContainerClick` on a server), so a
vanilla server sees nothing unusual. With the extra off, the hooks return at
once and the screens click exactly as vanilla's (`tools/test_menu_click_parity.py`
and the container screen tests are unchanged).
## Shared rules
- All extras are hidden with F1 and drawn in the HUD layer: under screens, over