[PR #6886] [MERGED] Square the /playsound range as a float #7174

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

📋 Pull Request Information

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

Base: main ← Head: fix/playsound-range-squared


📝 Commits (2)

📊 Changes

1 file changed (+89 additions, -18 deletions)

View changed files

📝 crates/horizon-client/src/game/commands/world_cmds.rs (+89 -18)

📄 Description

Vanilla's /playsound compares the target's squared distance against the sound's range squared in float:

// javap -p -c on PlaySoundCommand.playSound
19-27: SoundEvent.createVariableRangeEvent(id).getRange(volume)
24:    -> Mth.square:(F)F          // float square
27:    -> f2d                       // then widen
162-167: if (dist2 > rangeSquared) { ... minVolume or skip }

SoundEvent.getRange(float) is volume > 1 ? 16 * volume : 16, a float. Mth.square(float) multiplies and rounds as a float, and only that result is widened to the double the distance is compared with.

Horizon computed f64::from(range) * f64::from(range), i.e. widened first and squared in double. For any volume above 1 whose 16 * volume is not exactly representable the two squares differ (volume 1.1: 309.760009765625 against 309.7600134277345), so a target whose squared distance falls between them is inside Horizon's range and outside vanilla's. Horizon played the sound at the command point at full volume where vanilla plays nothing, or moves the point two blocks from the target at minVolume when one was given.

The comparison and the minVolume placement now live in playsound_placement, which takes the float range and squares it in float.

Proven: on the build VM, cargo test -q -p horizon-client --lib world_cmds::tests -> 2 passed:

  • a_target_past_the_range_hears_it_two_blocks_away: inside the range the point and volume are the command's own, exactly on it (distance 16, range 16) still is, past it without minVolume hears nothing, and with 0.5 the point is two blocks from the target towards the sound at 0.5.
  • the_range_square_rounds_as_a_float: at volume 1.1 the float square is 309.760009765625 and the double square 309.7600134277345; a target at the midpoint of the two gets None at minVolume 0 and the two-block placement at 0.7. The previous double square put that target inside the range, so this case fails without the change.

cargo clippy -q -p horizon-client --lib is silent.

Not proven: not listened to in game; the window is a few millionths of a block at the range boundary, so this is command fidelity rather than an audible mix change. The two-block placement and the > boundary were already right and the first test pins them.


🔄 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/6886 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/playsound-range-squared` --- ### 📝 Commits (2) - [`2b5514d`](https://github.com/horizon-rust/horizon/commit/2b5514dba92fcdd6ea8e74e34a042b78f0a6e63b) Square the /playsound range as a float - [`41f8806`](https://github.com/horizon-rust/horizon/commit/41f880696f9b0bcf2db4a0d55dfea162355389f9) Merge main into #6886 ### 📊 Changes **1 file changed** (+89 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands/world_cmds.rs` (+89 -18) </details> ### 📄 Description Vanilla's `/playsound` compares the target's squared distance against the sound's range squared **in float**: ```java // javap -p -c on PlaySoundCommand.playSound 19-27: SoundEvent.createVariableRangeEvent(id).getRange(volume) 24: -> Mth.square:(F)F // float square 27: -> f2d // then widen 162-167: if (dist2 > rangeSquared) { ... minVolume or skip } ``` `SoundEvent.getRange(float)` is `volume > 1 ? 16 * volume : 16`, a float. `Mth.square(float)` multiplies and rounds as a float, and only that result is widened to the double the distance is compared with. Horizon computed `f64::from(range) * f64::from(range)`, i.e. widened first and squared in double. For any volume above 1 whose `16 * volume` is not exactly representable the two squares differ (volume 1.1: 309.760009765625 against 309.7600134277345), so a target whose squared distance falls between them is inside Horizon's range and outside vanilla's. Horizon played the sound at the command point at full volume where vanilla plays nothing, or moves the point two blocks from the target at `minVolume` when one was given. The comparison and the minVolume placement now live in `playsound_placement`, which takes the float range and squares it in float. **Proven:** on the build VM, `cargo test -q -p horizon-client --lib world_cmds::tests` -> `2 passed`: - `a_target_past_the_range_hears_it_two_blocks_away`: inside the range the point and volume are the command's own, exactly on it (distance 16, range 16) still is, past it without `minVolume` hears nothing, and with 0.5 the point is two blocks from the target towards the sound at 0.5. - `the_range_square_rounds_as_a_float`: at volume 1.1 the float square is 309.760009765625 and the double square 309.7600134277345; a target at the midpoint of the two gets `None` at `minVolume` 0 and the two-block placement at 0.7. The previous double square put that target inside the range, so this case fails without the change. `cargo clippy -q -p horizon-client --lib` is silent. **Not proven:** not listened to in game; the window is a few millionths of a block at the range boundary, so this is command fidelity rather than an audible mix change. The two-block placement and the `>` boundary were already right and the first test pins them. --- <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:15 +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#7174
No description provided.