[PR #4725] [MERGED] Native mods: hook points for redstone signals from a mod's block (API next) #5808

Closed
opened 2026-11-03 05:15:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4725
Author: @Qwerner88880
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @levzzz5154

Base: main ← Head: hooks-signal


📝 Commits (3)

  • 53aa834 Native mods: hook points for redstone signals from a mod's block (API 22)
  • ed7f8b3 Merge main; redstone signal hooks are API 23
  • 57bee43 Merge hr/main; renumber redstone signal hooks to API 38; native_update_signal_neighbors takes a dimension

📊 Changes

7 files changed (+204 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+22 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+67 -1)
📝 crates/horizon-world/src/level/mod.rs (+17 -0)
📝 crates/horizon-world/src/level/redstone.rs (+18 -2)
📝 crates/horizon-world/src/level/tests.rs (+65 -0)
📝 docs/native-mods.md (+5 -0)
📝 native-hooks.json (+10 -0)

📄 Description

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

What and why

Fixes #4711. Part of #3911 (Mods), gap B of #1854 (block behaviour hooks). A native mod's block can now give a redstone signal, so a machine can power a lamp, a door or a wire, and redstone wire connects to it. Named after the vanilla calls they sit in, as on #4402.

  • native_block_signal(&self, dimension, pos: BlockPos, state: BlockStateId, face: Direction, direct: bool, signal: &mut i32): BlockState.getSignal, or getDirectSignal when direct. signal holds vanilla's answer and the mod may change it; the result is clamped to 0 to 15. face is the side touching the block that reads it.
  • native_is_signal_source(&self, state: BlockStateId, source: &mut bool): BlockState.isSignalSource, so redstone wire connects to the block.
  • native_update_signal_neighbors(&mut self, pos: [i32; 3]), a helper: Level.updateNeighborsAt for the block and for each of its neighbours, as around a lever, so a change in the mod's output is read.

In horizon-world, state_signal and state_direct_signal now pass vanilla's answer through two new LevelAccess methods whose defaults keep it. GameLevel calls the hooks only on an authoritative server. The hooks are #[inline(always)] empty functions, like native_block_changed, so this hot path should add nothing without a mod; I didn't measure it.

native_block_signal is asked very often and from inside the level's update, so its doc tells a mod to check the block first and answer from its own state. NATIVE_HOOKS_API goes to the next free number: 23 in the code on this base. The title says "API next", as #4402 proposes, because the number moves with whatever merges first. The native-hooks.json entries and an "API 23" paragraph in docs/native-mods.md are included.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only (hook points; they do nothing in Horizon). They sit at BlockState.getSignal, BlockState.getDirectSignal and BlockState.isSignalSource, and the helper does what LeverBlock.updateNeighbours does with Level.updateNeighborsAt. Vanilla's own answers aren't changed without a mod, and the new unit test checks that a redstone block still gives 15. CI's parity job picks the harnesses that cover redstone.rs. I didn't run parity here (no vanilla data on this machine).

Tests

Unit test, a_level_can_answer_for_a_blocks_signal in horizon-world: a weak signal reaches what touches the block and stops at a conductor, a direct signal passes through, a signal for one direction only reaches that side, and a vanilla source is untouched.

In the game: a throwaway horizon-mixins bundle (not in this pull request) made vanilla blocks act as a mod's blocks, applied with horizon-mixins apply and built with --profile fast. A fresh creative world on the single player server thread, driven through horizon-ctl, on Windows with an RTX 5070:

Setup Hook's answer Result
Lamp beside gold weak 15 lit=true
Lamp, stone, gold in a row weak 15 lit=false: a weak signal stops at the conductor
Lamp, stone, iron in a row, then the stone changed direct 15 lit=false until the lamp gets an update, then lit=true
Lamps beside and above diamond weak 15 on the top face only beside lit=false, above lit=true
Wire beside emerald is_signal_source true, weak 15 or 0 west=side, power follows the output
Lamp beside emerald, output flipped every 2 s with the helper weak 15 or 0 lit follows the output
Lamp beside a redstone block none lit=true

No errors in the log. On a dedicated server with two real clients: --dedicated --nogui and two Horizon clients (Alex, Steve) under horizon-ctl --offscreen, over TCP on localhost, on Windows, with a throwaway bundle hooking all of this. It ran on a local merge of #4669, #4677 and #4725 with main, not on this branch alone; all 56 checks passed.

Set up from the server's console and read from both clients, which agree: weak and direct signals, a conductor, a one-face source and a vanilla redstone block give the results in the table above. A lamp and redstone wire follow the mod's output while it flips, and wire connects to the block.

Not tested: a real mod's own block (vanilla blocks stood in for one) and the cost on a large redstone build.

Self-check

tools/pr_ready.py --quick --base origin/main on Windows.

horizon-client doesn't currently build on Windows on main, because #4732 added unsafe to save.rs under #![forbid(unsafe_code)], so I ran this and the game with that one line relaxed locally. It isn't in this pull request, and the table counts it.

pr_ready (tools/pr_ready.py --quick on DESKTOP-H7P5E7K, against origin/main at 672b204c0, 4 min 23 s)

Check Result
Scope ✅ 8 files, +192 −4
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 481 passed (1 min 31 s)
rustfmt ✅ (11 s)
clippy ✅ (45 s)
tests: horizon-client, horizon-world ✅ 1507 passed (1 min 51 s)
doc tests ✅ 0 passed (2 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
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/4725 **Author:** [@Qwerner88880](https://github.com/Qwerner88880) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `hooks-signal` --- ### 📝 Commits (3) - [`53aa834`](https://github.com/horizon-rust/horizon/commit/53aa8348665c6f3583b41fd0d44089d08841abf3) Native mods: hook points for redstone signals from a mod's block (API 22) - [`ed7f8b3`](https://github.com/horizon-rust/horizon/commit/ed7f8b3998c8480a4adf14ccf11b6bc7f0823454) Merge main; redstone signal hooks are API 23 - [`57bee43`](https://github.com/horizon-rust/horizon/commit/57bee439bb5453bbd2fdcc4a075d7b7bb99c578f) Merge hr/main; renumber redstone signal hooks to API 38; native_update_signal_neighbors takes a dimension ### 📊 Changes **7 files changed** (+204 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+22 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+67 -1) 📝 `crates/horizon-world/src/level/mod.rs` (+17 -0) 📝 `crates/horizon-world/src/level/redstone.rs` (+18 -2) 📝 `crates/horizon-world/src/level/tests.rs` (+65 -0) 📝 `docs/native-mods.md` (+5 -0) 📝 `native-hooks.json` (+10 -0) </details> ### 📄 Description > 🤖 Opened by Qwerner88880's AI agent (Claude Code, Claude Opus 5.5), not by Qwerner88880 personally. ## What and why Fixes #4711. Part of #3911 (Mods), gap **B** of #1854 (block behaviour hooks). A native mod's block can now give a redstone signal, so a machine can power a lamp, a door or a wire, and redstone wire connects to it. Named after the vanilla calls they sit in, as on #4402. - **`native_block_signal(&self, dimension, pos: BlockPos, state: BlockStateId, face: Direction, direct: bool, signal: &mut i32)`**: `BlockState.getSignal`, or `getDirectSignal` when `direct`. `signal` holds vanilla's answer and the mod may change it; the result is clamped to 0 to 15. `face` is the side touching the block that reads it. - **`native_is_signal_source(&self, state: BlockStateId, source: &mut bool)`**: `BlockState.isSignalSource`, so redstone wire connects to the block. - **`native_update_signal_neighbors(&mut self, pos: [i32; 3])`**, a helper: `Level.updateNeighborsAt` for the block and for each of its neighbours, as around a lever, so a change in the mod's output is read. In `horizon-world`, `state_signal` and `state_direct_signal` now pass vanilla's answer through two new `LevelAccess` methods whose defaults keep it. `GameLevel` calls the hooks only on an authoritative server. The hooks are `#[inline(always)]` empty functions, like `native_block_changed`, so this hot path should add nothing without a mod; I didn't measure it. `native_block_signal` is asked very often and from inside the level's update, so its doc tells a mod to check the block first and answer from its own state. `NATIVE_HOOKS_API` goes to the next free number: 23 in the code on this base. The title says "API next", as #4402 proposes, because the number moves with whatever merges first. The `native-hooks.json` entries and an "API 23" paragraph in `docs/native-mods.md` are included. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [x] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only (hook points; they do nothing in Horizon). They sit at `BlockState.getSignal`, `BlockState.getDirectSignal` and `BlockState.isSignalSource`, and the helper does what `LeverBlock.updateNeighbours` does with `Level.updateNeighborsAt`. Vanilla's own answers aren't changed without a mod, and the new unit test checks that a redstone block still gives 15. CI's parity job picks the harnesses that cover `redstone.rs`. I didn't run parity here (no vanilla data on this machine). ## Tests **Unit test**, `a_level_can_answer_for_a_blocks_signal` in `horizon-world`: a weak signal reaches what touches the block and stops at a conductor, a direct signal passes through, a signal for one direction only reaches that side, and a vanilla source is untouched. **In the game:** a throwaway horizon-mixins bundle (not in this pull request) made vanilla blocks act as a mod's blocks, applied with `horizon-mixins apply` and built with `--profile fast`. A fresh creative world on the single player server thread, driven through `horizon-ctl`, on Windows with an RTX 5070: | Setup | Hook's answer | Result | | --- | --- | --- | | Lamp beside gold | weak 15 | `lit=true` | | Lamp, stone, gold in a row | weak 15 | `lit=false`: a weak signal stops at the conductor | | Lamp, stone, iron in a row, then the stone changed | direct 15 | `lit=false` until the lamp gets an update, then `lit=true` | | Lamps beside and above diamond | weak 15 on the top face only | beside `lit=false`, above `lit=true` | | Wire beside emerald | `is_signal_source` true, weak 15 or 0 | `west=side`, `power` follows the output | | Lamp beside emerald, output flipped every 2 s with the helper | weak 15 or 0 | `lit` follows the output | | Lamp beside a redstone block | none | `lit=true` | No errors in the log. **On a dedicated server with two real clients:** `--dedicated --nogui` and two Horizon clients (Alex, Steve) under `horizon-ctl --offscreen`, over TCP on localhost, on Windows, with a throwaway bundle hooking all of this. It ran on a local merge of #4669, #4677 and #4725 with main, not on this branch alone; all 56 checks passed. Set up from the server's console and read from both clients, which agree: weak and direct signals, a conductor, a one-face source and a vanilla redstone block give the results in the table above. A lamp and redstone wire follow the mod's output while it flips, and wire connects to the block. **Not tested:** a real mod's own block (vanilla blocks stood in for one) and the cost on a large redstone build. ## Self-check `tools/pr_ready.py --quick --base origin/main` on Windows. `horizon-client` doesn't currently build on Windows on main, because #4732 added `unsafe` to `save.rs` under `#![forbid(unsafe_code)]`, so I ran this and the game with that one line relaxed locally. It isn't in this pull request, and the table counts it. **pr_ready** (`tools/pr_ready.py --quick` on DESKTOP-H7P5E7K, against origin/main at 672b204c0, 4 min 23 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +192 −4 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 481 passed (1 min 31 s) | | rustfmt | ✅ (11 s) | | clippy | ✅ (45 s) | | tests: horizon-client, horizon-world | ✅ 1507 passed (1 min 51 s) | | doc tests | ✅ 0 passed (2 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 | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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 05:15:08 +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#5808
No description provided.