LAN: a guest's chest, crafting table or sign no longer takes the host's mouse (#687)
A guest's action runs on the host's game with the guest's state swapped in (`as_guest`). The swap restored the open screen but not what opening one does to the window: `capture(false)` released the host's pointer, so the cursor showed and the camera stopped whenever a guest opened a chest, a crafting table or any other menu. `keys.clear()` dropped the keys the host was holding, and a sign, book, command block or mount menu the guest opened was drawn on the host's screen. - `capture` leaves the window alone while a guest acts. - `as_guest` keeps the host's held keys, sign editor, book, command block screen and mount menu, as it already kept the open screen. - `state` reports `pointer_grabbed` (mouse movement turns the camera). - tools/lan_e2e.py: `chest` and `crafting` check that the host keeps its screen and its mouse look; a new `sign` check places a sign as the guest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3666,6 +3666,11 @@ impl Game<'_> {
|
||||
) || self.book.is_some())
|
||||
}
|
||||
fn capture(&mut self, capture: bool) {
|
||||
// A guest's action (`as_guest`) opens and closes screens on the
|
||||
// guest's own client: the window's pointer stays the host's (#687).
|
||||
if self.lan_acting.is_some() {
|
||||
return;
|
||||
}
|
||||
// MouseHandler.grabMouse never captures an inactive window.
|
||||
if capture && !self.focused {
|
||||
return;
|
||||
|
||||
@@ -469,6 +469,9 @@ impl Game<'_> {
|
||||
"time": { "day_time": self.world.day_time, "day": self.world.day_time.div_euclid(24000), "time_of_day": self.world.day_time.rem_euclid(24000) },
|
||||
"weather": { "raining": self.world.weather.raining, "thundering": self.world.weather.thundering },
|
||||
"paused": self.pause,
|
||||
// Mouse movement turns the camera (`apply_mouse_look`): the real
|
||||
// pointer is grabbed, or an agent's `mouse-move` stands in for it.
|
||||
"pointer_grabbed": self.captured || self.agent_pointer,
|
||||
"player": player,
|
||||
"selected": self.selected + 1,
|
||||
"held": self.held().map(|s| self.stack_value(s)),
|
||||
|
||||
@@ -140,13 +140,20 @@ impl Game<'_> {
|
||||
total: g.xp_total,
|
||||
},
|
||||
);
|
||||
let sneak = self.keys.contains(&KeyCode::ShiftLeft);
|
||||
// The host's held keys stay theirs: the guest holds only sneak, and a
|
||||
// screen the guest opens (`keys.clear()`) leaves the host walking.
|
||||
let host_keys = std::mem::take(&mut self.keys);
|
||||
if g.sneaking {
|
||||
self.keys.insert(KeyCode::ShiftLeft);
|
||||
} else {
|
||||
self.keys.remove(&KeyCode::ShiftLeft);
|
||||
}
|
||||
// The window's screens are the host's: a sign, book, command block or
|
||||
// mount menu the guest's action opens is not drawn over the host's
|
||||
// world (#687). The guest's client opens its own.
|
||||
let screen = std::mem::replace(&mut self.screen, Screen::Playing);
|
||||
let host_sign = self.sign_edit.take();
|
||||
let host_book = self.book.take();
|
||||
let host_command_block = self.command_block_screen.take();
|
||||
let host_mount_menu = std::mem::take(&mut self.mount_menu);
|
||||
// The host's crafting grid stays theirs; a crafting table the guest
|
||||
// opens shows as the 3x3 size.
|
||||
let craft_size = std::mem::replace(&mut self.craft_size, 2);
|
||||
@@ -205,11 +212,11 @@ impl Game<'_> {
|
||||
play.swing = std::mem::replace(&mut self.swing, swing);
|
||||
self.container = container;
|
||||
self.screen = screen;
|
||||
if sneak {
|
||||
self.keys.insert(KeyCode::ShiftLeft);
|
||||
} else {
|
||||
self.keys.remove(&KeyCode::ShiftLeft);
|
||||
}
|
||||
self.sign_edit = host_sign;
|
||||
self.book = host_book;
|
||||
self.command_block_screen = host_command_block;
|
||||
self.mount_menu = host_mount_menu;
|
||||
self.keys = host_keys;
|
||||
let g = &mut host.hub.guests[i];
|
||||
std::mem::swap(&mut self.ender_items, &mut g.ender_items);
|
||||
std::mem::swap(&mut self.adv.progress, &mut g.advancements);
|
||||
|
||||
Reference in New Issue
Block a user