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 <noreply@anthropic.com>
This commit is contained in:
levzzz
2026-10-24 15:56:11 +05:00
parent 9624e99801
commit ebd25abd0e
@@ -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<Option<Value>> {
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<String> = 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<i32> {
Ok(words
.get(i)