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)