[PR #6512] [MERGED] Run a mod's loot function for a block's drops #6925

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

📋 Pull Request Information

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

Base: main ← Head: fix/mm-loot


📝 Commits (1)

  • 25f3bbd Run a mod's loot function on the items engine's drops

📊 Changes

2 files changed (+271 additions, -26 deletions)

View changed files

📝 crates/horizon-items/src/items.rs (+262 -21)
📝 docs/native-mods.md (+9 -5)

📄 Description

A mod's loot function never ran for the tables the items engine rolls. Block drops, entity drops, loot_table and interact_loot answered native_loot_condition, but modifiers had no arm for a function kind of a mod's own, so a block's loot table could not carry a mod function — for example one that copies a machine's contents into the dropped item. The hook and its LootStack existed only in the main loot engine (crates/horizon-world/src/loot.rs); the items engine has its own stack (crates/horizon-items' ItemStack), and the docs said the function hook there "follows when the stack types converge".

What changed

  • The items engine's modifiers now reaches native_loot_function for a type outside minecraft:, as the main engine does.
  • The engine's stack crosses to the loot engine's form (loot_of) and back (apply_loot): item, count, damage, enchantments (a book's stored ones), potion, ominous bottle amplifier, stew effects, names and the components the engine keeps as saved (their JSON, as set_components writes them). Only what the hook changed is written back, so a field it leaves alone keeps the engine's own form.
  • The condition arm's context construction moved to LootContext::native_loot_context, used by both arms, so a function sees exactly what a condition sees there: the block and the tool, luck 0, no entity, damage, player or biome, and one next_long from the roll.
  • docs/native-mods.md no longer says the function hook "follows when the stack types converge" in that engine.

Scope limits

  • A function that asks for a map's structure search (map/exploration) changes nothing in this engine: it has no level to search.
  • Components the engine models as typed fields outside StackData.other (a container's contents, charged projectiles, fireworks, banner patterns, the rest of potion_contents) are not carried into the loot stack; a mod reading them sees only the saved components, and a component it sets still arrives with the drop.

Proven

On the build VM:

python3 ~/pushrun.py ~/horizon-worktrees/mm-loot --name mm-loot -- 'cargo test -q -p horizon-items --lib a_mod_function'
running 3 tests
test result: ok. 3 passed; 0 failed

python3 ~/pushrun.py ~/horizon-worktrees/mm-loot --name mm-loot -- 'cargo test -q -p horizon-items --lib'
running 54 tests
test result: ok. 54 passed; 0 failed

python3 ~/pushrun.py ~/horizon-worktrees/mm-loot --name mm-loot -- 'cargo clippy -q -p horizon-items --lib -- -D warnings'
clippy_exit=0

rustfmt --edition 2024 --check crates/horizon-items/src/items.rs is clean.

The three tests are: a function's item, count and component come back to the engine's stack; a function that changes nothing leaves the stack identical (its enchantment and custom name included); and a pool with a mod function draws exactly the hook's one next_long where a vanilla pool draws none, which is what shows the engine reaches the hook rather than skipping it.

Not proven

  • The hook with a real bundle in the game: it needs a native mod built, a mod block's table broken and the game run. The hook point itself is an empty function that horizon-mixins patches at build time, so a unit test can only reach it through the same conversion these tests exercise.
  • The typed components listed above, and the map/structure-search field.
  • The other three paths the same engine rolls (entity drops, loot_table, interact_loot): they share LootContext::evaluate, so they take the same arm, but only block drops were exercised.

Vanilla reference

None: the function and condition kinds are Horizon's own native-mod API (docs/native-mods.md, API 133). This makes the items engine call the hook the main loot engine already calls (crates/horizon-world/src/loot.rs, LootContext::modify's mod-kind arm), in the shape that engine documents.

Related: #6197 names the same gap for block and entity drops (its other half, the block entity in the context, landed in #6200), so this covers that part too. The tool-in-the-context note left on that issue is untouched.

Fixes #6199.


🔄 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/6512 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/mm-loot` --- ### 📝 Commits (1) - [`25f3bbd`](https://github.com/horizon-rust/horizon/commit/25f3bbd2cebb3fafe6bf0237ff2482bfa7de00d7) Run a mod's loot function on the items engine's drops ### 📊 Changes **2 files changed** (+271 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-items/src/items.rs` (+262 -21) 📝 `docs/native-mods.md` (+9 -5) </details> ### 📄 Description A mod's loot function never ran for the tables the items engine rolls. Block drops, entity drops, `loot_table` and `interact_loot` answered `native_loot_condition`, but `modifiers` had no arm for a function kind of a mod's own, so a block's loot table could not carry a mod function — for example one that copies a machine's contents into the dropped item. The hook and its `LootStack` existed only in the main loot engine (`crates/horizon-world/src/loot.rs`); the items engine has its own stack (`crates/horizon-items`' `ItemStack`), and the docs said the function hook there "follows when the stack types converge". ## What changed - The items engine's `modifiers` now reaches `native_loot_function` for a `type` outside `minecraft:`, as the main engine does. - The engine's stack crosses to the loot engine's form (`loot_of`) and back (`apply_loot`): item, count, damage, enchantments (a book's stored ones), potion, ominous bottle amplifier, stew effects, names and the components the engine keeps as saved (their JSON, as `set_components` writes them). Only what the hook changed is written back, so a field it leaves alone keeps the engine's own form. - The condition arm's context construction moved to `LootContext::native_loot_context`, used by both arms, so a function sees exactly what a condition sees there: the block and the tool, `luck` 0, no entity, damage, player or biome, and one `next_long` from the roll. - `docs/native-mods.md` no longer says the function hook "follows when the stack types converge" in that engine. ## Scope limits - A function that asks for a map's structure search (`map`/`exploration`) changes nothing in this engine: it has no level to search. - Components the engine models as typed fields outside `StackData.other` (a container's contents, charged projectiles, fireworks, banner patterns, the rest of `potion_contents`) are not carried into the loot stack; a mod reading them sees only the saved components, and a component it sets still arrives with the drop. ## Proven On the build VM: ``` python3 ~/pushrun.py ~/horizon-worktrees/mm-loot --name mm-loot -- 'cargo test -q -p horizon-items --lib a_mod_function' running 3 tests test result: ok. 3 passed; 0 failed python3 ~/pushrun.py ~/horizon-worktrees/mm-loot --name mm-loot -- 'cargo test -q -p horizon-items --lib' running 54 tests test result: ok. 54 passed; 0 failed python3 ~/pushrun.py ~/horizon-worktrees/mm-loot --name mm-loot -- 'cargo clippy -q -p horizon-items --lib -- -D warnings' clippy_exit=0 ``` `rustfmt --edition 2024 --check crates/horizon-items/src/items.rs` is clean. The three tests are: a function's item, count and component come back to the engine's stack; a function that changes nothing leaves the stack identical (its enchantment and custom name included); and a pool with a mod function draws exactly the hook's one `next_long` where a vanilla pool draws none, which is what shows the engine reaches the hook rather than skipping it. ## Not proven - The hook with a real bundle in the game: it needs a native mod built, a mod block's table broken and the game run. The hook point itself is an empty function that horizon-mixins patches at build time, so a unit test can only reach it through the same conversion these tests exercise. - The typed components listed above, and the map/structure-search field. - The other three paths the same engine rolls (entity drops, `loot_table`, `interact_loot`): they share `LootContext::evaluate`, so they take the same arm, but only block drops were exercised. ## Vanilla reference None: the function and condition kinds are Horizon's own native-mod API (docs/native-mods.md, API 133). This makes the items engine call the hook the main loot engine already calls (`crates/horizon-world/src/loot.rs`, `LootContext::modify`'s mod-kind arm), in the shape that engine documents. Related: #6197 names the same gap for block and entity drops (its other half, the block entity in the context, landed in #6200), so this covers that part too. The tool-in-the-context note left on that issue is untouched. Fixes #6199. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:29:19 +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#6925
No description provided.