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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-18 15:46:35 +02:00
parent 2b6ae71fb7
commit 7a6a4d9249
4 changed files with 30 additions and 4 deletions
@@ -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 {
@@ -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),
+14
View File
@@ -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,
+9 -3
View File
@@ -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<u128>,
/// 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!(