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

# Conflicts:
#	tools/lan_e2e.py
This commit is contained in:
Ludovic Marie
2026-10-18 19:16:35 +02:00
3 changed files with 65 additions and 6 deletions
+11 -1
View File
@@ -770,6 +770,14 @@ enum Screen {
impl Game<'_> {
fn machine_screen(&self) -> Option<Screen> {
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 {
+21 -4
View File
@@ -1141,14 +1141,16 @@ impl Game<'_> {
/// Map a menu slot to Horizon's inventory screen slot ids.
fn menu_slot(menu: &str, slot: i32) -> Option<usize> {
let s = usize::try_from(slot).ok()?;
let rows = |n: usize| -> Option<usize> {
// A container of `n` slots, then the inventory and the hotbar.
let slots = |n: usize| -> Option<usize> {
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),
@@ -1186,6 +1188,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,
}
}
@@ -3589,6 +3594,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")
@@ -3636,6 +3645,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<String> {
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()?;
+33 -1
View File
@@ -24,6 +24,8 @@ address. The script then checks, from both sides, what a guest's game used to ge
the guest too;
- 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;
- 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;
@@ -89,7 +91,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', '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', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'effects', 'portals', 'distance']
class Game:
@@ -681,6 +683,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']:
@@ -1329,6 +1360,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
'mobs': check_mobs, 'hazards': check_hazards, 'pvp': check_pvp,
'respawn': check_respawn,
'containers': check_containers, 'feedback': check_feedback, 'titles': check_titles, 'chat': check_chat,
'machines': check_machines,
'commands': check_commands,
'recipes': check_recipes, 'trials': check_trials, 'walls': check_walls,
'effects': check_effects, 'portals': check_portals, 'distance': check_distance, 'clicks': check_clicks,