[PR #6935] [MERGED] Selectors gather entities through the entity walk #7209

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

📋 Pull Request Information

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

Base: main ← Head: refactor/entity-walk-selectors


📝 Commits (7)

  • c8141f1 Merge origin/main
  • d225506 refactor: gather selector targets with the entity walk
  • 0ee91d9 Merge branch 'fix/pearl-test-drag' into refactor/entity-walk-selectors
  • a977d85 Merge remote-tracking branch 'origin/main' into refactor/entity-walk-selectors
  • a7bdd05 Merge origin/main into refactor/entity-walk-selectors
  • 6e932ea Merge origin/main into refactor/entity-walk-selectors
  • 22c2240 Merge main into #6935

📊 Changes

2 files changed (+54 additions, -34 deletions)

View changed files

📝 crates/horizon-client/src/game/commands.rs (+8 -34)
📝 crates/horizon-client/src/game/entity.rs (+46 -0)

📄 Description

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

Stacks on #6734: the commits up to its head belong to that PR, and this slice is the rest. A PR's base has to be a branch in this repo and ours are on a fork, so this targets main, and the diff shrinks to the slice once #6734 merges.

Part of #6509, slice 8 (#6543), stacked on slice 3 (#6538, #6734). Moves the selector's candidate gathering onto for_each_entity.

level_candidates in commands.rs named ten entity lists one by one and mapped each to a Target. Now one walk does it, and each kind answers Entity::selector_target (required, so a new kind has to say what a selector finds it as): mobs return None while dying, projectiles None for the kinds /data cannot write, as before. Item frames, paintings, unsimulated entities, End crystals, the dragon and ominous spawners are not on the walk and are gathered as before. About 54 lines added and 34 removed.

Differences, stated plainly:

  • Order of an unsorted selector (@e, @e[limit=1], sort=arbitrary) changes from the old list-by-list order to the walk's order (mobs, items, boats, minecarts, armor stands, TNT, falling blocks, orbs, projectiles, rockets, then the kinds not on the walk). Sorted selectors (nearest, furthest) are identical except ties. Keeping the old order needed a sort of the candidates, which tripled the gathering time in a first version (see Tick cost), so it was dropped.
  • @e still does not find thrown tridents: Target has no variant for them, so selector_target returns None. This is the same as before the change, and unlike vanilla (see below). A trident needs a Target variant and its arms in kill, data and position code, which is a separate change.

Fixes #6543

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

Real server (26.3 dedicated), side-by-side scene selwalk: 21 entity kinds including two pigs riding a boat and a minecart, counted by type and tag, by #minecraft:boats and #minecraft:arrows, by box, with sort=nearest/furthest, limit=1, type=! and a peel of @e[limit=1,type=!...] that shows the order. Vanilla's unsorted order here is the order the entities were summoned in.

Before this change 112 of 148 values matched vanilla; after, 120 of 148 (the numbers are probes at two moments, before and after killing the pigs). The 28 values that still differ: thrown tridents are not found by @e (vanilla finds 1; this also moves the @e total, the #minecraft:impact_projectiles count, the box count and sort=furthest), a summoned item frame is not found (vanilla finds 1), and 3 of the 12 order probes.

The order probes are @e[limit=1,type=!A,type=!B,...] with more kinds excluded each step, which shows which entity comes first. Before, 7 of the 12 differed from vanilla; after, 3 do. One probe that matched before now differs: with pig, cow and item excluded, vanilla's first is the entity at x=8.5 and Horizon's is now the one at x=10.5 (before: 8.5). The other two that differ after are the steps that need the trident, which @e cannot find. Passengers: @e[type=minecraft:pig] counts the pigs riding the boat and the minecart and @e[tag=w_rider] finds both, identical before and after, and equal to vanilla.

Tick cost

Time in level_candidates per call, 2000 entities of seven kinds (items, orbs, pigs, minecarts, boats, TNT, marker armor stands), headless dedicated server, 300 calls of execute if entity @e[type=minecraft:pig,limit=1], one run per build, under a lock, machine load about 8 to 11, so noisy:

before after
per call 14.69 us 14.98 us

A first version that kept the old order with a stable sort of the candidates measured 9.99 us before and 29.86 us after in an earlier round (load about 6 to 8). That version is not in this branch. One run each gives no spread, so the 0.3 us difference is no measurable change and does not exclude a small one. The gathering is a small part of a selector's cost (the per-candidate filtering after it is unchanged and was not measured here).

Harnesses

Run locally, the ones that use selectors on entities: server_entities, remote_fireball, arrow_wind_charge, pearl_wind_charge, server_knockback, armor_stand_frost, cursor_death, spawn_egg_fluid, mount_submerged, plus tools/lan_e2e.py --check selector-tags. The full --changed set is 239 harnesses on this stack and was not run; CI runs it on the merge.

PASS pearl_wind_charge 499s
PASS cursor_death 533s
PASS spawn_egg_fluid 536s
PASS server_entities 536s
PASS armor_stand_frost 636s
PASS remote_fireball 145s
PASS arrow_wind_charge 157s
PASS server_knockback 831s
PASS mount_submerged 919s
9 passed, 0 failed in 15.3 min.

Proved by script against the real 26.3 server; no human played this change.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on Valhalla, against origin/main at 5d65d7b50, 5 min 37 s)

Check Result
Scope ✅ 2 files, +54 −34
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 610 passed (37 s)
rustfmt ✅ (10 s)
Rust ⚠️ 1.98.0 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with rustup update
clippy ✅ (2 min 13 s)
tests: horizon-client ✅ 652 passed (2 min 7 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
mod API up to date ✅ (19 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 233 affected, to run in CI (--quick): armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, block_removal, boat_authority, boat_paddle_reset, boat_submerged, command_exec, composter, crafter, cursor_death and 221 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Claude Code

https://claude.ai/code/session_018zuDTsnyHkP28bzn3u7S3m


🔄 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/6935 **Author:** [@HrafnaValkyrja](https://github.com/HrafnaValkyrja) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `refactor/entity-walk-selectors` --- ### 📝 Commits (7) - [`c8141f1`](https://github.com/horizon-rust/horizon/commit/c8141f144e6c7ec104b2466ce951bcfee2493ccb) Merge origin/main - [`d225506`](https://github.com/horizon-rust/horizon/commit/d225506eff637ccd68a6dfad3eaa349f4530bcab) refactor: gather selector targets with the entity walk - [`0ee91d9`](https://github.com/horizon-rust/horizon/commit/0ee91d90979e2e8ec431945659f5aafdf04fa290) Merge branch 'fix/pearl-test-drag' into refactor/entity-walk-selectors - [`a977d85`](https://github.com/horizon-rust/horizon/commit/a977d85017b8868e078ee577eb539485834ff4d7) Merge remote-tracking branch 'origin/main' into refactor/entity-walk-selectors - [`a7bdd05`](https://github.com/horizon-rust/horizon/commit/a7bdd058f9634cf4d9f9728b82314cafda6974ab) Merge origin/main into refactor/entity-walk-selectors - [`6e932ea`](https://github.com/horizon-rust/horizon/commit/6e932ea3c5fa2438399fd546beffcd99c245bf2e) Merge origin/main into refactor/entity-walk-selectors - [`22c2240`](https://github.com/horizon-rust/horizon/commit/22c2240767a986231c797c5412bd8dcccd51646b) Merge main into #6935 ### 📊 Changes **2 files changed** (+54 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands.rs` (+8 -34) 📝 `crates/horizon-client/src/game/entity.rs` (+46 -0) </details> ### 📄 Description > 🤖 Opened by Valkyrie's AI agent (Claude Code, Opus 5.5), not by Valkyrie herself. Stacks on #6734: the commits up to its head belong to that PR, and this slice is the rest. A PR's base has to be a branch in this repo and ours are on a fork, so this targets main, and the diff shrinks to the slice once #6734 merges. Part of #6509, slice 8 (#6543), stacked on slice 3 (#6538, #6734). Moves the selector's candidate gathering onto `for_each_entity`. `level_candidates` in `commands.rs` named ten entity lists one by one and mapped each to a `Target`. Now one walk does it, and each kind answers `Entity::selector_target` (required, so a new kind has to say what a selector finds it as): mobs return `None` while dying, projectiles `None` for the kinds `/data` cannot write, as before. Item frames, paintings, unsimulated entities, End crystals, the dragon and ominous spawners are not on the walk and are gathered as before. About 54 lines added and 34 removed. Differences, stated plainly: - Order of an unsorted selector (`@e`, `@e[limit=1]`, `sort=arbitrary`) changes from the old list-by-list order to the walk's order (mobs, items, boats, minecarts, armor stands, TNT, falling blocks, orbs, projectiles, rockets, then the kinds not on the walk). Sorted selectors (`nearest`, `furthest`) are identical except ties. Keeping the old order needed a sort of the candidates, which tripled the gathering time in a first version (see Tick cost), so it was dropped. - `@e` still does not find thrown tridents: `Target` has no variant for them, so `selector_target` returns `None`. This is the same as before the change, and unlike vanilla (see below). A trident needs a `Target` variant and its arms in kill, data and position code, which is a separate change. Fixes #6543 ## 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 Real server (26.3 dedicated), side-by-side scene `selwalk`: 21 entity kinds including two pigs riding a boat and a minecart, counted by type and tag, by `#minecraft:boats` and `#minecraft:arrows`, by box, with `sort=nearest`/`furthest`, `limit=1`, `type=!` and a peel of `@e[limit=1,type=!...]` that shows the order. Vanilla's unsorted order here is the order the entities were summoned in. Before this change 112 of 148 values matched vanilla; after, 120 of 148 (the numbers are probes at two moments, before and after killing the pigs). The 28 values that still differ: thrown tridents are not found by `@e` (vanilla finds 1; this also moves the `@e` total, the `#minecraft:impact_projectiles` count, the box count and `sort=furthest`), a summoned item frame is not found (vanilla finds 1), and 3 of the 12 order probes. The order probes are `@e[limit=1,type=!A,type=!B,...]` with more kinds excluded each step, which shows which entity comes first. Before, 7 of the 12 differed from vanilla; after, 3 do. One probe that matched before now differs: with pig, cow and item excluded, vanilla's first is the entity at x=8.5 and Horizon's is now the one at x=10.5 (before: 8.5). The other two that differ after are the steps that need the trident, which `@e` cannot find. Passengers: `@e[type=minecraft:pig]` counts the pigs riding the boat and the minecart and `@e[tag=w_rider]` finds both, identical before and after, and equal to vanilla. ## Tick cost Time in `level_candidates` per call, 2000 entities of seven kinds (items, orbs, pigs, minecarts, boats, TNT, marker armor stands), headless dedicated server, 300 calls of `execute if entity @e[type=minecraft:pig,limit=1]`, one run per build, under a lock, machine load about 8 to 11, so noisy: | | before | after | |---|---|---| | per call | 14.69 us | 14.98 us | A first version that kept the old order with a stable sort of the candidates measured 9.99 us before and 29.86 us after in an earlier round (load about 6 to 8). That version is not in this branch. One run each gives no spread, so the 0.3 us difference is no measurable change and does not exclude a small one. The gathering is a small part of a selector's cost (the per-candidate filtering after it is unchanged and was not measured here). ## Harnesses Run locally, the ones that use selectors on entities: server_entities, remote_fireball, arrow_wind_charge, pearl_wind_charge, server_knockback, armor_stand_frost, cursor_death, spawn_egg_fluid, mount_submerged, plus `tools/lan_e2e.py --check selector-tags`. The full `--changed` set is 239 harnesses on this stack and was not run; CI runs it on the merge. ``` PASS pearl_wind_charge 499s PASS cursor_death 533s PASS spawn_egg_fluid 536s PASS server_entities 536s PASS armor_stand_frost 636s PASS remote_fireball 145s PASS arrow_wind_charge 157s PASS server_knockback 831s PASS mount_submerged 919s 9 passed, 0 failed in 15.3 min. ``` Proved by script against the real 26.3 server; no human played this change. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on Valhalla, against origin/main at 5d65d7b50, 5 min 37 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +54 −34 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 610 passed (37 s) | | rustfmt | ✅ (10 s) | | Rust | ⚠️ 1.98.0 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with `rustup update` | | clippy | ✅ (2 min 13 s) | | tests: horizon-client | ✅ 652 passed (2 min 7 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (19 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 233 affected, to run in CI (--quick): armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, block_removal, boat_authority, boat_paddle_reset, boat_submerged, command_exec, composter, crafter, cursor_death and 221 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018zuDTsnyHkP28bzn3u7S3m --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:35:44 +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#7209
No description provided.