[GH-ISSUE #6774] Native mods: hook points for custom payloads (plugin channels) on the client #2212

Open
opened 2026-11-02 15:53:02 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @randomusrrname on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6774

What

Today a client-side native mod cannot send or receive custom payloads on a channel of its own (namespace:path) when it joins a server. Native hook points go up to API 153 and none of them touches ClientboundCustomPayloadPacket / ServerboundCustomPayloadPacket.

native_net_* (API 40) carries messages between the server and client halves of one Horizon mod. As far as I can tell from the docs it is Horizon's own channel, so it does not let a mod talk to a server that is not running the same Horizon mod. If it can already carry arbitrary channel ids to non-Horizon servers, please say so and I will close this.

Why

Many existing servers rely on plugin messaging for client features. The motivating case is a proximity voice chat client that is compatible with servers already running Simple Voice Chat: before any audio flows, the client has to receive the server's secret on a custom channel and request it on another. Without a hook, a native mod has no way to take part in that exchange. The same hook would serve any client mod that needs to talk to a plugin (minimaps with server waypoints, server-driven UI, etc.).

Proposal

Four additions in crates/horizon-client/src/game/native_hooks.rs, named after the vanilla packets they sit on. Names and signatures are a first draft: happy to change them to fit the conventions in #4402.

/// Channels the client mod listens on. Asked once when a connection to a
/// server starts: push each `namespace:path`. They are announced to the
/// server the way a vanilla or Fabric client announces its channels.
pub(super) fn native_custom_payload_channels(&mut self, channels: &mut Vec<String>)

/// A custom payload arrived from the server (`ClientboundCustomPayloadPacket`),
/// in the configuration or the play phase. Set `claimed` when the mod handled
/// it, so the game does not treat it as an unknown payload.
pub(super) fn native_custom_payload_received(&mut self, phase: PayloadPhase, channel: &str, data: &[u8], claimed: &mut bool)

/// Helper: send `data` on `channel` (`ServerboundCustomPayloadPacket`).
/// Returns whether it was queued (false when not connected to a server or
/// when `data` is over vanilla's size limit).
pub fn native_send_custom_payload(&mut self, channel: &str, data: &[u8]) -> bool

/// Helper: the host and port of the server the client is connected to,
/// `None` in single player. Needed by mods that open a second connection
/// to the same host (UDP voice, for example).
pub fn native_server_address(&self) -> Option<String>
  • Called on the network thread's handoff to the game, like the other client hooks, never from inside packet decoding.
  • Only a client joined to a server is affected. Single player, LAN host and dedicated servers behave as today.
  • data is the raw payload bytes, no parsing by the game. Sizes follow vanilla's limits in each direction.
  • Nothing changes without a native mod: with none installed no channel is announced and every payload is handled as now.
  • Bodies stay empty with no cfg and no macros, as hook_points_stay_hookable requires.
  • NATIVE_HOOKS_API + 1 (next free number on main, currently 153), its native-hooks.json entry, and a paragraph in docs/native-mods.md.

Push to talk can use native_input_key (121), indicators native_gui_layer_post (139), settings native_mod_screen (111), and resetting state native_client_level_load / native_client_level_unload (135). Custom payloads and the server address are what is missing.

Open questions

  • Should the hook cover the configuration phase, or only play? A voice mod needs play; some mods will need both.
  • Is there a reason to keep channel ids out of the minecraft namespace?

I can open the PR once the shape is agreed.

Originally created by @randomusrrname on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6774 ## What Today a client-side native mod cannot send or receive custom payloads on a channel of its own (`namespace:path`) when it joins a server. Native hook points go up to API 153 and none of them touches `ClientboundCustomPayloadPacket` / `ServerboundCustomPayloadPacket`. `native_net_*` (API 40) carries messages between the server and client halves of one Horizon mod. As far as I can tell from the docs it is Horizon's own channel, so it does not let a mod talk to a server that is not running the same Horizon mod. If it can already carry arbitrary channel ids to non-Horizon servers, please say so and I will close this. ## Why Many existing servers rely on plugin messaging for client features. The motivating case is a proximity voice chat client that is compatible with servers already running Simple Voice Chat: before any audio flows, the client has to receive the server's secret on a custom channel and request it on another. Without a hook, a native mod has no way to take part in that exchange. The same hook would serve any client mod that needs to talk to a plugin (minimaps with server waypoints, server-driven UI, etc.). ## Proposal Four additions in `crates/horizon-client/src/game/native_hooks.rs`, named after the vanilla packets they sit on. Names and signatures are a first draft: happy to change them to fit the conventions in #4402. ```rust /// Channels the client mod listens on. Asked once when a connection to a /// server starts: push each `namespace:path`. They are announced to the /// server the way a vanilla or Fabric client announces its channels. pub(super) fn native_custom_payload_channels(&mut self, channels: &mut Vec<String>) /// A custom payload arrived from the server (`ClientboundCustomPayloadPacket`), /// in the configuration or the play phase. Set `claimed` when the mod handled /// it, so the game does not treat it as an unknown payload. pub(super) fn native_custom_payload_received(&mut self, phase: PayloadPhase, channel: &str, data: &[u8], claimed: &mut bool) /// Helper: send `data` on `channel` (`ServerboundCustomPayloadPacket`). /// Returns whether it was queued (false when not connected to a server or /// when `data` is over vanilla's size limit). pub fn native_send_custom_payload(&mut self, channel: &str, data: &[u8]) -> bool /// Helper: the host and port of the server the client is connected to, /// `None` in single player. Needed by mods that open a second connection /// to the same host (UDP voice, for example). pub fn native_server_address(&self) -> Option<String> ``` - Called on the network thread's handoff to the game, like the other client hooks, never from inside packet decoding. - Only a client joined to a server is affected. Single player, LAN host and dedicated servers behave as today. - `data` is the raw payload bytes, no parsing by the game. Sizes follow vanilla's limits in each direction. - Nothing changes without a native mod: with none installed no channel is announced and every payload is handled as now. - Bodies stay empty with no `cfg` and no macros, as `hook_points_stay_hookable` requires. - `NATIVE_HOOKS_API` + 1 (next free number on main, currently 153), its `native-hooks.json` entry, and a paragraph in `docs/native-mods.md`. ## Related hooks that already exist Push to talk can use `native_input_key` (121), indicators `native_gui_layer_post` (139), settings `native_mod_screen` (111), and resetting state `native_client_level_load` / `native_client_level_unload` (135). Custom payloads and the server address are what is missing. ## Open questions - Should the hook cover the configuration phase, or only play? A voice mod needs play; some mods will need both. - Is there a reason to keep channel ids out of the `minecraft` namespace? I can open the PR once the shape is agreed.
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#2212
No description provided.