[PR #5561] [MERGED] Native mods: change vanilla loot tables and drops #6353

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5561
Author: @some-du6e
Created: 10/31/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: mods/loot-table-hooks


📝 Commits (10+)

  • f749bbe Native mods: change vanilla loot tables and drops
  • 603fda2 Native loot hooks: review fixes
  • 7f9f86a Native loot hooks: round 2 fixes
  • 0c987c9 Native loot hooks: round 3 fixes
  • 8226fb0 Native loot hooks: a mob's drops name its position as the origin
  • 5bc2501 Native loot hooks: clippy's auto-deref
  • 33efc55 Native loot hooks: keep a replaced table's random_sequence; test the loot hook stays hookable
  • 8d3e175 Native loot drops: the killing player only while the hurt memory lasts
  • 998049b Merge branch 'pr/F5561new' into fix5561
  • 0ed5f55 Native loot hooks: name what the drops hook doesn't hear; check the loot hook's attributes

📊 Changes

10 files changed (+323 additions, -52 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+5 -2)
📝 crates/horizon-client/src/game/creatures.rs (+64 -17)
📝 crates/horizon-client/src/game/explosion.rs (+2 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+106 -0)
📝 crates/horizon-client/src/mobs/drops.rs (+11 -6)
📝 crates/horizon-items/src/items.rs (+68 -16)
📝 crates/horizon-world/src/loot.rs (+35 -7)
📝 docs/api/stability.md (+1 -1)
📝 docs/native-mods.md (+22 -2)
➕ tools/native-hook-fragments/loot_tables.json (+9 -0)

📄 Description

What and why

Fixes #5522 (part of #4953). A native mod couldn't add to or change a loot table it didn't make: a dungeon chest's loot, a block's drops, a mob's drops. NeoForge has LootTableLoadEvent and global loot modifiers for this, and Fabric has LootTableEvents.MODIFY and MODIFY_DROPS. This PR adds the same two points for native mods. #5451 covers a mod's own loot functions and conditions.

  • horizon_world::loot::native_loot_table_load(id, &mut Value): called once per loot table, in id order, as shared_tables loads it, after the data packs' files. A mod pushes pools or entries onto the JSON, or changes it. Items (block drops) and LootData (chests, mob drops, fishing…) share that one map, so every roll sees the change. It's a free function in a lib crate, like the renderer's native_render hooks, and the catalog test now reads loot.rs too. It runs outside the cache's lock.
  • Game::native_loot_drops(&NativeLootDrops, &mut Vec<ItemStack>): the items about to drop, which a mod can add to, change or empty. Stacks it empties don't spawn. It is called for blocks broken by a player (block_loot_at), by an explosion and by a mob, and for mob deaths. The context gives the table that rolled, the dimension, the origin, the block or mob, the killing or breaking player, the tool and an explosion's radius.
  • Items::block_loot_table gives a block's table id with the wall-variant fallback. block_loot_sequence and block_drops_raw now use it instead of each building the id themselves. drops::death_loot_table is the one place a mob's death table is chosen.
  • Fragment: tools/native-hook-fragments/loot_tables.json, plus a "Loot tables" section in docs/native-mods.md.

Not covered yet: blocks that break inside the level's own update (leaf decay, a torch losing its wall, pistons, /setblock … destroy). That path runs in GameLevel and can't reach Game's hooks. It could get its own hook later.

Without a mod nothing changes: death drops still spawn in the same order (item drops, then an enderman's carried block, then orbs), and no random draws move.

Kind

  • feature: something new for players (listed under New in the release notes)

Vanilla reference

NeoForge LootTableLoadEvent / IGlobalLootModifier, Fabric LootTableEvents.MODIFY / MODIFY_DROPS. Vanilla: LivingEntity.dropAllDeathLoot, Block.getDrops, Blocks.wallVariant. Existing harnesses (entity_death_loot and others) cover the drop paths.

Other projects' code

none

Self-check

Tests and type checks run in CI only, not locally (the user asked for that). New unit tests: items::tests::wall_blocks_use_the_standing_blocks_table and loot_table_load_stays_hookable (the hook in loot.rs keeps no cfg or macro). catalog_matches_hook_points now reads loot.rs too. Reviewed in rounds of fresh subagent reviewers. Their fixes: empty stacks don't drop, the hook runs outside the cache lock, the mob death table id, the killer when a guest has left or on a server, the mob's position as the origin, docs on keeping a replaced table's random_sequence and on what the drops hook doesn't hear, and drop_death_loot names every non-item drop it skips, so a new Drop kind won't vanish silently. Ludovic's commit names the killing player only while the mob remembers the hit (100 ticks), as vanilla's LAST_DAMAGE_PLAYER.

Note

Filed by Opus 5.5 using 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/5561 **Author:** [@some-du6e](https://github.com/some-du6e) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `mods/loot-table-hooks` --- ### 📝 Commits (10+) - [`f749bbe`](https://github.com/horizon-rust/horizon/commit/f749bbeef1f6299a7b1159d09190402886bfb11d) Native mods: change vanilla loot tables and drops - [`603fda2`](https://github.com/horizon-rust/horizon/commit/603fda280ec752040e398e45ab6f3dad157e4957) Native loot hooks: review fixes - [`7f9f86a`](https://github.com/horizon-rust/horizon/commit/7f9f86a7abaf79fb06e2f5d9f52e5a7597c1d03e) Native loot hooks: round 2 fixes - [`0c987c9`](https://github.com/horizon-rust/horizon/commit/0c987c9f636f7b5b1760d975bc13158d6c65c57c) Native loot hooks: round 3 fixes - [`8226fb0`](https://github.com/horizon-rust/horizon/commit/8226fb0b51bc76ed0fb81b2f230b891625e2bf06) Native loot hooks: a mob's drops name its position as the origin - [`5bc2501`](https://github.com/horizon-rust/horizon/commit/5bc2501d7fc8effb18ee452db1d3b3985a792499) Native loot hooks: clippy's auto-deref - [`33efc55`](https://github.com/horizon-rust/horizon/commit/33efc55c5b6e319ac12f083e77b46a04421f491c) Native loot hooks: keep a replaced table's random_sequence; test the loot hook stays hookable - [`8d3e175`](https://github.com/horizon-rust/horizon/commit/8d3e175d49fea0e1b8602dee2d5b34277f40a980) Native loot drops: the killing player only while the hurt memory lasts - [`998049b`](https://github.com/horizon-rust/horizon/commit/998049b7ddf263a72747fd86f4fc48d4833213c2) Merge branch 'pr/F5561new' into fix5561 - [`0ed5f55`](https://github.com/horizon-rust/horizon/commit/0ed5f554b3fd04235e9bb994327d34ec67c53a2e) Native loot hooks: name what the drops hook doesn't hear; check the loot hook's attributes ### 📊 Changes **10 files changed** (+323 additions, -52 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+5 -2) 📝 `crates/horizon-client/src/game/creatures.rs` (+64 -17) 📝 `crates/horizon-client/src/game/explosion.rs` (+2 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+106 -0) 📝 `crates/horizon-client/src/mobs/drops.rs` (+11 -6) 📝 `crates/horizon-items/src/items.rs` (+68 -16) 📝 `crates/horizon-world/src/loot.rs` (+35 -7) 📝 `docs/api/stability.md` (+1 -1) 📝 `docs/native-mods.md` (+22 -2) ➕ `tools/native-hook-fragments/loot_tables.json` (+9 -0) </details> ### 📄 Description ## What and why Fixes #5522 (part of #4953). A native mod couldn't add to or change a loot table it didn't make: a dungeon chest's loot, a block's drops, a mob's drops. NeoForge has `LootTableLoadEvent` and global loot modifiers for this, and Fabric has `LootTableEvents.MODIFY` and `MODIFY_DROPS`. This PR adds the same two points for native mods. #5451 covers a mod's own loot functions and conditions. - **`horizon_world::loot::native_loot_table_load(id, &mut Value)`**: called once per loot table, in id order, as `shared_tables` loads it, after the data packs' files. A mod pushes pools or entries onto the JSON, or changes it. `Items` (block drops) and `LootData` (chests, mob drops, fishing…) share that one map, so every roll sees the change. It's a free function in a lib crate, like the renderer's `native_render` hooks, and the catalog test now reads `loot.rs` too. It runs outside the cache's lock. - **`Game::native_loot_drops(&NativeLootDrops, &mut Vec<ItemStack>)`**: the items about to drop, which a mod can add to, change or empty. Stacks it empties don't spawn. It is called for blocks broken by a player (`block_loot_at`), by an explosion and by a mob, and for mob deaths. The context gives the table that rolled, the dimension, the origin, the block or mob, the killing or breaking player, the tool and an explosion's radius. - `Items::block_loot_table` gives a block's table id with the wall-variant fallback. `block_loot_sequence` and `block_drops_raw` now use it instead of each building the id themselves. `drops::death_loot_table` is the one place a mob's death table is chosen. - Fragment: `tools/native-hook-fragments/loot_tables.json`, plus a "Loot tables" section in `docs/native-mods.md`. Not covered yet: blocks that break inside the level's own update (leaf decay, a torch losing its wall, pistons, `/setblock … destroy`). That path runs in `GameLevel` and can't reach `Game`'s hooks. It could get its own hook later. Without a mod nothing changes: death drops still spawn in the same order (item drops, then an enderman's carried block, then orbs), and no random draws move. ## Kind - [x] feature: something new for players (listed under New in the release notes) ## Vanilla reference NeoForge `LootTableLoadEvent` / `IGlobalLootModifier`, Fabric `LootTableEvents.MODIFY` / `MODIFY_DROPS`. Vanilla: `LivingEntity.dropAllDeathLoot`, `Block.getDrops`, `Blocks.wallVariant`. Existing harnesses (`entity_death_loot` and others) cover the drop paths. ## Other projects' code none ## Self-check Tests and type checks run in CI only, not locally (the user asked for that). New unit tests: `items::tests::wall_blocks_use_the_standing_blocks_table` and `loot_table_load_stays_hookable` (the hook in `loot.rs` keeps no `cfg` or macro). `catalog_matches_hook_points` now reads `loot.rs` too. Reviewed in rounds of fresh subagent reviewers. Their fixes: empty stacks don't drop, the hook runs outside the cache lock, the mob death table id, the killer when a guest has left or on a server, the mob's position as the origin, docs on keeping a replaced table's `random_sequence` and on what the drops hook doesn't hear, and `drop_death_loot` names every non-item drop it skips, so a new `Drop` kind won't vanish silently. Ludovic's commit names the killing player only while the mob remembers the hit (100 ticks), as vanilla's `LAST_DAMAGE_PLAYER`. > [!NOTE] > Filed by Opus 5.5 using 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:19: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#6353
No description provided.