[PR #1110] [MERGED] Items merge with their neighbours; falling blocks land in their own tick #3058

Closed
opened 2026-11-02 16:01:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1110
Author: @ludovic111
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @ludovic111

Base: main ← Head: fix/item-merge-falling-landing


📝 Commits (1)

  • b4100ed Items merge with their neighbours; falling blocks land in their own tick

📊 Changes

4 files changed (+504 additions, -137 deletions)

View changed files

📝 crates/horizon-client/src/entities.rs (+305 -0)
📝 crates/horizon-client/src/entity_nbt.rs (+2 -0)
📝 crates/horizon-client/src/game.rs (+196 -137)
📝 crates/horizon-client/src/game/remote.rs (+1 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #996.

What

Fresh worlds left about twice as many dropped items lying around as vanilla. Two causes, both in crates/horizon-client:

  1. Dropped items never merged. Vanilla's ItemEntity.tick calls mergeWithNeighbours every 2 ticks while the item moves between blocks and every 40 otherwise. Each mergeable item whose box meets this one's (grown by 0.5 sideways) takes this stack or gives it its own: the smaller goes into the larger (tryToMerge), up to min(max stack, 64). The kept item takes the longer pickup delay and the younger age (merge). Horizon had none of this, so every leaf litter, moss carpet or seed popped by water in a fresh chunk stayed a separate entity. Horizon now does the same (entities::merge_with_neighbours, with ItemCells, a grid of items by block so the search stays local). It counts ticks with a new ticks field, vanilla's tickCount, and age rules match: isMergable is checked with the age before this tick's increment, as in vanilla. The host merges; LAN guests and remote clients don't (!isClientSide).
  2. Falling blocks landed after every other falling block had moved. tick_falling moved all of them and placed the landed ones after the loop, so a block falling right behind another moved into the cell the first was about to take, landed on the same spot and broke into an item. Vanilla's FallingBlockEntity.tick places (or drops) the block within the entity's own tick. Horizon does that now. The move is in fall_step, and the landing or drop runs right after it for each block.

Measurements

horizon-server with one horizon-bots bot for 150 s on a fresh world (seed 12345, view and simulation distance 10, tools/server_bench.py's settings). The script is in the agent's scratch area (drops.py); it counts @e[type=item] at the end and queries mspt every 10 s. Same machine (Mac mini M4 Pro), same script, before and after. "Ring" walks a bot around an already generated area (a copy of vanilla's idle world) after clearing its items, so only the chunks loaded on the walk drop items.

Run Horizon main This PR Vanilla 26.3
fresh world, mixed bot: item entities 657–679 496 313
… of which sand / gravel 30 / 7 0 / 0 0 / 4
fresh world, idle bot 389 332 305
ring walk on a generated world 263–268 204 116

Tick cost (mean of the 10-second mspt averages, worst p99 of those windows):

Run Horizon main This PR Vanilla 26.3
fresh, mixed 2.16 ms (p99 4.6) 2.09 ms (p99 7.2, one window; the others 2.8–4.7) 9.57 ms (p99 144.5)
fresh, idle 1.94 ms (p99 3.7) 1.97 ms (p99 4.0) 7.06 ms (p99 74.9)
ring walk 1.72–1.80 ms (p99 4.5–4.9) 1.82 ms (p99 4.2) 13.85 ms (p99 155.5)

Merging costs nothing measurable. What is left is mostly leaf litter and moss carpet that vanilla's flowing water carries and piles up: items here aren't pushed by water currents yet (Entity.updateInWaterStateAndDoFluidPushing for items). That is noted as a follow-up, not part of this PR. The chunk generation harness now also compares postprocessing marks (#1109), and they match vanilla: the same blocks tick after generation, so the drops come from what happens to those blocks, not from generation.

Checks

  • cargo fmt --all -- --check: clean.
  • cargo clippy -p horizon-client --all-targets -- -D warnings (run with set -o pipefail): clean.
  • cargo test -p horizon-client: all pass (956 lib tests + the integration tests), including 6 new entities::merge_tests (smaller into larger, the 0.75-block reach and no vertical growth, different or full stacks, unmergeable items and the age-6000 edge, several neighbours in spawn order until full, the grid following moves).
  • tools/parity.py --changed origin/main: 142 harnesses depend on the four P4 branches (#996, #1037, #770 and this one); they ran once on the branches merged onto main ae21bd54 (Mac mini, --changed origin/main): all 142 pass, including chunk_generation (with the new comparison), decorated_region, structure_density, terrain, tree_feature, worldgen, worldgen_random and world_spawn (60/60 seeds). Nothing failed, so no rerun on plain main was needed.

Found by the agent's server benchmark run (#996's measurements); #678's frame spikes are partly the same fresh-chunk work.

🤖 Generated with Claude Code


🔄 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/1110 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/item-merge-falling-landing` --- ### 📝 Commits (1) - [`b4100ed`](https://github.com/horizon-rust/horizon/commit/b4100ed752a50bc707d20816528c7289bf079d5d) Items merge with their neighbours; falling blocks land in their own tick ### 📊 Changes **4 files changed** (+504 additions, -137 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/entities.rs` (+305 -0) 📝 `crates/horizon-client/src/entity_nbt.rs` (+2 -0) 📝 `crates/horizon-client/src/game.rs` (+196 -137) 📝 `crates/horizon-client/src/game/remote.rs` (+1 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #996. ## What Fresh worlds left about twice as many dropped items lying around as vanilla. Two causes, both in `crates/horizon-client`: 1. **Dropped items never merged.** Vanilla's `ItemEntity.tick` calls `mergeWithNeighbours` every 2 ticks while the item moves between blocks and every 40 otherwise. Each mergeable item whose box meets this one's (grown by 0.5 sideways) takes this stack or gives it its own: the smaller goes into the larger (`tryToMerge`), up to `min(max stack, 64)`. The kept item takes the longer pickup delay and the younger age (`merge`). Horizon had none of this, so every leaf litter, moss carpet or seed popped by water in a fresh chunk stayed a separate entity. Horizon now does the same (`entities::merge_with_neighbours`, with `ItemCells`, a grid of items by block so the search stays local). It counts ticks with a new `ticks` field, vanilla's `tickCount`, and age rules match: `isMergable` is checked with the age before this tick's increment, as in vanilla. The host merges; LAN guests and remote clients don't (`!isClientSide`). 2. **Falling blocks landed after every other falling block had moved.** `tick_falling` moved all of them and placed the landed ones after the loop, so a block falling right behind another moved into the cell the first was about to take, landed on the same spot and broke into an item. Vanilla's `FallingBlockEntity.tick` places (or drops) the block within the entity's own tick. Horizon does that now. The move is in `fall_step`, and the landing or drop runs right after it for each block. ## Measurements `horizon-server` with one `horizon-bots` bot for 150 s on a fresh world (seed 12345, view and simulation distance 10, `tools/server_bench.py`'s settings). The script is in the agent's scratch area (`drops.py`); it counts `@e[type=item]` at the end and queries `mspt` every 10 s. Same machine (Mac mini M4 Pro), same script, before and after. "Ring" walks a bot around an already generated area (a copy of vanilla's idle world) after clearing its items, so only the chunks loaded on the walk drop items. | Run | Horizon main | This PR | Vanilla 26.3 | |---|---:|---:|---:| | fresh world, mixed bot: item entities | 657–679 | **496** | 313 | | … of which sand / gravel | 30 / 7 | **0 / 0** | 0 / 4 | | fresh world, idle bot | 389 | **332** | 305 | | ring walk on a generated world | 263–268 | **204** | 116 | Tick cost (mean of the 10-second `mspt` averages, worst p99 of those windows): | Run | Horizon main | This PR | Vanilla 26.3 | |---|---:|---:|---:| | fresh, mixed | 2.16 ms (p99 4.6) | 2.09 ms (p99 7.2, one window; the others 2.8–4.7) | 9.57 ms (p99 144.5) | | fresh, idle | 1.94 ms (p99 3.7) | 1.97 ms (p99 4.0) | 7.06 ms (p99 74.9) | | ring walk | 1.72–1.80 ms (p99 4.5–4.9) | 1.82 ms (p99 4.2) | 13.85 ms (p99 155.5) | Merging costs nothing measurable. What is left is mostly leaf litter and moss carpet that vanilla's flowing water carries and piles up: items here aren't pushed by water currents yet (`Entity.updateInWaterStateAndDoFluidPushing` for items). That is noted as a follow-up, not part of this PR. The chunk generation harness now also compares postprocessing marks (#1109), and they match vanilla: the same blocks tick after generation, so the drops come from what happens to those blocks, not from generation. ## Checks - `cargo fmt --all -- --check`: clean. - `cargo clippy -p horizon-client --all-targets -- -D warnings` (run with `set -o pipefail`): clean. - `cargo test -p horizon-client`: all pass (956 lib tests + the integration tests), including 6 new `entities::merge_tests` (smaller into larger, the 0.75-block reach and no vertical growth, different or full stacks, unmergeable items and the age-6000 edge, several neighbours in spawn order until full, the grid following moves). - `tools/parity.py --changed origin/main`: 142 harnesses depend on the four P4 branches (#996, #1037, #770 and this one); they ran once on the branches merged onto main ae21bd54 (Mac mini, `--changed origin/main`): **all 142 pass**, including chunk_generation (with the new comparison), decorated_region, structure_density, terrain, tree_feature, worldgen, worldgen_random and world_spawn (60/60 seeds). Nothing failed, so no rerun on plain main was needed. Found by the agent's server benchmark run (#996's measurements); #678's frame spikes are partly the same fresh-chunk work. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 16:01:10 +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#3058
No description provided.