From a49f93f9ef342a246a77cc91565c9cdc2d14f8d0 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 18 Oct 2026 14:14:48 +0200 Subject: [PATCH] LAN: guests open hoppers, dispensers and droppers The guest's client closed every menu it had no screen for, so hoppers (MenuType.HOPPER) and dispensers and droppers (GENERIC_3x3) did nothing. They open as their 5 and 9 slot screens now, drawn by the menu's type and under the server's title. lan_e2e.py machines: each opens with its slots and keeps a stack the guest shift-clicks in. Part of #848 Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/machines.rs | 12 +++++++- crates/horizon-client/src/game/remote.rs | 25 +++++++++++++--- tools/lan_e2e.py | 35 ++++++++++++++++++++-- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/crates/horizon-client/src/game/machines.rs b/crates/horizon-client/src/game/machines.rs index d46928060..d40d6a3e8 100644 --- a/crates/horizon-client/src/game/machines.rs +++ b/crates/horizon-client/src/game/machines.rs @@ -770,6 +770,14 @@ enum Screen { impl Game<'_> { fn machine_screen(&self) -> Option { let key = self.container?; + // A server's menu shows by its type, whatever block (or minecart) holds it. + if let Some(menu) = self.remote_menu_type() { + return match menu { + "minecraft:hopper" => Some(Screen::Hopper), + "minecraft:generic_3x3" => Some(Screen::Dispenser), + _ => None, + }; + } if key.1 == super::minecarts::CART_KEY_Y { return (self.open_cart_kind() == Some(super::minecarts::CartKind::Hopper)) .then_some(Screen::Hopper); @@ -852,7 +860,9 @@ impl Game<'_> { batch.rect_uv(ox, oy, 176.0, height, r, u32::MAX); } let grey = horizon_client::hud::rgba(64, 64, 64, 255); - let title = &self.container_title(title.to_owned()); + let title = &self + .remote_menu_title() + .unwrap_or_else(|| self.container_title(title.to_owned())); let title_x = if screen == Screen::Hopper { 8.0 } else { diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 680360c93..3b7d51609 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -1130,14 +1130,16 @@ impl Game<'_> { /// Map a menu slot to Horizon's inventory screen slot ids. fn menu_slot(menu: &str, slot: i32) -> Option { let s = usize::try_from(slot).ok()?; - let rows = |n: usize| -> Option { + // A container of `n` slots, then the inventory and the hotbar. + let slots = |n: usize| -> Option { match s { - _ if s < n * 9 => Some(300 + s), - _ if s < n * 9 + 27 => Some(9 + s - n * 9), - _ if s < n * 9 + 36 => Some(s - n * 9 - 27), + _ if s < n => Some(300 + s), + _ if s < n + 27 => Some(9 + s - n), + _ if s < n + 36 => Some(s - n - 27), _ => None, } }; + let rows = |n: usize| slots(n * 9); match menu { "inventory" => match s { 0 => Some(200), @@ -1175,6 +1177,9 @@ impl Game<'_> { "minecraft:generic_9x4" => rows(4), "minecraft:generic_9x5" => rows(5), "minecraft:generic_9x6" => rows(6), + // HopperMenu; DispenserMenu (dispensers and droppers). + "minecraft:hopper" => slots(5), + "minecraft:generic_3x3" => slots(9), _ => None, } } @@ -3544,6 +3549,10 @@ impl Game<'_> { speed: 1.0, })) } + // HopperMenu, and DispenserMenu (MenuType.GENERIC_3x3: dispensers + // and droppers). + "minecraft:hopper" => Some(BlockEntity::Chest(vec![None; 5])), + "minecraft:generic_3x3" => Some(BlockEntity::Chest(vec![None; 9])), m if m.starts_with("minecraft:generic_9x") || m == "minecraft:shulker_box" => { let rows = m .strip_prefix("minecraft:generic_9x") @@ -3591,6 +3600,14 @@ impl Game<'_> { self.screen = Screen::Inventory; self.capture(false); } + /// The type of the menu a server opened (`MenuType`'s id). + pub(super) fn remote_menu_type(&self) -> Option<&str> { + Some(self.remote.as_ref()?.menu.as_ref()?.1.as_str()) + } + /// The title the server gave the menu it opened. + pub(super) fn remote_menu_title(&self) -> Option { + self.remote.as_ref()?.menu_title.clone() + } /// A server's chest-like menu (`MenuType.GENERIC_9xN`): its rows and title. pub(super) fn remote_chest_menu(&self) -> Option<(usize, String)> { let r = self.remote.as_ref()?; diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 4d13b1c22..a0ae2615e 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -21,6 +21,8 @@ address. The script then checks, from both sides, what a guest's game used to ge - pvp: the guest and the host hit each other with a sword; with the pvp game rule off, nothing; - containers: the guest's ender chest holds the guest's items, not the host's, and a double chest 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); - feedback: the guest's command feedback names the guest and shows the numbers; - effects: a beacon's power reaches every player in range, the host and the guest; - distance: (--server-thread) the server follows the host's render distance, past vanilla's 32 too @@ -84,7 +86,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', 'containers', 'feedback', 'titles', 'commands', 'recipes', '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', 'containers', 'feedback', 'titles', 'commands', 'recipes', 'machines', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'effects', 'portals', 'distance'] class Game: @@ -637,6 +639,35 @@ def check_containers(host, guest, out): return {'ender': ender, 'double': double, 'taken': taken} +def check_machines(host, guest, out): + # After `recipes`: the stacks given here unlock recipes, which would move the book's first one. + guest('command', command='gamemode survival') + x, y, z = (int(v // 1) for v in pos_of(guest)) + at = (x, y, z + 2) + seen = {} + for block in ('hopper', 'dispenser', 'dropper'): + guest('command', command='clear @s') + guest('command', command='give @s minecraft:cobblestone 4') + guest('command', command=f'setblock {at[0]} {at[1]} {at[2]} minecraft:{block}') + guest.wait(10) + guest.raw('interact', *at) + guest.raw('wait-for', 'screen', 'container', '--timeout', 10) + guest.wait(10) + size = container_items(guest)[1] + guest.shot(out, f'machines-{block}') + guest.raw('click-slot', hotbar_slot(guest, 'minecraft:cobblestone'), 'shift') + guest.wait(10) + guest.raw('key', 'esc', 'tap') + guest.wait(10) + # Opened again, the menu holds what the server has. + seen[block] = (size, open_container(guest, at, out, f'machines-{block}-after')[0]) + guest('command', command=f'setblock {at[0]} {at[1]} {at[2]} minecraft:air') + want = {'hopper': (5, {0: 'minecraft:cobblestone'}), 'dispenser': (9, {0: 'minecraft:cobblestone'}), + 'dropper': (9, {0: 'minecraft:cobblestone'})} + assert seen == want, f'the machines 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']: @@ -1272,7 +1303,7 @@ def check_light(host, guest, out): CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'nametags': check_nametags, 'chest': check_chest, 'crafting': check_crafting, 'sign': check_sign, 'damage': check_damage, 'mobs': check_mobs, 'hazards': check_hazards, 'pvp': check_pvp, - 'containers': check_containers, 'feedback': check_feedback, 'titles': check_titles, + 'containers': check_containers, 'machines': check_machines, 'feedback': check_feedback, 'titles': check_titles, 'commands': check_commands, 'recipes': check_recipes, 'trials': check_trials, 'walls': check_walls, 'effects': check_effects, 'portals': check_portals, 'distance': check_distance, 'clicks': check_clicks,