[PR #3674] [MERGED] Eating: the eater hears each bite once #5141

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

📋 Pull Request Information

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

Base: main ← Head: fix-3129


📝 Commits (3)

  • 158075a Eating: the eater hears each bite once
  • 3931a46 lan_e2e: the player beside the eater hears each bite once too
  • 9aeb985 lan_e2e eating: one loaf each, and read the bites once they settle

📊 Changes

5 files changed (+82 additions, -8 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+5 -0)
📝 crates/horizon-client/src/game/consume.rs (+11 -2)
📝 crates/horizon-client/src/game/lan_actions.rs (+9 -0)
📝 crates/horizon-client/src/game/remote.rs (+4 -2)
📝 tools/lan_e2e.py (+53 -4)

📄 Description

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

Fixes #3129

What and why

When you eat, every bite sound plays twice, almost on top of itself. This happens to every single-player player (the window is a client of its server thread) and to every LAN or dedicated-server guest.

Root cause: Consumable.emitParticlesAndSounds plays the bite through LivingEntity.playSound. For a player that is Player.playSound, which calls level.playSound(this, ...) with the player as the excluded listener:

  • the server sends the sound to everyone but the eater;
  • the eater's own client plays it locally.

Horizon's server ran a guest's eating inside the guest's turn (as_guest). There, Emitter::play_sound used a plain audio.play, which is captured and broadcast to all guests, the eater included. So the eater heard its client's bite and the server's copy of the same bite.

Fix:

  • game/consume.rs: while the server acts for a guest (lan_acting), Emitter::play_sound queues the sound in guest_player_sounds instead of broadcasting it to everyone.
  • game/lan_actions.rs (leave_guest): the queued sounds go out with the guest excepted, in the player source, as Player.getSoundSource() gives. The host still hears them locally (play_unshared).
  • game/remote.rs (remote_complete_using): on USE_ITEM_COMPLETE (entity event 9), the client now runs the whole emitParticlesAndSounds(16), as vanilla's completeUsingItem does on the client. Before, it drew the final crumbs without the final bite sound and relied on the server's copy for it. Now the server no longer sends that copy to the eater.

Unchanged on purpose:

  • FoodProperties.onConsume's extra eat sound and the burp use level.playSound(null, ...). The server sends them to everyone, the eater included, and a vanilla client doesn't play them locally, so they still come from the server.
  • Other players hear exactly what they heard before.

The particles weren't doubled in these runs. The eater draws one set: 5 crumbs per bite plus 16 at the end, from its client only.

Vanilla reference

  • Consumable.emitParticlesAndSounds: spawnItemParticles, then LivingEntity.playSound(sound, volume, pitch).
  • Player.playSound(SoundEvent, float, float): level().playSound(this, getX(), getY(), getZ(), sound, getSoundSource(), ...).
  • FoodProperties.onConsume: level.playSound(null, ...) for the consumable's sound and PLAYER_BURP.
  • LivingEntity.updateUsingItem and Consumable.shouldEmitParticlesAndSounds: every 4 ticks once more than consumeTicks * 0.21875 have passed.

All checked with javap on the 26.3 jars.

Test

tools/lan_e2e.py's eat check now counts the bite sounds the guest hears and compares them with the crumb bursts its client drew. The expected count is one sound per burst, plus FoodProperties' sound and the client's own last bite for each loaf eaten. I couldn't run lan_e2e here: it needs Linux or macOS (symlinks, vscreen, unix sockets).

Instead, I ran the same measurement on Windows through horizon-ctl status (heard, particles). The setup: a single-player host on its server thread, with a second game joined over LAN. Both players are hungry and each eats one bread with use-item --hold 2.2.

Fix code reverted, everything else on the same base:

guest eats: eater heard 16 (own crumb bursts 7, expected 9); watcher heard 9
host eats:  eater heard 16 (own crumb bursts 7, expected 9); watcher heard 9

With the fix:

guest eats: eater heard 9 (own crumb bursts 7, expected 9); watcher heard 9
host eats:  eater heard 9 (own crumb bursts 7, expected 9); watcher heard 9

Every bite now reaches the eater once, and the player watching still hears all of them.

The same with a single game (single player alone, survival, hungry), two loaves each:

fix code reverted: heard eat=16 burp=1 item particles=51 (7 bursts, expected 9)   x2
with the fix:      heard eat=9  burp=1 item particles=51 (7 bursts, expected 9)
honey bottle, with the fix: item.honey_bottle.drink heard 9, burp 1

Self-check

tools/pr_ready.py and tools/parity.py don't run on Windows (signal.SIGHUP). These ran instead:

cargo fmt --all -- --check                                                        # clean
cargo clippy -p horizon-client --features mods --bins -- -D warnings              # clean
cargo test -p horizon-client --features mods --bin horizon-client -- game::remote game::lan_actions game::consume   # 17 passed

🤖 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/3674 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix-3129` --- ### 📝 Commits (3) - [`158075a`](https://github.com/horizon-rust/horizon/commit/158075a8e837fad79b649e3ff08c7b9a651ec143) Eating: the eater hears each bite once - [`3931a46`](https://github.com/horizon-rust/horizon/commit/3931a46585213ff8e331269aee72215a9472b067) lan_e2e: the player beside the eater hears each bite once too - [`9aeb985`](https://github.com/horizon-rust/horizon/commit/9aeb98530534ef87aa505a2a978c9cdc0e974fc3) lan_e2e eating: one loaf each, and read the bites once they settle ### 📊 Changes **5 files changed** (+82 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+5 -0) 📝 `crates/horizon-client/src/game/consume.rs` (+11 -2) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+9 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+4 -2) 📝 `tools/lan_e2e.py` (+53 -4) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. Fixes #3129 ## What and why When you eat, every bite sound plays twice, almost on top of itself. This happens to every single-player player (the window is a client of its server thread) and to every LAN or dedicated-server guest. **Root cause:** `Consumable.emitParticlesAndSounds` plays the bite through `LivingEntity.playSound`. For a player that is `Player.playSound`, which calls `level.playSound(this, ...)` with the player as the excluded listener: - the server sends the sound to everyone **but** the eater; - the eater's own client plays it locally. Horizon's server ran a guest's eating inside the guest's turn (`as_guest`). There, `Emitter::play_sound` used a plain `audio.play`, which is captured and broadcast to all guests, **the eater included**. So the eater heard its client's bite and the server's copy of the same bite. **Fix:** - `game/consume.rs`: while the server acts for a guest (`lan_acting`), `Emitter::play_sound` queues the sound in `guest_player_sounds` instead of broadcasting it to everyone. - `game/lan_actions.rs` (`leave_guest`): the queued sounds go out with the guest excepted, in the `player` source, as `Player.getSoundSource()` gives. The host still hears them locally (`play_unshared`). - `game/remote.rs` (`remote_complete_using`): on `USE_ITEM_COMPLETE` (entity event 9), the client now runs the whole `emitParticlesAndSounds(16)`, as vanilla's `completeUsingItem` does on the client. Before, it drew the final crumbs without the final bite sound and relied on the server's copy for it. Now the server no longer sends that copy to the eater. Unchanged on purpose: - `FoodProperties.onConsume`'s extra eat sound and the burp use `level.playSound(null, ...)`. The server sends them to everyone, the eater included, and a vanilla client doesn't play them locally, so they still come from the server. - Other players hear exactly what they heard before. The particles weren't doubled in these runs. The eater draws one set: 5 crumbs per bite plus 16 at the end, from its client only. ## Vanilla reference - `Consumable.emitParticlesAndSounds`: `spawnItemParticles`, then `LivingEntity.playSound(sound, volume, pitch)`. - `Player.playSound(SoundEvent, float, float)`: `level().playSound(this, getX(), getY(), getZ(), sound, getSoundSource(), ...)`. - `FoodProperties.onConsume`: `level.playSound(null, ...)` for the consumable's sound and `PLAYER_BURP`. - `LivingEntity.updateUsingItem` and `Consumable.shouldEmitParticlesAndSounds`: every 4 ticks once more than `consumeTicks * 0.21875` have passed. All checked with `javap` on the 26.3 jars. ## Test `tools/lan_e2e.py`'s `eat` check now counts the bite sounds the guest hears and compares them with the crumb bursts its client drew. The expected count is one sound per burst, plus `FoodProperties`' sound and the client's own last bite for each loaf eaten. I couldn't run `lan_e2e` here: it needs Linux or macOS (symlinks, `vscreen`, unix sockets). Instead, I ran the same measurement on Windows through `horizon-ctl status` (`heard`, `particles`). The setup: a single-player host on its server thread, with a second game joined over LAN. Both players are hungry and each eats one bread with `use-item --hold 2.2`. Fix code reverted, everything else on the same base: ``` guest eats: eater heard 16 (own crumb bursts 7, expected 9); watcher heard 9 host eats: eater heard 16 (own crumb bursts 7, expected 9); watcher heard 9 ``` With the fix: ``` guest eats: eater heard 9 (own crumb bursts 7, expected 9); watcher heard 9 host eats: eater heard 9 (own crumb bursts 7, expected 9); watcher heard 9 ``` Every bite now reaches the eater once, and the player watching still hears all of them. The same with a single game (single player alone, survival, hungry), two loaves each: ``` fix code reverted: heard eat=16 burp=1 item particles=51 (7 bursts, expected 9) x2 with the fix: heard eat=9 burp=1 item particles=51 (7 bursts, expected 9) honey bottle, with the fix: item.honey_bottle.drink heard 9, burp 1 ``` ## Self-check `tools/pr_ready.py` and `tools/parity.py` don't run on Windows (`signal.SIGHUP`). These ran instead: ``` cargo fmt --all -- --check # clean cargo clippy -p horizon-client --features mods --bins -- -D warnings # clean cargo test -p horizon-client --features mods --bin horizon-client -- game::remote game::lan_actions game::consume # 17 passed ``` 🤖 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:10:32 +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#5141
No description provided.