[PR #7037] [MERGED] Gravity and fluid push are decided once, on the entity trait #7286

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

📋 Pull Request Information

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

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


📝 Commits (7)

  • 288df0a Merge remote-tracking branch 'origin/main' into refactor/entity-walk-fluids
  • be05eaa Merge commit '40b190f49' into refactor/entity-walk-fluids
  • 6f33e2b refactor: decide gravity and fluid push once for every entity kind
  • b938d5b Merge origin/main into refactor/entity-walk-fluids
  • 42d3c87 Merge remote-tracking branch 'origin/main' into refactor/entity-walk-fluids
  • 385aa3b Keep the Entity trait's one header after the merge
  • b07a0cc Merge remote-tracking branch 'origin/main' into refactor/entity-walk-fluids

📊 Changes

12 files changed (+221 additions, -232 deletions)

View changed files

📝 crates/horizon-client/src/arrows.rs (+3 -2)
📝 crates/horizon-client/src/client_lib.rs (+1 -0)
📝 crates/horizon-client/src/entities.rs (+24 -5)
➕ crates/horizon-client/src/entity_rules.rs (+33 -0)
📝 crates/horizon-client/src/game.rs (+1 -3)
📝 crates/horizon-client/src/game/boats.rs (+4 -10)
📝 crates/horizon-client/src/game/entity.rs (+94 -1)
📝 crates/horizon-client/src/game/minecarts.rs (+5 -16)
📝 crates/horizon-client/src/game/remote_projectiles.rs (+3 -2)
📝 crates/horizon-client/src/game/tnt.rs (+28 -176)
📝 crates/horizon-client/src/mobs.rs (+5 -0)
📝 crates/horizon-client/src/projectiles.rs (+20 -17)

📄 Description

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

What and why

Slice 9 of #6509, part of #6544: gravity and fluid push are decided once for every kind, not once per kind.

  • New EntityRules trait (horizon-client, entity_rules.rs): is_no_gravity, get_default_gravity, get_gravity (zero with NoGravity, else the default), is_pushed_by_fluid. Defaults are vanilla Entity's. The Entity trait extends it.
  • Eight inline NoGravity checks (items, orbs, arrows, other projectiles, boats, minecarts, TNT, falling blocks) are now one get_gravity() each. A new kind gets the check by implementing the trait.
  • Entity::push_by_fluid and Entity::push_by_bubble_column are default methods. Boats, minecarts and TNT call them. push_by_fluid calls update_entity_fluids.
  • TNT had its own copy of the fluid world (TntFluidWorld, about 140 lines). It now calls update_entity_fluids, so that copy is gone. PrimedTnt::tick takes the fluid tables as a new argument.
  • Net change: 211 lines added, 232 removed.

No behaviour change is intended.

Not moved: items and armor stands still call update_fluids and the bubble column from inside their own tick in horizon-client, which cannot see the Entity trait in the game crate. They already go through update_entity_fluids. Moving them needs their ticks split or the trait moved into the library; that would be the next slice. Armor stands keep no NoGravity flag, so they take the trait defaults. TNT's bubble column push stays inline because it also collects surface positions.

Armor stand with NoGravity on plates: not fixed here. In the side-by-side scene below a stand with NoGravity hangs in the air exactly as in vanilla, so the gravity decision is not what presses the plate. The cause is somewhere else and I did not find it.

Part of #6544

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

Read through tools/rea_vanilla.py: Entity.isNoGravity reads the NoGravity flag, and no class in the entity survey overrides it. getGravity is zero with NoGravity, else getDefaultGravity. Entity.isPushedByFluid is true; AbstractArrow returns !isInGround(). Default gravities as already used in the code: item and TNT and falling block 0.04, orb 0.03, boat 0.04, minecart 0.04 or 0.005 in water, arrow and trident 0.05, throwables 0.03, llama spit 0.06, potions 0.05, fireballs 0.

Numbers

Side-by-side scenes against the real server (dedicated servers, flat world, no player):

scene what result
nograv item, TNT, falling block, boat, minecart, arrow, snowball, orb, armor stand, each with and without NoGravity, 8 ticks 72 of 72 values match vanilla
tnt_fluids TNT in a bubble column and beside flowing water, 6 ticks 28 of 28 match
flow_vehicles minecart, falling block (NoGravity) and boat in a stream and in a bubble column, 10 ticks 132 of 132 match

In the nograv scene the NoGravity entities stay at y 110.0 with zero motion and the others fall to y 108.625 (item, TNT, falling block) or the kind's own value, as vanilla. Unit tests for TNT, projectiles, minecarts, boats, items, orbs and arrows (67 tests) pass.

Tick cost

Rule from #6509: no dyn, no allocation per walk. Nothing added here walks entities, all calls are static, and no Vec is added; the TNT path drops an adapter struct. By reading the code, not measured: the other kinds are unchanged apart from reading a constant instead of a field.

Measured, one round, under flock: PrimedTnt::tick in water, 20000 ticks per batch, 5 batches, dev profile test (not optimised), median per tick.

median batches (ns)
base 11974 ns 13047, 12101, 11486, 11974, 11648
this PR 10958 ns 10991, 10679, 11005, 10892, 10958

The two runs ran at different machine load (about 5 for base, 9 to 10 for this PR), so this shows no slowdown; it does not show a speed-up. No rerun.

Harnesses

Run locally: the ones covering fluids, boats, projectiles and entities. CI runs the full --changed set.

PASS boat_authority 64s
PASS entity_fluid 86s
PASS entity_fluid_tick 101s
PASS trident 37s
PASS arrow 104s
PASS remote_fireball 106s
PASS remote_fireworks 111s
PASS registered_entity_fluid 156s
PASS server_entities 206s
PASS boat_submerged 306s
PASS mount_submerged 584s
11 passed, 0 failed in 9.7 min.

Run with DISPLAY=:0 HORIZON_E2E_HEADLESS=1. pr_ready --quick: rustfmt, clippy and 2053 unit tests pass.

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 2b6d855da, 12 min 12 s)

