[PR #6332] [MERGED] Native mods: data maps, RegisterDataMapTypesEvent #6802

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

📋 Pull Request Information

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

Base: main ← Head: mods/data-maps


📝 Commits (1)

  • 168eb9f Native mods: data maps (RegisterDataMapTypesEvent), first step

📊 Changes

5 files changed (+459 additions, -3 deletions)

View changed files

📝 crates/horizon-client-render/src/datapack.rs (+13 -3)
📝 crates/horizon-client/src/game.rs (+13 -0)
➕ crates/horizon-client/src/game/native_data_maps.rs (+408 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+17 -0)
➕ tools/native-hook-fragments/data_map_types.json (+8 -0)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally.

What and why

Fixes #6312, the first step of data maps for #4953 ("Data maps and mod datapack registries (RegisterDataMapTypesEvent, DataPackRegistryEvent.NewRegistry)"). A native mod can attach data to registry entries that a data pack can change (fuel burn times per item, a block class), as NeoForge's data maps do. The issue lays out the steps: this is step 1 (types for items and blocks, files from packs and mods, merging, reading). Other registries and mergers, sync to clients, conditions, and mod datapack registries (its own issue) are the next steps.

API from a fragment (tools/native-hook-fragments/data_map_types.json):

  • native_data_map_types(types): the mod pushes NativeDataMapType { id, registry }: an id mod_id:name (not in minecraft) for minecraft:item or minecraft:block. Asked once per load of the server's data, a world's first open and every /reload, next to native_data_pack_files. A type with another registry, a bad id, or an id registered twice is left out with a warning.
  • Files: data/<mod_id>/data_maps/<registry path>/<name>.json in the world's data packs (DataStore now keeps the data_maps kind, as it keeps recipe or dialog), and files a mod pushes through native_data_pack_files under the key data_maps/<mod_id>:<registry path>/<name>. Contributed files sit below the packs', as for every kind.
  • Merging (native_data_maps.rs, per type, in pack order): replace: true clears what earlier files set; values maps entry ids and #tags to values (a tag gives every member the value, resolved against the loaded item or block tags), a value being the data itself or {"value": ..., "replace": false}; remove (ids, #tags, or {"key": ...}) applies after the file's own values; a newer value overrides an older one (NeoForge's default merger). A file that isn't JSON or has no values object is skipped alone.
  • native_data_map(registry, type, entry) reads an entry's value (the JSON as the file held it); native_data_map_entries(registry, type) lists every entry with one.

Server side only (the single player's server thread and a dedicated server, where the tables are built from packs or files); the deprecated in-frame path and clients of a server read none. Values are not synced to clients. Entry-level replace is accepted and ignored until types can have mergers.

Kind

  • feature: something new for players (mod authors)

Vanilla reference

Vanilla 26.3 has no data maps. The contract is NeoForge's DataMapType, DataMapFile, DataMapEntry and RegisterDataMapTypesEvent javadoc (file location, replace/values/remove, tag keys, the value wrapper, default merger; names and behaviour only). Horizon's loading follows how it already layers data pack files over the tables (overlay_files, PackOverlay).

Other projects' code

None.

Proof in the real game

Engine from this branch plus a throwaway probe (types testmod:fuel for items and testmod:hard for blocks, plus a bad id and an unsupported registry; two files pushed from native_data_pack_files: fuel {coal: {burn: 1600}, #minecraft:logs: 300, stick: 100}, hard {#minecraft:logs: 2}; eprintln!s in native_server_data_loaded; not in this PR). A world pack datapacks/pack with data/testmod/data_maps/item/fuel.json = {"values": {"minecraft:coal": {"burn": 2000}}, "remove": ["minecraft:stick"]}.

Server thread, world L, mods only, then with the pack, then after /reload (the role label in the probe is unreliable, ignore it):

--- mods only
TESTHOOK data loaded reload=false: coal=Some({"burn": 1600}) oak_log=Some(300) stick=Some(100) stone=None block oak_log=Some(2) bad=None biome=None
TESTHOOK entries fuel=50 wrong registry=0
--- with a pack
TESTHOOK data loaded reload=false: coal=Some({"burn": 2000}) oak_log=Some(300) stick=None stone=None block oak_log=Some(2) bad=None biome=None
TESTHOOK entries fuel=49 wrong registry=0
--- after /reload
TESTHOOK data loaded reload=true: coal=Some({"burn": 2000}) oak_log=Some(300) stick=None stone=None block oak_log=Some(2) bad=None biome=None
TESTHOOK entries fuel=49 wrong registry=0

Dedicated server (world/datapacks/pack, started without and then with the pack, then reload on the console): the same values, fuel=50 without the pack, fuel=49 with it and after reload. Not run: a client of a server (reads none, by design), the pack's data_maps file enabled by /datapack, tags from a pack that add to the item tags (the tag tables used are the ones the tables load, Items::item_tags).

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at dea6dea98, 2 min 6 s)

Check Result
Scope ✅ 5 files, +459 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 586 passed (33 s)
rustfmt ✅ (7 s)
clippy ✅ (30 s)
tests: horizon-client, horizon-client-render ✅ 2729 passed (53 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses

🤖 Generated with 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/6332 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/data-maps` --- ### 📝 Commits (1) - [`168eb9f`](https://github.com/horizon-rust/horizon/commit/168eb9ff048b378b39ebc13c55c76f4625dde0ff) Native mods: data maps (RegisterDataMapTypesEvent), first step ### 📊 Changes **5 files changed** (+459 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/datapack.rs` (+13 -3) 📝 `crates/horizon-client/src/game.rs` (+13 -0) ➕ `crates/horizon-client/src/game/native_data_maps.rs` (+408 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+17 -0) ➕ `tools/native-hook-fragments/data_map_types.json` (+8 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. ## What and why Fixes #6312, the first step of data maps for #4953 ("Data maps and mod datapack registries (`RegisterDataMapTypesEvent`, `DataPackRegistryEvent.NewRegistry`)"). A native mod can attach data to registry entries that a data pack can change (fuel burn times per item, a block class), as NeoForge's data maps do. The issue lays out the steps: this is step 1 (types for items and blocks, files from packs and mods, merging, reading). Other registries and mergers, sync to clients, conditions, and mod datapack registries (its own issue) are the next steps. API from a fragment (`tools/native-hook-fragments/data_map_types.json`): - `native_data_map_types(types)`: the mod pushes `NativeDataMapType { id, registry }`: an `id` `mod_id:name` (not in `minecraft`) for `minecraft:item` or `minecraft:block`. Asked once per load of the server's data, a world's first open and every `/reload`, next to `native_data_pack_files`. A type with another registry, a bad id, or an id registered twice is left out with a warning. - Files: `data/<mod_id>/data_maps/<registry path>/<name>.json` in the world's data packs (`DataStore` now keeps the `data_maps` kind, as it keeps `recipe` or `dialog`), and files a mod pushes through `native_data_pack_files` under the key `data_maps/<mod_id>:<registry path>/<name>`. Contributed files sit below the packs', as for every kind. - Merging (`native_data_maps.rs`, per type, in pack order): `replace: true` clears what earlier files set; `values` maps entry ids and `#tags` to values (a tag gives every member the value, resolved against the loaded item or block tags), a value being the data itself or `{"value": ..., "replace": false}`; `remove` (ids, `#tags`, or `{"key": ...}`) applies after the file's own values; a newer value overrides an older one (NeoForge's default merger). A file that isn't JSON or has no `values` object is skipped alone. - `native_data_map(registry, type, entry)` reads an entry's value (the JSON as the file held it); `native_data_map_entries(registry, type)` lists every entry with one. Server side only (the single player's server thread and a dedicated server, where the tables are built from packs or files); the deprecated in-frame path and clients of a server read none. Values are not synced to clients. Entry-level `replace` is accepted and ignored until types can have mergers. ## Kind - [x] feature: something new for players (mod authors) ## Vanilla reference Vanilla 26.3 has no data maps. The contract is NeoForge's `DataMapType`, `DataMapFile`, `DataMapEntry` and `RegisterDataMapTypesEvent` javadoc (file location, `replace`/`values`/`remove`, tag keys, the value wrapper, default merger; names and behaviour only). Horizon's loading follows how it already layers data pack files over the tables (`overlay_files`, `PackOverlay`). ## Other projects' code None. ## Proof in the real game Engine from this branch plus a throwaway probe (types `testmod:fuel` for items and `testmod:hard` for blocks, plus a bad id and an unsupported registry; two files pushed from `native_data_pack_files`: fuel `{coal: {burn: 1600}, #minecraft:logs: 300, stick: 100}`, hard `{#minecraft:logs: 2}`; `eprintln!`s in `native_server_data_loaded`; not in this PR). A world pack `datapacks/pack` with `data/testmod/data_maps/item/fuel.json` = `{"values": {"minecraft:coal": {"burn": 2000}}, "remove": ["minecraft:stick"]}`. Server thread, world `L`, mods only, then with the pack, then after `/reload` (the role label in the probe is unreliable, ignore it): ``` --- mods only TESTHOOK data loaded reload=false: coal=Some({"burn": 1600}) oak_log=Some(300) stick=Some(100) stone=None block oak_log=Some(2) bad=None biome=None TESTHOOK entries fuel=50 wrong registry=0 --- with a pack TESTHOOK data loaded reload=false: coal=Some({"burn": 2000}) oak_log=Some(300) stick=None stone=None block oak_log=Some(2) bad=None biome=None TESTHOOK entries fuel=49 wrong registry=0 --- after /reload TESTHOOK data loaded reload=true: coal=Some({"burn": 2000}) oak_log=Some(300) stick=None stone=None block oak_log=Some(2) bad=None biome=None TESTHOOK entries fuel=49 wrong registry=0 ``` Dedicated server (`world/datapacks/pack`, started without and then with the pack, then `reload` on the console): the same values, `fuel=50` without the pack, `fuel=49` with it and after `reload`. Not run: a client of a server (reads none, by design), the pack's `data_maps` file enabled by `/datapack`, tags from a pack that add to the item tags (the tag tables used are the ones the tables load, `Items::item_tags`). ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at dea6dea98, 2 min 6 s) | Check | Result | | --- | --- | | Scope | ✅ 5 files, +459 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 586 passed (33 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (30 s) | | tests: horizon-client, horizon-client-render | ✅ 2729 passed (53 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | 🤖 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:27: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#6802
No description provided.