[PR #7224] [MERGED] Native mods: attachments can sync to Horizon clients #7423

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7224
Author: @arismoko
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: v2/ses_01M6E1Z4GQ0S5X4JCHHMZRPF31-attachment-sync


📝 Commits (10+)

  • 04e36b1 Add synced attachment data model and wire format
  • 500fd70 Send synced attachments from the server
  • 653d32a Keep synced attachments on the client
  • dca1953 Fix attachment sync snapshots, recipients and wire limits
  • 30078d5 Fix attachment sync review findings
  • 479a03d Fix attachment sync review findings
  • d9fd6ae Fix attachment sync review findings
  • b68e32f Merge remote-tracking branch 'upstream/main' into v2/ses_01M6E1Z4GQ0S5X4JCHHMZRPF31-attachment-sync
  • 05ac306 Fix attachment sync lifecycle and far chunk snapshots
  • 4d97da3 Merge remote-tracking branch 'upstream/main' into v2/ses_01M6E1Z4GQ0S5X4JCHHMZRPF31-attachment-sync

📊 Changes

19 files changed (+855 additions, -57 deletions)

View changed files

📝 crates/horizon-client-render/src/block_entities.rs (+1 -0)
📝 crates/horizon-client-render/src/world.rs (+4 -0)
📝 crates/horizon-client/src/game.rs (+1 -0)
➕ crates/horizon-client/src/game/attachment_sync.rs (+148 -0)
📝 crates/horizon-client/src/game/lan.rs (+2 -0)
📝 crates/horizon-client/src/game/mod_api_host.rs (+20 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+2 -1)
📝 crates/horizon-client/src/game/persist.rs (+1 -0)
📝 crates/horizon-client/src/game/remote.rs (+42 -2)
📝 crates/horizon-client/src/game/remote_chunks.rs (+10 -0)
📝 crates/horizon-client/src/lan/guest.rs (+27 -1)
📝 crates/horizon-client/src/lan/hub.rs (+94 -11)
📝 crates/horizon-client/src/lan/playerdata.rs (+1 -0)
📝 crates/horizon-client/src/mod_api/generated_host.rs (+2 -1)
📝 crates/horizon-client/src/save.rs (+2 -0)
➕ crates/horizon-protocol/src/attachment_sync.rs (+212 -0)
📝 crates/horizon-protocol/src/lib.rs (+1 -0)
📝 crates/horizon-world/src/attachments.rs (+253 -30)
📝 docs/native-mods.md (+32 -10)

📄 Description

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

Part of #6452 (Attachments: sync to clients).

What it does

Attachments were server-only, so a mod that shows attached data on the client (a chunk's pollution, a player's mana) had to send it itself with mod messages. With this PR an AttachmentType can set sync: true, and its value reaches Horizon clients:

  • When: the default is created by get, on set, on remove, and on demand with the new AttachmentType::sync_data(host, holder).
  • Who: the players who track the holder. A block entity or chunk goes to players who have the chunk. An entity goes to players tracking it. A player goes to that player and the players tracking them. A level goes to every player in it.
  • Snapshots: a player also gets a full snapshot of a holder's synced values when they start seeing it. That covers a chunk sent (with its block entities), joining a level, respawning or travelling (the level and their own player), and an entity they start tracking.
  • Wire form: the type's existing AttachmentCodec compound, so sync needs a codec (AttachmentError::InvalidSyncPolicy otherwise). The flag is saved as sync: 1b in the entry, next to copy_on_death, so a value loaded from disk is sent even before any mod has decoded it.
  • On the client: Host::attachments returns the client's copy. get reads what the server sent (or the default). set and remove change only that copy, as on NeoForge's client-side holders. The copy is dropped when its chunk, entity or player goes away, on respawn, and when the client is sent back to configuration or logs in to another server.
  • Transport: a clientbound horizon:attachment_sync custom payload, sent only to Horizon clients, as horizon:mod_net is. Vanilla clients get nothing. With no native mod loaded, nothing is queued.

With a native mod loaded, a far-ring column that enters view is sent again as a near chunk so its snapshot can follow. This only affects Horizon clients with far terrain enabled.

The storage, wire format, server send and client copy each do nothing alone, so they are kept together. No new hook and no catalog change.

Note for review: AttachmentType gains a public field, so existing declarations add sync: false.

NeoForge counterpart

AttachmentType.Builder#sync with a StreamCodec, and syncData on the holder (data attachments, "Sharing data with the client"). Like the StreamCodec overloads, the whole value is sent each time. Not covered: the sendToPlayer predicate, AttachmentSyncHandler's partial updates, and a wire codec separate from the saved one. docs/native-mods.md says so.

Tests

  • Unit tests in horizon-world (attachments::): what is reported and when, the saved sync flag, the snapshot of undecoded values, and the client applying changes.
  • Unit tests in horizon-protocol (attachment_sync::): a round trip for each holder kind, and malformed payloads refused.

Tested in game

The test used a throwaway trait-API mod based on horizon-machine-sample, with synced chunk pollution and player mana attachments. It was built at this branch's commit 4d97da3bca. The later merge of main and the brand guard on the far-column resend weren't retested in game.

  • Single-player server thread: the client observed chunk and mana values 2, 3 and 4 after the corresponding server changes, then chunk 0 after removal. After death and respawn, mana returned to 0. After saving and relaunching with server writes disabled, the client received the saved chunk value 34.
  • Dedicated server: a helper loaded the chunk and the server set it to 3; after that helper left, a separate late-joining Horizon client read its default 0 and then received the snapshot value 3.
  • No vanilla client was run. Sending is gated on the horizon brand, the same check horizon:mod_net and far terrain use.

pr_ready

pr_ready (tools/pr_ready.py --quick --base db84d8508e08d87bcbb7f538f08daff312ed8968 on 61ea80f7ace3, against db84d8508e at db84d8508, 11 min 1 s)

Check Result
Scope ⚠️ 19 files, +855 −57; 870 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (40 s)
rustfmt ✅ (11 s)
clippy ✅ (1 s)
tests: horizon-client, horizon-client-lib, horizon-client-render, horizon-protocol, horizon-world ❌ 3753 passed, 6 failed (9 min 40 s)
doc tests ✅ 0 passed (5 s)
content root tests ➖ content root untouched
mod API up to date ✅ (21 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 375 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute and 363 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The horizon-world tests a_client_replays_a_pistons_block_event, dust_on_a_downward_piston_survives_extend_and_retract, lever_on_piston_back_survives_extend_and_retract, pistons_pop_fragile_blocks_and_refuse_obsidian, pistons_push_and_sticky_pistons_pull, and refused_sticky_pull_keeps_the_block_and_sends_no_event fail identically at the base commit in a local run with the same resources; this change does not touch horizon-world's level code.

🤖 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/7224 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `v2/ses_01M6E1Z4GQ0S5X4JCHHMZRPF31-attachment-sync` --- ### 📝 Commits (10+) - [`04e36b1`](https://github.com/horizon-rust/horizon/commit/04e36b1c1a21754f5ae91ffd506139e3de76323f) Add synced attachment data model and wire format - [`500fd70`](https://github.com/horizon-rust/horizon/commit/500fd70a2f708f77cae2662359f816766ba3c58b) Send synced attachments from the server - [`653d32a`](https://github.com/horizon-rust/horizon/commit/653d32aebb815f741c80b4bc0faeb7f83615c2f9) Keep synced attachments on the client - [`dca1953`](https://github.com/horizon-rust/horizon/commit/dca1953712ad3678c31556eef23e234bc629dfa6) Fix attachment sync snapshots, recipients and wire limits - [`30078d5`](https://github.com/horizon-rust/horizon/commit/30078d515b1c656a91a32a381171937d999039fd) Fix attachment sync review findings - [`479a03d`](https://github.com/horizon-rust/horizon/commit/479a03daefb41ae0b92a73d17ce7797f0397128f) Fix attachment sync review findings - [`d9fd6ae`](https://github.com/horizon-rust/horizon/commit/d9fd6ae395db189cb0f7b10a91d2fb17ff5625a2) Fix attachment sync review findings - [`b68e32f`](https://github.com/horizon-rust/horizon/commit/b68e32f307f4b1def241a0d33eb009a3ecb7a2fb) Merge remote-tracking branch 'upstream/main' into v2/ses_01M6E1Z4GQ0S5X4JCHHMZRPF31-attachment-sync - [`05ac306`](https://github.com/horizon-rust/horizon/commit/05ac3060c0d1ef70174ca2bb9fdf7699ab7f33af) Fix attachment sync lifecycle and far chunk snapshots - [`4d97da3`](https://github.com/horizon-rust/horizon/commit/4d97da3bcaaabb3ad1964860b4de2caba061f1b2) Merge remote-tracking branch 'upstream/main' into v2/ses_01M6E1Z4GQ0S5X4JCHHMZRPF31-attachment-sync ### 📊 Changes **19 files changed** (+855 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/block_entities.rs` (+1 -0) 📝 `crates/horizon-client-render/src/world.rs` (+4 -0) 📝 `crates/horizon-client/src/game.rs` (+1 -0) ➕ `crates/horizon-client/src/game/attachment_sync.rs` (+148 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+2 -0) 📝 `crates/horizon-client/src/game/mod_api_host.rs` (+20 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+2 -1) 📝 `crates/horizon-client/src/game/persist.rs` (+1 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+42 -2) 📝 `crates/horizon-client/src/game/remote_chunks.rs` (+10 -0) 📝 `crates/horizon-client/src/lan/guest.rs` (+27 -1) 📝 `crates/horizon-client/src/lan/hub.rs` (+94 -11) 📝 `crates/horizon-client/src/lan/playerdata.rs` (+1 -0) 📝 `crates/horizon-client/src/mod_api/generated_host.rs` (+2 -1) 📝 `crates/horizon-client/src/save.rs` (+2 -0) ➕ `crates/horizon-protocol/src/attachment_sync.rs` (+212 -0) 📝 `crates/horizon-protocol/src/lib.rs` (+1 -0) 📝 `crates/horizon-world/src/attachments.rs` (+253 -30) 📝 `docs/native-mods.md` (+32 -10) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Part of #6452 (Attachments: sync to clients). ## What it does Attachments were server-only, so a mod that shows attached data on the client (a chunk's pollution, a player's mana) had to send it itself with mod messages. With this PR an `AttachmentType` can set `sync: true`, and its value reaches Horizon clients: - **When:** the default is created by `get`, on `set`, on `remove`, and on demand with the new `AttachmentType::sync_data(host, holder)`. - **Who:** the players who track the holder. A block entity or chunk goes to players who have the chunk. An entity goes to players tracking it. A player goes to that player and the players tracking them. A level goes to every player in it. - **Snapshots:** a player also gets a full snapshot of a holder's synced values when they start seeing it. That covers a chunk sent (with its block entities), joining a level, respawning or travelling (the level and their own player), and an entity they start tracking. - **Wire form:** the type's existing `AttachmentCodec` compound, so `sync` needs a codec (`AttachmentError::InvalidSyncPolicy` otherwise). The flag is saved as `sync: 1b` in the entry, next to `copy_on_death`, so a value loaded from disk is sent even before any mod has decoded it. - **On the client:** `Host::attachments` returns the client's copy. `get` reads what the server sent (or the default). `set` and `remove` change only that copy, as on NeoForge's client-side holders. The copy is dropped when its chunk, entity or player goes away, on respawn, and when the client is sent back to configuration or logs in to another server. - **Transport:** a clientbound `horizon:attachment_sync` custom payload, sent only to Horizon clients, as `horizon:mod_net` is. Vanilla clients get nothing. With no native mod loaded, nothing is queued. With a native mod loaded, a far-ring column that enters view is sent again as a near chunk so its snapshot can follow. This only affects Horizon clients with far terrain enabled. The storage, wire format, server send and client copy each do nothing alone, so they are kept together. No new hook and no catalog change. **Note for review:** `AttachmentType` gains a public field, so existing declarations add `sync: false`. ## NeoForge counterpart `AttachmentType.Builder#sync` with a `StreamCodec`, and `syncData` on the holder ([data attachments](https://docs.neoforged.net/docs/datastorage/attachments/), "Sharing data with the client"). Like the StreamCodec overloads, the whole value is sent each time. Not covered: the `sendToPlayer` predicate, `AttachmentSyncHandler`'s partial updates, and a wire codec separate from the saved one. docs/native-mods.md says so. ## Tests - Unit tests in `horizon-world` (`attachments::`): what is reported and when, the saved sync flag, the snapshot of undecoded values, and the client applying changes. - Unit tests in `horizon-protocol` (`attachment_sync::`): a round trip for each holder kind, and malformed payloads refused. ## Tested in game The test used a throwaway trait-API mod based on [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample), with synced chunk pollution and player mana attachments. It was built at this branch's commit 4d97da3bca. The later merge of main and the brand guard on the far-column resend weren't retested in game. - **Single-player server thread:** the client observed chunk and mana values 2, 3 and 4 after the corresponding server changes, then chunk 0 after removal. After death and respawn, mana returned to 0. After saving and relaunching with server writes disabled, the client received the saved chunk value 34. - **Dedicated server:** a helper loaded the chunk and the server set it to 3; after that helper left, a separate late-joining Horizon client read its default 0 and then received the snapshot value 3. - No vanilla client was run. Sending is gated on the `horizon` brand, the same check `horizon:mod_net` and far terrain use. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base db84d8508e08d87bcbb7f538f08daff312ed8968` on 61ea80f7ace3, against db84d8508e08d87bcbb7f538f08daff312ed8968 at db84d8508, 11 min 1 s) | Check | Result | | --- | --- | | Scope | ⚠️ 19 files, +855 −57; 870 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (40 s) | | rustfmt | ✅ (11 s) | | clippy | ✅ (1 s) | | tests: horizon-client, horizon-client-lib, horizon-client-render, horizon-protocol, horizon-world | ❌ 3753 passed, 6 failed (9 min 40 s) | | doc tests | ✅ 0 passed (5 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (21 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 375 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute and 363 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The `horizon-world` tests `a_client_replays_a_pistons_block_event`, `dust_on_a_downward_piston_survives_extend_and_retract`, `lever_on_piston_back_survives_extend_and_retract`, `pistons_pop_fragile_blocks_and_refuse_obsidian`, `pistons_push_and_sticky_pistons_pull`, and `refused_sticky_pull_keeps_the_block_and_sends_no_event` fail identically at the base commit in a local run with the same resources; this change does not touch `horizon-world`'s level code. 🤖 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:39:19 +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#7423
No description provided.