[PR #6556] [MERGED] Add an Entity trait and move pistons onto it #6948

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

📋 Pull Request Information

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

Base: main ← Head: refactor/entity-trait-pistons


📝 Commits (6)

  • 918e2a3 Add an Entity trait and move pistons onto it
  • a651e47 Entity walk: static dispatch, no allocation
  • b12410f Piston walk folds its chain
  • 1334088 Allow ref bindings in the entity match macro
  • adef157 Entity macros pass & and &mut, not ref bindings
  • 10fcd81 Merge remote-tracking branch 'origin/main' into refactor/entity-trait-pistons

📊 Changes

3 files changed (+357 additions, -262 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
➕ crates/horizon-client/src/game/entity.rs (+308 -0)
📝 crates/horizon-client/src/game/piston_push.rs (+48 -262)

📄 Description

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

What and why

First slice of #6509: a small Entity trait, and pistons moved onto it. No behaviour change.

game/entity.rs adds the trait, and EntityHandle, which names one entity by list and index. piston_push.rs used to have one match arm per kind in three places (push_body, apply_push, bounce), plus the Target enum and the list of targets. Those are now one arm each, going through the trait. Defaults follow vanilla's Entity, so each kind writes only what differs: an armor-stand marker ignores pistons, items and orbs update on_ground, projectiles set needs_sync.

Dispatch is static: with_entity! expands to one match with an arm per kind, each compiled for its concrete type, so there is no dyn Entity. entity_handles() is a plain iterator holding only the list lengths, so a walk allocates nothing and doesn't borrow Game.

A new kind is now one line in entity_lists! and one impl Entity, and pistons pick it up with no change to piston_push.rs.

Left outside the trait: the player and LAN guests. A guest is found by connection id in the hub, its body may be absent, its position lives in two places, and step height needs a mutable attribute lookup. They keep their own Target arms. The mob's own piston limiter and the armor stand's on_ground update in move_pushed also stay as they were. id isn't in the trait yet because nothing here uses it; #6537 adds it.

Size: 357 lines added, 262 removed, against the merge base.

Fixes #6536

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

Entity.getPistonPushReaction (armor stand override for markers), Entity.isSupportedBy, Entity.move(MoverType.PISTON, …), PistonMovingBlockEntity.causeBounce. Method names follow vanilla's.

No behaviour change, measured:

  • Side-by-side scene piston_entities against the real 26.3 server, run twice on vanilla: 48 of 48 values match, same as before this change.
  • tools/lan_e2e.py --check piston-entities passes.

Tick cost

Method: a temporary timer around push_piston_entities (not in this PR), both builds in the fast profile from the same base. Dedicated server, 60 piston clocks and 2000 entities (items, orbs, armor stands, boats), so about 40 pushes per tick, each walking every entity. tick sprint for 2800 ticks, split into 400-tick windows with the first dropped. Four runs each, alternating builds, 28 windows each.

median per tick range sd
main 7021 µs 6716 to 7515 190
this PR 7109 µs 6753 to 8767 596

The difference is 88 µs (1.2%), inside the spread between main's own runs (run medians 6937 to 7117). This PR's four run medians were 6865, 7024, 8300 and 7136, and the 8300 run is unexplained; the machine had other work on it. So this shows no clear change, not a proven zero, and a small cost can't be ruled out. An earlier version using for over the same chain measured 7001 µs against 6850 (2.2%), so the hot loops use for_each; that gap is also inside the spread, so the change isn't proven to help.

These numbers are from the commit before the macros switched from ref bindings to & and &mut. That change only alters how the same reference is written, so it wasn't re-measured.

Allocation, by reading the code: main built one Vec<Target> per push, with one element per entity. This PR allocates none without LAN guests, and with guests one Vec per push holding only the guests. The piston accumulator HashMap and StepHeights are unchanged from main.

What wasn't compared

The scene covers falling blocks, orbs and arrows. Other kinds go through the same code paths, checked by reading each override against the old match arm. Parity harnesses touching this are left to CI.

Harnesses

Run locally on this head, per the ruling on Discord: the ones covering pistons. CI runs the full --changed set.

PASS piston_movement 72s
PASS piston_push 72s
PASS piston_shape 76s
3 passed, 0 failed in 1.3 min.

A refactor with no behaviour change; proved by script, no human played this change.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on Valhalla, against origin/main at 81e528f92, 5 min 53 s)

Check Result
Scope ⚠️ 3 files, +357 −262; 619 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 598 passed (32 s)
rustfmt ✅ (17 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 ✅ (3 min 7 s)
tests: horizon-client ✅ 593 passed (1 min 52 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 324 affected, to run in CI (--quick): armor_stand_frost, arrow, arrow_wind_charge, block_particles, block_removal, boat_authority, boat_paddle_reset, boat_submerged, breaking_model, bulk_section, bundle_weight, camera and 312 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/6556 **Author:** [@HrafnaValkyrja](https://github.com/HrafnaValkyrja) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `refactor/entity-trait-pistons` --- ### 📝 Commits (6) - [`918e2a3`](https://github.com/horizon-rust/horizon/commit/918e2a372d91dc264033123c14e738c0d1eb73d8) Add an Entity trait and move pistons onto it - [`a651e47`](https://github.com/horizon-rust/horizon/commit/a651e476a332b614e4b185f8ba9c7b07912935aa) Entity walk: static dispatch, no allocation - [`b12410f`](https://github.com/horizon-rust/horizon/commit/b12410ff5279c08b0d029607a11cc9898f4c1047) Piston walk folds its chain - [`1334088`](https://github.com/horizon-rust/horizon/commit/133408899f8f4c7679d8f415871e1b0965e404be) Allow ref bindings in the entity match macro - [`adef157`](https://github.com/horizon-rust/horizon/commit/adef15790dd5dca0b7723d7058d7f0ee38af8e84) Entity macros pass & and &mut, not ref bindings - [`10fcd81`](https://github.com/horizon-rust/horizon/commit/10fcd81920c153f8699bd2e72fc91c00328d2b73) Merge remote-tracking branch 'origin/main' into refactor/entity-trait-pistons ### 📊 Changes **3 files changed** (+357 additions, -262 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) ➕ `crates/horizon-client/src/game/entity.rs` (+308 -0) 📝 `crates/horizon-client/src/game/piston_push.rs` (+48 -262) </details> ### 📄 Description > 🤖 Opened by Valkyrie's AI agent (Claude Code, Opus 5.5), not by Valkyrie herself. ## What and why First slice of #6509: a small `Entity` trait, and pistons moved onto it. No behaviour change. `game/entity.rs` adds the trait, and `EntityHandle`, which names one entity by list and index. `piston_push.rs` used to have one match arm per kind in three places (`push_body`, `apply_push`, `bounce`), plus the `Target` enum and the list of targets. Those are now one arm each, going through the trait. Defaults follow vanilla's `Entity`, so each kind writes only what differs: an armor-stand marker ignores pistons, items and orbs update `on_ground`, projectiles set `needs_sync`. Dispatch is static: `with_entity!` expands to one `match` with an arm per kind, each compiled for its concrete type, so there is no `dyn Entity`. `entity_handles()` is a plain iterator holding only the list lengths, so a walk allocates nothing and doesn't borrow `Game`. A new kind is now one line in `entity_lists!` and one `impl Entity`, and pistons pick it up with no change to `piston_push.rs`. Left outside the trait: the player and LAN guests. A guest is found by connection id in the hub, its body may be absent, its position lives in two places, and step height needs a mutable attribute lookup. They keep their own `Target` arms. The mob's own piston limiter and the armor stand's `on_ground` update in `move_pushed` also stay as they were. `id` isn't in the trait yet because nothing here uses it; #6537 adds it. Size: 357 lines added, 262 removed, against the merge base. Fixes #6536 ## 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 - [x] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `Entity.getPistonPushReaction` (armor stand override for markers), `Entity.isSupportedBy`, `Entity.move(MoverType.PISTON, …)`, `PistonMovingBlockEntity.causeBounce`. Method names follow vanilla's. No behaviour change, measured: - Side-by-side scene `piston_entities` against the real 26.3 server, run twice on vanilla: 48 of 48 values match, same as before this change. - `tools/lan_e2e.py --check piston-entities` passes. ## Tick cost Method: a temporary timer around `push_piston_entities` (not in this PR), both builds in the `fast` profile from the same base. Dedicated server, 60 piston clocks and 2000 entities (items, orbs, armor stands, boats), so about 40 pushes per tick, each walking every entity. `tick sprint` for 2800 ticks, split into 400-tick windows with the first dropped. Four runs each, alternating builds, 28 windows each. | | median per tick | range | sd | |---|---|---|---| | main | 7021 µs | 6716 to 7515 | 190 | | this PR | 7109 µs | 6753 to 8767 | 596 | The difference is 88 µs (1.2%), inside the spread between main's own runs (run medians 6937 to 7117). This PR's four run medians were 6865, 7024, 8300 and 7136, and the 8300 run is unexplained; the machine had other work on it. So this shows no clear change, not a proven zero, and a small cost can't be ruled out. An earlier version using `for` over the same chain measured 7001 µs against 6850 (2.2%), so the hot loops use `for_each`; that gap is also inside the spread, so the change isn't proven to help. These numbers are from the commit before the macros switched from `ref` bindings to `&` and `&mut`. That change only alters how the same reference is written, so it wasn't re-measured. Allocation, by reading the code: main built one `Vec<Target>` per push, with one element per entity. This PR allocates none without LAN guests, and with guests one `Vec` per push holding only the guests. The piston accumulator `HashMap` and `StepHeights` are unchanged from main. ## What wasn't compared The scene covers falling blocks, orbs and arrows. Other kinds go through the same code paths, checked by reading each override against the old match arm. Parity harnesses touching this are left to CI. ## Harnesses Run locally on this head, per the ruling on Discord: the ones covering pistons. CI runs the full `--changed` set. ``` PASS piston_movement 72s PASS piston_push 72s PASS piston_shape 76s 3 passed, 0 failed in 1.3 min. ``` A refactor with no behaviour change; proved by script, no human played this change. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on Valhalla, against origin/main at 81e528f92, 5 min 53 s) | Check | Result | | --- | --- | | Scope | ⚠️ 3 files, +357 −262; 619 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 598 passed (32 s) | | rustfmt | ✅ (17 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 | ✅ (3 min 7 s) | | tests: horizon-client | ✅ 593 passed (1 min 52 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 324 affected, to run in CI (--quick): armor_stand_frost, arrow, arrow_wind_charge, block_particles, block_removal, boat_authority, boat_paddle_reset, boat_submerged, breaking_model, bulk_section, bundle_weight, camera and 312 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:30:01 +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#6948
No description provided.