[PR #2037] [MERGED] Loot: the enchantment functions reach every table that rolls #3957

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2037
Author: @levzzz5154
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ludovic111

Base: main ← Head: fix/loot-enchant-functions


📝 Commits (2)

  • c68e554 Loot: the enchantment functions reach every table that rolls
  • 941f148 Loot: a single-level enchantment draws no level

📊 Changes

2 files changed (+167 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/items.rs (+164 -1)
📝 crates/horizon-client/src/stations.rs (+3 -2)

📄 Description

🤖 Opened by levzzz5154's AI agent ([CC], deepseek-v4.1-flash), not by levzzz5154.

What and why

Fixes #1660.

/loot give @s loot minecraft:chests/end_city_treasure hands out bare gear, and so does every other table this
dispatcher rolls. #1911 (and #1437) fixed the chunk-generation path, which rolls through horizon_world::loot;
the second loot implementation in items.rs — the one /loot, bartering, raids, dispenser tables, advancements
and mob drops use — had no minecraft:enchant_with_levels or minecraft:enchant_randomly arm, so both fell
through untouched. That is why the End cities' enchanted armour still never appeared when a player looked.

  • Items::modifiers now runs both, as vanilla does: EnchantWithLevelsFunction picks from
    EnchantmentHelper.enchantItem's results (a book becomes one enchanted book), EnchantRandomlyFunction picks
    one compatible enchantment at a level between its min and max. Both resolve options as a tag, a list or one
    id, else the whole registry (enchant_pool).
  • Items carries that registry (Items::enchantments), and StationData shares the same Arc instead of
    loading a second copy.

Vanilla reference

  • EnchantWithLevelsFunction.run → EnchantmentHelper.enchantItem(random, stack, cost, registry, options).
  • EnchantRandomlyFunction.run/enchantItem: the compatible candidates, one picked, a level from min to max, a
    book becoming enchanted_book.
  • EnchantmentHelper.getAvailableEnchantmentResults / selectEnchantment (already modelled by
    enchant::Enchantments::select).

Verification

In game, six /loot give @s loot minecraft:chests/end_city_treasure rolls: 10 pieces of gear, all 10 enchanted
(unbreaking 3, mending 1 + protection 4, efficiency 4, …) where all 10 were bare before the change.

loot_enchant_functions_enchant_the_rolled_item (real prepared resources): 40 rolls of a diamond sword at levels
20–39 all come out enchanted with levels inside each enchantment's range; enchant_randomly on a book makes one
enchanted_book with one stored enchantment from #minecraft:on_random_loot; a dirt stack at level 30 stays
unenchantable.

Scope

2 files, +117 −2 (items.rs, stations.rs).

🤖 Generated with [CC].

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on cachyos-x8664, upstream 7ecb43cc, 2 min 14 s)

Check Result
Scope ✅ 2 files, +129 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (5 s)
clippy ❌ failed (9 s)
tests: horizon-client ✅ 1293 passed (1 min 55 s)
doc tests ✅ 0 passed (2 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt / clippy / tests ➖ launcher untouched
Parity ➖ 272 affected, to run in CI (--quick)
Label no label for a fix

clippy fails on crates/horizon-client/src/mobs/axolotl.rs:169 (overly_complex_bool_expr), which fails the same way on upstream/main at 7ecb43cc: nothing in this branch touches it.


🔄 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/2037 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/loot-enchant-functions` --- ### 📝 Commits (2) - [`c68e554`](https://github.com/horizon-rust/horizon/commit/c68e55438f4daf6f0c744f980eae3a335f820c99) Loot: the enchantment functions reach every table that rolls - [`941f148`](https://github.com/horizon-rust/horizon/commit/941f1489578c5e33ce8e38a18688c82e52f0020e) Loot: a single-level enchantment draws no level ### 📊 Changes **2 files changed** (+167 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/items.rs` (+164 -1) 📝 `crates/horizon-client/src/stations.rs` (+3 -2) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent ([CC], deepseek-v4.1-flash), not by levzzz5154. ## What and why Fixes #1660. `/loot give @s loot minecraft:chests/end_city_treasure` hands out bare gear, and so does every other table this dispatcher rolls. #1911 (and #1437) fixed the chunk-generation path, which rolls through `horizon_world::loot`; the second loot implementation in `items.rs` — the one `/loot`, bartering, raids, dispenser tables, advancements and mob drops use — had no `minecraft:enchant_with_levels` or `minecraft:enchant_randomly` arm, so both fell through untouched. That is why the End cities' enchanted armour still never appeared when a player looked. - `Items::modifiers` now runs both, as vanilla does: `EnchantWithLevelsFunction` picks from `EnchantmentHelper.enchantItem`'s results (a book becomes one enchanted book), `EnchantRandomlyFunction` picks one compatible enchantment at a level between its min and max. Both resolve `options` as a tag, a list or one id, else the whole registry (`enchant_pool`). - `Items` carries that registry (`Items::enchantments`), and `StationData` shares the same `Arc` instead of loading a second copy. ## Vanilla reference - `EnchantWithLevelsFunction.run` → `EnchantmentHelper.enchantItem(random, stack, cost, registry, options)`. - `EnchantRandomlyFunction.run`/`enchantItem`: the compatible candidates, one picked, a level from min to max, a book becoming `enchanted_book`. - `EnchantmentHelper.getAvailableEnchantmentResults` / `selectEnchantment` (already modelled by `enchant::Enchantments::select`). ## Verification In game, six `/loot give @s loot minecraft:chests/end_city_treasure` rolls: **10 pieces of gear, all 10 enchanted** (`unbreaking 3`, `mending 1 + protection 4`, `efficiency 4`, …) where all 10 were bare before the change. `loot_enchant_functions_enchant_the_rolled_item` (real prepared resources): 40 rolls of a diamond sword at levels 20–39 all come out enchanted with levels inside each enchantment's range; `enchant_randomly` on a book makes one `enchanted_book` with one stored enchantment from `#minecraft:on_random_loot`; a dirt stack at level 30 stays unenchantable. ## Scope 2 files, +117 −2 (`items.rs`, `stations.rs`). 🤖 Generated with [[CC]](https://github.com/levzzz5154/horizon). ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on cachyos-x8664, upstream 7ecb43cc, 2 min 14 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +129 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (5 s) | | clippy | ❌ failed (9 s) | | tests: horizon-client | ✅ 1293 passed (1 min 55 s) | | doc tests | ✅ 0 passed (2 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt / clippy / tests | ➖ launcher untouched | | Parity | ➖ 272 affected, to run in CI (--quick) | | Label | no label for a fix | `clippy` fails on `crates/horizon-client/src/mobs/axolotl.rs:169` (`overly_complex_bool_expr`), which fails the same way on `upstream/main` at 7ecb43cc: nothing in this branch touches it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:13:35 +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#3957
No description provided.