[PR #7506] [MERGED] /loot rolls loot_table entries #7633

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7506
Author: @k3yh
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/loot-command-nested-tables


📝 Commits (1)

  • 79ae7cf /loot rolls loot_table entries

📊 Changes

3 files changed (+105 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game/commands/terrain_cmds.rs (+3 -2)
📝 crates/horizon-items/src/items.rs (+99 -1)
📝 tools/command_exec_corpus.py (+3 -0)

📄 Description

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

What and why

/loot drops nothing from a table that picks another table:

/loot spawn ~ ~ ~ loot minecraft:chests/trial_chambers/reward
Dropped 0 items

Vanilla drops the reward (its entries are minecraft:loot_table entries naming reward_common, reward_rare...). /loot rolls tables through the items engine (horizon-items), whose expand had no case for that entry type, so the chosen entry produced nothing. Chests were right: they roll through horizon_world::loot, which has table_raw. Data packs and mods use these entries a lot (found while porting a dungeon mod whose chest tables are made of them).

A chosen loot_table entry now rolls its table (an id, or an inline table) in full, then applies the entry's own functions to each stack (NestedLootTable.createItemStack). A table already rolling further out, the outermost one included, adds nothing (LootContext.pushVisitedElement), as table_raw does.

With nested tables dropping several stacks, the parity cases also showed /loot's result counting items where vanilla counts stacks: CommandResponseTracker.track(drop) adds one per stack, so two stacks of two return 2, not 4. That's two lines in cmd_loot, kept here since the same cases check it.

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

Change

  • horizon-items/src/items.rs: expand takes a minecraft:loot_table entry as a candidate by its weight; choose rolls it through nested, which guards against a table rolling inside itself (NESTED_ROLLS, with loot_table marking the outermost table).
  • terrain_cmds.rs (cmd_loot): the tracker counts one per stack.
  • Test loot_table_entries_roll_their_table: by id with a set_count on the entry, inline, and a table naming itself.
  • command_exec_corpus.py ("items and loot"): /loot spawn of trial_chambers/reward and /loot give of reward_ominous.

Vanilla reference

NestedLootTable.createItemStack, LootTable.getRandomItemsRaw, LootContext.pushVisitedElement; LootCommand.dropInWorld / CommandResponseTracker.track(Element) and sendFeedback (returns totalValue). tools/test_command_exec_parity.py --only "items and loot": 76/76 commands match vanilla (74/76 with the new cases before the tracker change: same messages, results 4 and 5 where vanilla has 2 and 3).

Other projects' code

none

Test

Single player (horizon-ctl, temp home) and dedicated server (horizon-server), each on nightly c9d474d and on this branch:

Command Before After
loot spawn … loot minecraft:chests/trial_chambers/reward Dropped 0 items Dropped 2 items (vanilla: 2)
loot spawn … loot minecraft:chests/trial_chambers/reward_ominous Dropped 0 items Dropped 3 items
loot spawn … loot minecraft:chests/simple_dungeon Dropped 6 items Dropped 6 items

Self-check

pr_ready (tools/pr_ready.py --quick --base 1952b56c6 on DESKTOP-S9O4938, 7 min 2 s):

Check Result
Scope ✅ 3 files, +105 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 614 run, FAILED (errors=1, skipped=1)
rustfmt ✅
clippy ✅
tests: horizon-client, horizon-items ✅ 750 passed
doc tests ✅
content root tests ✅ 23 passed
mod API up to date ✅
Parity ➖ not run (--quick); "items and loot" run by hand: 76/76

The Python failure is not in this change: test_port_ledger cannot import tests.test_class_index on this machine, as on main.

🤖 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/7506 **Author:** [@k3yh](https://github.com/k3yh) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/loot-command-nested-tables` --- ### 📝 Commits (1) - [`79ae7cf`](https://github.com/horizon-rust/horizon/commit/79ae7cfe1912a49d659cfe6bf6ccb7a481bbbdb7) /loot rolls loot_table entries ### 📊 Changes **3 files changed** (+105 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands/terrain_cmds.rs` (+3 -2) 📝 `crates/horizon-items/src/items.rs` (+99 -1) 📝 `tools/command_exec_corpus.py` (+3 -0) </details> ### 📄 Description > 🤖 Opened by k3yh's AI agent (Claude Code, Claude Opus 5.5), not by k3yh personally. ## What and why `/loot` drops nothing from a table that picks another table: ``` /loot spawn ~ ~ ~ loot minecraft:chests/trial_chambers/reward Dropped 0 items ``` Vanilla drops the reward (its entries are `minecraft:loot_table` entries naming `reward_common`, `reward_rare`...). `/loot` rolls tables through the items engine (`horizon-items`), whose `expand` had no case for that entry type, so the chosen entry produced nothing. Chests were right: they roll through `horizon_world::loot`, which has `table_raw`. Data packs and mods use these entries a lot (found while porting a dungeon mod whose chest tables are made of them). A chosen `loot_table` entry now rolls its table (an id, or an inline table) in full, then applies the entry's own functions to each stack (`NestedLootTable.createItemStack`). A table already rolling further out, the outermost one included, adds nothing (`LootContext.pushVisitedElement`), as `table_raw` does. With nested tables dropping several stacks, the parity cases also showed `/loot`'s result counting items where vanilla counts stacks: `CommandResponseTracker.track(drop)` adds one per stack, so two stacks of two return 2, not 4. That's two lines in `cmd_loot`, kept here since the same cases check it. ## 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 ## Change - `horizon-items/src/items.rs`: `expand` takes a `minecraft:loot_table` entry as a candidate by its weight; `choose` rolls it through `nested`, which guards against a table rolling inside itself (`NESTED_ROLLS`, with `loot_table` marking the outermost table). - `terrain_cmds.rs` (`cmd_loot`): the tracker counts one per stack. - Test `loot_table_entries_roll_their_table`: by id with a `set_count` on the entry, inline, and a table naming itself. - `command_exec_corpus.py` ("items and loot"): `/loot spawn` of `trial_chambers/reward` and `/loot give` of `reward_ominous`. ## Vanilla reference `NestedLootTable.createItemStack`, `LootTable.getRandomItemsRaw`, `LootContext.pushVisitedElement`; `LootCommand.dropInWorld` / `CommandResponseTracker.track(Element)` and `sendFeedback` (returns `totalValue`). `tools/test_command_exec_parity.py --only "items and loot"`: 76/76 commands match vanilla (74/76 with the new cases before the tracker change: same messages, results 4 and 5 where vanilla has 2 and 3). ## Other projects' code none ## Test Single player (`horizon-ctl`, temp home) and dedicated server (`horizon-server`), each on nightly c9d474d and on this branch: | Command | Before | After | | --- | --- | --- | | `loot spawn … loot minecraft:chests/trial_chambers/reward` | Dropped 0 items | Dropped 2 items (vanilla: 2) | | `loot spawn … loot minecraft:chests/trial_chambers/reward_ominous` | Dropped 0 items | Dropped 3 items | | `loot spawn … loot minecraft:chests/simple_dungeon` | Dropped 6 items | Dropped 6 items | ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base 1952b56c6` on DESKTOP-S9O4938, 7 min 2 s): | Check | Result | | --- | --- | | Scope | ✅ 3 files, +105 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 614 run, FAILED (errors=1, skipped=1) | | rustfmt | ✅ | | clippy | ✅ | | tests: horizon-client, horizon-items | ✅ 750 passed | | doc tests | ✅ | | content root tests | ✅ 23 passed | | mod API up to date | ✅ | | Parity | ➖ not run (--quick); "items and loot" run by hand: 76/76 | The Python failure is not in this change: `test_port_ledger` cannot import `tests.test_class_index` on this machine, as on main. 🤖 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 07:21:08 +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#7633
No description provided.