Merge pull request #1086 from ludovic111/fix/creative-middle-click
🤖 Agent: merged. Creative pick block in inventories (fixes #1048, Visivel). Integration proof (main + #1079 #1081 #1082 #1083 #1085 #1086 #1087), 2026-10-21: desktop parity 103/105; the 2 others (world_reopen, save_roundtrip) need a display and pass on the Mac mini. Verify passed.
This commit is contained in:
@@ -282,10 +282,10 @@ pub const COMMANDS: &[Cmd] = &[
|
||||
cmd!("ui", Screens, "ui", "every widget of the open screen: id, kind, label, bounds, value",
|
||||
"Kinds: button, slider (value 0..1), field, row (worlds, servers, packs, languages), tab (selected), slot (slot-ID, with its stack). Ids come from labels (\"FOV: 70\" is fov, a repeat gets -2) or kind-N without one, and stay put when a value changes. Reflects the last drawn frame (frame counts them).",
|
||||
["horizon-ctl ui"], &[], mcp: true, local: false),
|
||||
cmd!("click", Screens, "click ID [right] [shift]", "click a widget of ui by its id, as the mouse would",
|
||||
"A field takes focus (then type); slot-ID clicks a slot like click-slot.",
|
||||
cmd!("click", Screens, "click ID [right|middle] [shift]", "click a widget of ui by its id, as the mouse would",
|
||||
"A field takes focus (then type); slot-ID clicks a slot like click-slot. middle presses the middle button (pick block: a creative player clones the stack).",
|
||||
["horizon-ctl click done", "horizon-ctl click video-settings", "horizon-ctl click row-0", "horizon-ctl click slot-0 shift"],
|
||||
&[p("id", Ty::Str, "widget id from ui"), opt("right", Ty::Bool, "right-click"), opt("shift", Ty::Bool, "shift-click (slots)")], mcp: true, local: false),
|
||||
&[p("id", Ty::Str, "widget id from ui"), opt("right", Ty::Bool, "right-click"), opt("middle", Ty::Bool, "middle-click"), opt("shift", Ty::Bool, "shift-click (slots)")], mcp: true, local: false),
|
||||
cmd!("set", Screens, "set ID VALUE", "move a slider of ui to VALUE (0..1), as a click on its track",
|
||||
"The option behind it rounds to its own steps; read the new label with ui.",
|
||||
["horizon-ctl set fov 0.5", "horizon-ctl set render-distance 0"],
|
||||
|
||||
@@ -5849,6 +5849,62 @@ impl Game<'_> {
|
||||
_ => self.inv_drag = None,
|
||||
}
|
||||
}
|
||||
/// A press of the pick block button (`keyPickItem`, the middle button by
|
||||
/// default) over an inventory screen: `mouseClicked` with `cloning`
|
||||
/// (infinite materials). An empty hand clones the hovered stack at its
|
||||
/// full size (`CLONE`), a carried stack starts a quick craft drag of type
|
||||
/// 2 that fills every slot it crosses; without infinite materials the
|
||||
/// press does nothing.
|
||||
fn inventory_pick_press(&mut self) {
|
||||
use horizon_client::container_screen::{Button, Target};
|
||||
let (slot, outside) = self.inventory_target();
|
||||
let was_crafting = self.inv_clicks.quick_crafting().is_some();
|
||||
let input = self.inv_clicks.press(
|
||||
&Target::of(slot, outside),
|
||||
Button::Middle,
|
||||
self.carried.is_none(),
|
||||
self.has_shift_down(),
|
||||
self.creative,
|
||||
);
|
||||
match (input, slot) {
|
||||
// Slot -999 (outside the window) clones nothing.
|
||||
(Some(input), Some(slot)) if !outside => {
|
||||
self.menu_click(Some(slot), 2, input);
|
||||
}
|
||||
(None, _) if !was_crafting && self.inv_clicks.quick_crafting().is_some() => {
|
||||
// Item tab display slots take no drags.
|
||||
let first = slot.filter(|&s| {
|
||||
s != 200 && s < Creative::DISPLAY && self.quick_craft_accepts(s, 2, 0)
|
||||
});
|
||||
self.inv_drag = Some((2, first.into_iter().collect()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// The pick block button's release (`mouseReleased`): ends its quick
|
||||
/// craft drag, cancels another button's, or clones onto the slot under a
|
||||
/// carried stack (`CLONE`, which only an item tab's display slot takes).
|
||||
fn inventory_pick_release(&mut self) {
|
||||
use horizon_client::container_screen::{Button, Release, Target};
|
||||
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(
|
||||
&Target::of(slot, outside),
|
||||
Button::Middle,
|
||||
self.carried.is_none(),
|
||||
dragged,
|
||||
self.has_shift_down(),
|
||||
true,
|
||||
);
|
||||
match (release, slot) {
|
||||
(Release::QuickCraft, _) => self.inventory_release(),
|
||||
(Release::Click(input), Some(slot)) if !outside => {
|
||||
self.inv_drag = None;
|
||||
self.menu_click(Some(slot), 2, input);
|
||||
}
|
||||
_ => self.inv_drag = None,
|
||||
}
|
||||
}
|
||||
/// Mouse release: finishes a quick craft drag (one slot is a plain click).
|
||||
fn inventory_release(&mut self) {
|
||||
use horizon_client::menu::Input;
|
||||
@@ -10443,6 +10499,25 @@ impl ApplicationHandler for Game<'_> {
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
Screen::Inventory | Screen::Creative
|
||||
if !matches!(button, MouseButton::Left | MouseButton::Right) =>
|
||||
{
|
||||
// AbstractContainerScreen: another button clicks
|
||||
// a slot only as the pick block key (its hotbar
|
||||
// keys were handled above).
|
||||
if self.settings.keys.get("key.pickItem")
|
||||
== horizon_client::keybinds::mouse_name(button)
|
||||
{
|
||||
if pressed {
|
||||
self.inventory_pick_press();
|
||||
} else {
|
||||
self.inventory_pick_release();
|
||||
}
|
||||
if let Some(key) = self.container {
|
||||
self.container_changed(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Screen::Inventory if pressed => {
|
||||
self.inventory_press(button == MouseButton::Right);
|
||||
if let Some(key) = self.container {
|
||||
|
||||
@@ -5,6 +5,7 @@ use super::{Game, Screen, agent::Handled};
|
||||
use horizon_client::{
|
||||
Result,
|
||||
control::Request,
|
||||
creative::Creative,
|
||||
widgets::{self, Kind, Node},
|
||||
};
|
||||
use serde_json::{Value, json};
|
||||
@@ -16,7 +17,7 @@ use winit::{event::MouseButton, event_loop::ActiveEventLoop};
|
||||
|
||||
pub(super) const HELP: &[&str] = &[
|
||||
"ui every widget of the open screen: id, kind, label, bounds, value",
|
||||
"click ID [right] [shift] click a widget of ui by its id (slot-N: as click-slot N)",
|
||||
"click ID [right|middle] [shift] click a widget of ui by its id (slot-N: as click-slot N)",
|
||||
"set ID VALUE move a slider to VALUE (0..1), as a click on its track",
|
||||
];
|
||||
|
||||
@@ -55,7 +56,7 @@ impl Game<'_> {
|
||||
pub(super) fn ui_nodes(&self) -> Vec<Node> {
|
||||
let size = self.gui_scale().map(|b| [b.width, b.height]);
|
||||
let mut nodes = widgets::tree(&widgets::last_labelled(), &widgets::last_targets(), size);
|
||||
if self.screen == Screen::Inventory
|
||||
if matches!(self.screen, Screen::Inventory | Screen::Creative)
|
||||
&& self.title.is_none()
|
||||
&& let Ok((ox, oy)) = self.gui_origin()
|
||||
{
|
||||
@@ -90,6 +91,11 @@ impl Game<'_> {
|
||||
if let Some(slot) = node.id.strip_prefix("slot-").and_then(|s| s.parse().ok()) {
|
||||
let stack = if slot == 200 {
|
||||
self.craft_result()
|
||||
} else if slot >= Creative::DISPLAY {
|
||||
// An item tab's display slot shows the tab's list.
|
||||
let first = self.creative_screen.first_row(&self.pack.names);
|
||||
let items = self.creative_screen.items(&self.pack.names);
|
||||
items.get(first * 9 + slot - Creative::DISPLAY).cloned()
|
||||
} else {
|
||||
self.slot_mut(slot).clone()
|
||||
};
|
||||
@@ -152,7 +158,8 @@ impl Game<'_> {
|
||||
return Err(format!("widget {:?} is disabled", node.id).into());
|
||||
}
|
||||
let right = words.contains(&"right");
|
||||
if node.kind == Kind::Slot {
|
||||
let middle = words.contains(&"middle");
|
||||
if node.kind == Kind::Slot && !middle {
|
||||
let slot = node.id.trim_start_matches("slot-");
|
||||
let mut click = vec!["click-slot", slot];
|
||||
click.extend(words.iter().filter(|w| matches!(**w, "right" | "shift")));
|
||||
@@ -162,7 +169,11 @@ impl Game<'_> {
|
||||
node.rect[0] + node.rect[2] / 2.0,
|
||||
node.rect[1] + node.rect[3] / 2.0,
|
||||
);
|
||||
let button = if right {
|
||||
// The middle button goes through the window's own
|
||||
// events at the widget's centre, slots included.
|
||||
let button = if middle {
|
||||
MouseButton::Middle
|
||||
} else if right {
|
||||
MouseButton::Right
|
||||
} else {
|
||||
MouseButton::Left
|
||||
|
||||
@@ -77,7 +77,7 @@ Legend: **yes** complete, **part** partial (see note), **no** missing, **—** n
|
||||
| Capability | Before | After |
|
||||
| --- | --- | --- |
|
||||
| Screens: widgets | labelled buttons only | every widget of every screen (`ui`): id, kind, label, bounds, slider value, tab selected, slots with stacks; both menu styles |
|
||||
| Screens: act on a widget | `click-button LABEL`, `click-at X Y` | `click ID [right] [shift]`, `set ID VALUE` (sliders), `click` focuses fields |
|
||||
| Screens: act on a widget | `click-button LABEL`, `click-at X Y` | `click ID [right\|middle] [shift]`, `set ID VALUE` (sliders), `click` focuses fields |
|
||||
| Options | open a page; `render-distance` only | `options-get` all 193 `options.txt` options typed with ranges/choices; `options-set` validates, applies, saves |
|
||||
| Waits | `wait TICKS`, `wait-ready` | `wait-for screen\|widget\|loaded\|chat\|event` with timeout errors |
|
||||
| Events | none (poll) | `events [--since SEQ]`: screen, chat, death, respawn, item, dimension, world |
|
||||
@@ -127,11 +127,12 @@ pause, options pages, inventories and stations, chat, death, Horizon-style menus
|
||||
unlabelled elements are `<kind>-<n>` in draw order. The id of a slider does not change
|
||||
when its value (and so its label) does. World, server and language rows carry their
|
||||
names; Horizon-style switches, sliders and segments carry their settings row's caption
|
||||
(`vsync`, `menu-style-horizon`); inventory and menu slots are `slot-<ID>` with their stack.
|
||||
(`vsync`, `menu-style-horizon`); inventory, creative and menu slots are `slot-<ID>` with
|
||||
their stack (an item tab's display slots are `slot-900` up).
|
||||
- **Kinds**: `button`, `slider` (`value` 0..1 as drawn), `field` (text box), `row` (list
|
||||
entry: world, server, pack, language), `tab` (`selected`), `slot`.
|
||||
- **Actions by id**: `click ID [right]` (move the pointer there and click, exactly as a
|
||||
player would), `set ID VALUE` (a slider to a 0..1 position, a click on its track, as vanilla
|
||||
- **Actions by id**: `click ID [right|middle]` (move the pointer there and click, exactly as a
|
||||
player would; `middle` is the pick block button, which clones a stack in creative), `set ID VALUE` (a slider to a 0..1 position, a click on its track, as vanilla
|
||||
`AbstractSliderButton.onClick` reads the pointer). `type TEXT` keeps typing into the focused
|
||||
field; `click` on a field focuses it. After a click or a set, the next `ui`, `click` or
|
||||
`set` waits for a redrawn frame, so it never reads the screen the click left.
|
||||
|
||||
@@ -8,7 +8,9 @@ small JSON-RPC client, and saves a screenshot of each run. The ui scenario drive
|
||||
widget id instead: the title screen, the options (a slider set by id) and the inventory's slots;
|
||||
the options scenario reads and sets options.txt values by key; the events scenario waits for
|
||||
states (wait-for) and reads the event log; the consume scenario eats and drinks consumables (a
|
||||
golden apple, milk, honey, chorus fruit) and checks their effects, remainders and teleport.
|
||||
golden apple, milk, honey, chorus fruit) and checks their effects, remainders and teleport; the
|
||||
pick scenario middle-clicks slots (AbstractContainerScreen's cloning): a full stack in creative, from
|
||||
the hotbar and from an item tab, and nothing in survival.
|
||||
|
||||
python3 tools/agent_control_e2e.py # both modes
|
||||
python3 tools/agent_control_e2e.py --mode mcp # one of them
|
||||
@@ -46,7 +48,7 @@ POSITIONAL = {
|
||||
'wait_for': ['condition', 'value'],
|
||||
}
|
||||
# Booleans the game takes as bare words.
|
||||
BARE = {'click_slot': ['right', 'shift'], 'click': ['right', 'shift']}
|
||||
BARE = {'click_slot': ['right', 'shift'], 'click': ['right', 'middle', 'shift']}
|
||||
|
||||
|
||||
class Failed(Exception):
|
||||
@@ -423,8 +425,55 @@ def consume_scenario(d, out):
|
||||
return {'teleported': [round(m, 2) for m in moved]}
|
||||
|
||||
|
||||
def pick_scenario(d, out):
|
||||
# The pick block button (middle) over a container screen clones only with infinite materials:
|
||||
# AbstractContainerScreen.mouseClicked sends CLONE, which fills the empty hand with a full stack
|
||||
# of the slot's item (#1048: it clicked like the left button and took the slot's stack).
|
||||
d('click', id='singleplayer')
|
||||
if 'game' not in widgets(d):
|
||||
d('click', id='create-new-world')
|
||||
d('type', field='name', replace=True, text='Pick')
|
||||
d('click', id='create-new-world')
|
||||
d('wait_for', condition='loaded', timeout=400)
|
||||
d('command', command='gamemode creative')
|
||||
d('command', command='clear @s')
|
||||
d('give', item='oak_log', count=2)
|
||||
|
||||
def carried():
|
||||
return d('inventory')['carried']
|
||||
|
||||
# 1. An item tab: the hotbar slot's stack is cloned, the slot keeps its 2 logs.
|
||||
assert d('open_inventory')['screen'] == 'creative'
|
||||
tree = widgets(d)
|
||||
assert tree['slot-0']['stack'] == {'item': 'minecraft:oak_log', 'count': 2}, tree['slot-0']
|
||||
d('click', id='slot-0', middle=True)
|
||||
assert carried() == {'item': 'minecraft:oak_log', 'count': 64}, carried()
|
||||
assert widgets(d)['slot-0']['stack']['count'] == 2
|
||||
d('close')
|
||||
d('command', command='clear @s')
|
||||
d('give', item='oak_log', count=2)
|
||||
|
||||
# 2. The tab's own display slot gives a full stack too, not one item.
|
||||
d('open_inventory')
|
||||
shown = widgets(d)['slot-900']['stack']
|
||||
d('click', id='slot-900', middle=True)
|
||||
assert carried() == {'item': shown['item'], 'count': 64}, (shown, carried())
|
||||
d('close')
|
||||
|
||||
# 3. Survival: the middle button over a slot does nothing.
|
||||
d('command', command='gamemode survival')
|
||||
d('command', command='clear @s')
|
||||
d('give', item='oak_log', count=2)
|
||||
assert d('open_inventory')['screen'] == 'inventory'
|
||||
d('click', id='slot-0', middle=True)
|
||||
assert carried() is None, carried()
|
||||
assert widgets(d)['slot-0']['stack'] == {'item': 'minecraft:oak_log', 'count': 2}
|
||||
d('close')
|
||||
return {'cloned': shown['item']}
|
||||
|
||||
|
||||
SCENARIOS = {'survival': scenario, 'ui': ui_scenario, 'options': options_scenario, 'events': events_scenario,
|
||||
'consume': consume_scenario}
|
||||
'consume': consume_scenario, 'pick': pick_scenario}
|
||||
|
||||
|
||||
def run(mode, ctl, out, resources, which='survival'):
|
||||
|
||||
Reference in New Issue
Block a user