[PR #4243] [MERGED] Volume sliders play a preview sound on the title screen's options #5510

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4243
Author: @d3grando
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3518-sound-slider-preview


📝 Commits (1)

  • 912b671 Volume sliders play a preview sound on the title screen's options

📊 Changes

9 files changed (+258 additions, -12 deletions)

View changed files

📝 crates/horizon-client-render/src/audio.rs (+10 -0)
📝 crates/horizon-client-render/src/lib.rs (+1 -0)
📝 crates/horizon-client-render/src/options_ui.rs (+53 -5)
➕ crates/horizon-client-render/src/sound_preview.rs (+179 -0)
📝 crates/horizon-client/src/game/options.rs (+6 -0)
📝 crates/horizon-client/src/game/startup_menu.rs (+3 -2)
📝 crates/horizon-client/src/lib.rs (+3 -2)
📝 tools/port_map/rest-004.tsv (+1 -1)
📝 tools/port_map/rest-005.tsv (+2 -2)

📄 Description

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

What and why

In vanilla, moving a category volume slider on the title screen's Sound options plays a short preview sound for that category: a zombie groan for Hostile Mobs, a cow for Friendly Mobs, thunder for Weather, and so on. Horizon played nothing: no code in horizon-client or horizon-client-render ported SoundPreviewHandler. The port ledger rows SoundPreviewHandler.preview and stopOtherCategoryPreview were both marked missing.

Fix:

  • crates/horizon-client-render/src/sound_preview.rs ports SoundPreviewHandler. It maps each category to vanilla's sound (record → block.note_block.guitar, weather → entity.lightning_bolt.thunder, block → block.grass.place, hostile → entity.zombie.ambient, neutral → the classic cow ambient entity.cow.ambient, player → entity.generic.eat, ambient → ambient.cave, ui → ui.button.click; master, music and voice → SoundEvents.EMPTY). It plays the sound as SimpleSoundInstance.forUI(event, 1, volume) and keeps activePreview and previousCategory. A preview that is still playing is not restarted (canPlaySound), and moving a different category's slider stops the last preview (stopOtherCategoryPreview). The new category's own sound then plays on a later move, as in vanilla, where the stopped channel stays active until the engine's next tick.
  • options_ui now emits Event::Volume(source, volume) after SliderDrag, and only when the category volume actually changed (as OptionInstance.set runs onValueUpdate only for a new value).
  • The game plays the preview only when the options were opened from the title screen. This matches Minecraft.level == null in Options.createSoundSliderOptionInstance. In a world, sliders stay silent as in vanilla. The startup menu, shown before the sound engine exists, ignores the event.
  • Port ledger rows updated (rest-005.tsv: both SoundPreviewHandler rows → port; rest-004.tsv: the createSoundSliderOptionInstance gap now only lists the now-playing toast).

Part of #3518 (the SoundPreviewHandler.preview row, plus the preview half of Options.createSoundSliderOptionInstance).

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

Checked with javap on the 26.3 client jar:

  • net.minecraft.client.Options.lambda$createSoundSliderOptionInstance$0: refreshCategoryVolume(source), then SoundPreviewHandler.preview(soundManager, source, value) only if Minecraft.level == null.
  • net.minecraft.client.sounds.SoundPreviewHandler.preview / stopOtherCategoryPreview / canPlaySound, and the SoundPreviewHandler$1 switch map (RECORDS..UI → the events above, default SoundEvents.EMPTY).
  • SimpleSoundInstance.forUI(SoundEvent, pitch, volume): UI source, no attenuation, relative.
  • SoundEvents.COW_SOUNDS / CowSoundVariants.SoundSet.CLASSIC ("cow") for the neutral preview.

No parity harness covers the options screen's sounds. Unit tests check the behaviour instead:

  • sound_preview::tests::each_category_previews_its_vanilla_sound: the category → event table.
  • sound_preview::tests::a_moving_slider_plays_one_preview_at_a_time_and_switching_stops_it: plays a forUI instance at the slider volume, does not restart while playing, plays again once finished, stops it when another category moves, and master plays nothing. It runs on the real SoundEngine with the null backend.
  • options_ui::tests::a_moved_volume_slider_reports_its_category_and_value: the event fires only for a changed value. classic_sliders_sound_once_on_release_including_unchanged_values is updated for the new event.

Self-check

tools/pr_ready.py doesn't run on Windows, so I ran its steps by hand:

cargo fmt --all -- --check                                          # ok
cargo clippy -p horizon-client-render --all-targets -- -D warnings  # ok
cargo clippy -p horizon-client --all-targets -- -D warnings         # ok
cargo test -p horizon-client-render --lib -- sound_preview options_ui:: audio::
    # test result: ok. 47 passed; 0 failed; 1 ignored
cargo build --profile fast -p horizon-client --bins                 # ok

Before the fix (the preview body and the Event::Volume emission stubbed out, the hostile row removed from the table), the new and updated tests fail:

test sound_preview::tests::each_category_previews_its_vanilla_sound ... FAILED   (hostile: left None, right Some("minecraft:entity.zombie.ambient"))
test sound_preview::tests::a_moving_slider_plays_one_preview_at_a_time_and_switching_stops_it ... FAILED
test options_ui::tests::a_moved_volume_slider_reports_its_category_and_value ... FAILED   (left [SliderDrag], right [SliderDrag, Volume(5, 0.5)])
test options_ui::tests::classic_sliders_sound_once_on_release_including_unchanged_values ... FAILED
test result: FAILED. 1 passed; 4 failed

With the fix, all 5 pass.

In game (Windows, fast build, audio on, title screen → Options → Music & Sounds, sliders moved with horizon-ctl set, horizon-ctl status → sounds.events):

  • origin/main: set hostile-mobs 0.6 → [music.menu]; set friendly-mobs 0.6 → [ui.button.click, music.menu]. No preview.
  • this branch: set hostile-mobs 0.6 → [entity.zombie.ambient, music.menu, ui.button.click]. A second move while it plays keeps one entity.zombie.ambient (not restarted), and it is gone 3 s later. friendly-mobs → entity.cow.ambient. weather stops the cow first, and the next move plays entity.lightning_bolt.thunder.
  • this branch, inside a single-player world (server thread), Options → Music & Sounds: moving Hostile Mobs plays no zombie sound, as in vanilla.

🤖 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/4243 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3518-sound-slider-preview` --- ### 📝 Commits (1) - [`912b671`](https://github.com/horizon-rust/horizon/commit/912b671416e79abbff4f7770f15020c45848ca02) Volume sliders play a preview sound on the title screen's options ### 📊 Changes **9 files changed** (+258 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/audio.rs` (+10 -0) 📝 `crates/horizon-client-render/src/lib.rs` (+1 -0) 📝 `crates/horizon-client-render/src/options_ui.rs` (+53 -5) ➕ `crates/horizon-client-render/src/sound_preview.rs` (+179 -0) 📝 `crates/horizon-client/src/game/options.rs` (+6 -0) 📝 `crates/horizon-client/src/game/startup_menu.rs` (+3 -2) 📝 `crates/horizon-client/src/lib.rs` (+3 -2) 📝 `tools/port_map/rest-004.tsv` (+1 -1) 📝 `tools/port_map/rest-005.tsv` (+2 -2) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why In vanilla, moving a category volume slider on the title screen's Sound options plays a short preview sound for that category: a zombie groan for Hostile Mobs, a cow for Friendly Mobs, thunder for Weather, and so on. Horizon played nothing: no code in horizon-client or horizon-client-render ported `SoundPreviewHandler`. The port ledger rows `SoundPreviewHandler.preview` and `stopOtherCategoryPreview` were both marked missing. Fix: - `crates/horizon-client-render/src/sound_preview.rs` ports `SoundPreviewHandler`. It maps each category to vanilla's sound (record → `block.note_block.guitar`, weather → `entity.lightning_bolt.thunder`, block → `block.grass.place`, hostile → `entity.zombie.ambient`, neutral → the classic cow ambient `entity.cow.ambient`, player → `entity.generic.eat`, ambient → `ambient.cave`, ui → `ui.button.click`; master, music and voice → `SoundEvents.EMPTY`). It plays the sound as `SimpleSoundInstance.forUI(event, 1, volume)` and keeps `activePreview` and `previousCategory`. A preview that is still playing is not restarted (`canPlaySound`), and moving a different category's slider stops the last preview (`stopOtherCategoryPreview`). The new category's own sound then plays on a later move, as in vanilla, where the stopped channel stays active until the engine's next tick. - `options_ui` now emits `Event::Volume(source, volume)` after `SliderDrag`, and only when the category volume actually changed (as `OptionInstance.set` runs `onValueUpdate` only for a new value). - The game plays the preview only when the options were opened from the title screen. This matches `Minecraft.level == null` in `Options.createSoundSliderOptionInstance`. In a world, sliders stay silent as in vanilla. The startup menu, shown before the sound engine exists, ignores the event. - Port ledger rows updated (`rest-005.tsv`: both `SoundPreviewHandler` rows → port; `rest-004.tsv`: the `createSoundSliderOptionInstance` gap now only lists the now-playing toast). Part of #3518 (the `SoundPreviewHandler.preview` row, plus the preview half of `Options.createSoundSliderOptionInstance`). ## 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 Checked with javap on the 26.3 client jar: - `net.minecraft.client.Options.lambda$createSoundSliderOptionInstance$0`: `refreshCategoryVolume(source)`, then `SoundPreviewHandler.preview(soundManager, source, value)` only if `Minecraft.level == null`. - `net.minecraft.client.sounds.SoundPreviewHandler.preview` / `stopOtherCategoryPreview` / `canPlaySound`, and the `SoundPreviewHandler$1` switch map (RECORDS..UI → the events above, default `SoundEvents.EMPTY`). - `SimpleSoundInstance.forUI(SoundEvent, pitch, volume)`: UI source, no attenuation, relative. - `SoundEvents.COW_SOUNDS` / `CowSoundVariants.SoundSet.CLASSIC` ("cow") for the neutral preview. No parity harness covers the options screen's sounds. Unit tests check the behaviour instead: - `sound_preview::tests::each_category_previews_its_vanilla_sound`: the category → event table. - `sound_preview::tests::a_moving_slider_plays_one_preview_at_a_time_and_switching_stops_it`: plays a forUI instance at the slider volume, does not restart while playing, plays again once finished, stops it when another category moves, and master plays nothing. It runs on the real `SoundEngine` with the null backend. - `options_ui::tests::a_moved_volume_slider_reports_its_category_and_value`: the event fires only for a changed value. `classic_sliders_sound_once_on_release_including_unchanged_values` is updated for the new event. ## Self-check `tools/pr_ready.py` doesn't run on Windows, so I ran its steps by hand: ``` cargo fmt --all -- --check # ok cargo clippy -p horizon-client-render --all-targets -- -D warnings # ok cargo clippy -p horizon-client --all-targets -- -D warnings # ok cargo test -p horizon-client-render --lib -- sound_preview options_ui:: audio:: # test result: ok. 47 passed; 0 failed; 1 ignored cargo build --profile fast -p horizon-client --bins # ok ``` Before the fix (the preview body and the `Event::Volume` emission stubbed out, the hostile row removed from the table), the new and updated tests fail: ``` test sound_preview::tests::each_category_previews_its_vanilla_sound ... FAILED (hostile: left None, right Some("minecraft:entity.zombie.ambient")) test sound_preview::tests::a_moving_slider_plays_one_preview_at_a_time_and_switching_stops_it ... FAILED test options_ui::tests::a_moved_volume_slider_reports_its_category_and_value ... FAILED (left [SliderDrag], right [SliderDrag, Volume(5, 0.5)]) test options_ui::tests::classic_sliders_sound_once_on_release_including_unchanged_values ... FAILED test result: FAILED. 1 passed; 4 failed ``` With the fix, all 5 pass. In game (Windows, fast build, audio on, title screen → Options → Music & Sounds, sliders moved with `horizon-ctl set`, `horizon-ctl status` → `sounds.events`): - origin/main: `set hostile-mobs 0.6` → `[music.menu]`; `set friendly-mobs 0.6` → `[ui.button.click, music.menu]`. No preview. - this branch: `set hostile-mobs 0.6` → `[entity.zombie.ambient, music.menu, ui.button.click]`. A second move while it plays keeps one `entity.zombie.ambient` (not restarted), and it is gone 3 s later. `friendly-mobs` → `entity.cow.ambient`. `weather` stops the cow first, and the next move plays `entity.lightning_bolt.thunder`. - this branch, inside a single-player world (server thread), Options → Music & Sounds: moving Hostile Mobs plays no zombie sound, as in vanilla. 🤖 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-03 05:13:05 +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#5510
No description provided.