[PR #5573] [MERGED] Native mods: change the default components of any item #6362

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

📋 Pull Request Information

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

Base: main ← Head: feat/native-modify-default-components


📝 Commits (10+)

  • 619b5fe Native mods: change the default components of any item (API next)
  • 42cfa78 Native mods: document the default-components hook, share the catalog scan
  • 9148cb6 Native mods: the default-components docs name every reader and thread
  • 2a34298 Native mods: keep a changed stack size to vanilla's 1 to 99
  • 96b7a33 Native mods: keep the stack size in range for every reader
  • e6d8501 Merge remote-tracking branch 'origin/main' into feat/native-modify-default-components
  • c2e44bd Native mods: the content identity hashes the changed defaults
  • 42ffde8 Merge remote-tracking branch 'origin/main' into n5573
  • c4cbf36 Merge main into #5573 (item-default and loot hooks both kept)
  • db0ec1e content_identity: no needless borrow (clippy)

📊 Changes

14 files changed (+168 additions, -64 deletions)

View changed files

📝 crates/horizon-client-render/src/block_entity_render.rs (+20 -19)
📝 crates/horizon-client/src/banner.rs (+1 -3)
📝 crates/horizon-client/src/content_identity.rs (+5 -6)
📝 crates/horizon-client/src/game/commands.rs (+4 -14)
📝 crates/horizon-client/src/game/native_hooks.rs (+15 -8)
📝 crates/horizon-client/src/game/stations.rs (+1 -1)
📝 crates/horizon-client/src/item_render.rs (+4 -2)
📝 crates/horizon-items/src/enchant.rs (+1 -3)
📝 crates/horizon-items/src/items.rs (+1 -2)
➕ crates/horizon-world/src/item_defaults.rs (+78 -0)
📝 crates/horizon-world/src/lib.rs (+1 -0)
📝 crates/horizon-world/src/loot.rs (+2 -3)
📝 docs/native-mods.md (+24 -3)
➕ tools/native-hook-fragments/modify_default_components.json (+11 -0)

📄 Description

Closes #5500 (part of #4953).

A native mod had no way to change the default components of an item it didn't add: a stack size, a food, a tool rule. NeoForge mods do this with ModifyDefaultComponentsEvent, and a large tech mod porting over needs it.

What changed

  • New hook point native_modify_default_components(item, components) in horizon-world's item_defaults.rs. It gets each item's default components in items.json's form. A mod inserts or replaces a key to set a component, or removes the key to take it away. The name follows the NeoForge naming rule in docs/native-hooks-neoforge.md. It's a free function, like the render hooks in horizon-client-render, because item defaults are read below Game, in horizon-world and horizon-items.
  • Every reader of items' defaults now goes through item_defaults::read, which applies the hook: the item table (Items::load), loot (LootData::load), enchanting, item models, banner dyes and patterns, pot sherds, and rarity in chat hover text. A change shows up everywhere, so there's no one table out of step with the rest. Two places still read items.json raw, on purpose: mod_content.rs reads item ids from the base root to build a content root, which read then reads with the hook, and horizon-port-pack is a porting tool that wants vanilla's defaults.
  • docs/native-mods.md gets an "Items' default components" section next to the render hook points: target path, both sides, loader threads, what a client without the mod sees. Known gap: creative search matches vanilla's exported tooltip text, so a changed item_name isn't searchable yet.
  • Client and server both read their defaults through the same hook, so stacks are saved and sent against the patched defaults just like vanilla's own. As with NeoForge, both sides need the mod.
  • read keeps minecraft:max_stack_size to vanilla's codec range of 1 to 99 after the hook, for every reader. Nothing decodes a mod's values, and a size of 0 made merchant.rs's clamp(1, 0) panic on the server thread. The durability tooltip uses saturating_sub, so a mod that lowers max_damage below a saved stack's damage can't underflow it.
  • Main's new content identity (content_identity.rs) hashes mod components' defaults so that peers who disagree get caught. It reads them through read now, so a native mod's change can't slip past that check.
  • API fragment tools/native-hook-fragments/modify_default_components.json (API next), and catalog_matches_hook_points now covers hooks in item_defaults.rs.

Live test

I gave the hook a temporary body, the way a HEAD mixin would: minecraft:stone gets max_stack_size 16, and minecraft:apple loses food and consumable. Then I built --profile fast and drove the game with horizon-ctl on the server thread (single player's default path), under Xvfb with scratch homes:

  • /give @s stone 64 filled four hotbar slots of 16 each. /give @s dirt 64 stayed one stack of 64.
  • In survival at food 0, holding right click on an apple ate nothing: still 3 apples, food 0. Bread as a control was eaten (food 0 → 5).
  • After quit and relaunch, the stone was still 4 × 16. Neither player .dat contains a max_stack_size component, so stacks are saved against the patched default and not as a per-stack override.

The temporary body is not in the PR.

Self-check

python3 tools/pr_ready.py --quick on the first commit (later commits are review fixes and a merge of main, tested by hand below). It was stopped at this machine's 2-hour limit during the tests step, so CI's tests are the record for those:

pr_ready: 11 files changed since origin/main; checks on local
  Public tree: pass (1 s)
  Python tests: pass (5 min 56 s)
  rustfmt: pass (31 s)
  clippy: pass (96 min 38 s)
  tests: horizon-client, horizon-client-render, horizon-items, horizon-world... (stopped)

Run by hand on the head: catalog_matches_hook_points, content_identity tests, item_defaults::tests::stack_sizes_stay_in_vanilla_range, horizon-world loot tests, and all of horizon-items' lib tests pass.

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/5573 **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:** `feat/native-modify-default-components` --- ### 📝 Commits (10+) - [`619b5fe`](https://github.com/horizon-rust/horizon/commit/619b5fe70949d6adcd2b64ef75473a7027d61894) Native mods: change the default components of any item (API next) - [`42cfa78`](https://github.com/horizon-rust/horizon/commit/42cfa789b93017d2cdd7e475d511cb3609ae7203) Native mods: document the default-components hook, share the catalog scan - [`9148cb6`](https://github.com/horizon-rust/horizon/commit/9148cb676fb4cb9922962d6c6188f1830d9f85f3) Native mods: the default-components docs name every reader and thread - [`2a34298`](https://github.com/horizon-rust/horizon/commit/2a3429819e2256aecb233c0d6f60481b4dacaf71) Native mods: keep a changed stack size to vanilla's 1 to 99 - [`96b7a33`](https://github.com/horizon-rust/horizon/commit/96b7a3332f822b209d44e77d1acbe92e5dcd6d37) Native mods: keep the stack size in range for every reader - [`e6d8501`](https://github.com/horizon-rust/horizon/commit/e6d85014865940c3cae6dacbe5c834be09a437a5) Merge remote-tracking branch 'origin/main' into feat/native-modify-default-components - [`c2e44bd`](https://github.com/horizon-rust/horizon/commit/c2e44bda19dfe16fff3c6c139a89a3732403bcdc) Native mods: the content identity hashes the changed defaults - [`42ffde8`](https://github.com/horizon-rust/horizon/commit/42ffde8cd2ffa5e03beaad1e190b808930e728b3) Merge remote-tracking branch 'origin/main' into n5573 - [`c4cbf36`](https://github.com/horizon-rust/horizon/commit/c4cbf36967721d724cf7ed705b483e4be9e0ffbf) Merge main into #5573 (item-default and loot hooks both kept) - [`db0ec1e`](https://github.com/horizon-rust/horizon/commit/db0ec1edd4f26d5cb6532468eaa59e352da413e6) content_identity: no needless borrow (clippy) ### 📊 Changes **14 files changed** (+168 additions, -64 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/block_entity_render.rs` (+20 -19) 📝 `crates/horizon-client/src/banner.rs` (+1 -3) 📝 `crates/horizon-client/src/content_identity.rs` (+5 -6) 📝 `crates/horizon-client/src/game/commands.rs` (+4 -14) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+15 -8) 📝 `crates/horizon-client/src/game/stations.rs` (+1 -1) 📝 `crates/horizon-client/src/item_render.rs` (+4 -2) 📝 `crates/horizon-items/src/enchant.rs` (+1 -3) 📝 `crates/horizon-items/src/items.rs` (+1 -2) ➕ `crates/horizon-world/src/item_defaults.rs` (+78 -0) 📝 `crates/horizon-world/src/lib.rs` (+1 -0) 📝 `crates/horizon-world/src/loot.rs` (+2 -3) 📝 `docs/native-mods.md` (+24 -3) ➕ `tools/native-hook-fragments/modify_default_components.json` (+11 -0) </details> ### 📄 Description Closes #5500 (part of #4953). A native mod had no way to change the default components of an item it didn't add: a stack size, a food, a tool rule. NeoForge mods do this with `ModifyDefaultComponentsEvent`, and a large tech mod porting over needs it. ## What changed - New hook point `native_modify_default_components(item, components)` in `horizon-world`'s `item_defaults.rs`. It gets each item's default components in `items.json`'s form. A mod inserts or replaces a key to set a component, or removes the key to take it away. The name follows the NeoForge naming rule in `docs/native-hooks-neoforge.md`. It's a free function, like the render hooks in `horizon-client-render`, because item defaults are read below `Game`, in `horizon-world` and `horizon-items`. - Every reader of items' defaults now goes through `item_defaults::read`, which applies the hook: the item table (`Items::load`), loot (`LootData::load`), enchanting, item models, banner dyes and patterns, pot sherds, and rarity in chat hover text. A change shows up everywhere, so there's no one table out of step with the rest. Two places still read `items.json` raw, on purpose: `mod_content.rs` reads item ids from the base root to build a content root, which `read` then reads with the hook, and `horizon-port-pack` is a porting tool that wants vanilla's defaults. - `docs/native-mods.md` gets an "Items' default components" section next to the render hook points: target path, both sides, loader threads, what a client without the mod sees. Known gap: creative search matches vanilla's exported tooltip text, so a changed `item_name` isn't searchable yet. - Client and server both read their defaults through the same hook, so stacks are saved and sent against the patched defaults just like vanilla's own. As with NeoForge, both sides need the mod. - `read` keeps `minecraft:max_stack_size` to vanilla's codec range of 1 to 99 after the hook, for every reader. Nothing decodes a mod's values, and a size of 0 made `merchant.rs`'s `clamp(1, 0)` panic on the server thread. The durability tooltip uses `saturating_sub`, so a mod that lowers `max_damage` below a saved stack's damage can't underflow it. - Main's new content identity (`content_identity.rs`) hashes mod components' defaults so that peers who disagree get caught. It reads them through `read` now, so a native mod's change can't slip past that check. - API fragment `tools/native-hook-fragments/modify_default_components.json` (API next), and `catalog_matches_hook_points` now covers hooks in `item_defaults.rs`. ## Live test I gave the hook a temporary body, the way a HEAD mixin would: `minecraft:stone` gets `max_stack_size` 16, and `minecraft:apple` loses `food` and `consumable`. Then I built `--profile fast` and drove the game with `horizon-ctl` on the server thread (single player's default path), under Xvfb with scratch homes: - `/give @s stone 64` filled four hotbar slots of 16 each. `/give @s dirt 64` stayed one stack of 64. - In survival at food 0, holding right click on an apple ate nothing: still 3 apples, food 0. Bread as a control was eaten (food 0 → 5). - After quit and relaunch, the stone was still 4 × 16. Neither player `.dat` contains a `max_stack_size` component, so stacks are saved against the patched default and not as a per-stack override. The temporary body is not in the PR. ## Self-check `python3 tools/pr_ready.py --quick` on the first commit (later commits are review fixes and a merge of main, tested by hand below). It was stopped at this machine's 2-hour limit during the tests step, so CI's tests are the record for those: ``` pr_ready: 11 files changed since origin/main; checks on local Public tree: pass (1 s) Python tests: pass (5 min 56 s) rustfmt: pass (31 s) clippy: pass (96 min 38 s) tests: horizon-client, horizon-client-render, horizon-items, horizon-world... (stopped) ``` Run by hand on the head: `catalog_matches_hook_points`, `content_identity` tests, `item_defaults::tests::stack_sizes_stay_in_vanilla_range`, `horizon-world` loot tests, and all of `horizon-items`' lib tests pass. > [!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:14 +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#6362
No description provided.