[PR #91] [MERGED] Entity particle bursts: five angry villager particles and the other bursts as in vanilla (part of #63) #2323

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

📋 Pull Request Information

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

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


📝 Commits (1)

  • 383fc11 Entity particle bursts: as many particles as vanilla, about the body

📊 Changes

13 files changed (+504 additions, -96 deletions)

View changed files

➕ crates/horizon-client/examples/entity_particles_probe.rs (+51 -0)
📝 crates/horizon-client/src/game/allays.rs (+3 -15)
📝 crates/horizon-client/src/game/creatures.rs (+31 -18)
📝 crates/horizon-client/src/game/llamas.rs (+8 -7)
📝 crates/horizon-client/src/game/mounts.rs (+6 -10)
📝 crates/horizon-client/src/game/nautili.rs (+7 -7)
📝 crates/horizon-client/src/game/villagers.rs (+55 -13)
📝 crates/horizon-client/src/mobs.rs (+14 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+9 -6)
📝 crates/horizon-client/src/mobs/villager_brain.rs (+21 -20)
📝 crates/horizon-client/src/particles.rs (+109 -0)
➕ mods/horizon/src/test/java/dev/horizonlab/parity/VanillaEntityParticlesOracle.java (+78 -0)
➕ tools/test_entity_particles_parity.py (+112 -0)

📄 Description

What was wrong

From #63: "only 1 minecraft:angry_villager particle spawns when villagers are hit; in Minecraft there are more."

When a player hits a villager, vanilla sends entity event 13. Villager.handleEntityEvent(13) calls AbstractVillager.addParticlesAroundSelf(ANGRY_VILLAGER), which spawns five particles. For each one it draws three Gaussian speeds × 0.02, then places it at getRandomX(1.0), getRandomY() + 1.0, getRandomZ(1.0), which spreads them over the villager's body. Horizon spawned one particle, at rest, 1.8 blocks above the villager's feet. The other villager events (12 hearts, 14 happy) had the same problem.

The other client-side bursts on entity events were off too:

burst vanilla Horizon before
taming (wolf, cat, parrot, nautilus, horse): TamableAnimal/AbstractHorse.spawnTamingParticles 7 particles about the body, +0.5 7, jittered about the middle of the body, from the world random
allay duplication: Allay.handleEntityEvent(18) 3 hearts about the body, Gaussian motion 3 at rest in a box around the feet
llama growth from food: AbstractHorse.handleEating 1 particle at rest about the body 1, jittered around the centre
animal love hearts: Animal.aiStep at the drawn position, moving at the drawn Gaussian speeds the speeds were discarded and the position jittered again
forced growth: AgeableMob.aiStep, sendParticles(…, 1, 0, 0, 0, 0) exactly at the drawn position jittered again
villager breeding hearts: VillagerMakeLove 5 hearts about each villager; at birth, about the child 1 heart over each parent; at birth, over the parent

The fix

  • particles::around_self places a burst the way the client handlers do.
  • particles::Burst holds vanilla's counts, Gaussian scales and heights: villager, taming/love, allay, dolphin, horse eating.
  • particles::entity_event_burst(entity, event) maps entity events to those bursts.
  • New MobEvent::AroundSelf and MobEvent::ParticleAt let mob code request exact bursts and exact particles.
  • The game sites use these. Client bursts draw from the particle engine's random, which stands in for the client entity's random, so no server-side (world/mob) draw moves. The mob-side draws (love hearts, forced growth, breeding chance) are unchanged.

How it's tested

New harness: tools/test_entity_particles_parity.py, with VanillaEntityParticlesOracle.java and examples/entity_particles_probe.rs.

  • The oracle calls the real client handleEntityEvent of Villager (12, 13, 14, 42), Cow, Wolf, Cat, Parrot, Nautilus, Horse, Llama, Camel (6, 7, 18), Ocelot (40, 41, 18), Dolphin (38) and Allay (18).
  • Each entity is allocated without its constructor and given a stand-in level, a position, dimensions and a seeded random.
  • The oracle records every addParticle, and the random's next value afterwards.
  • The probe runs entity_event_burst and around_self with the same seed.
python3 tools/test_entity_particles_parity.py
1,200 entity events, 7,920 particles match the pinned client (5 lines within the Math.log tolerance)

The motion is Gaussian, and MarsagliaPolarGaussian calls Math.log. HotSpot's x86-64 intrinsic rounds a small fraction of those results one unit apart from the platform libm that horizon_core::jmath uses. So motion doubles are compared to 1e-12 relative error: 5 of 9,120 lines differ, each by one unit. Everything else is exact.

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

This PR is independent of #89; the missing particle types come in another PR. The villager raid splash (42) and dolphin (38) events have no Horizon emitter yet; their bursts are in the table and covered by the harness.

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/91 **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-emitters` --- ### 📝 Commits (1) - [`383fc11`](https://github.com/horizon-rust/horizon/commit/383fc116c98720a8f06cfb13c2ba16b2ec4e4929) Entity particle bursts: as many particles as vanilla, about the body ### 📊 Changes **13 files changed** (+504 additions, -96 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/entity_particles_probe.rs` (+51 -0) 📝 `crates/horizon-client/src/game/allays.rs` (+3 -15) 📝 `crates/horizon-client/src/game/creatures.rs` (+31 -18) 📝 `crates/horizon-client/src/game/llamas.rs` (+8 -7) 📝 `crates/horizon-client/src/game/mounts.rs` (+6 -10) 📝 `crates/horizon-client/src/game/nautili.rs` (+7 -7) 📝 `crates/horizon-client/src/game/villagers.rs` (+55 -13) 📝 `crates/horizon-client/src/mobs.rs` (+14 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+9 -6) 📝 `crates/horizon-client/src/mobs/villager_brain.rs` (+21 -20) 📝 `crates/horizon-client/src/particles.rs` (+109 -0) ➕ `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaEntityParticlesOracle.java` (+78 -0) ➕ `tools/test_entity_particles_parity.py` (+112 -0) </details> ### 📄 Description ## What was wrong From #63: "only 1 minecraft:angry_villager particle spawns when villagers are hit; in Minecraft there are more." When a player hits a villager, vanilla sends entity event 13. `Villager.handleEntityEvent(13)` calls `AbstractVillager.addParticlesAroundSelf(ANGRY_VILLAGER)`, which spawns five particles. For each one it draws three Gaussian speeds × 0.02, then places it at `getRandomX(1.0)`, `getRandomY() + 1.0`, `getRandomZ(1.0)`, which spreads them over the villager's body. Horizon spawned one particle, at rest, 1.8 blocks above the villager's feet. The other villager events (12 hearts, 14 happy) had the same problem. The other client-side bursts on entity events were off too: | burst | vanilla | Horizon before | |---|---|---| | taming (wolf, cat, parrot, nautilus, horse): `TamableAnimal`/`AbstractHorse.spawnTamingParticles` | 7 particles about the body, +0.5 | 7, jittered about the middle of the body, from the world random | | allay duplication: `Allay.handleEntityEvent(18)` | 3 hearts about the body, Gaussian motion | 3 at rest in a box around the feet | | llama growth from food: `AbstractHorse.handleEating` | 1 particle at rest about the body | 1, jittered around the centre | | animal love hearts: `Animal.aiStep` | at the drawn position, moving at the drawn Gaussian speeds | the speeds were discarded and the position jittered again | | forced growth: `AgeableMob.aiStep`, `sendParticles(…, 1, 0, 0, 0, 0)` | exactly at the drawn position | jittered again | | villager breeding hearts: `VillagerMakeLove` | 5 hearts about each villager; at birth, about the child | 1 heart over each parent; at birth, over the parent | ## The fix - `particles::around_self` places a burst the way the client handlers do. - `particles::Burst` holds vanilla's counts, Gaussian scales and heights: villager, taming/love, allay, dolphin, horse eating. - `particles::entity_event_burst(entity, event)` maps entity events to those bursts. - New `MobEvent::AroundSelf` and `MobEvent::ParticleAt` let mob code request exact bursts and exact particles. - The game sites use these. Client bursts draw from the particle engine's random, which stands in for the client entity's random, so no server-side (`world`/mob) draw moves. The mob-side draws (love hearts, forced growth, breeding chance) are unchanged. ## How it's tested New harness: `tools/test_entity_particles_parity.py`, with `VanillaEntityParticlesOracle.java` and `examples/entity_particles_probe.rs`. - The oracle calls the real client `handleEntityEvent` of `Villager` (12, 13, 14, 42), `Cow`, `Wolf`, `Cat`, `Parrot`, `Nautilus`, `Horse`, `Llama`, `Camel` (6, 7, 18), `Ocelot` (40, 41, 18), `Dolphin` (38) and `Allay` (18). - Each entity is allocated without its constructor and given a stand-in level, a position, dimensions and a seeded random. - The oracle records every `addParticle`, and the random's next value afterwards. - The probe runs `entity_event_burst` and `around_self` with the same seed. ``` python3 tools/test_entity_particles_parity.py 1,200 entity events, 7,920 particles match the pinned client (5 lines within the Math.log tolerance) ``` The motion is Gaussian, and `MarsagliaPolarGaussian` calls `Math.log`. HotSpot's x86-64 intrinsic rounds a small fraction of those results one unit apart from the platform libm that `horizon_core::jmath` uses. So motion doubles are compared to 1e-12 relative error: 5 of 9,120 lines differ, each by one unit. Everything else is exact. `cargo clippy --workspace --all-targets --locked -- -D warnings` and `cargo test --workspace --locked` pass (Mac mini), and `tools/check_public_tree.py` passes. This PR is independent of #89; the missing particle types come in another PR. The villager raid splash (42) and dolphin (38) events have no Horizon emitter yet; their bursts are in the table and covered by the harness. 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:57 +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#2323
No description provided.