Move every matching stack on a Shift double click
AbstractContainerScreen.mouseReleased: a Shift double click QUICK_MOVEs every slot of the clicked slot's container that holds the item the last Shift click moved (lastQuickMoved), when canTakeItemForPickAll allows the clicked slot. Menu::quick_move_all runs it on the menu engine; test_menu_click_parity generates it as a QUICK_MOVE_ALL op that the oracle runs with the real Slot.mayPickup, Slot.container and AbstractContainerMenu.canItemQuickReplace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -103,8 +103,17 @@ fn main() -> horizon_client::Result<()> {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let kind = Input::parse(op[2].as_str().unwrap_or_default()).ok_or("input")?;
|
||||
let clicked = menu.click(&env, slot, button, kind);
|
||||
let clicked = if op[2] == "QUICK_MOVE_ALL" {
|
||||
// A Shift double click: lastQuickMoved is the op's fourth field.
|
||||
let moved = parse_stack(op[3].as_str().unwrap_or("-"))?;
|
||||
match moved {
|
||||
Some(moved) => menu.quick_move_all(&env, slot as usize, &moved),
|
||||
None => Ok(()),
|
||||
}
|
||||
} else {
|
||||
let kind = Input::parse(op[2].as_str().unwrap_or_default()).ok_or("input")?;
|
||||
menu.click(&env, slot, button, kind)
|
||||
};
|
||||
if let Some(f) = furnace.as_mut() {
|
||||
let before = f.items[0].clone();
|
||||
f.items = [0, 1, 2].map(|i| menu.slot(i).cloned());
|
||||
|
||||
@@ -688,6 +688,9 @@ struct Game<'a> {
|
||||
inv_clicks: horizon_client::container_screen::Clicks,
|
||||
/// 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
|
||||
/// double click moves every stack of.
|
||||
last_quick_moved: Option<ItemStack>,
|
||||
/// Open container block entity, if any.
|
||||
container: Option<(i32, i32, i32)>,
|
||||
/// Open workstation menu (enchanting table, anvil, ...).
|
||||
@@ -4702,6 +4705,41 @@ impl Game<'_> {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(slot) = slot
|
||||
&& shift
|
||||
&& slot != 200
|
||||
{
|
||||
let now = std::time::Instant::now();
|
||||
let double = self.last_inv_click.is_some_and(|(at, last, was_right)| {
|
||||
last == slot && was_right == right && now.duration_since(at).as_millis() < 250
|
||||
});
|
||||
self.last_inv_click = Some((now, slot, right));
|
||||
// mouseClicked's QUICK_MOVE (and Horizon's at-press QUICK_MOVE
|
||||
// of a carried stack, mouseReleased's in vanilla) remember the
|
||||
// stack it moves.
|
||||
if input == Some(Input::QuickMove) || (self.carried.is_some() && !double) {
|
||||
self.last_quick_moved = self.slot_view(slot);
|
||||
}
|
||||
if double && !right {
|
||||
// mouseReleased: every stack of lastQuickMoved's item in the
|
||||
// clicked slot's container is quick-moved.
|
||||
if let Some(input) = input
|
||||
&& !self.menu_click(Some(slot), 0, input)
|
||||
{
|
||||
// A screen the menu engine doesn't model: its own click.
|
||||
self.click_inventory(right);
|
||||
return;
|
||||
}
|
||||
if let Some(moved) = self.last_quick_moved.clone() {
|
||||
self.menu_session(|menu, env, to_menu| {
|
||||
Some(menu.quick_move_all(env, to_menu(slot)?, &moved).is_ok())
|
||||
});
|
||||
}
|
||||
self.last_inv_click = None;
|
||||
self.inv_clicks.skip_release();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Some(slot) = slot
|
||||
&& !shift
|
||||
&& slot != 200
|
||||
@@ -9668,6 +9706,7 @@ pub fn run() -> Result<()> {
|
||||
inv_drag: None,
|
||||
inv_clicks: Default::default(),
|
||||
last_inv_click: None,
|
||||
last_quick_moved: None,
|
||||
container: None,
|
||||
station: None,
|
||||
potions: Default::default(),
|
||||
|
||||
@@ -1652,6 +1652,39 @@ impl Menu {
|
||||
}
|
||||
|
||||
/// The PICKUP_ALL branch (double click).
|
||||
/// `canTakeItemForPickAll`: never the result slots (the loom's is a
|
||||
/// plain slot), MerchantMenu's or an item tab's display slots.
|
||||
fn can_take_for_pick_all(&self, t: usize) -> bool {
|
||||
self.kind != Kind::Merchant
|
||||
&& self.slots[t].role != Role::CreativeDisplay
|
||||
&& (self.slots[t].container != RESULT || self.kind == Kind::Loom)
|
||||
}
|
||||
|
||||
/// `AbstractContainerScreen.mouseReleased` on a Shift double click:
|
||||
/// QUICK_MOVE on every slot of `clicked`'s container that holds
|
||||
/// `moved`'s item (`lastQuickMoved`, the stack the first click moved).
|
||||
pub fn quick_move_all(
|
||||
&mut self,
|
||||
env: &Env,
|
||||
clicked: usize,
|
||||
moved: &ItemStack,
|
||||
) -> Result<(), &'static str> {
|
||||
if clicked >= self.slots.len() || !self.can_take_for_pick_all(clicked) {
|
||||
return Ok(());
|
||||
}
|
||||
let container = self.slots[clicked].container;
|
||||
for t in 0..self.slots.len() {
|
||||
if self.may_pickup(env, t)
|
||||
&& self.has_item(t)
|
||||
&& self.slots[t].container == container
|
||||
&& self.quick_replace(t, moved, env)
|
||||
{
|
||||
self.click(env, t as i32, 0, Input::QuickMove)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `canDragTo`: ItemPickerMenu keeps drags off its display slots.
|
||||
fn can_drag_to(&self, s: usize) -> bool {
|
||||
self.slots[s].role != Role::CreativeDisplay
|
||||
@@ -1674,13 +1707,10 @@ impl Menu {
|
||||
let t = i as usize;
|
||||
i += step;
|
||||
let have = self.carried.clone().expect("some");
|
||||
// MerchantMenu.canTakeItemForPickAll is always false.
|
||||
if self.kind != Kind::Merchant
|
||||
&& self.slots[t].role != Role::CreativeDisplay
|
||||
&& self.has_item(t)
|
||||
if self.has_item(t)
|
||||
&& self.quick_replace(t, &have, env)
|
||||
&& self.may_pickup(env, t)
|
||||
&& (self.slots[t].container != RESULT || self.kind == Kind::Loom)
|
||||
&& self.can_take_for_pick_all(t)
|
||||
{
|
||||
let item = self.slot(t).expect("has item").clone();
|
||||
if pass != 0 || item.count != Self::max_stack(env, &item) {
|
||||
|
||||
@@ -246,6 +246,22 @@ public final class VanillaMenuOracle {
|
||||
out.println(state(menu, inv));
|
||||
continue;
|
||||
}
|
||||
if (kind.equals("QUICK_MOVE_ALL")) {
|
||||
// AbstractContainerScreen.mouseReleased on a Shift double click, lastQuickMoved
|
||||
// being the op's fourth field.
|
||||
var clicked = menu.getSlot(slot);
|
||||
var moved = ParityData.stack(op.get(3).getAsString());
|
||||
if (menu.canTakeItemForPickAll(ItemStack.EMPTY, clicked) && !moved.isEmpty()) {
|
||||
for (var target : menu.slots) {
|
||||
if (target.mayPickup(player) && target.hasItem() && target.container == clicked.container
|
||||
&& AbstractContainerMenu.canItemQuickReplace(target, moved, true)) {
|
||||
menu.clicked(target.index, 0, ContainerInput.QUICK_MOVE, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
out.println(state(menu, inv));
|
||||
continue;
|
||||
}
|
||||
var input = ContainerInput.valueOf(kind);
|
||||
try {
|
||||
menu.clicked(slot, button, input, player);
|
||||
|
||||
@@ -5,7 +5,9 @@ The Java oracle (VanillaMenuOracle) runs each case's clicks on the real menu
|
||||
class with a stand-in player and level; the Rust example (menu_fixture) runs
|
||||
horizon_client::menu. Cases are randomized slot contents with random click
|
||||
sequences covering every ContainerInput (pickup, quick move, swap, clone,
|
||||
throw, the three quick craft drags, pickup all) over the player inventory,
|
||||
throw, the three quick craft drags, pickup all, and the screens' Shift double
|
||||
click: QUICK_MOVE on every slot of the clicked slot's container holding the
|
||||
item the first click moved) over the player inventory,
|
||||
crafting table, chests, hopper, dispenser, shulker box, the furnaces, the
|
||||
brewing stand, the crafter (the client's menu, and the server's over the block
|
||||
entity with slot state packets), the loom (with its pattern buttons) and the
|
||||
@@ -109,7 +111,7 @@ class Gen:
|
||||
for x, name in enumerate(row):
|
||||
slots[start + x + y * width] = snbt('minecraft:' + name, amount() if name != 'milk_bucket' else 1)
|
||||
|
||||
def ops(self, size, menu=None):
|
||||
def ops(self, size, menu, slots):
|
||||
rng = self.rng
|
||||
out = []
|
||||
for _ in range(rng.randrange(1, 9)):
|
||||
@@ -124,9 +126,15 @@ class Gen:
|
||||
if menu == 'crafter_be' and rng.random() < 0.2:
|
||||
out.append([rng.choice([0, 1, 4, 8, 8, 9, -1]), rng.randrange(0, 2), 'SLOT_STATE'])
|
||||
continue
|
||||
kind = rng.choices(['PICKUP', 'QUICK_MOVE', 'SWAP', 'CLONE', 'THROW', 'DRAG', 'PICKUP_ALL', 'JUNK'],
|
||||
[30, 20, 8, 3, 6, 14, 6, 2])[0]
|
||||
kind = rng.choices(['PICKUP', 'QUICK_MOVE', 'SWAP', 'CLONE', 'THROW', 'DRAG', 'PICKUP_ALL', 'JUNK',
|
||||
'QUICK_MOVE_ALL'], [30, 20, 8, 3, 6, 14, 6, 2, 0 if menu.endswith('_be') else 6])[0]
|
||||
slot = 0 if rng.random() < 0.2 and size in (46,) else rng.randrange(size)
|
||||
if kind == 'QUICK_MOVE_ALL':
|
||||
# A Shift double click: lastQuickMoved is mostly what a slot of the menu holds.
|
||||
held = [s for s in slots if s != '-']
|
||||
moved = rng.choice(held) if held and rng.random() < 0.85 else self.stack()
|
||||
out.append([slot, 0, kind, moved])
|
||||
continue
|
||||
if kind == 'PICKUP':
|
||||
out.append([rng.choice([slot, slot, slot, -999, -1]), rng.randrange(0, 3), kind])
|
||||
elif kind == 'QUICK_MOVE':
|
||||
@@ -208,7 +216,7 @@ def main():
|
||||
carried = carried_food
|
||||
cases.append({'menu': menu, 'creative': rng.random() < 0.25, 'slots': slots,
|
||||
'carried': carried, 'data': [datum(i) for i in range(DATA.get(menu, 0))],
|
||||
'ops': g.ops(size, menu)})
|
||||
'ops': g.ops(size, menu, slots)})
|
||||
(work / 'cases.jsonl').write_text(''.join(json.dumps(c) + '\n' for c in cases))
|
||||
vanilla.run('VanillaMenuOracle', work / 'cases.jsonl', work / 'native.txt')
|
||||
lib.cargo_example('horizon-client', 'menu_fixture', lib.RESOURCES, work / 'cases.jsonl', work / 'rust.txt')
|
||||
|
||||
Reference in New Issue
Block a user