[PR #6071] [MERGED] Discard invalid enchantment levels and preserve untranslated level names #6641

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

📋 Pull Request Information

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

Base: main ← Head: fix/enchantment-levels-6030


📝 Commits (1)

  • ac5f512 Fix persistent enchantment level decoding and names

📊 Changes

5 files changed (+237 additions, -5 deletions)

View changed files

➕ crates/horizon-items/examples/enchantment_components_probe.rs (+45 -0)
📝 crates/horizon-items/src/enchant.rs (+28 -4)
📝 crates/horizon-items/src/item_data.rs (+31 -1)
➕ mods/horizon/src/test/java/dev/horizonlab/parity/VanillaEnchantmentComponentsOracle.java (+48 -0)
➕ tools/test_enchantment_components_parity.py (+85 -0)

📄 Description

🤖 Opened by Corbonat's AI agent (Codex, gpt-6.1-sol), not by Corbonat personally.

What and why

Loading persistent looting:256 currently grants Looting 255. Follow vanilla's numeric conversion and range validation instead: discard the invalid enchantment entry while preserving valid neighbors and unrelated item data, for both ordinary and stored enchantments. High-level tooltips retain enchantment.level.N when no translation exists and respect language/resource-pack translations.

Fixes #6030. The command-block observations are tracked separately in #6066 and #6067.

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
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Pinned 26.3 ItemEnchantments persistent codec (LEVEL_CODEC), TagValueInput.read, and Enchantment.getFullname. The new harness compares Horizon's item-NBT path with real item stacks loaded through vanilla's TagValueInput, against both shipped client and server jars. All 64 cases match each jar, including invalid entries, numeric NBT conversion boundaries, valid neighbors, ordinary/stored components and unrelated damage. The pre-fix run fails on clamping and high-level display names.

Other projects' code

None.

Self-check

pr_ready (tools/pr_ready.py --base upstream/main on HOME-PC, against upstream/main at 6f30860d0, 13 min 24 s)

Check Result
Scope ✅ 5 files, +237 −5
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 527 passed (1 min 56 s)
rustfmt ✅ (23 s)
clippy ✅ (3 min 51 s)
tests: horizon-items ✅ 50 passed (49 s)
doc tests ✅ 0 passed (2 s)
content root tests ✅ 20 passed (6 min 15 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ❌ 377 affected, (3 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The general parity runner cannot execute on this Windows host: ModuleNotFoundError: No module named 'fcntl' in machine_slot. Its wider affected set is not locally verified. The new python tools/test_enchantment_components_parity.py harness was run directly and passes against both pinned jars; CI runs the broader set on Linux.

GitHub verify passed at this head. The maintainer-triggered upstream parity run was cancelled before any steps ran, so it provides no parity result. A maintainer rerun remains pending before merge; the source head has not changed since the approving review.

Optimized game build passes. In fresh test homes, the real default integrated-server path passes six /data modify block ... Items cases for a diamond sword and enchanted book (valid 255, invalid 256 with a valid neighbor, and invalid-only 256). Item stacks survive; invalid Looting is absent after loading, Sharpness III remains. Tooltips were rendered and visually inspected. Tests used offscreen rendering at 30 FPS / distance 2; no performance claim.

python tools/port_ledger.py --json check --base upstream/main passes: no new gaps, lost mappings, stale citations or missing citations. The existing Style.withColor heuristic callee gap is unchanged.

Screenshots

Before is the preserved clean workstation baseline af669895a; after is this PR's ac5f51226. Both use the same test inputs and private-home scenario.

Valid 255 before (incorrect numeric suffix):

Before: valid Looting 255

Valid 255 after (vanilla untranslated key):

After: Looting enchantment.level.255

Input 256 plus Sharpness III before (incorrectly capped):

Before: invalid Looting 256 becomes 255

The same input after (invalid entry discarded; Sharpness III preserved):

After: only Sharpness III remains

🤖 Generated with Codex.


🔄 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/6071 **Author:** [@Corbonat](https://github.com/Corbonat) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/enchantment-levels-6030` --- ### 📝 Commits (1) - [`ac5f512`](https://github.com/horizon-rust/horizon/commit/ac5f51226b442c29bca03acf79779972dcc77bfa) Fix persistent enchantment level decoding and names ### 📊 Changes **5 files changed** (+237 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-items/examples/enchantment_components_probe.rs` (+45 -0) 📝 `crates/horizon-items/src/enchant.rs` (+28 -4) 📝 `crates/horizon-items/src/item_data.rs` (+31 -1) ➕ `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaEnchantmentComponentsOracle.java` (+48 -0) ➕ `tools/test_enchantment_components_parity.py` (+85 -0) </details> ### 📄 Description > 🤖 Opened by Corbonat's AI agent (Codex, gpt-6.1-sol), not by Corbonat personally. ## What and why Loading persistent `looting:256` currently grants Looting 255. Follow vanilla's numeric conversion and range validation instead: discard the invalid enchantment entry while preserving valid neighbors and unrelated item data, for both ordinary and stored enchantments. High-level tooltips retain `enchantment.level.N` when no translation exists and respect language/resource-pack translations. Fixes #6030. The command-block observations are tracked separately in #6066 and #6067. ## 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 - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Pinned 26.3 `ItemEnchantments` persistent codec (`LEVEL_CODEC`), `TagValueInput.read`, and `Enchantment.getFullname`. The new harness compares Horizon's item-NBT path with real item stacks loaded through vanilla's `TagValueInput`, against both shipped client and server jars. All 64 cases match each jar, including invalid entries, numeric NBT conversion boundaries, valid neighbors, ordinary/stored components and unrelated damage. The pre-fix run fails on clamping and high-level display names. ## Other projects' code None. ## Self-check **pr_ready** (`tools/pr_ready.py --base upstream/main` on HOME-PC, against upstream/main at 6f30860d0, 13 min 24 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +237 −5 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 527 passed (1 min 56 s) | | rustfmt | ✅ (23 s) | | clippy | ✅ (3 min 51 s) | | tests: horizon-items | ✅ 50 passed (49 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ✅ 20 passed (6 min 15 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ❌ 377 affected, (3 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The general parity runner cannot execute on this Windows host: `ModuleNotFoundError: No module named 'fcntl'` in `machine_slot`. Its wider affected set is **not locally verified**. The new `python tools/test_enchantment_components_parity.py` harness was run directly and passes against both pinned jars; CI runs the broader set on Linux. GitHub `verify` passed at this head. The [maintainer-triggered upstream parity run](https://github.com/horizon-rust/horizon/actions/runs/41324988499) was cancelled before any steps ran, so it provides no parity result. A maintainer rerun remains pending before merge; the source head has not changed since the approving review. Optimized game build passes. In fresh test homes, the real default integrated-server path passes six `/data modify block ... Items` cases for a diamond sword and enchanted book (valid 255, invalid 256 with a valid neighbor, and invalid-only 256). Item stacks survive; invalid Looting is absent after loading, Sharpness III remains. Tooltips were rendered and visually inspected. Tests used offscreen rendering at 30 FPS / distance 2; no performance claim. `python tools/port_ledger.py --json check --base upstream/main` passes: no new gaps, lost mappings, stale citations or missing citations. The existing Style.withColor heuristic callee gap is unchanged. ## Screenshots Before is the preserved clean workstation baseline `af669895a`; after is this PR's `ac5f51226`. Both use the same test inputs and private-home scenario. Valid 255 before (incorrect numeric suffix): ![Before: valid Looting 255](https://github.com/user-attachments/assets/ea87c399-90f5-479f-a2d6-af9c723627ea) Valid 255 after (vanilla untranslated key): ![After: Looting enchantment.level.255](https://github.com/user-attachments/assets/97479306-23d3-4aa0-b2a1-292ed8198589) Input 256 plus Sharpness III before (incorrectly capped): ![Before: invalid Looting 256 becomes 255](https://github.com/user-attachments/assets/b0da58af-5858-44c0-b7ba-bce65bb981e1) The same input after (invalid entry discarded; Sharpness III preserved): ![After: only Sharpness III remains](https://github.com/user-attachments/assets/948dcc6a-9e56-4a7c-9fa0-d099495d72b8) 🤖 Generated with [Codex](https://openai.com/codex/). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:24:11 +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#6641
No description provided.