[PR #89] [MERGED] Particles: vanilla random streams, and fixes to 20 providers (part of #63) #2320

Closed
opened 2026-11-02 15:54:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/particles-63-providers


📝 Commits (1)

  • d9461c6 Particles: build each one with vanilla's random streams, fix the providers that differed

📊 Changes

4 files changed (+986 additions, -82 deletions)

View changed files

➕ crates/horizon-client/examples/particle_providers_probe.rs (+217 -0)
📝 crates/horizon-client/src/particles.rs (+259 -82)
➕ mods/horizon/src/test/java/dev/horizonlab/parity/VanillaParticleProvidersOracle.java (+292 -0)
➕ tools/test_particle_providers_parity.py (+218 -0)

📄 Description

What was wrong

Horizon's ParticleEngine drew every random value from one generator. Vanilla uses four:

  • each Particle has its own RandomSource.create() (Particle.random), used by the constructors and tick();
  • providers get ParticleEngine.random;
  • a few providers use ClientLevel.random (level.getRandom());
  • SpellParticle uses a static RANDOM.

Because all draws came from one place, constructor and provider values (lifetimes, motion, colours, sprites) were drawn from the wrong stream. Several providers also had wrong values:

type vanilla was
gust, small_gust SingleQuadParticle(x, y, z), so the lifetime is 12..15 from the right draw (GustParticle) built with the moving constructor, which shifted the lifetime
explosion_emitter, gust_emitter_* NoRenderParticle draws no quad size an extra draw that moved every spawned explosion and gust
effect, instant_effect, entity_effect, witch, infested x/z motion from SpellParticle.RANDOM; witch brightness from the provider particle random
landing_honey, landing_obsidian_tear, falling_nectar, spore_blossom_air, crimson_spore, warped_spore, white_ash, sculk_charge, sculk_charge_pop, dolphin lifetime, motion and alpha come from the provider's random, in the provider's order around sprite.get(random) (DripParticle, SuspendedParticle, SuspendedTownParticle, WhiteAshParticle, SculkCharge*Particle); crimson spore motion uses the float constants 1.0E-6F and 1.0E-4F particle random, double constants
composter lifetime 3 + level.getRandom().nextInt(5) particle random
enchanted_hit MagicProvider tints r×0.3 and g×0.8 after the constructor's tick no tint (white crits)
damage_indicator lives 20 ticks (DamageIndicatorProvider) a crit lifetime
note colour from Mth.sin's table f32::sin
shriek one random sprite (sprite.get(random)), not animated animated by age
trail 7-argument Particle constructor, ARGB.scaleRGB on 8-bit channels, Mth.lerp(1/ticksRemaining, …) 4-argument constructor, float channels, clamped lerp
firework sparks full bright (SimpleAnimatedParticle.getLightCoords) world light

The fix

Particle carries its own LegacyRandom. ParticleEngine keeps a provider random, a level random and a spell random, and make() sends each draw to the stream vanilla uses. Everything above is fixed in crates/horizon-client/src/particles.rs. Nothing here changes how the game calls the engine.

How it's tested

New harness: tools/test_particle_providers_parity.py, with VanillaParticleProvidersOracle.java and examples/particle_providers_probe.rs.

  • The oracle builds every particle type Horizon implements (91 types) through its real registered provider. It uses the real ParticleResources, with sprite sets bound to stand-in sprites named after the textures in vanilla's particles/*.json.
  • Particles run in a stand-in ClientLevel: air, optionally a stone floor at y 63, no fluids. Positions, velocities and seeds vary across 1,080 cases, each ticked for up to 80 ticks.
  • Each vanilla particle's random is seeded from the clock. The oracle recovers that seed from the uniquifier, the System.nanoTime window around the call and the random's state stepped back. The probe replays the same seed.
  • The provider, level and spell randoms are seeded from the case, and their next values are compared afterwards, so the number of draws on each stream is checked.
  • Compared tick by tick: position, previous position, motion, age, lifetime, removal, onGround, quad size at partial 0 and 0.5, colour, alpha, roll, sprite, UVs, light, and the particles and sounds requested from the level.
  • Leaves call Math.cos, Math.sin and Math.pow every tick. HotSpot's x86-64 intrinsics round about 0.2% of arguments one unit apart from glibc, which horizon_core::jmath uses. For those types only, motion doubles are compared to a relative error of 1e-12 (48 of 37,857 lines). Everything else is exact.
python3 tools/parity.py particle_providers
PASS particle_providers 113s   (1,080 cases, 37,857 lines, 48 within the libm tolerance)

cargo clippy --workspace --all-targets --locked -- -D warnings and cargo test --workspace --locked pass (Mac mini), and tools/check_public_tree.py passes.

The missing particle types, and the emitters that spawn too few or wrong particles (such as the villager's angry particles), come in separate PRs.

Part of #63

🤖 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/89 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/particles-63-providers` --- ### 📝 Commits (1) - [`d9461c6`](https://github.com/horizon-rust/horizon/commit/d9461c6d2d6f738841435be69abb0dc0cd265a75) Particles: build each one with vanilla's random streams, fix the providers that differed ### 📊 Changes **4 files changed** (+986 additions, -82 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/particle_providers_probe.rs` (+217 -0) 📝 `crates/horizon-client/src/particles.rs` (+259 -82) ➕ `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaParticleProvidersOracle.java` (+292 -0) ➕ `tools/test_particle_providers_parity.py` (+218 -0) </details> ### 📄 Description ## What was wrong Horizon's `ParticleEngine` drew every random value from one generator. Vanilla uses four: - each `Particle` has its own `RandomSource.create()` (`Particle.random`), used by the constructors and `tick()`; - providers get `ParticleEngine.random`; - a few providers use `ClientLevel.random` (`level.getRandom()`); - `SpellParticle` uses a static `RANDOM`. Because all draws came from one place, constructor and provider values (lifetimes, motion, colours, sprites) were drawn from the wrong stream. Several providers also had wrong values: | type | vanilla | was | |---|---|---| | `gust`, `small_gust` | `SingleQuadParticle(x, y, z)`, so the lifetime is 12..15 from the right draw (`GustParticle`) | built with the moving constructor, which shifted the lifetime | | `explosion_emitter`, `gust_emitter_*` | `NoRenderParticle` draws no quad size | an extra draw that moved every spawned explosion and gust | | `effect`, `instant_effect`, `entity_effect`, `witch`, `infested` | x/z motion from `SpellParticle.RANDOM`; witch brightness from the provider | particle random | | `landing_honey`, `landing_obsidian_tear`, `falling_nectar`, `spore_blossom_air`, `crimson_spore`, `warped_spore`, `white_ash`, `sculk_charge`, `sculk_charge_pop`, `dolphin` | lifetime, motion and alpha come from the provider's random, in the provider's order around `sprite.get(random)` (`DripParticle`, `SuspendedParticle`, `SuspendedTownParticle`, `WhiteAshParticle`, `SculkCharge*Particle`); crimson spore motion uses the float constants `1.0E-6F` and `1.0E-4F` | particle random, double constants | | `composter` | lifetime `3 + level.getRandom().nextInt(5)` | particle random | | `enchanted_hit` | `MagicProvider` tints r×0.3 and g×0.8 after the constructor's tick | no tint (white crits) | | `damage_indicator` | lives 20 ticks (`DamageIndicatorProvider`) | a crit lifetime | | `note` | colour from `Mth.sin`'s table | `f32::sin` | | `shriek` | one random sprite (`sprite.get(random)`), not animated | animated by age | | `trail` | 7-argument `Particle` constructor, `ARGB.scaleRGB` on 8-bit channels, `Mth.lerp(1/ticksRemaining, …)` | 4-argument constructor, float channels, clamped lerp | | `firework` sparks | full bright (`SimpleAnimatedParticle.getLightCoords`) | world light | ## The fix `Particle` carries its own `LegacyRandom`. `ParticleEngine` keeps a provider random, a level random and a spell random, and `make()` sends each draw to the stream vanilla uses. Everything above is fixed in `crates/horizon-client/src/particles.rs`. Nothing here changes how the game calls the engine. ## How it's tested New harness: `tools/test_particle_providers_parity.py`, with `VanillaParticleProvidersOracle.java` and `examples/particle_providers_probe.rs`. - The oracle builds every particle type Horizon implements (91 types) through its real registered provider. It uses the real `ParticleResources`, with sprite sets bound to stand-in sprites named after the textures in vanilla's `particles/*.json`. - Particles run in a stand-in `ClientLevel`: air, optionally a stone floor at y 63, no fluids. Positions, velocities and seeds vary across 1,080 cases, each ticked for up to 80 ticks. - Each vanilla particle's random is seeded from the clock. The oracle recovers that seed from the uniquifier, the `System.nanoTime` window around the call and the random's state stepped back. The probe replays the same seed. - The provider, level and spell randoms are seeded from the case, and their next values are compared afterwards, so the number of draws on each stream is checked. - Compared tick by tick: position, previous position, motion, age, lifetime, removal, onGround, quad size at partial 0 and 0.5, colour, alpha, roll, sprite, UVs, light, and the particles and sounds requested from the level. - Leaves call `Math.cos`, `Math.sin` and `Math.pow` every tick. HotSpot's x86-64 intrinsics round about 0.2% of arguments one unit apart from glibc, which `horizon_core::jmath` uses. For those types only, motion doubles are compared to a relative error of 1e-12 (48 of 37,857 lines). Everything else is exact. ``` python3 tools/parity.py particle_providers PASS particle_providers 113s (1,080 cases, 37,857 lines, 48 within the libm tolerance) ``` `cargo clippy --workspace --all-targets --locked -- -D warnings` and `cargo test --workspace --locked` pass (Mac mini), and `tools/check_public_tree.py` passes. The missing particle types, and the emitters that spawn too few or wrong particles (such as the villager's angry particles), come in separate PRs. Part of #63 🤖 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 15:54:56 +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#2320
No description provided.