[PR #4213] [MERGED] Tools and armour break with their sound and crumbs on servers #5489

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

📋 Pull Request Information

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

Base: main ← Head: fix-3514-equipment-break-events


📝 Commits (1)

  • 3891dd9 Break sound and crumbs for equipment a server says broke

📊 Changes

5 files changed (+230 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game/item_particles.rs (+73 -0)
📝 crates/horizon-client/src/game/remote.rs (+6 -0)
📝 crates/horizon-client/src/game/remote_mob_data.rs (+3 -0)
📝 crates/horizon-client/src/mobs.rs (+1 -0)
➕ crates/horizon-client/src/mobs/item_break.rs (+147 -0)

📄 Description

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

What and why

Part of #3514 (the LivingEntity.entityEventForEquipmentBreak row).

On a vanilla or Paper server, when a tool or armour piece broke, nothing played: no break sound and no crumbs. This happened for your own items and for other players' and mobs' items. A vanilla server never plays the break itself. LivingEntity.onEquippedItemBroken sends the entity event for the slot to the tracking players and to the player itself: 47 main hand, 48 off hand, 49 to 52 head to feet, 65 body, 68 saddle. Each client's LivingEntity.handleEntityEvent then runs breakItem on the stack it still has in that slot. The equipment update that empties the slot comes later. Horizon's remote C::EntityEvent handler had no case for these events.

Fix:

  • mobs/item_break.rs (lib): equipment_break_slot(event) maps the event byte to its EquipmentSlot, the reverse of entityEventForEquipmentBreak. Mob::item_by_slot stands in for getItemBySlot on a mob or another player drawn from a server. It covers held items, worn armour (with components from SetEquipment when they are kept), body armour kept in head with its lost durability, and the saddle.

  • game/item_particles.rs: remote_equipment_break handles both cases:

    • For this player, it takes the stack from the player's own hand, off hand or armour slot. It plays the stack's break_sound component at the feet, as playLocalSound with volume 0.8 and pitch 0.8 to 1.2. It also spawns the 5 crumbs of spawnItemParticles.
    • For another entity, it does the same at that entity, using its eye height, head pitch and yaw. The sound is skipped when the entity is silent.

    The sound comes from the item's own component, so wolf armour plays item.wolf_armor.break and a shield plays item.shield.break.

  • game/remote_mob_data.rs: Entity.DATA_SILENT (index 4) is now copied to Mob::silent for remote entities. Before this, the isSilent() check in breakItem could not work on a server.

The local and integrated-server break paths are not touched. #3949 adds crumbs there. A Horizon host does not send these events, so its guests cannot hear a break twice.

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

  • LivingEntity.entityEventForEquipmentBreak(EquipmentSlot) and LivingEntity.onEquippedItemBroken: which byte goes with which slot.
  • LivingEntity.handleEntityEvent(byte) cases 47 to 52, 65 and 68: breakItem(getItemBySlot(slot)).
  • LivingEntity.breakItem(ItemStack): reads DataComponents.BREAK_SOUND. Unless isSilent(), it calls level.playLocalSound(x, y, z, sound, getSoundSource(), 0.8F, 0.8F + random.nextFloat() * 0.4F, false). Then it calls spawnItemParticles(stack, 5).
  • Entity synched data order: index 4 is DATA_SILENT.

All of these were read with javap on the 26.3 client.jar. No parity harness covers entity events. New unit tests in mobs::item_break::tests check the event-to-slot mapping and the slot lookup.

Self-check

tools/pr_ready.py does not run on Windows (it needs SIGHUP), so I ran these steps by hand:

cargo fmt --all -- --check                                      -> ok
cargo clippy -p horizon-client --all-targets -- -D warnings     -> ok (Finished, no warnings)
cargo test -p horizon-client --lib mobs::item_break             -> 3 passed
cargo test -p horizon-client --lib mobs::                       -> 152 passed, 6 ignored
cargo test -p horizon-client --bin horizon-client remote_mob_data -> 13 passed

Test before and after: I stubbed the new code back to the old behaviour (no event names a slot, no stack is found) and left the tests unchanged:

test mobs::item_break::tests::each_equipment_break_event_names_its_slot ... FAILED
test mobs::item_break::tests::a_player_breaks_what_it_holds_and_wears ... FAILED
test mobs::item_break::tests::body_armour_and_saddles_break_from_their_slots ... FAILED
test result: FAILED. 0 passed; 3 failed

With the fix: test result: ok. 3 passed; 0 failed.

In game, I connected Horizon to a local vanilla 26.3 server.jar (offline mode, flat world). The counts below come from horizon-ctl status (heard sounds, item particles made) on a build of main and on this branch:

Case main this PR
Own nearly broken diamond pickaxe breaks on grass (event 47) 0 entity.item.break, 0 item particles (the pickaxe is gone) 1 entity.item.break, 5 item particles
Zombie's iron helmet wears out in sunlight (event 49) 0 / 0 +1 sound / +5 particles
Wolf's armour breaks from /damage … mob_attack (event 65) 0 / 0 1 item.wolf_armor.break / +5 particles
A second player (client "Guest") breaks a pickaxe; the observer's counts — 1 entity.item.break / 5 particles
Silent wolf's armour breaks — no sound, 5 particles (as isSilent says)
Own diamond chestplate breaks from /damage Tester 1 mob_attack (event 50) — +1 sound / +5 particles

Screenshots

Same view, same time of day (noon), on the vanilla server: a wolf whose armour has just broken from one hit.

  • Before (main): nothing at the wolf's snout. The armour is gone silently.
  • After (this PR): the brown wolf-armour crumbs fall from in front of the wolf's head, and item.wolf_armor.break plays.

🤖 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/4213 **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-3514-equipment-break-events` --- ### 📝 Commits (1) - [`3891dd9`](https://github.com/horizon-rust/horizon/commit/3891dd9410c99bf36fb6e3e01797985969ee3c54) Break sound and crumbs for equipment a server says broke ### 📊 Changes **5 files changed** (+230 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/item_particles.rs` (+73 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+6 -0) 📝 `crates/horizon-client/src/game/remote_mob_data.rs` (+3 -0) 📝 `crates/horizon-client/src/mobs.rs` (+1 -0) ➕ `crates/horizon-client/src/mobs/item_break.rs` (+147 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why Part of #3514 (the `LivingEntity.entityEventForEquipmentBreak` row). On a vanilla or Paper server, when a tool or armour piece broke, nothing played: no break sound and no crumbs. This happened for your own items and for other players' and mobs' items. A vanilla server never plays the break itself. `LivingEntity.onEquippedItemBroken` sends the entity event for the slot to the tracking players and to the player itself: 47 main hand, 48 off hand, 49 to 52 head to feet, 65 body, 68 saddle. Each client's `LivingEntity.handleEntityEvent` then runs `breakItem` on the stack it still has in that slot. The equipment update that empties the slot comes later. Horizon's remote `C::EntityEvent` handler had no case for these events. Fix: - `mobs/item_break.rs` (lib): `equipment_break_slot(event)` maps the event byte to its `EquipmentSlot`, the reverse of `entityEventForEquipmentBreak`. `Mob::item_by_slot` stands in for `getItemBySlot` on a mob or another player drawn from a server. It covers held items, worn armour (with components from `SetEquipment` when they are kept), body armour kept in `head` with its lost durability, and the saddle. - `game/item_particles.rs`: `remote_equipment_break` handles both cases: - For this player, it takes the stack from the player's own hand, off hand or armour slot. It plays the stack's `break_sound` component at the feet, as `playLocalSound` with volume 0.8 and pitch 0.8 to 1.2. It also spawns the 5 crumbs of `spawnItemParticles`. - For another entity, it does the same at that entity, using its eye height, head pitch and yaw. The sound is skipped when the entity is silent. The sound comes from the item's own component, so wolf armour plays `item.wolf_armor.break` and a shield plays `item.shield.break`. - `game/remote_mob_data.rs`: `Entity.DATA_SILENT` (index 4) is now copied to `Mob::silent` for remote entities. Before this, the `isSilent()` check in `breakItem` could not work on a server. The local and integrated-server break paths are not touched. #3949 adds crumbs there. A Horizon host does not send these events, so its guests cannot hear a break twice. ## 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 - `LivingEntity.entityEventForEquipmentBreak(EquipmentSlot)` and `LivingEntity.onEquippedItemBroken`: which byte goes with which slot. - `LivingEntity.handleEntityEvent(byte)` cases 47 to 52, 65 and 68: `breakItem(getItemBySlot(slot))`. - `LivingEntity.breakItem(ItemStack)`: reads `DataComponents.BREAK_SOUND`. Unless `isSilent()`, it calls `level.playLocalSound(x, y, z, sound, getSoundSource(), 0.8F, 0.8F + random.nextFloat() * 0.4F, false)`. Then it calls `spawnItemParticles(stack, 5)`. - `Entity` synched data order: index 4 is `DATA_SILENT`. All of these were read with javap on the 26.3 `client.jar`. No parity harness covers entity events. New unit tests in `mobs::item_break::tests` check the event-to-slot mapping and the slot lookup. ## Self-check `tools/pr_ready.py` does not run on Windows (it needs SIGHUP), so I ran these steps by hand: ``` cargo fmt --all -- --check -> ok cargo clippy -p horizon-client --all-targets -- -D warnings -> ok (Finished, no warnings) cargo test -p horizon-client --lib mobs::item_break -> 3 passed cargo test -p horizon-client --lib mobs:: -> 152 passed, 6 ignored cargo test -p horizon-client --bin horizon-client remote_mob_data -> 13 passed ``` Test before and after: I stubbed the new code back to the old behaviour (no event names a slot, no stack is found) and left the tests unchanged: ``` test mobs::item_break::tests::each_equipment_break_event_names_its_slot ... FAILED test mobs::item_break::tests::a_player_breaks_what_it_holds_and_wears ... FAILED test mobs::item_break::tests::body_armour_and_saddles_break_from_their_slots ... FAILED test result: FAILED. 0 passed; 3 failed ``` With the fix: `test result: ok. 3 passed; 0 failed`. In game, I connected Horizon to a local vanilla 26.3 `server.jar` (offline mode, flat world). The counts below come from `horizon-ctl status` (`heard` sounds, `item` particles made) on a build of main and on this branch: | Case | main | this PR | |---|---|---| | Own nearly broken diamond pickaxe breaks on grass (event 47) | 0 `entity.item.break`, 0 item particles (the pickaxe is gone) | 1 `entity.item.break`, 5 item particles | | Zombie's iron helmet wears out in sunlight (event 49) | 0 / 0 | +1 sound / +5 particles | | Wolf's armour breaks from `/damage … mob_attack` (event 65) | 0 / 0 | 1 `item.wolf_armor.break` / +5 particles | | A second player (client "Guest") breaks a pickaxe; the observer's counts | — | 1 `entity.item.break` / 5 particles | | Silent wolf's armour breaks | — | no sound, 5 particles (as `isSilent` says) | | Own diamond chestplate breaks from `/damage Tester 1 mob_attack` (event 50) | — | +1 sound / +5 particles | ## Screenshots Same view, same time of day (noon), on the vanilla server: a wolf whose armour has just broken from one hit. - Before (main): nothing at the wolf's snout. The armour is gone silently. - After (this PR): the brown wolf-armour crumbs fall from in front of the wolf's head, and `item.wolf_armor.break` plays. 🤖 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:12:56 +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#5489
No description provided.