[PR #5426] [MERGED] Allow native mods to register item component types #6282

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

📋 Pull Request Information

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

Base: main ← Head: native-component-api


📝 Commits (10+)

  • daaeda8 Expose native item component types
  • 1ca6da7 Update component validation tests
  • 0ff27ff Keep component helpers outside mixin hook source
  • 3ad5a23 Retain cached wire patches like existing item edits
  • 1761d30 Reuse identifier validation for native components
  • fff998e Merge main into #5426
  • 2d5ca3a Native components: install nothing, and skip registries.json, when no mod registers a type
  • d72a661 Validate content component identifiers consistently
  • 708cee4 Isolate invalid content component patches
  • 6d50c26 Make component acceptance and tests deterministic

📊 Changes

14 files changed (+525 additions, -50 deletions)

View changed files

📝 crates/horizon-client/src/content_identity.rs (+16 -0)
📝 crates/horizon-client/src/game.rs (+2 -0)
📝 crates/horizon-client/src/game/mods.rs (+45 -16)
➕ crates/horizon-client/src/game/native_components.rs (+93 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+4 -0)
📝 crates/horizon-client/src/mod_content.rs (+78 -16)
📝 crates/horizon-client/src/mod_content_tests.rs (+2 -2)
➕ crates/horizon-client/tests/custom_component_api.rs (+150 -0)
📝 crates/horizon-items/src/items.rs (+14 -0)
📝 crates/horizon-mods/src/content.rs (+41 -16)
📝 crates/horizon-protocol/src/item/custom.rs (+55 -0)
📝 crates/horizon-world/src/identifier.rs (+8 -0)
📝 docs/mods.md (+7 -0)
➕ tools/native-hook-fragments/component_types.json (+10 -0)

📄 Description

🤖 Opened by Aria's agent swarm, Dyna, not by Aria.

Closes #4806.

Summary

Native mods can register namespaced item component types through Game::native_component_types before content loads. They can read, set and remove opaque NBT values with native_component, native_set_component and native_remove_component. Content item defaults can use registered types. Invalid names, duplicate names, the minecraft namespace and values beyond the network reader limits are rejected.

The API reuses the item stack patch, default overlay and content identity challenge. The identity includes custom defaults because patches omit defaults. The NeoForge counterpart registers DataComponentType in Registries.DATA_COMPONENT_TYPE through RegisterEvent; registration runs on both sides and is not cancelable.

The existing lan/containers.rs::hashed_matches remains unchanged: it checks item ID and count, not component hashes. Like existing item mutations, component edits can invalidate cached wire patches and reconstruct them without unmodeled fields. This limitation already affects other item mutations.

The review fixes add per-mod validation and tests. The maintainer's commit 139c4be315206e6db7ee4db2262dc6cda93cf2d2 removed the horizon-world dependency from horizon-mods and merged main.

In-game proof

On arch, the recommended end-to-end test route https://github.com/arismoko/horizon-machine-sample was used on a throwaway branch at exact Horizon head 5b4f72ada54ee3a38fab322a2d2e36655ce29a1a. Both integrated and dedicated servers preserved charge 42, a removed content default and canonical equality through save and reload. Both returned the component patch to the client. The dedicated server used a packaged .hmod. The build and both game checks passed before the maintainer's commit. An unmodded server-thread world also started, ran 100 ticks and quit cleanly at 5b4f72ada. The screenshot from the earlier fffbe279 run shows the client holding the sample item on the dedicated server. The logs below show its component value and removal, which the image alone cannot show.

server: COMPONENT_PROOF initialized canonical=true
server: COMPONENT_PROOF observed charge=42 mode=removed
client: {"components":"{\"!sample:mode\":{},\"sample:charge\":42}","count":1,"item":"machine_sample:machine"}
INTEGRATED_RELOAD_CLIENT_PASS
DEDICATED_RELOAD_CLIENT_PASS

Client holds the sample machine item on the dedicated server

A vanilla-brand protocol bot was rejected with a content registry mismatch in the earlier transport proof at 2238e66444027163094bc4feb1adbeed8675b7eb; it was not a Mojang client. A custom-enabled client joined an older unchallenged Horizon server with custom components disabled for that connection.

Readiness

The readiness block below ran at 5b4f72ada54ee3a38fab322a2d2e36655ce29a1a, before the maintainer's 139c4be31 commit. The checks used RUST_TEST_THREADS=1 after parallel graphics tests stalled on arch.

pr_ready (tools/pr_ready.py --quick --base 21bddafb20bd92f6bae449db36230b5d5d90dbbb on arch, against 21bddafb20 at 21bddafb2, 2 min 55 s)

Check Result
Scope ⚠️ 17 files, +516 −50; mixes game, launcher
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ✅ 510 passed (42 s)
rustfmt ✅ (9 s)
clippy ✅
tests: workspace ✅ 3837 passed (1 min 48 s)
doc tests ✅ 0 passed (5 s)
content root tests ✅ 14 passed
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (1 s)
launcher tests ✅ 341 passed (9 s)
Parity ➖ 365 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 353 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Dyna.


🔄 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/5426 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `native-component-api` --- ### 📝 Commits (10+) - [`daaeda8`](https://github.com/horizon-rust/horizon/commit/daaeda8c8f2c6bfee865f04f0c8ac1613cf64fa3) Expose native item component types - [`1ca6da7`](https://github.com/horizon-rust/horizon/commit/1ca6da70abbe581ce7529e6fa43c649da96739ed) Update component validation tests - [`0ff27ff`](https://github.com/horizon-rust/horizon/commit/0ff27ffb83783d07d25901e60279b2cc139758dc) Keep component helpers outside mixin hook source - [`3ad5a23`](https://github.com/horizon-rust/horizon/commit/3ad5a237cdcd56c4e52af30e6c57aaa9067f620f) Retain cached wire patches like existing item edits - [`1761d30`](https://github.com/horizon-rust/horizon/commit/1761d307fbde409205629e6bdd133992c0e5e619) Reuse identifier validation for native components - [`fff998e`](https://github.com/horizon-rust/horizon/commit/fff998e85f802bb41f94bd292f9f62fc04a1cd6c) Merge main into #5426 - [`2d5ca3a`](https://github.com/horizon-rust/horizon/commit/2d5ca3a1a6a2b5098ba77b1112bd255e61304b78) Native components: install nothing, and skip registries.json, when no mod registers a type - [`d72a661`](https://github.com/horizon-rust/horizon/commit/d72a6615e9250d54388ce745cba2397cb6a67a67) Validate content component identifiers consistently - [`708cee4`](https://github.com/horizon-rust/horizon/commit/708cee40542275166ce32e1f618575ae582c6512) Isolate invalid content component patches - [`6d50c26`](https://github.com/horizon-rust/horizon/commit/6d50c264597db1c28fe8713ba36bf2fce930d8b5) Make component acceptance and tests deterministic ### 📊 Changes **14 files changed** (+525 additions, -50 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/content_identity.rs` (+16 -0) 📝 `crates/horizon-client/src/game.rs` (+2 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+45 -16) ➕ `crates/horizon-client/src/game/native_components.rs` (+93 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+4 -0) 📝 `crates/horizon-client/src/mod_content.rs` (+78 -16) 📝 `crates/horizon-client/src/mod_content_tests.rs` (+2 -2) ➕ `crates/horizon-client/tests/custom_component_api.rs` (+150 -0) 📝 `crates/horizon-items/src/items.rs` (+14 -0) 📝 `crates/horizon-mods/src/content.rs` (+41 -16) 📝 `crates/horizon-protocol/src/item/custom.rs` (+55 -0) 📝 `crates/horizon-world/src/identifier.rs` (+8 -0) 📝 `docs/mods.md` (+7 -0) ➕ `tools/native-hook-fragments/component_types.json` (+10 -0) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Closes #4806. ## Summary Native mods can register namespaced item component types through `Game::native_component_types` before content loads. They can read, set and remove opaque NBT values with `native_component`, `native_set_component` and `native_remove_component`. Content item defaults can use registered types. Invalid names, duplicate names, the `minecraft` namespace and values beyond the network reader limits are rejected. The API reuses the item stack patch, default overlay and content identity challenge. The identity includes custom defaults because patches omit defaults. The NeoForge counterpart registers `DataComponentType` in `Registries.DATA_COMPONENT_TYPE` through `RegisterEvent`; registration runs on both sides and is not cancelable. The existing `lan/containers.rs::hashed_matches` remains unchanged: it checks item ID and count, not component hashes. Like existing item mutations, component edits can invalidate cached wire patches and reconstruct them without unmodeled fields. This limitation already affects other item mutations. The review fixes add per-mod validation and tests. The maintainer's commit `139c4be315206e6db7ee4db2262dc6cda93cf2d2` removed the `horizon-world` dependency from `horizon-mods` and merged main. ## In-game proof On arch, the recommended end-to-end test route https://github.com/arismoko/horizon-machine-sample was used on a throwaway branch at exact Horizon head `5b4f72ada54ee3a38fab322a2d2e36655ce29a1a`. Both integrated and dedicated servers preserved charge 42, a removed content default and canonical equality through save and reload. Both returned the component patch to the client. The dedicated server used a packaged `.hmod`. The build and both game checks passed before the maintainer's commit. An unmodded server-thread world also started, ran 100 ticks and quit cleanly at `5b4f72ada`. The screenshot from the earlier `fffbe279` run shows the client holding the sample item on the dedicated server. The logs below show its component value and removal, which the image alone cannot show. ```text server: COMPONENT_PROOF initialized canonical=true server: COMPONENT_PROOF observed charge=42 mode=removed client: {"components":"{\"!sample:mode\":{},\"sample:charge\":42}","count":1,"item":"machine_sample:machine"} INTEGRATED_RELOAD_CLIENT_PASS DEDICATED_RELOAD_CLIENT_PASS ``` ![Client holds the sample machine item on the dedicated server](https://raw.githubusercontent.com/arismoko/horizon/4299d030c0b0d243613bd998aba033cd38a18464/component-api-dedicated-fffbe279.png) A vanilla-brand protocol bot was rejected with a content registry mismatch in the earlier transport proof at `2238e66444027163094bc4feb1adbeed8675b7eb`; it was not a Mojang client. A custom-enabled client joined an older unchallenged Horizon server with custom components disabled for that connection. ## Readiness The readiness block below ran at `5b4f72ada54ee3a38fab322a2d2e36655ce29a1a`, before the maintainer's `139c4be31` commit. The checks used `RUST_TEST_THREADS=1` after parallel graphics tests stalled on arch. **pr_ready** (`tools/pr_ready.py --quick --base 21bddafb20bd92f6bae449db36230b5d5d90dbbb` on arch, against 21bddafb20bd92f6bae449db36230b5d5d90dbbb at 21bddafb2, 2 min 55 s) | Check | Result | | --- | --- | | Scope | ⚠️ 17 files, +516 −50; mixes game, launcher | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ✅ 510 passed (42 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ | | tests: workspace | ✅ 3837 passed (1 min 48 s) | | doc tests | ✅ 0 passed (5 s) | | content root tests | ✅ 14 passed | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (1 s) | | launcher tests | ✅ 341 passed (9 s) | | Parity | ➖ 365 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 353 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with Dyna. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:17:43 +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#6282
No description provided.