[PR #6925] [MERGED] Lightning finds its targets through the entity walk #7200

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

📋 Pull Request Information

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

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


📝 Commits (8)

  • 365cc67 Move lightning's thunderHit onto the entity walk
  • 9a3ad87 Merge refactor/entity-walk-plates (slice 3 final)
  • 80f78b6 Skip a thunderHit stage no entity is in
  • 532827b Merge branch 'fix/pearl-test-drag' into refactor/entity-walk-lightning
  • ed05ba3 Merge remote-tracking branch 'origin/main' into refactor/entity-walk-lightning
  • 7797b1d Format after merging main
  • a1a973a Merge remote-tracking branch 'origin/main' into refactor/entity-walk-lightning
  • 0c8f97e Merge origin/main into refactor/entity-walk-lightning

📊 Changes

2 files changed (+137 additions, -53 deletions)

View changed files

📝 crates/horizon-client/src/game/entity.rs (+59 -0)
📝 crates/horizon-client/src/game/lightning.rs (+78 -53)

📄 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.

What and why

Slice 6 of #6509, closes #6541: lightning's thunderHit now finds its targets with the entity walk instead of naming the lists. Stacked on slice 3 (#6538).

  • New Entity::thunder_hit (default Untouched) says what a kind does when struck; ThunderHit has Mob, Vehicle, Orb and Item. Mobs, boats, minecarts, orbs and items override it; every other kind stays untouched, as before.
  • Entity::thunder_bounds is the box the strike tests (a mob uses its kind's size, as before).
  • thunder_count counts a stage's targets with for_each_entity!; a stage with none is skipped. Stages run in the old order: mobs, cushions, vehicles and orbs, players, items.
  • entity_handles_rev walks each list last-first, so a destroyed boat, cart, orb or burnt item can be removed mid-walk.
  • Players and cushions are not on the walk and stay as they were. No dyn; the stage walks reuse the handle iterators, which allocate nothing.

Behaviour is meant to be unchanged.

Fixes #6541

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.thunderHit sets the entity on fire and calls hurtServer(lightning_bolt, 5). Read through tools/rea_vanilla.py (survey in the slice notes): hurtServer does nothing for Projectile kinds (they only mark hurt), AbstractHurtingProjectile, EvokerFangs, EyeOfEnder, AreaEffectCloud, LightningBolt, Marker, Interaction and Display, so those stay untouched. VehicleEntity.hurtServer adds 5 x 10 against a limit of 40, so boats and minecarts are destroyed.

Side-by-side

Scenes light_walk (new: pig, villager, creeper, cow, boat, minecart, orb, stone and netherite items, arrow, snowball, TNT, armor stand, and controls 7 blocks out), light_kinds, light_cushion, light_nobolt, dedicated servers, vanilla run twice with --noise.

result
base vs this PR output identical, all four scenes
light_walk vs vanilla 30 of 32 values match, base and PR alike

The two that differ are in base too and are left alone here: after a strike vanilla has 1 item and no netherite ingot, Horizon 2 items and 1 ingot. light_kinds, light_cushion and light_nobolt also differ from vanilla in base (paintings, cushions); not from this PR.

Tick cost

Rule from #6509: no dyn, no allocation per walk. Method: a temporary timer (not in this PR) around the thunder_hit call. fast profile, dedicated server, 2000 marker armor stands plus 30 minecarts and 30 pigs, 40 bolts at once, 8 times, microseconds per call. Other builds were running (load about 21 to 27).

My first version walked every handle in every stage and was clearly worse: 1.78 to 3.09 µs per call in base against 23.14 and 34.72 in the PR (two runs, then stopped). The version here counts targets per stage first and skips empty stages.

one round µs per thunder_hit call
base 5.32
this PR 3.04

One pair on a loaded machine is noise, not a result: the same base build ranged 1.78 to 5.32 across runs. It shows no clear change, in either direction. With many entities and a mob in the strike box, the mob stage still walks the handle list until its last target.

Harnesses

Run locally: the ones covering lightning (entity_death_loot has the lightning turtle cases; server_entities the dedicated-server entities). CI runs the full --changed set.

PASS entity_death_loot 11s
PASS server_entities 95s
2 passed, 0 failed in 1.6 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 1331c9ea3, 2 min 30 s)

Check Result
Scope ⚠️ 5 files, +323 −206; 529 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 610 passed (28 s)
rustfmt ✅ (6 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 ✅ (50 s)
tests: horizon-client ✅ 652 passed (52 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
mod API up to date ✅ (9 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 236 affected, to run in CI (--quick): armor_stand_frost, armor_stand_turtle_egg, arrow_wind_charge, block_particles, block_removal, boat_authority, boat_paddle_reset, boat_submerged, breaking_model, command_exec, composter, crafter and 224 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/6925 **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-lightning` --- ### 📝 Commits (8) - [`365cc67`](https://github.com/horizon-rust/horizon/commit/365cc67662c4a0807abcc0cf0c2584939a7b4f39) Move lightning's thunderHit onto the entity walk - [`9a3ad87`](https://github.com/horizon-rust/horizon/commit/9a3ad873bca03cd1e08527cf1d4cd1b377d27c90) Merge refactor/entity-walk-plates (slice 3 final) - [`80f78b6`](https://github.com/horizon-rust/horizon/commit/80f78b66288e285a6588342b9162dae5a191744f) Skip a thunderHit stage no entity is in - [`532827b`](https://github.com/horizon-rust/horizon/commit/532827b1486ca135f115b2f9b15b34c7c341f83a) Merge branch 'fix/pearl-test-drag' into refactor/entity-walk-lightning - [`ed05ba3`](https://github.com/horizon-rust/horizon/commit/ed05ba3f6cb202d00776241ab231c6ac925f0822) Merge remote-tracking branch 'origin/main' into refactor/entity-walk-lightning - [`7797b1d`](https://github.com/horizon-rust/horizon/commit/7797b1d1a4cb1a4e6cbcc0973e383c882b79e9a1) Format after merging main - [`a1a973a`](https://github.com/horizon-rust/horizon/commit/a1a973a444bf8ab7140603232ac1c410f0f25bab) Merge remote-tracking branch 'origin/main' into refactor/entity-walk-lightning - [`0c8f97e`](https://github.com/horizon-rust/horizon/commit/0c8f97e4a31260137a2775d0ed3afef1adc5f578) Merge origin/main into refactor/entity-walk-lightning ### 📊 Changes **2 files changed** (+137 additions, -53 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/entity.rs` (+59 -0) 📝 `crates/horizon-client/src/game/lightning.rs` (+78 -53) </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. ## What and why Slice 6 of #6509, closes #6541: lightning's `thunderHit` now finds its targets with the entity walk instead of naming the lists. Stacked on slice 3 (#6538). - New `Entity::thunder_hit` (default `Untouched`) says what a kind does when struck; `ThunderHit` has `Mob`, `Vehicle`, `Orb` and `Item`. Mobs, boats, minecarts, orbs and items override it; every other kind stays untouched, as before. - `Entity::thunder_bounds` is the box the strike tests (a mob uses its kind's size, as before). - `thunder_count` counts a stage's targets with `for_each_entity!`; a stage with none is skipped. Stages run in the old order: mobs, cushions, vehicles and orbs, players, items. - `entity_handles_rev` walks each list last-first, so a destroyed boat, cart, orb or burnt item can be removed mid-walk. - Players and cushions are not on the walk and stay as they were. No `dyn`; the stage walks reuse the handle iterators, which allocate nothing. Behaviour is meant to be unchanged. Fixes #6541 ## 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 `Entity.thunderHit` sets the entity on fire and calls `hurtServer(lightning_bolt, 5)`. Read through `tools/rea_vanilla.py` (survey in the slice notes): `hurtServer` does nothing for `Projectile` kinds (they only mark hurt), `AbstractHurtingProjectile`, `EvokerFangs`, `EyeOfEnder`, `AreaEffectCloud`, `LightningBolt`, `Marker`, `Interaction` and `Display`, so those stay untouched. `VehicleEntity.hurtServer` adds 5 x 10 against a limit of 40, so boats and minecarts are destroyed. ## Side-by-side Scenes `light_walk` (new: pig, villager, creeper, cow, boat, minecart, orb, stone and netherite items, arrow, snowball, TNT, armor stand, and controls 7 blocks out), `light_kinds`, `light_cushion`, `light_nobolt`, dedicated servers, vanilla run twice with `--noise`. | | result | |---|---| | base vs this PR | output identical, all four scenes | | `light_walk` vs vanilla | 30 of 32 values match, base and PR alike | The two that differ are in base too and are left alone here: after a strike vanilla has 1 item and no netherite ingot, Horizon 2 items and 1 ingot. `light_kinds`, `light_cushion` and `light_nobolt` also differ from vanilla in base (paintings, cushions); not from this PR. ## Tick cost Rule from #6509: no `dyn`, no allocation per walk. Method: a temporary timer (not in this PR) around the `thunder_hit` call. `fast` profile, dedicated server, 2000 marker armor stands plus 30 minecarts and 30 pigs, 40 bolts at once, 8 times, microseconds per call. Other builds were running (load about 21 to 27). My first version walked every handle in every stage and was clearly worse: 1.78 to 3.09 µs per call in base against 23.14 and 34.72 in the PR (two runs, then stopped). The version here counts targets per stage first and skips empty stages. | one round | µs per `thunder_hit` call | |---|---| | base | 5.32 | | this PR | 3.04 | One pair on a loaded machine is noise, not a result: the same base build ranged 1.78 to 5.32 across runs. It shows no clear change, in either direction. With many entities and a mob in the strike box, the mob stage still walks the handle list until its last target. ## Harnesses Run locally: the ones covering lightning (`entity_death_loot` has the lightning turtle cases; `server_entities` the dedicated-server entities). CI runs the full `--changed` set. ``` PASS entity_death_loot 11s PASS server_entities 95s 2 passed, 0 failed in 1.6 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 1331c9ea3, 2 min 30 s) | Check | Result | | --- | --- | | Scope | ⚠️ 5 files, +323 −206; 529 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 610 passed (28 s) | | rustfmt | ✅ (6 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 | ✅ (50 s) | | tests: horizon-client | ✅ 652 passed (52 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (9 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 236 affected, to run in CI (--quick): armor_stand_frost, armor_stand_turtle_egg, arrow_wind_charge, block_particles, block_removal, boat_authority, boat_paddle_reset, boat_submerged, breaking_model, command_exec, composter, crafter and 224 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:35 +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#7200
No description provided.