[PR #5755] [MERGED] No durability bar on an unbreakable item #6478

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5755
Author: @navinor
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/unbreakable-durability-bar


📝 Commits (2)

  • 8860e92 No durability bar on an unbreakable item
  • e3fcbf1 Keep unbreakable when syncing an inventory stack

📊 Changes

3 files changed (+66 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+6 -1)
📝 crates/horizon-client/src/item_sync.rs (+52 -0)
📝 crates/horizon-client/src/lan/guest.rs (+8 -0)

📄 Description

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

What and why

Fixes #5721: a damaged unbreakable item (/give @s diamond_hoe[damage=58,unbreakable={}]) showed a green durability bar. Vanilla 26.3 shows none.

Vanilla draws the bar when ItemStack.isBarVisible, which for most items is Item.isBarVisible: stack.isDamaged(). That needs isDamageableItem(): a max_damage and a damage, and no minecraft:unbreakable. Horizon's draw_item_decorations passed the item's max_damage and the stack's damage straight to damage_bar. It now passes a max_damage of 0 unless stations::is_damageable holds, the port of isDamageableItem the anvil and the grindstone already use.

The rendering guard alone was insufficient: lan::guest::network_stack also dropped minecraft:unbreakable during inventory sync. The server retained it, but the single-player window received only damage. The follow-up sends it as Component::Unit, matching vanilla's DataComponents.UNBREAKABLE stream codec. The existing client decoder already restores unit components as empty compounds.

Every GUI item draw goes through draw_item_decorations: the hotbar, the carried stack, container and creative slots, the recipe book, items pictured in bundle tooltips. The bundle's fullness bar is chosen before this fallback, and the native mods' native_item_bar hook still runs after it, so both behave as before.

Kind

  • parity: Horizon now does what vanilla 26.3 does

Vanilla reference

GuiGraphicsExtractor.itemDecorations (if (itemStack.isBarVisible())), Item.isBarVisible (stack.isDamaged()), ItemStack.isDamaged / isDamageableItem, BundleItem.isBarVisible, DataComponents.UNBREAKABLE (Unit.CODEC and Unit.STREAM_CODEC).

What checks it: the running game on its server thread, driven with horizon-ctl (offscreen, 1280×720). Hotbar slot 1 holds diamond_hoe[damage=58], slot 2 diamond_hoe[damage=58,unbreakable={}], slot 3 a plain diamond_hoe:

  • Before the sync correction (8860e928f, the original PR): slots 1 and 2 both show a green bar, slot 3 none. The original description incorrectly claimed slot 2's bar was gone; retaking cropped screenshots exposed the missing sync fix.
  • With both fixes (e3fcbf1b3): slot 1 shows the bar, slots 2 and 3 none. The client's held-stack data also retains both minecraft:damage:58 and minecraft:unbreakable:{}.

Before/after PNGs were retaken, cropped to the hotbar and scaled 3× without smoothing. Uploaded with gh --attach through the public fork's evidence PR, since this account has no upstream upload permission. Both attachment URLs were checked without authentication and match the local PNGs byte-for-byte.

Before inventory-sync correction (8860e928f) With both fixes (e3fcbf1b3)
Before: slots 1 and 2 show a durability bar After: only slot 1 shows a durability bar

The screenshot check counts bright green pixels in the bar region of each slot: damaged / unbreakable / undamaged goes from 117 / 117 / 0 before to 117 / 0 / 0 after.

Regression test: item_sync::tests::unbreakable_survives_inventory_sync sends ordinary and unbreakable damaged hoes through stack_to_network, Slot byte encoding/decoding and from_network. It asserts component presence and item/count/damage preservation. It failed with None instead of Some(Unit) before the encoder fix, and passes afterward. All eight item_sync tests pass. The rendering guard itself is checked in the running game; the HUD fixture uses a separate calculation.

Not in this PR (already wrong before it):

  • A stack's own minecraft:max_damage is ignored: draw_item_decorations and stations::is_damageable read the item's default. diamond_hoe[max_damage=100,damage=58] gets a bar measured against 1561.
  • The advanced tooltip's "Durability" line (game/stations.rs) still shows on a damaged unbreakable item; vanilla uses isDamaged there too.

Other projects' code

None.

Self-check

pr_ready (tools/pr_ready.py --quick --base cbfae5931 on Aaron, against cbfae5931, 12 min 55 s)

Check Result
Scope ✅ 4 files, +71 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed (1 min 51 s)
rustfmt ✅ (17 s)
clippy ✅ (3 min 8 s)
tests: horizon-client ❌ 1601 passed, 1 failed (7 min 28 s)
doc tests ✅ 0 passed (7 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
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 row includes the untracked .codegraph/.gitignore (5 lines), which is not committed. The actual PR changes 3 files, +66 −1. The one test failure is the unchanged native_hooks::tests::loot_table_load_stays_hookable: it searches horizon-world/src/loot.rs for "\n}\n", which is absent in this Windows checkout's CRLF text. The same test failed before the sync follow-up. All eight inventory-sync tests, including the new regression, pass. The fast game build and the live client component/pixel checks pass as described above.

🤖 Generated with OpenCode


🔄 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/5755 **Author:** [@navinor](https://github.com/navinor) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/unbreakable-durability-bar` --- ### 📝 Commits (2) - [`8860e92`](https://github.com/horizon-rust/horizon/commit/8860e928fc73117f21ae41b54cd2fc6201d8685a) No durability bar on an unbreakable item - [`e3fcbf1`](https://github.com/horizon-rust/horizon/commit/e3fcbf1b3cca04b1ce3abd5d55ce50f848b9834c) Keep unbreakable when syncing an inventory stack ### 📊 Changes **3 files changed** (+66 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+6 -1) 📝 `crates/horizon-client/src/item_sync.rs` (+52 -0) 📝 `crates/horizon-client/src/lan/guest.rs` (+8 -0) </details> ### 📄 Description > 🤖 Opened by navinor's AI agent (OpenCode, Claude Opus 5.5), not by navinor personally. ## What and why Fixes #5721: a damaged unbreakable item (`/give @s diamond_hoe[damage=58,unbreakable={}]`) showed a green durability bar. Vanilla 26.3 shows none. Vanilla draws the bar when `ItemStack.isBarVisible`, which for most items is `Item.isBarVisible`: `stack.isDamaged()`. That needs `isDamageableItem()`: a `max_damage` and a `damage`, and no `minecraft:unbreakable`. Horizon's `draw_item_decorations` passed the item's `max_damage` and the stack's `damage` straight to `damage_bar`. It now passes a `max_damage` of 0 unless `stations::is_damageable` holds, the port of `isDamageableItem` the anvil and the grindstone already use. The rendering guard alone was insufficient: `lan::guest::network_stack` also dropped `minecraft:unbreakable` during inventory sync. The server retained it, but the single-player window received only `damage`. The follow-up sends it as `Component::Unit`, matching vanilla's `DataComponents.UNBREAKABLE` stream codec. The existing client decoder already restores unit components as empty compounds. Every GUI item draw goes through `draw_item_decorations`: the hotbar, the carried stack, container and creative slots, the recipe book, items pictured in bundle tooltips. The bundle's fullness bar is chosen before this fallback, and the native mods' `native_item_bar` hook still runs after it, so both behave as before. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does ## Vanilla reference `GuiGraphicsExtractor.itemDecorations` (`if (itemStack.isBarVisible())`), `Item.isBarVisible` (`stack.isDamaged()`), `ItemStack.isDamaged` / `isDamageableItem`, `BundleItem.isBarVisible`, `DataComponents.UNBREAKABLE` (`Unit.CODEC` and `Unit.STREAM_CODEC`). What checks it: the running game on its server thread, driven with `horizon-ctl` (offscreen, 1280×720). Hotbar slot 1 holds `diamond_hoe[damage=58]`, slot 2 `diamond_hoe[damage=58,unbreakable={}]`, slot 3 a plain `diamond_hoe`: - Before the sync correction (`8860e928f`, the original PR): slots 1 and 2 both show a green bar, slot 3 none. The original description incorrectly claimed slot 2's bar was gone; retaking cropped screenshots exposed the missing sync fix. - With both fixes (`e3fcbf1b3`): slot 1 shows the bar, slots 2 and 3 none. The client's held-stack data also retains both `minecraft:damage:58` and `minecraft:unbreakable:{}`. Before/after PNGs were retaken, cropped to the hotbar and scaled 3× without smoothing. Uploaded with `gh --attach` through [the public fork's evidence PR](https://github.com/navinor/horizon/pull/1), since this account has no upstream upload permission. Both attachment URLs were checked without authentication and match the local PNGs byte-for-byte. | Before inventory-sync correction (`8860e928f`) | With both fixes (`e3fcbf1b3`) | | --- | --- | | ![Before: slots 1 and 2 show a durability bar](https://github.com/user-attachments/assets/34897a3a-ac47-4c23-9091-6d16f819248c) | ![After: only slot 1 shows a durability bar](https://github.com/user-attachments/assets/9ee0acea-d506-4f09-9d66-05e8bb1a0c5a) | The screenshot check counts bright green pixels in the bar region of each slot: damaged / unbreakable / undamaged goes from `117 / 117 / 0` before to `117 / 0 / 0` after. Regression test: `item_sync::tests::unbreakable_survives_inventory_sync` sends ordinary and unbreakable damaged hoes through `stack_to_network`, `Slot` byte encoding/decoding and `from_network`. It asserts component presence and item/count/damage preservation. It failed with `None` instead of `Some(Unit)` before the encoder fix, and passes afterward. All eight `item_sync` tests pass. The rendering guard itself is checked in the running game; the HUD fixture uses a separate calculation. Not in this PR (already wrong before it): - A stack's own `minecraft:max_damage` is ignored: `draw_item_decorations` and `stations::is_damageable` read the item's default. `diamond_hoe[max_damage=100,damage=58]` gets a bar measured against 1561. - The advanced tooltip's "Durability" line (`game/stations.rs`) still shows on a damaged unbreakable item; vanilla uses `isDamaged` there too. ## Other projects' code None. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base cbfae5931` on Aaron, against cbfae5931, 12 min 55 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +71 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed (1 min 51 s) | | rustfmt | ✅ (17 s) | | clippy | ✅ (3 min 8 s) | | tests: horizon-client | ❌ 1601 passed, 1 failed (7 min 28 s) | | doc tests | ✅ 0 passed (7 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | 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 row includes the untracked `.codegraph/.gitignore` (5 lines), which is not committed. The actual PR changes 3 files, +66 −1. The one test failure is the unchanged `native_hooks::tests::loot_table_load_stays_hookable`: it searches `horizon-world/src/loot.rs` for `"\n}\n"`, which is absent in this Windows checkout's CRLF text. The same test failed before the sync follow-up. All eight inventory-sync tests, including the new regression, pass. The fast game build and the live client component/pixel checks pass as described above. 🤖 Generated with [OpenCode](https://opencode.ai) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:21:17 +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#6478
No description provided.