Merge pull request #1125 from ludovic111/fix/station-quick-move

🤖 Agent: merged. Verify passes. Local integration of #1121–#1125 on main 2d586fac: parity --changed, all 101 affected harnesses pass. Screenshots in the body.
This commit is contained in:
Ludovic Marie
2026-10-22 03:00:02 +02:00
committed by GitHub
2 changed files with 87 additions and 95 deletions
+1 -3
View File
@@ -5443,9 +5443,7 @@ impl Game<'_> {
}; };
(kind, size) (kind, size)
} }
// A server's BrewingStandMenu; a local stand's clicks are the Some(BlockEntity::Brewing(_)) => (Kind::Brewing, 5),
// station screen's.
Some(BlockEntity::Brewing(_)) if self.remote.is_some() => (Kind::Brewing, 5),
Some(BlockEntity::Furnace(f)) => ( Some(BlockEntity::Furnace(f)) => (
Kind::Furnace( Kind::Furnace(
match f.kind.recipe_type().trim_start_matches("minecraft:") { match f.kind.recipe_type().trim_start_matches("minecraft:") {
+86 -92
View File
@@ -503,7 +503,7 @@ impl Game<'_> {
.get(&stack.item) .get(&stack.item)
.map_or(64, |i| i.max_stack) .map_or(64, |i| i.max_stack)
} }
/// `Slot.mayPlace` and `getMaxStackSize` for station and brewing slots. /// `Slot.mayPlace` and `getMaxStackSize` for station slots.
fn slot_rules(&self, slot: usize, stack: &ItemStack) -> (bool, u32) { fn slot_rules(&self, slot: usize, stack: &ItemStack) -> (bool, u32) {
let data = self.data(); let data = self.data();
if slot >= super::mount_menu::SADDLE { if slot >= super::mount_menu::SADDLE {
@@ -519,19 +519,6 @@ impl Game<'_> {
// ShulkerBoxSlot.mayPlace. // ShulkerBoxSlot.mayPlace.
return (false, 64); return (false, 64);
} }
if self.brewing_open() && (300..305).contains(&slot) {
return match slot - 300 {
0..=2 => (data.brewing.is_bottle(stack), 1),
3 => (data.brewing.is_reagent(stack), 64),
_ => (
self.res
.items()
.get(&stack.item)
.is_some_and(|i| i.brewing_fuel.is_some()),
64,
),
};
}
let Some(s) = self.station.as_ref() else { let Some(s) = self.station.as_ref() else {
return (true, 64); return (true, 64);
}; };
@@ -661,98 +648,104 @@ impl Game<'_> {
fn player_slots() -> Vec<usize> { fn player_slots() -> Vec<usize> {
(9..36).chain(0..9).collect() (9..36).chain(0..9).collect()
} }
/// `quickMoveStack` for one slot; returns whether anything moved. /// A shift-click: `AbstractContainerMenu.doClick`'s QUICK_MOVE repeats
fn quick_move(&mut self, slot: usize) -> bool { /// `quickMoveStack` while it moves something and the slot still holds the
/// same item.
fn quick_move(&mut self, slot: usize) {
while let Some(item) = self.slot_mut(slot).as_ref().map(|s| s.item.clone())
&& self.quick_move_once(slot)
&& self.slot_mut(slot).as_ref().is_some_and(|s| s.item == item)
{}
}
/// The station menu's `quickMoveStack` for one slot (`EnchantmentMenu`,
/// `BeaconMenu`, `GrindstoneMenu`, `StonecutterMenu`,
/// `CartographyTableMenu`, and `ItemCombinerMenu` with `SmithingMenu`'s
/// `canMoveIntoInputSlots`); whether the stack's count changed. Each
/// rule that names its target slots moves nowhere else when they are full.
fn quick_move_once(&mut self, slot: usize) -> bool {
let Some(kind) = self.station.as_ref().map(|s| s.kind) else {
return false;
};
let Some(mut stack) = self.slot_mut(slot).take() else { let Some(mut stack) = self.slot_mut(slot).take() else {
return false; return false;
}; };
let player = Self::player_slots(); let start = stack.count;
let moved = if (300..305).contains(&slot) || slot >= INPUT { let empty = |game: &mut Self, i: usize| game.station_slot_mut(INPUT + i).is_none();
self.move_to(&mut stack, &player, true) // The other half of the inventory: main rows to the hotbar and back.
} else if self.brewing_open() { let halves: Vec<usize> = if slot < 9 {
// BrewingStandMenu.quickMoveStack: fuel, ingredient, bottles, then the other half. (9..36).collect()
let data = self.data(); } else {
let fuel = self (0..9).collect()
.res };
.items() if slot >= INPUT {
.get(&stack.item) // An input slot: into the inventory, the hotbar's last slot first
.is_some_and(|i| i.brewing_fuel.is_some()); // where vanilla moves in reverse.
let (reagent, bottle) = ( let reverse = matches!(kind, Kind::Enchanting | Kind::Beacon);
data.brewing.is_reagent(&stack), self.move_to(&mut stack, &Self::player_slots(), reverse);
data.brewing.is_bottle(&stack),
);
let mut moved = false;
if fuel {
moved = self.move_to(&mut stack, &[304], false);
}
if !moved && reagent {
moved = self.move_to(&mut stack, &[303], false);
}
if !moved && bottle {
moved = self.move_to(&mut stack, &[300, 301, 302], false);
}
if !moved {
let other: Vec<usize> = if slot < 9 {
(9..36).collect()
} else {
(0..9).collect()
};
moved = self.move_to(&mut stack, &other, false);
}
moved
} else { } else {
let kind = self.station.as_ref().map(|s| s.kind);
let mut moved = false;
match kind { match kind {
Some(Kind::Enchanting) => { Kind::Enchanting => {
if &*stack.item == "minecraft:lapis_lazuli" { if &*stack.item == "minecraft:lapis_lazuli" {
moved = self.move_to(&mut stack, &[INPUT + 1], true); self.move_to(&mut stack, &[INPUT + 1], true);
} else if self.station_slot_mut(INPUT).is_none() { } else if empty(self, 0) {
let one = ItemStack { *self.station_slot_mut(INPUT) = Some(ItemStack {
count: 1, count: 1,
..stack.clone() ..stack.clone()
}; });
*self.station_slot_mut(INPUT) = Some(one);
stack.count -= 1; stack.count -= 1;
moved = true;
} }
} }
Some(Kind::Grindstone) => { Kind::Beacon => {
let both = self if empty(self, 0) && super::beacon::is_payment(&stack.item) && stack.count == 1
.station {
.as_ref() self.move_to(&mut stack, &[INPUT], false);
.is_some_and(|s| s.inputs.iter().all(Option::is_some)); } else {
if !both { self.move_to(&mut stack, &halves, false);
moved = self.move_to(&mut stack, &[INPUT, INPUT + 1], false);
} }
} }
Some(Kind::Merchant | Kind::Loom) => {} Kind::Grindstone => {
Some(Kind::Beacon) => { if empty(self, 0) || empty(self, 1) {
// BeaconMenu.quickMoveStack: one payment item into the empty slot. self.move_to(&mut stack, &[INPUT, INPUT + 1], false);
if super::beacon::is_payment(&stack.item) { } else {
moved = self.move_to(&mut stack, &[INPUT], false); self.move_to(&mut stack, &halves, false);
} }
} }
Some(Kind::Smithing) Kind::Stonecutter => {
| Some(Kind::Anvil) if self.data().recipes.stonecutter(&stack).is_empty() {
| Some(Kind::Stonecutter) self.move_to(&mut stack, &halves, false);
| Some(Kind::Cartography) => { } else {
let n = self.station.as_ref().map_or(0, |s| s.inputs.len()); self.move_to(&mut stack, &[INPUT], false);
let inputs: Vec<usize> = (0..n).map(|i| INPUT + i).collect(); }
moved = self.move_to(&mut stack, &inputs, false);
} }
None => {} Kind::Cartography => {
if super::maps::map_id(&stack).is_some() {
self.move_to(&mut stack, &[INPUT], false);
} else if matches!(
&*stack.item,
"minecraft:paper" | "minecraft:map" | "minecraft:glass_pane"
) {
self.move_to(&mut stack, &[INPUT + 1], false);
} else {
self.move_to(&mut stack, &halves, false);
}
}
Kind::Anvil | Kind::Smithing => {
let inputs: Vec<usize> = (0..kind.inputs()).map(|i| INPUT + i).collect();
// ItemCombinerMenu.canMoveIntoInputSlots: always for the
// anvil; the smithing table needs an empty slot whose
// ingredient test takes the stack.
let into_inputs = kind == Kind::Anvil
|| (0..3).any(|i| {
empty(self, i) && self.data().recipes.smithing_accepts(i, &stack)
});
let targets = if into_inputs { &inputs } else { &halves };
self.move_to(&mut stack, targets, false);
}
// Their clicks run on the menu engine.
Kind::Merchant | Kind::Loom => {}
} }
if !moved { }
let other: Vec<usize> = if slot < 9 { let moved = stack.count != start;
(9..36).collect()
} else {
(0..9).collect()
};
moved = self.move_to(&mut stack, &other, false);
}
moved
};
if stack.count > 0 { if stack.count > 0 {
*self.slot_mut(slot) = Some(stack); *self.slot_mut(slot) = Some(stack);
} }
@@ -1127,9 +1120,10 @@ impl Game<'_> {
if self if self
.station .station
.as_ref() .as_ref()
.is_some_and(|s| matches!(s.kind, Kind::Loom | Kind::Merchant)) .is_none_or(|s| matches!(s.kind, Kind::Loom | Kind::Merchant))
{ {
// LoomMenu and MerchantMenu clicks run on the verified menu engine. // LoomMenu, MerchantMenu and the brewing stand's BrewingStandMenu
// clicks run on the verified menu engine.
let input = if shift { let input = if shift {
horizon_client::menu::Input::QuickMove horizon_client::menu::Input::QuickMove
} else { } else {
@@ -1144,7 +1138,7 @@ impl Game<'_> {
} }
if shift { if shift {
self.quick_move(slot); self.quick_move(slot);
} else if slot >= INPUT || (300..305).contains(&slot) { } else if slot >= INPUT {
self.click_filtered(slot, right); self.click_filtered(slot, right);
} else { } else {
return false; return false;