From 704931ed14f7cb14e29f27ede60aba3e59df49ff Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:27:50 +0200 Subject: [PATCH] Keep horizon-ctl getblock on a client's copy, run server ones in the owner's level On a LAN guest or any remote client, getblock and container read what that client has again (test_friends waits on a guest's getblock). On the server thread the block commands run in the owner's level, not whichever level the server ticked last. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/blockctl.rs | 14 +++++++------- crates/horizon-client/src/game/integrated.rs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/crates/horizon-client/src/game/blockctl.rs b/crates/horizon-client/src/game/blockctl.rs index 8e0ea287e..6765c3df8 100644 --- a/crates/horizon-client/src/game/blockctl.rs +++ b/crates/horizon-client/src/game/blockctl.rs @@ -64,22 +64,22 @@ impl Game<'_> { Some(&("setblock" | "fill" | "getblock" | "container")) ); // Single player on its server thread: the world is the server's, so - // the command runs there and the client hears of it like any change. + // the command runs there, in the owner's level, and the client hears + // of it like any change. if ours && let Some(server) = &self.integrated { let owned: Vec = words.iter().map(|w| (*w).to_owned()).collect(); return server .call(move |g| { let words: Vec<&str> = owned.iter().map(String::as_str).collect(); - g.block_command(&words).map_err(|e| e.to_string()) + g.in_owner_level(|g| g.block_command(&words).map_err(|e| e.to_string())) }) .ok_or("the integrated server stopped")? .map_err(Into::into); } - // Another server's world changes only through its commands. - if ours && self.remote.is_some() { - if !matches!(words[0], "setblock" | "fill") { - return Err(format!("{} needs a world on this machine", words[0]).into()); - } + // Another server's world changes only through its own commands, which + // it checks as the player's; `getblock` and `container` read what this + // client has of it. + if self.remote.is_some() && matches!(words.first(), Some(&("setblock" | "fill"))) { self.send_chat(&format!("/{}", words.join(" "))); return Ok(Some(json!({ "ok": true, "sent": true }))); } diff --git a/crates/horizon-client/src/game/integrated.rs b/crates/horizon-client/src/game/integrated.rs index ee343c64b..44df5fe20 100644 --- a/crates/horizon-client/src/game/integrated.rs +++ b/crates/horizon-client/src/game/integrated.rs @@ -496,6 +496,22 @@ impl Game<'_> { out } + /// Run `f` with the owner's level in place (the server holds one per + /// dimension), then put back the level that was. + pub(super) fn in_owner_level(&mut self, f: impl FnOnce(&mut Self) -> T) -> T { + let owner = self.serving.as_ref().map(|s| s.owner); + let dim = self.lan.as_ref().and_then(|h| { + let g = h.hub.guests.iter().find(|g| Some(g.uuid) == owner)?; + Some(super::Dim::from_id(&g.dimension)) + }); + let back = dim.and_then(|d| self.enter_command_level(d)); + let out = f(self); + if let Some(back) = back { + self.enter_command_level(back); + } + out + } + /// The window's requests, between two ticks. fn run_tasks(&mut self) { let tasks: Vec = match &self.serving {