[PR #6142] [MERGED] Native mods: a loot table's function and condition of a mod's own kind #6675

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

📋 Pull Request Information

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

Base: main ← Head: hooks-loot


📝 Commits (2)

  • f7bff20 Native mods: a loot table's function and condition of a mod's own kind
  • 082ad98 Merge main into #6142 (the mod block entity test fix, #6143)

📊 Changes

5 files changed (+284 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game/native_hooks.rs (+21 -0)
📝 crates/horizon-items/src/items.rs (+47 -0)
📝 crates/horizon-world/src/loot.rs (+184 -0)
📝 docs/native-mods.md (+15 -0)
➕ tools/native-hook-fragments/loot_kinds.json (+17 -0)

📄 Description

🤖 Opened by Qwerner88880's AI agent (ZCode, GLM-5.3), not by Qwerner88880 personally.

What and why

Fixes #5451. Part of #4953 ("More content registration") and #3911 (Mods).

A loot table's function or condition that names a type in a namespace outside minecraft: — where the loot roll used to silently skip it (functions) or fail it (conditions) — now reaches two free functions in loot.rs, which mixin bundles hook as they do the game's own hook points:

  • native_loot_function(kind, data, ctx, stack) — changes the stack.
  • native_loot_condition(kind, data, ctx, holds) — says whether it holds.

The context (NativeLootContext) brings the entity, the damage, the player who killed it, the tool, the block, the luck, the biome and a seed from the roll's random, drawn only when a mod's kind is in the table (a table without one stays bit-for-bit the same). The tool and block are filled by the items engine (block drops, entity drops, loot_table, interact_loot); the entity, damage and player by the main loot engine; each is None in the other.

What works where: the main loot engine (loot.rs: mob deaths, chest LootTables, fishing) gets both hooks. The items engine (items.rs: block_drops, entity_drops, loot_table, interact_loot) answers the condition hook with the tool and block in the context; its function hook follows when the ItemStack/LootStack types converge.

A bare type name is minecraft's own, not a mod's. An unclaimed function leaves the stack, an unclaimed condition fails, as unknown kinds do.

Kind

  • feature: something new for players (listed under New in the release notes)
  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • tooling
  • docs

Vanilla reference

Vanilla 26.3 dispatches loot kinds through Registries.LOOT_FUNCTION_TYPE and LOOT_CONDITION_TYPE (jar-checked: LootItemFunctions.TYPED_CODEC, LootItemConditionTypes.bootstrap), where a mod platform registers its own kind. The free functions are the game's stand-in for that registration. An unknown type in a vanilla codec rejects the whole table — stricter than Horizon's silent skip; the hooks keep Horizon's tolerance while giving mod kinds a real path.

Other projects' code

none

Tests

Unit: three tests in loot.rs — an unclaimed condition fails and an unclaimed function leaves the count; an unknown minecraft: function is skipped and minecraft:set_count still runs; a mod kind draws exactly one next_long and a vanilla table shifts the random by nothing, and the same seed gives the same result. One test in items.rs: a mod's kind nobody claims fails in this engine too.

Live, on this branch (HEAD f7bff2018, dedicated server, two horizon-ctl --offscreen clients): RESULT: 21 checks, 0 failures. Hook traces: fn=3 cond=6, exact counts per scenario.

Scenario Traces Item on ground
minecraft:inverted(lootmod:never) chest cond 1, fn 0 gold_ingot
lootmod:always chest (items engine) cond 1, fn 0 diamond
zombie /kill (loot engine) cond 1, fn 1 iron_ingot count: 2
zombie killed by player attack cond 1, fn 1, player=Some iron_ingot count: 2
dirt + iron_pickaxe (items engine) cond 1, fn 0, tool + block coal
lootmod:unclaimed condition cond 1, holds=false none
lootmod:unclaimed function on skeleton fn 1, count=1 bone count: 1
items-engine function not called fn 0 —
vanilla table (no mod kinds) fn 0, cond 0 3 vanilla items
no errors on both clients — —

Not run: single player (the single-player server thread is the same Game the dedicated server runs, by code); two bundles on one kind (a kind belongs to one mod's namespace); parity — 374 of 375 harness are affected, which is CI's job.

Self-check

pr_ready (full run on this commit, on a temp copy of fresh main c86e86145)

Check Result
Scope ✅ 5 files, +284 −0
Python tests ✅ 585 passed
rustfmt, clippy ✅
tests: horizon-client, horizon-items, horizon-world ✅ 2205 passed
content root tests ✅ 20 passed
Parity ➖ not run here (374/375 harness affected — CI)

🤖 Generated with Claude Code (https://claude.com/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/6142 **Author:** [@Qwerner88880](https://github.com/Qwerner88880) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `hooks-loot` --- ### 📝 Commits (2) - [`f7bff20`](https://github.com/horizon-rust/horizon/commit/f7bff20187529eca39a813ba221a23ce9a5f9aab) Native mods: a loot table's function and condition of a mod's own kind - [`082ad98`](https://github.com/horizon-rust/horizon/commit/082ad987a6c7b1a68aac39ae65b0a6b2936f2706) Merge main into #6142 (the mod block entity test fix, #6143) ### 📊 Changes **5 files changed** (+284 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/native_hooks.rs` (+21 -0) 📝 `crates/horizon-items/src/items.rs` (+47 -0) 📝 `crates/horizon-world/src/loot.rs` (+184 -0) 📝 `docs/native-mods.md` (+15 -0) ➕ `tools/native-hook-fragments/loot_kinds.json` (+17 -0) </details> ### 📄 Description > 🤖 Opened by Qwerner88880's AI agent (ZCode, GLM-5.3), not by Qwerner88880 personally. ## What and why Fixes #5451. Part of #4953 ("More content registration") and #3911 (Mods). A loot table's function or condition that names a `type` in a namespace outside `minecraft:` — where the loot roll used to silently skip it (functions) or fail it (conditions) — now reaches two free functions in `loot.rs`, which mixin bundles hook as they do the game's own hook points: - **`native_loot_function(kind, data, ctx, stack)`** — changes the stack. - **`native_loot_condition(kind, data, ctx, holds)`** — says whether it holds. The context (`NativeLootContext`) brings the entity, the damage, the player who killed it, the tool, the block, the luck, the biome and a seed from the roll's random, drawn only when a mod's kind is in the table (a table without one stays bit-for-bit the same). The tool and block are filled by the items engine (block drops, entity drops, `loot_table`, `interact_loot`); the entity, damage and player by the main loot engine; each is `None` in the other. **What works where:** the main loot engine (`loot.rs`: mob deaths, chest LootTables, fishing) gets both hooks. The items engine (`items.rs`: `block_drops`, `entity_drops`, `loot_table`, `interact_loot`) answers the condition hook with the tool and block in the context; its function hook follows when the `ItemStack`/`LootStack` types converge. A bare type name is minecraft's own, not a mod's. An unclaimed function leaves the stack, an unclaimed condition fails, as unknown kinds do. ## Kind - [x] feature: something new for players (listed under New in the release notes) - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] tooling - [ ] docs ## Vanilla reference Vanilla 26.3 dispatches loot kinds through `Registries.LOOT_FUNCTION_TYPE` and `LOOT_CONDITION_TYPE` (jar-checked: `LootItemFunctions.TYPED_CODEC`, `LootItemConditionTypes.bootstrap`), where a mod platform registers its own kind. The free functions are the game's stand-in for that registration. An unknown `type` in a vanilla codec rejects the whole table — stricter than Horizon's silent skip; the hooks keep Horizon's tolerance while giving mod kinds a real path. ## Other projects' code none ## Tests **Unit:** three tests in `loot.rs` — an unclaimed condition fails and an unclaimed function leaves the count; an unknown `minecraft:` function is skipped and `minecraft:set_count` still runs; a mod kind draws exactly one `next_long` and a vanilla table shifts the random by nothing, and the same seed gives the same result. One test in `items.rs`: a mod's kind nobody claims fails in this engine too. **Live, on this branch (HEAD `f7bff2018`, dedicated server, two `horizon-ctl --offscreen` clients):** RESULT: 21 checks, 0 failures. Hook traces: `fn=3 cond=6`, exact counts per scenario. | Scenario | Traces | Item on ground | |---|---|---| | `minecraft:inverted(lootmod:never)` chest | cond 1, fn 0 | gold_ingot | | `lootmod:always` chest (items engine) | cond 1, fn 0 | diamond | | zombie `/kill` (loot engine) | cond 1, fn 1 | iron_ingot **count: 2** | | zombie killed by player attack | cond 1, fn 1, **player=Some** | iron_ingot **count: 2** | | dirt + iron_pickaxe (items engine) | cond 1, fn 0, **tool + block** | coal | | `lootmod:unclaimed` condition | cond 1, holds=false | none | | `lootmod:unclaimed` function on skeleton | fn 1, count=1 | bone **count: 1** | | items-engine function not called | fn 0 | — | | vanilla table (no mod kinds) | fn 0, cond 0 | 3 vanilla items | | no errors on both clients | — | — | **Not run:** single player (the single-player server thread is the same `Game` the dedicated server runs, by code); two bundles on one kind (a kind belongs to one mod's namespace); parity — 374 of 375 harness are affected, which is CI's job. ## Self-check **pr_ready** (full run on this commit, on a temp copy of fresh main c86e86145) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +284 −0 | | Python tests | ✅ 585 passed | | rustfmt, clippy | ✅ | | tests: horizon-client, horizon-items, horizon-world | ✅ 2205 passed | | content root tests | ✅ 20 passed | | Parity | ➖ not run here (374/375 harness affected — CI) | 🤖 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 06:24:46 +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#6675
No description provided.