[PR #7676] Native mods: sounds and particles in a level through LevelRef (#7387) #7752

Open
opened 2026-11-03 07:23:43 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7676
Author: @levzzz5154
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: modapi/level-effects


📝 Commits (5)

  • b21901f Native mods: entity and level handles, and an entity's position, type, UUID and level (#7387)
  • 7b77a5e Merge main into modapi/entity-handles
  • b978111 Native mods: a level's blocks and time through LevelRef (#7387)
  • c367cb9 Native mods: sounds and particles in a level through LevelRef (#7387)
  • 3568cc4 Native mods: name the shared sound and particle checks outside the hook catalog

📊 Changes

15 files changed (+1026 additions, -49 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+3 -0)
📝 crates/horizon-client/src/game/mod_api_host_generated.rs (+68 -0)
📝 crates/horizon-client/src/game/native_entities.rs (+5 -5)
➕ crates/horizon-client/src/game/native_entity_refs.rs (+114 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+67 -42)
➕ crates/horizon-client/src/game/native_level_effects.rs (+87 -0)
➕ crates/horizon-client/src/game/native_level_refs.rs (+97 -0)
📝 crates/horizon-client/src/game/native_lifecycle.rs (+6 -0)
📝 crates/horizon-client/src/mod_api.rs (+53 -1)
📝 crates/horizon-client/src/mod_api/generated_host.rs (+256 -0)
📝 docs/native-mods.md (+20 -0)
➕ tools/native-hook-fragments/entity_handles.json (+48 -0)
➕ tools/native-hook-fragments/level_effects.json (+20 -0)
➕ tools/native-hook-fragments/level_reads.json (+45 -0)
📝 xtask/src/mod_api.rs (+137 -1)

📄 Description

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

Stacked on #7454 and #7559 (draft until they merge; review only the last two commits).

Part of #7387: the LevelRef particles, sounds and events line, first part (claimed in this comment). It answers reservedbytes's point 2 (server-side play_sound and send_particles), and the sound #7583's backstab enchantment plays could go through it.

What it adds

LevelRef methods, usable from any server hook, not only from a level hook's LevelWriteHost:

  • play_sound(host, sound, at, source, volume, pitch): ServerLevel.playSound(null, ...). It is sent to the players in that level within 16 blocks (times the volume above 1). A minecraft: event must be registered; a mod's event (mymod:machine/hum) goes by name, as the level-hook version already sends it.
  • send_particles(host, options, state, at, spread, speed, count): ServerLevel.sendParticles, to the players in that level within 32 blocks. Block particle types need state, and item, trail and vibration particles aren't supported, as in the level-hook version.

Both return false on a client, for a stale handle, or for arguments the network can't carry (a malformed id, a bad source, a non-finite position or spread, a negative volume). They push into the same queues as LevelWriteHost::play_sound/send_particles (creatures.lan_sounds, lan_particles), which the server flushes each tick. The checks those two made move into mod_sound_ok/mod_particles_ok in native_hooks.rs, so both paths share them.

Proof

A probe bundle with a server injection at Game::tick_mobs plays and sends every 100 ticks. Two client injections at remote_sound_name and remote_level_particles log what the window's client gets. It ran on this branch's fast build, server thread, offscreen, in scratch homes.

FXPROBE sound tick=60 at=[-26.5, 72.0, 0.5] ok=true mod=true far=true bad_name=false bad_source=false nan=false neg_volume=false stale=false nether=None
FXPROBE particles hearts=true block_no_state=false block_stone=true item=false nan_spread=false far=true stale=false mod=true unnamespaced_mod=false
FXCLIENT particles pos=[-26.5, 72.0, 0.5] count=7 dist=[0.5, 0.5, 0.5]
FXCLIENT particles pos=[-26.5, 72.0, 0.5] count=4 dist=[0.3, 0.3, 0.3]
FXCLIENT particles pos=[-26.5, 72.0, 0.5] count=2 dist=[0.5, 0.5, 0.5]
FXCLIENT sound id=1173 inline=None
FXCLIENT sound id=-1 inline=Some("fxprobe:machine/hum")
  • The client gets the registered sound by id and the mod's sound inline. It also gets the hearts (7), the stone block particles (4) and the mod's particle (2).
  • The sound and the hearts sent 200 blocks away are queued (far=true) but don't reach the player, as the range says.
  • The bad inputs and the stale handle are refused. nether=None because the Nether isn't loaded in this run, so host.level gives no handle.
  • Not run separately on a dedicated server: it flushes through the same flush_native_sounds/flush_lan_particles as the server thread.

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at b09827e93, 2 min 35 s)

Check Result
Scope ⚠️ 15 files, +1026 −49; 1055 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (37 s)
rustfmt ✅ (6 s)
clippy ✅ (49 s)
tests: horizon-client, horizon-client-lib, xtask ✅ 2178 passed (39 s)
doc tests ✅ 0 passed (12 s)
content root tests ➖ content root untouched
mod API up to date ✅ (12 s)
tokens.css up to date ✅
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The scope line counts the two PRs this stacks on; this PR's own commits are 7 files, +282 −43.

🤖 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/7676 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `modapi/level-effects` --- ### 📝 Commits (5) - [`b21901f`](https://github.com/horizon-rust/horizon/commit/b21901f67698b54bb46148a0409769ce9e24c8d5) Native mods: entity and level handles, and an entity's position, type, UUID and level (#7387) - [`7b77a5e`](https://github.com/horizon-rust/horizon/commit/7b77a5ec989f448298572d44dee9ab84fe38cb50) Merge main into modapi/entity-handles - [`b978111`](https://github.com/horizon-rust/horizon/commit/b978111dddea704a7cf7d1e7cf7129a2ca445fbf) Native mods: a level's blocks and time through LevelRef (#7387) - [`c367cb9`](https://github.com/horizon-rust/horizon/commit/c367cb95a2316a707f947ed147b91dbe36266f45) Native mods: sounds and particles in a level through LevelRef (#7387) - [`3568cc4`](https://github.com/horizon-rust/horizon/commit/3568cc4cc7b9d6ee061c532e4fa0a7da387dd596) Native mods: name the shared sound and particle checks outside the hook catalog ### 📊 Changes **15 files changed** (+1026 additions, -49 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+3 -0) 📝 `crates/horizon-client/src/game/mod_api_host_generated.rs` (+68 -0) 📝 `crates/horizon-client/src/game/native_entities.rs` (+5 -5) ➕ `crates/horizon-client/src/game/native_entity_refs.rs` (+114 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+67 -42) ➕ `crates/horizon-client/src/game/native_level_effects.rs` (+87 -0) ➕ `crates/horizon-client/src/game/native_level_refs.rs` (+97 -0) 📝 `crates/horizon-client/src/game/native_lifecycle.rs` (+6 -0) 📝 `crates/horizon-client/src/mod_api.rs` (+53 -1) 📝 `crates/horizon-client/src/mod_api/generated_host.rs` (+256 -0) 📝 `docs/native-mods.md` (+20 -0) ➕ `tools/native-hook-fragments/entity_handles.json` (+48 -0) ➕ `tools/native-hook-fragments/level_effects.json` (+20 -0) ➕ `tools/native-hook-fragments/level_reads.json` (+45 -0) 📝 `xtask/src/mod_api.rs` (+137 -1) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. **Stacked on #7454 and #7559** (draft until they merge; review only the last two commits). Part of #7387: the LevelRef **particles, sounds and events** line, first part (claimed in [this comment](https://github.com/horizon-rust/horizon/issues/7387#issuecomment-6586075209)). It answers reservedbytes's point 2 (server-side `play_sound` and `send_particles`), and the sound #7583's backstab enchantment plays could go through it. ## What it adds `LevelRef` methods, usable from any server hook, not only from a level hook's `LevelWriteHost`: - `play_sound(host, sound, at, source, volume, pitch)`: `ServerLevel.playSound(null, ...)`. It is sent to the players in that level within 16 blocks (times the volume above 1). A `minecraft:` event must be registered; a mod's event (`mymod:machine/hum`) goes by name, as the level-hook version already sends it. - `send_particles(host, options, state, at, spread, speed, count)`: `ServerLevel.sendParticles`, to the players in that level within 32 blocks. Block particle types need `state`, and item, trail and vibration particles aren't supported, as in the level-hook version. Both return false on a client, for a stale handle, or for arguments the network can't carry (a malformed id, a bad source, a non-finite position or spread, a negative volume). They push into the same queues as `LevelWriteHost::play_sound`/`send_particles` (`creatures.lan_sounds`, `lan_particles`), which the server flushes each tick. The checks those two made move into `mod_sound_ok`/`mod_particles_ok` in `native_hooks.rs`, so both paths share them. ## Proof A probe bundle with a server injection at `Game::tick_mobs` plays and sends every 100 ticks. Two client injections at `remote_sound_name` and `remote_level_particles` log what the window's client gets. It ran on this branch's fast build, server thread, offscreen, in scratch homes. ``` FXPROBE sound tick=60 at=[-26.5, 72.0, 0.5] ok=true mod=true far=true bad_name=false bad_source=false nan=false neg_volume=false stale=false nether=None FXPROBE particles hearts=true block_no_state=false block_stone=true item=false nan_spread=false far=true stale=false mod=true unnamespaced_mod=false FXCLIENT particles pos=[-26.5, 72.0, 0.5] count=7 dist=[0.5, 0.5, 0.5] FXCLIENT particles pos=[-26.5, 72.0, 0.5] count=4 dist=[0.3, 0.3, 0.3] FXCLIENT particles pos=[-26.5, 72.0, 0.5] count=2 dist=[0.5, 0.5, 0.5] FXCLIENT sound id=1173 inline=None FXCLIENT sound id=-1 inline=Some("fxprobe:machine/hum") ``` - The client gets the registered sound by id and the mod's sound inline. It also gets the hearts (7), the stone block particles (4) and the mod's particle (2). - The sound and the hearts sent 200 blocks away are queued (`far=true`) but don't reach the player, as the range says. - The bad inputs and the stale handle are refused. `nether=None` because the Nether isn't loaded in this run, so `host.level` gives no handle. - Not run separately on a dedicated server: it flushes through the same `flush_native_sounds`/`flush_lan_particles` as the server thread. **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at b09827e93, 2 min 35 s) | Check | Result | | --- | --- | | Scope | ⚠️ 15 files, +1026 −49; 1055 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (37 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (49 s) | | tests: horizon-client, horizon-client-lib, xtask | ✅ 2178 passed (39 s) | | doc tests | ✅ 0 passed (12 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (12 s) | | tokens.css up to date | ✅ | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The scope line counts the two PRs this stacks on; this PR's own commits are 7 files, +282 −43. 🤖 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>
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#7752
No description provided.