Check Result
Scope ✅ 12 files, +221 −232
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 611 passed (36 s)
rustfmt ✅ (16 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 37 s)
tests: horizon-client, horizon-client-lib ✅ 2067 passed (8 min 21 s)
doc tests ✅ 0 passed (4 s)
content root tests ➖ content root untouched
mod API up to date ✅ (15 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 267 affected, to run in CI (--quick): armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer and 255 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/7037 **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-fluids` --- ### 📝 Commits (7) - [`288df0a`](https://github.com/horizon-rust/horizon/commit/288df0adddc6dc201a3900956a6b7400f764ab2d) Merge remote-tracking branch 'origin/main' into refactor/entity-walk-fluids - [`be05eaa`](https://github.com/horizon-rust/horizon/commit/be05eaab28a85728456592479940ea4238301601) Merge commit '40b190f49' into refactor/entity-walk-fluids - [`6f33e2b`](https://github.com/horizon-rust/horizon/commit/6f33e2bba3ad75db881a818614f55db976c82df3) refactor: decide gravity and fluid push once for every entity kind - [`b938d5b`](https://github.com/horizon-rust/horizon/commit/b938d5bb82d2fdbba7196604a4bac798210b766c) Merge origin/main into refactor/entity-walk-fluids - [`42d3c87`](https://github.com/horizon-rust/horizon/commit/42d3c8794e22a528b2b4f30cfc12a5ad0d440f58) Merge remote-tracking branch 'origin/main' into refactor/entity-walk-fluids - [`385aa3b`](https://github.com/horizon-rust/horizon/commit/385aa3b5d7fc0b48a9c536842c907af17f0ba131) Keep the Entity trait's one header after the merge - [`b07a0cc`](https://github.com/horizon-rust/horizon/commit/b07a0ccaa4aa98b6d32e3794550ad1942cc0cc94) Merge remote-tracking branch 'origin/main' into refactor/entity-walk-fluids ### 📊 Changes **12 files changed** (+221 additions, -232 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/arrows.rs` (+3 -2) 📝 `crates/horizon-client/src/client_lib.rs` (+1 -0) 📝 `crates/horizon-client/src/entities.rs` (+24 -5) ➕ `crates/horizon-client/src/entity_rules.rs` (+33 -0) 📝 `crates/horizon-client/src/game.rs` (+1 -3) 📝 `crates/horizon-client/src/game/boats.rs` (+4 -10) 📝 `crates/horizon-client/src/game/entity.rs` (+94 -1) 📝 `crates/horizon-client/src/game/minecarts.rs` (+5 -16) 📝 `crates/horizon-client/src/game/remote_projectiles.rs` (+3 -2) 📝 `crates/horizon-client/src/game/tnt.rs` (+28 -176) 📝 `crates/horizon-client/src/mobs.rs` (+5 -0) 📝 `crates/horizon-client/src/projectiles.rs` (+20 -17) </details> ### 📄 Description > 🤖 Opened by Valkyrie's AI agent (Claude Code, Opus 5.5), not by Valkyrie herself. ## What and why Slice 9 of #6509, part of #6544: gravity and fluid push are decided once for every kind, not once per kind. - New `EntityRules` trait (`horizon-client`, `entity_rules.rs`): `is_no_gravity`, `get_default_gravity`, `get_gravity` (zero with `NoGravity`, else the default), `is_pushed_by_fluid`. Defaults are vanilla `Entity`'s. The `Entity` trait extends it. - Eight inline `NoGravity` checks (items, orbs, arrows, other projectiles, boats, minecarts, TNT, falling blocks) are now one `get_gravity()` each. A new kind gets the check by implementing the trait. - `Entity::push_by_fluid` and `Entity::push_by_bubble_column` are default methods. Boats, minecarts and TNT call them. `push_by_fluid` calls `update_entity_fluids`. - TNT had its own copy of the fluid world (`TntFluidWorld`, about 140 lines). It now calls `update_entity_fluids`, so that copy is gone. `PrimedTnt::tick` takes the fluid tables as a new argument. - Net change: 211 lines added, 232 removed. No behaviour change is intended. Not moved: items and armor stands still call `update_fluids` and the bubble column from inside their own tick in `horizon-client`, which cannot see the `Entity` trait in the game crate. They already go through `update_entity_fluids`. Moving them needs their ticks split or the trait moved into the library; that would be the next slice. Armor stands keep no `NoGravity` flag, so they take the trait defaults. TNT's bubble column push stays inline because it also collects surface positions. Armor stand with `NoGravity` on plates: not fixed here. In the side-by-side scene below a stand with `NoGravity` hangs in the air exactly as in vanilla, so the gravity decision is not what presses the plate. The cause is somewhere else and I did not find it. Part of #6544 ## 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 Read through `tools/rea_vanilla.py`: `Entity.isNoGravity` reads the `NoGravity` flag, and no class in the entity survey overrides it. `getGravity` is zero with `NoGravity`, else `getDefaultGravity`. `Entity.isPushedByFluid` is true; `AbstractArrow` returns `!isInGround()`. Default gravities as already used in the code: item and TNT and falling block 0.04, orb 0.03, boat 0.04, minecart 0.04 or 0.005 in water, arrow and trident 0.05, throwables 0.03, llama spit 0.06, potions 0.05, fireballs 0. ## Numbers Side-by-side scenes against the real server (dedicated servers, flat world, no player): | scene | what | result | |---|---|---| | nograv | item, TNT, falling block, boat, minecart, arrow, snowball, orb, armor stand, each with and without `NoGravity`, 8 ticks | 72 of 72 values match vanilla | | tnt_fluids | TNT in a bubble column and beside flowing water, 6 ticks | 28 of 28 match | | flow_vehicles | minecart, falling block (`NoGravity`) and boat in a stream and in a bubble column, 10 ticks | 132 of 132 match | In the nograv scene the NoGravity entities stay at y 110.0 with zero motion and the others fall to y 108.625 (item, TNT, falling block) or the kind's own value, as vanilla. Unit tests for TNT, projectiles, minecarts, boats, items, orbs and arrows (67 tests) pass. ## Tick cost Rule from #6509: no `dyn`, no allocation per walk. Nothing added here walks entities, all calls are static, and no `Vec` is added; the TNT path drops an adapter struct. By reading the code, not measured: the other kinds are unchanged apart from reading a constant instead of a field. Measured, one round, under `flock`: `PrimedTnt::tick` in water, 20000 ticks per batch, 5 batches, dev profile test (not optimised), median per tick. | | median | batches (ns) | |---|---|---| | base | 11974 ns | 13047, 12101, 11486, 11974, 11648 | | this PR | 10958 ns | 10991, 10679, 11005, 10892, 10958 | The two runs ran at different machine load (about 5 for base, 9 to 10 for this PR), so this shows no slowdown; it does not show a speed-up. No rerun. ## Harnesses Run locally: the ones covering fluids, boats, projectiles and entities. CI runs the full `--changed` set. ``` PASS boat_authority 64s PASS entity_fluid 86s PASS entity_fluid_tick 101s PASS trident 37s PASS arrow 104s PASS remote_fireball 106s PASS remote_fireworks 111s PASS registered_entity_fluid 156s PASS server_entities 206s PASS boat_submerged 306s PASS mount_submerged 584s 11 passed, 0 failed in 9.7 min. ``` Run with `DISPLAY=:0 HORIZON_E2E_HEADLESS=1`. `pr_ready --quick`: rustfmt, clippy and 2053 unit tests pass. 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 2b6d855da, 12 min 12 s) | Check | Result | | --- | --- | | Scope | ✅ 12 files, +221 −232 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 611 passed (36 s) | | rustfmt | ✅ (16 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 37 s) | | tests: horizon-client, horizon-client-lib | ✅ 2067 passed (8 min 21 s) | | doc tests | ✅ 0 passed (4 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (15 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 267 affected, to run in CI (--quick): armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer and 255 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:37:06 +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#7286
No description provided.