From 7a6a4d92497ab3373f8f6f7178df8e2b3a37b464 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 18 Oct 2026 15:46:35 +0200 Subject: [PATCH] Server thread: horizon-ctl tp and fly make the server load the new chunks (#861) With the world on its server thread, a horizon-ctl `tp` or `fly` moved the window's player to chunks the server had not sent. The client skips its tick while its own chunk isn't loaded, so it never sent the move, and the server kept streaming the old area: "loading terrain..." forever. - The client sends a move made where nothing is loaded (by horizon-ctl; a player who walks there has already sent it), so the server streams the chunks there. - The integrated server doesn't check its owner's moves, as vanilla's `shouldCheckPlayerMovement` (`isSingleplayerOwner`); a long `tp` was "moved too quickly". - `wait-ready` on a server also waits for the level around the player (`PlayerLoaded`); the status shows it as `server.loaded`. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/bin/horizon-ctl/main.rs | 7 ++++++- crates/horizon-client/src/game/integrated.rs | 1 + crates/horizon-client/src/game/remote.rs | 14 ++++++++++++++ crates/horizon-client/src/lan/hub.rs | 12 +++++++++--- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/horizon-client/src/bin/horizon-ctl/main.rs b/crates/horizon-client/src/bin/horizon-ctl/main.rs index 2e1b1bb56..27d9d5ba1 100644 --- a/crates/horizon-client/src/bin/horizon-ctl/main.rs +++ b/crates/horizon-client/src/bin/horizon-ctl/main.rs @@ -215,7 +215,12 @@ impl Session { let deadline = Instant::now() + Duration::from_secs_f64(limit.max(0.0)); loop { let status = self.game("status")?; - if !status["player"].is_null() && status["pending_chunks"] == 0 { + // On a server (single player's server thread too), also the + // level around the player. + if !status["player"].is_null() + && status["pending_chunks"] == 0 + && status["server"]["loaded"] != false + { return Ok(status); } if Instant::now() > deadline { diff --git a/crates/horizon-client/src/game/integrated.rs b/crates/horizon-client/src/game/integrated.rs index b2c0a2e7f..56d71ca96 100644 --- a/crates/horizon-client/src/game/integrated.rs +++ b/crates/horizon-client/src/game/integrated.rs @@ -316,6 +316,7 @@ impl Game<'_> { // The owner is an operator when the world allows commands // (`IntegratedPlayerList`, `MinecraftServer.getProfilePermissions`). host.hub.ops.insert(owner, if commands { 4 } else { 0 }); + host.hub.singleplayer_owner = Some(owner); host.owner = Some(Owner { uuid: owner, saved: Some(saved), diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 680360c93..3be2df388 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -2418,6 +2418,17 @@ impl Game<'_> { (player.position.z.floor() as i32) >> 4, ); if !self.streaming.is_lit(cx, cz) { + // Moved where nothing is loaded by horizon-ctl (`tp`, `fly`): + // the server hears of it, and sends the chunks there. A player + // who walked there has already sent that move. + let pos = [player.position.x, player.position.y, player.position.z]; + if let Some(r) = self.remote.as_ref() + && r.loaded_sent + && r.last_pos != pos + { + let input = r.last_input; + self.remote_send_state(input); + } return Ok(()); } if self.remote.as_ref().is_some_and(|r| !r.loaded_sent) { @@ -3707,6 +3718,9 @@ impl Game<'_> { "address": horizon_client::net::shown_address(&r.session.address), "name": r.session.name, "joined": r.joined, + // ServerboundPlayerLoadedPacket sent: the level around the + // player is ready, and the client ticks and sends its moves. + "loaded": r.loaded_sent, "status": r.status, "entity_id": r.entity_id, "dimension": r.dimension.name, diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index 5d593be2d..ca198b7b6 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -132,6 +132,9 @@ pub struct Hub { /// The `player_movement_check` and `elytra_movement_check` game rules, /// set by the game before each tick. pub movement_checks: (bool, bool), + /// An integrated server's owner (`MinecraftServer.isSingleplayerOwner`), + /// whose moves are never checked. + pub singleplayer_owner: Option, /// Who rides what, set by the game before each tick. pub riding: super::entity::Riding, last_clock: i64, @@ -265,6 +268,7 @@ impl Hub { sync, ticks: 0, movement_checks: (true, true), + singleplayer_owner: None, riding: Default::default(), last_clock: i64::MIN, last_rate: 0.0, @@ -1893,6 +1897,7 @@ impl Hub { ) { let (frozen, (check, elytra_check)) = (self.ticking.1, self.movement_checks); let g = &mut self.guests[i]; + let owner = self.singleplayer_owner == Some(g.uuid); let to = [ to[0].clamp(-3.0E7, 3.0E7), to[1].clamp(-2.0E7, 2.0E7), @@ -1916,9 +1921,10 @@ impl Hub { if packets > 5 { packets = 1; } - // shouldCheckPlayerMovement. The server holds no velocity for a - // guest (getDeltaMovement), so nothing is expected. - if check && (!g.fall_flying || elytra_check) { + // shouldCheckPlayerMovement (never the single-player owner). + // The server holds no velocity for a guest (getDeltaMovement), + // so nothing is expected. + if !owner && check && (!g.fall_flying || elytra_check) { let limit = if g.fall_flying { 300.0 } else { 100.0 }; if moved > limit * f64::from(packets) { events.push(HostEvent::Warn(format!(