From ebd25abd0eada5a4ae9cf3c174c3502d069979a3 Mon Sep 17 00:00:00 2001 From: levzzz <86072227+levzzz5154@users.noreply.github.com> Date: Sat, 24 Oct 2026 15:56:11 +0500 Subject: [PATCH] Run horizon-ctl block commands in the server's world With the integrated server thread on, setblock, fill, getblock and container ran on the client's copy only. They now run on the server, and on a remote server setblock and fill go out as chat commands. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/blockctl.rs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/horizon-client/src/game/blockctl.rs b/crates/horizon-client/src/game/blockctl.rs index 719ce8dd2..8e0ea287e 100644 --- a/crates/horizon-client/src/game/blockctl.rs +++ b/crates/horizon-client/src/game/blockctl.rs @@ -59,6 +59,30 @@ impl Game<'_> { } /// Block commands; None when `words[0]` is not one of them. pub(super) fn block_command(&mut self, words: &[&str]) -> Result> { + let ours = matches!( + words.first(), + 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. + 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()) + }) + .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()); + } + self.send_chat(&format!("/{}", words.join(" "))); + return Ok(Some(json!({ "ok": true, "sent": true }))); + } let int = |i: usize| -> Result { Ok(words .get(i)