[PR #7273] [MERGED] Clients are paired with an entity added late in the tick as it joined #7458

Closed
opened 2026-11-03 06:39:48 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7273
Author: @Ragbie
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/late-entity-add-state


📝 Commits (6)

  • a706e19 Clients are paired with an entity added late in the tick as it joined
  • ab41c7e First updates in the pass for spawns and thunder; joined states kept fresh
  • 5cb1bf0 server_entities harness: an item's last synced motion is the level's random's too
  • 06a4f65 rustfmt
  • 5ca1a4d Describe only the entities that joined after the tick's states
  • 60aa0ec Merge main into #7273

📊 Changes

7 files changed (+360 additions, -38 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+6 -0)
📝 crates/horizon-client/src/game/creatures.rs (+3 -0)
📝 crates/horizon-client/src/game/lan.rs (+80 -6)
📝 crates/horizon-client/src/game/lan_entities.rs (+26 -23)
📝 crates/horizon-client/src/lan/entity.rs (+169 -2)
📝 crates/horizon-client/src/lan/hub.rs (+55 -1)
📝 tools/test_server_entities_parity.py (+21 -6)

📄 Description

🤖 Opened by Ragbie's AI agent (Claude Code, Opus 5.5), not by Ragbie personally.

What and why

Fixes #7194.

Problem 1: AddEntity carried a moved state. A server's clients were first told about an entity added late in the tick only after its first tick had moved it. tick_lan takes the tick's entity snapshot before tick_falling, tick_tnt, tick_block_entities, tick_end and the host's use_with_hand. An entity those add, such as the item a falling block drops when it breaks on a torch, therefore only appeared in the next tick's snapshot, after tick_items / tick_mobs had moved it once. Its AddEntity carried that moved position and motion. Vanilla's ChunkMap.addEntity tracks the entity as it joins and sends the state it joined with.

  • At the end of the level's tick, lan_note_joined describes the entities again and Hub::note_joined keeps those the level's tracker hasn't met.
    • This only happens when the id counter moved since the snapshot and a guest is in the level.
  • The next tick's pass pairs them from that state (Entities::joined_states / starting_from).
    • It keeps what the tick's own state carries for that tick alone: drained minecart steps and needs_sync.
    • The noted states are used only in the next server tick.

Problem 2: the first update came one pass late. ServerLevel.tick runs ChunkMap.tick after the block ticks, the raids and ServerChunkCache.tickChunks' spawning and thunder, and before the entities. An entity that joined by then gets its tick-0 sendChanges in that same tick, before it moves. Horizon held back every new entity's first update until the next pass. For example, sand falling from a scheduled tick was sent a move after its first fall, and vanilla's never is if it lands within its 20-tick interval.

  • Entities::synced holds the id ranges taken in those phases:
    • up to the point after tick_blocks (which includes the last tick's late joins);
    • spawn_natural, the custom spawners and tick_raids;
    • tick_thunder.
  • Entities in these ranges are first updated in the pass that pairs them.
  • The client just paired with them also gets those changes, since vanilla's updatePlayers comes before sendChanges.
  • Entities the entities' own ticks add still wait for the next pass, as vanilla's wait for the next tick.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Classes and methods followed (read through tools/rea_vanilla.py):

  • ServerLevel.tick, where the order is tickPending → raid → chunkSource → entities.
  • ServerChunkCache.tick, which runs tickChunks and then chunkMap.tick().
  • ChunkMap.tick() and ChunkMap.addEntity → TrackedEntity.updatePlayers.
  • ServerEntity.sendChanges and UpdateInterval.periodic.
  • FallingBlockEntity.tick / fall.

Harness: tools/test_server_entities_parity.py.

  • The scene adds a torch with sand set above it. The sand falls once the ticks run, lands on the torch and breaks into an item.
  • An item's yaw, sideways motion and the motion last synced as it comes to rest come from the level's random, and vanilla's own runs differ there, so those fields are normalised.
  • Where the item was added, its upward motion and the height it rests at are compared exactly.
  • The sand is set with setblock rather than summoned while frozen. The tracker's interval keeps counting during /tick freeze, so whether a 20-tick update falls inside the fall would depend on the wall clock.

Before:

-play-entities entity minecraft:falling_block 6,-55,-4 | … | now (6.5, -55.0, -3.5) … | removed
+play-entities entity minecraft:falling_block 6,-55,-4 | … | now (6.5, -55.0400390625, -3.5) … | removed
-play-entities entity minecraft:item 6,-60,-4 | add at (6.5, -60.0, -3.5) rot ~ head 0.0 data 0 motion (~, 0.2000244155527071, ~) | …
+play-entities entity minecraft:item 6,-60,-4 | add at (6.483957670533576, -59.84, -3.5230065323912023) rot ~ head 0.0 data 0 motion (~, 0.15680888726118547, ~) | …

After: server entities: 33 entities identical, which passed twice in a row (parity.py --repeat 2).

Related harnesses, run on Windows with this branch: server_dragon, fishing_hook_entities, arrow_wind_charge, pearl_wind_charge, pearl_death, item_use_order, server_knockback, dedicated_server and lunge_motion all pass.

New unit tests:

  • lan::entity::tests::an_entity_added_after_the_pass_is_paired_as_it_joined
  • an_entity_joined_before_the_chunk_map_tick_is_updated_as_it_is_paired
  • lan::hub::tests::joined_states_last_only_into_the_next_tick

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on Evrim-PC, against upstream/main at e8b55fbe5, 7 min 40 s)

Check Result
Scope ✅ 7 files, +359 −37
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (2 min 11 s)
rustfmt ✅ (9 s)
clippy ✅ (22 s)
tests: horizon-client, horizon-client-lib ✅ 2110 passed (4 min 30 s)
doc tests ✅ 0 passed (5 s)
content root tests ➖ content root untouched
mod API up to date ✅ (18 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 301 affected, to run in CI (--quick): anvil_turtle_egg, arrow, block_particles, breaking_model, chunk_generation, command_exec, command_parse, composter, consumable_emission, consumable, consume_effect, container_screen and 289 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/7273 **Author:** [@Ragbie](https://github.com/Ragbie) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/late-entity-add-state` --- ### 📝 Commits (6) - [`a706e19`](https://github.com/horizon-rust/horizon/commit/a706e19c597e867d65bd6254de00d7f97dd2ac00) Clients are paired with an entity added late in the tick as it joined - [`ab41c7e`](https://github.com/horizon-rust/horizon/commit/ab41c7eebc13c76a3798aed5a6b445d4d8d5f1d4) First updates in the pass for spawns and thunder; joined states kept fresh - [`5cb1bf0`](https://github.com/horizon-rust/horizon/commit/5cb1bf0afeb42584fe5b40fd62a23d0c8f43381d) server_entities harness: an item's last synced motion is the level's random's too - [`06a4f65`](https://github.com/horizon-rust/horizon/commit/06a4f6560a24333701ea8110dd5031f33c2abadd) rustfmt - [`5ca1a4d`](https://github.com/horizon-rust/horizon/commit/5ca1a4d7ef773404af546681c113b82a01413649) Describe only the entities that joined after the tick's states - [`60aa0ec`](https://github.com/horizon-rust/horizon/commit/60aa0ec37fd4ee66bda2ce9512b86aa57a398202) Merge main into #7273 ### 📊 Changes **7 files changed** (+360 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+6 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+3 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+80 -6) 📝 `crates/horizon-client/src/game/lan_entities.rs` (+26 -23) 📝 `crates/horizon-client/src/lan/entity.rs` (+169 -2) 📝 `crates/horizon-client/src/lan/hub.rs` (+55 -1) 📝 `tools/test_server_entities_parity.py` (+21 -6) </details> ### 📄 Description > 🤖 Opened by Ragbie's AI agent (Claude Code, Opus 5.5), not by Ragbie personally. ## What and why Fixes #7194. **Problem 1: AddEntity carried a moved state.** A server's clients were first told about an entity added late in the tick only after its first tick had moved it. `tick_lan` takes the tick's entity snapshot before `tick_falling`, `tick_tnt`, `tick_block_entities`, `tick_end` and the host's `use_with_hand`. An entity those add, such as the item a falling block drops when it breaks on a torch, therefore only appeared in the next tick's snapshot, after `tick_items` / `tick_mobs` had moved it once. Its AddEntity carried that moved position and motion. Vanilla's `ChunkMap.addEntity` tracks the entity as it joins and sends the state it joined with. - At the end of the level's tick, `lan_note_joined` describes the entities again and `Hub::note_joined` keeps those the level's tracker hasn't met. - This only happens when the id counter moved since the snapshot and a guest is in the level. - The next tick's pass pairs them from that state (`Entities::joined_states` / `starting_from`). - It keeps what the tick's own state carries for that tick alone: drained minecart steps and `needs_sync`. - The noted states are used only in the next server tick. **Problem 2: the first update came one pass late.** `ServerLevel.tick` runs `ChunkMap.tick` after the block ticks, the raids and `ServerChunkCache.tickChunks`' spawning and thunder, and before the entities. An entity that joined by then gets its tick-0 `sendChanges` in that same tick, before it moves. Horizon held back every new entity's first update until the next pass. For example, sand falling from a scheduled tick was sent a move after its first fall, and vanilla's never is if it lands within its 20-tick interval. - `Entities::synced` holds the id ranges taken in those phases: - up to the point after `tick_blocks` (which includes the last tick's late joins); - `spawn_natural`, the custom spawners and `tick_raids`; - `tick_thunder`. - Entities in these ranges are first updated in the pass that pairs them. - The client just paired with them also gets those changes, since vanilla's `updatePlayers` comes before `sendChanges`. - Entities the entities' own ticks add still wait for the next pass, as vanilla's wait for the next tick. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference **Classes and methods followed** (read through `tools/rea_vanilla.py`): - `ServerLevel.tick`, where the order is tickPending → raid → chunkSource → entities. - `ServerChunkCache.tick`, which runs `tickChunks` and then `chunkMap.tick()`. - `ChunkMap.tick()` and `ChunkMap.addEntity` → `TrackedEntity.updatePlayers`. - `ServerEntity.sendChanges` and `UpdateInterval.periodic`. - `FallingBlockEntity.tick` / `fall`. **Harness:** `tools/test_server_entities_parity.py`. - The scene adds a torch with sand set above it. The sand falls once the ticks run, lands on the torch and breaks into an item. - An item's yaw, sideways motion and the motion last synced as it comes to rest come from the level's random, and vanilla's own runs differ there, so those fields are normalised. - Where the item was added, its upward motion and the height it rests at are compared exactly. - The sand is set with `setblock` rather than summoned while frozen. The tracker's interval keeps counting during `/tick freeze`, so whether a 20-tick update falls inside the fall would depend on the wall clock. **Before:** ``` -play-entities entity minecraft:falling_block 6,-55,-4 | … | now (6.5, -55.0, -3.5) … | removed +play-entities entity minecraft:falling_block 6,-55,-4 | … | now (6.5, -55.0400390625, -3.5) … | removed -play-entities entity minecraft:item 6,-60,-4 | add at (6.5, -60.0, -3.5) rot ~ head 0.0 data 0 motion (~, 0.2000244155527071, ~) | … +play-entities entity minecraft:item 6,-60,-4 | add at (6.483957670533576, -59.84, -3.5230065323912023) rot ~ head 0.0 data 0 motion (~, 0.15680888726118547, ~) | … ``` **After:** `server entities: 33 entities identical`, which passed twice in a row (`parity.py --repeat 2`). **Related harnesses, run on Windows with this branch:** `server_dragon`, `fishing_hook_entities`, `arrow_wind_charge`, `pearl_wind_charge`, `pearl_death`, `item_use_order`, `server_knockback`, `dedicated_server` and `lunge_motion` all pass. **New unit tests:** - `lan::entity::tests::an_entity_added_after_the_pass_is_paired_as_it_joined` - `an_entity_joined_before_the_chunk_map_tick_is_updated_as_it_is_paired` - `lan::hub::tests::joined_states_last_only_into_the_next_tick` ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on Evrim-PC, against upstream/main at e8b55fbe5, 7 min 40 s) | Check | Result | | --- | --- | | Scope | ✅ 7 files, +359 −37 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (2 min 11 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (22 s) | | tests: horizon-client, horizon-client-lib | ✅ 2110 passed (4 min 30 s) | | doc tests | ✅ 0 passed (5 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (18 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 301 affected, to run in CI (--quick): anvil_turtle_egg, arrow, block_particles, breaking_model, chunk_generation, command_exec, command_parse, composter, consumable_emission, consumable, consume_effect, container_screen and 289 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:39:48 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#7458
No description provided.