Merge remote-tracking branch 'origin/fix/lan-guest-brewing' into integ/bl4

# Conflicts:
#	crates/horizon-client/src/game/lan_crafting.rs
#	tools/lan_e2e.py
This commit is contained in:
Ludovic Marie
2026-10-18 19:16:56 +02:00
7 changed files with 121 additions and 40 deletions
+3
View File
@@ -5067,6 +5067,9 @@ impl Game<'_> {
};
(kind, size)
}
// A server's BrewingStandMenu; a local stand's clicks are the
// station screen's.
Some(BlockEntity::Brewing(_)) if self.remote.is_some() => (Kind::Brewing, 5),
Some(BlockEntity::Furnace(f)) => (
Kind::Furnace(
match f.kind.recipe_type().trim_start_matches("minecraft:") {
@@ -570,6 +570,13 @@ impl Game<'_> {
_ => ("minecraft:furnace", "container.furnace"),
};
(menu, title, Slots::Block(pos))
} else if let Some(BlockEntity::Brewing(_)) = self.world.block_entities.get(&pos) {
// BrewingStandBlock.useWithoutItem: BrewingStandMenu.
(
"minecraft:brewing_stand",
"container.brewing",
Slots::Block(pos),
)
} else if let Some((other, right)) = self.chest_partner(pos) {
// ChestBlock.combine: the right half's slots come first.
let halves = if right {
@@ -781,7 +788,7 @@ impl Game<'_> {
S::ContainerClick(p) if self.lan_merchant_click(host, conn, &p) => {}
S::ContainerClick(p) if self.lan_inventory_click(host, conn, &p) => {}
S::ContainerClick(p) if self.lan_crafting_click(host, conn, &p) => {}
S::ContainerClick(p) if self.lan_furnace_click(host, conn, &p) => {}
S::ContainerClick(p) if self.lan_machine_click(host, conn, &p) => {}
S::SelectTrade(p) => self.lan_select_trade(host, conn, p.item),
S::ContainerClose(p) if self.lan_merchant_closed(host, conn, Some(p.container)) => {
let g = &mut host.hub.guests[gi];
+37 -23
View File
@@ -21,9 +21,10 @@ pub(super) struct GuestCrafting {
inventory: Option<Box<Menu>>,
/// The open crafting table: its window, state id and menu.
table: Option<(i32, i32, Box<Menu>)>,
/// The open furnace's window and menu (`AbstractFurnaceMenu`); its slots live in
/// the furnace block entity and the hub's container menu keeps the client in sync.
furnace: Option<(i32, Box<Menu>)>,
/// The open furnace's or brewing stand's window and menu (`AbstractFurnaceMenu`,
/// `BrewingStandMenu`); its slots live in the block entity and the hub's
/// container menu keeps the client in sync.
machine: Option<(i32, Box<Menu>)>,
}
/// ServerboundContainerClickPacket's input.
@@ -157,10 +158,11 @@ impl Game<'_> {
true
}
/// A click on the guest's open furnace, blast furnace or smoker: the host's
/// `AbstractFurnaceMenu` (fuel slot, take-only result, quick moves by recipe and
/// fuel) over the block entity's slots. False for other windows.
pub(super) fn lan_furnace_click(
/// A click on the guest's open furnace, blast furnace, smoker or brewing stand:
/// the host's `AbstractFurnaceMenu` (fuel slot, take-only result, quick moves by
/// recipe and fuel) or `BrewingStandMenu` (one bottle per slot, ingredient and
/// blaze powder slots) over the block entity's slots. False for other windows.
pub(super) fn lan_machine_click(
&mut self,
host: &mut LanHost,
conn: u32,
@@ -180,15 +182,18 @@ impl Game<'_> {
else {
return false;
};
let Some(BlockEntity::Furnace(f)) = self.world.block_entities.get(&pos) else {
return false;
let (kind, items) = match self.world.block_entities.get(&pos) {
Some(BlockEntity::Furnace(f)) => {
let recipe = match f.kind.recipe_type() {
"minecraft:blasting" => "blasting",
"minecraft:smoking" => "smoking",
_ => "smelting",
};
(Kind::Furnace(recipe), f.items.to_vec())
}
Some(BlockEntity::Brewing(b)) => (Kind::Brewing, b.items.to_vec()),
_ => return false,
};
let recipe = match f.kind.recipe_type() {
"minecraft:blasting" => "blasting",
"minecraft:smoking" => "smoking",
_ => "smelting",
};
let items = f.items.clone();
if host.hub.guests[gi].spectator() {
return true;
}
@@ -197,10 +202,10 @@ impl Game<'_> {
.entry(conn)
.or_default()
.crafting
.furnace
.machine
.take()
.filter(|(window, _)| *window == p.container)
.map_or_else(|| Box::new(Menu::new(Kind::Furnace(recipe))), |(_, m)| m);
.map_or_else(|| Box::new(Menu::new(kind)), |(_, m)| m);
let changed = self.guest_menu_op(host, gi, &mut menu, |menu, env| {
for (k, s) in items.iter().enumerate() {
menu.set_slot(env, k, s.clone());
@@ -213,14 +218,23 @@ impl Game<'_> {
.filter(|&s| menu.slot(s) != before[s].as_ref())
.collect::<Vec<_>>()
});
if let Some(BlockEntity::Furnace(f)) = self.world.block_entities.get_mut(&pos) {
for k in 0..3 {
f.items[k] = menu.slot(k).cloned();
match self.world.block_entities.get_mut(&pos) {
Some(BlockEntity::Furnace(f)) => {
for k in 0..3 {
f.items[k] = menu.slot(k).cloned();
}
// AbstractFurnaceBlockEntity.setItem: only a new input restarts cooking.
f.input_clicked(self.res.recipes(), items[0].clone());
}
// AbstractFurnaceBlockEntity.setItem: only a new input restarts cooking.
f.input_clicked(self.res.recipes(), items[0].clone());
// BrewingStandBlockEntity.serverTick notices a new ingredient itself.
Some(BlockEntity::Brewing(b)) => {
for k in 0..5 {
b.items[k] = menu.slot(k).cloned();
}
}
_ => {}
}
host.play.entry(conn).or_default().crafting.furnace = Some((p.container, menu));
host.play.entry(conn).or_default().crafting.machine = Some((p.container, menu));
host.hub.inventory_clicked(conn, p, &self.world, &changed);
true
}
+20 -5
View File
@@ -1191,6 +1191,7 @@ impl Game<'_> {
// HopperMenu; DispenserMenu (dispensers and droppers).
"minecraft:hopper" => slots(5),
"minecraft:generic_3x3" => slots(9),
"minecraft:brewing_stand" => slots(5),
_ => None,
}
}
@@ -1786,17 +1787,27 @@ impl Game<'_> {
self.remote_synced();
}
C::ContainerSetData(p) => {
if let Some(key) = self.container
&& let Some(BlockEntity::Furnace(f)) = self.world.block_entities.get_mut(&key)
let v = i32::from(p.value);
match self
.container
.and_then(|key| self.world.block_entities.get_mut(&key))
{
let v = i32::from(p.value);
match p.id {
Some(BlockEntity::Furnace(f)) => match p.id {
0 => f.lit_remaining = v,
1 => f.lit_total = v,
2 => f.cooking_timer = v,
3 => f.cooking_total = v,
_ => {}
}
},
// BrewingStandBlockEntity.dataAccess.
Some(BlockEntity::Brewing(b)) => match p.id {
0 => b.brew_time = v,
1 => b.fuel = v,
2 => b.total_brew_time = v,
3 => b.total_fuel = v,
_ => {}
},
_ => {}
}
}
C::OpenScreen(p) => self.remote_open_screen(p),
@@ -3597,6 +3608,10 @@ impl Game<'_> {
// HopperMenu, and DispenserMenu (MenuType.GENERIC_3x3: dispensers
// and droppers).
"minecraft:hopper" => Some(BlockEntity::Chest(vec![None; 5])),
// BrewingStandMenu: its times come in ContainerSetData.
"minecraft:brewing_stand" => Some(BlockEntity::Brewing(Box::new(
horizon_client::brewing::BrewingStand::new(),
))),
"minecraft:generic_3x3" => Some(BlockEntity::Chest(vec![None; 9])),
m if m.starts_with("minecraft:generic_9x") || m == "minecraft:shulker_box" => {
let rows = m
+3 -1
View File
@@ -1058,7 +1058,8 @@ impl Game<'_> {
}
}
pub(super) fn station_click(&mut self, right: bool) -> bool {
if self.station.is_none() && !self.brewing_open() {
// A server's brewing stand: its slots are the server's.
if self.station.is_none() && (!self.brewing_open() || self.remote.is_some()) {
return false;
}
let Some(size) = self
@@ -1403,6 +1404,7 @@ impl Game<'_> {
.as_ref()
.and_then(|s| self.world.block_names.get(&(s.pos[0], s.pos[1], s.pos[2])))
.cloned()
.or_else(|| self.remote_menu_title())
.unwrap_or(default);
let tw = HudBatch::text_width(atlas, &title);
batch.text(
+11 -9
View File
@@ -428,15 +428,17 @@ impl Hub {
let Slots::Block(pos) = m.slots else {
return;
};
let Some(BlockEntity::Furnace(f)) = world.block_entities.get(&pos) else {
return;
};
let data = [
f.lit_remaining,
f.lit_total,
f.cooking_timer,
f.cooking_total,
]
// AbstractFurnaceBlockEntity.dataAccess, BrewingStandBlockEntity.dataAccess.
let data = match world.block_entities.get(&pos) {
Some(BlockEntity::Furnace(f)) => [
f.lit_remaining,
f.lit_total,
f.cooking_timer,
f.cooking_total,
],
Some(BlockEntity::Brewing(b)) => [b.brew_time, b.fuel, b.total_brew_time, b.total_fuel],
_ => return,
}
.map(|v| v as i16);
m.sent_data.resize(data.len(), i16::MIN);
let window = m.window;
+39 -1
View File
@@ -26,6 +26,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
opens as 9x6 with the right half first;
- machines: a hopper, a dispenser and a dropper open on the guest's screen with their 5 and 9
slots, and keep what the guest shift-clicks into them (#848);
- brewing: a brewing stand opens on the guest's screen; blaze powder, nether wart and a bottle the
guest shift-clicks go to the fuel, ingredient and bottle slots, and the stand's fuel shows
(#848);
- feedback: the guest's command feedback names the guest and shows the numbers;
- chat: a line the host sends reaches the guest's event log (`wait-for chat`), and on the
server thread the host window's too;
@@ -91,7 +94,7 @@ ROOT = Path(__file__).resolve().parents[1]
GUEST_NAME = 'Guest'
# The host plays single player on its server thread (--server-thread).
SERVER_THREAD = False
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'effects', 'portals', 'distance']
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'effects', 'portals', 'distance']
class Game:
@@ -712,6 +715,40 @@ def check_machines(host, guest, out):
return seen
def check_brewing(host, guest, out):
guest('command', command='gamemode survival')
guest('command', command='clear @s')
loads = ('blaze_powder', 'nether_wart', 'glass_bottle')
for item in loads:
guest('command', command=f'give @s minecraft:{item}')
x, y, z = (int(v // 1) for v in pos_of(guest))
at = (x, y, z + 2)
guest('command', command=f'setblock {at[0]} {at[1]} {at[2]} minecraft:brewing_stand')
guest.wait(10)
guest.raw('interact', *at)
guest.raw('wait-for', 'screen', 'container', '--timeout', 10)
guest.wait(10)
size = container_items(guest)[1]
# BrewingStandMenu.quickMoveStack: blaze powder to the fuel slot, an ingredient to its slot,
# a bottle to the bottle slots.
for item in loads:
guest.raw('click-slot', hotbar_slot(guest, f'minecraft:{item}'), 'shift')
guest.wait(5)
# BrewingStandBlockEntity.serverTick burns the blaze powder into 20 uses; the guest sees them
# through the menu's data slots.
guest.wait(10)
info = guest.raw('menu')['info']
guest.shot(out, 'brewing')
guest.raw('key', 'esc', 'tap')
guest.wait(10)
items = open_container(guest, at, out, 'brewing-after')[0]
guest('command', command=f'setblock {at[0]} {at[1]} {at[2]} minecraft:air')
seen = {'size': size, 'items': items, 'fuel': info and info.get('fuel')}
want = {'size': 5, 'items': {0: 'minecraft:glass_bottle', 3: 'minecraft:nether_wart'}, 'fuel': 20}
assert seen == want, f'the brewing stand on the guest: {seen}'
return seen
def slot_point(game, slot):
"""The GUI point in the middle of slot `slot` of the open screen (`ui`'s slot-N)."""
for w in game.raw('ui')['widgets']:
@@ -1361,6 +1398,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
'respawn': check_respawn,
'containers': check_containers, 'feedback': check_feedback, 'titles': check_titles, 'chat': check_chat,
'machines': check_machines,
'brewing': check_brewing,
'commands': check_commands,
'recipes': check_recipes, 'trials': check_trials, 'walls': check_walls,
'effects': check_effects, 'portals': check_portals, 'distance': check_distance, 'clicks': check_clicks,