[PR #5520] [MERGED] Native mods: a mod block's comparator output #6335

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

📋 Pull Request Information

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

Base: main ← Head: mods/analog-output


📝 Commits (1)

  • acfac25 Native mods: a mod block's comparator output

📊 Changes

7 files changed (+181 additions, -8 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+20 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+53 -0)
📝 crates/horizon-world/src/level/mod.rs (+17 -0)
📝 crates/horizon-world/src/level/redstone.rs (+21 -4)
📝 crates/horizon-world/src/level/tests.rs (+61 -0)
📝 crates/horizon-world/src/level/update.rs (+1 -4)
➕ tools/native-hook-fragments/analog_output.json (+8 -0)

📄 Description

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

What and why

Closes #5497 (part of #4953). A mod block that isn't a container couldn't give a comparator signal. Vanilla asks BlockBehaviour.hasAnalogOutputSignal and getAnalogOutputSignal(state, level, pos, direction), so a block can say how full or far along it is (a cake's bites, a composter's level).

  • Hooks (on GameLevel, next to native_block_signal):
    • native_has_analog_output(state, &mut bool): the block has an output.
    • native_analog_output(dimension, pos, state, face, &mut i32): the output, 0 to 15 (clamped). face is the side that touches the comparator.
  • Helper native_update_output_neighbors(dimension, pos): Level.updateNeighbourForOutputSignal, for an output that changes without the block's state.
  • horizon-world: LevelAccess gains adjust_has_analog_output and adjust_analog_output (pass-through by default). ComparatorBlock.getInputSignal (the block in front, and behind a conductor) and Level.setBlock's "new state has an analog output → update comparators" both go through them. So a mod block that changes its own state through native_set_block/native_set_block_property updates comparators by itself, as in vanilla.
  • Fragment: tools/native-hook-fragments/analog_output.json. Bundles need the API number the stamp assigns.

Kind

  • feature: something new for players (listed under New in the release notes)

Vanilla reference

BlockBehaviour.hasAnalogOutputSignal / getAnalogOutputSignal, ComparatorBlock.getInputSignal, Level.markAndNotifyBlock (newState.hasAnalogOutputSignal() → updateNeighbourForOutputSignal), Level.updateNeighbourForOutputSignal.

Self-check

  • New test level::tests::a_level_can_answer_for_a_blocks_comparator_output, with a real comparator in the test level:
    • gold gives nothing by itself;
    • once the level says gold has an output, placing it powers the comparator;
    • an output that changes without the block waits for update_neighbour_for_output_signal;
    • behind a conductor it is read, and 40 clamps to 15.
  • In game, on the server thread, with a throwaway answer in the two hooks (gold → 11; removed before committing): gold + comparator + dust gives power=11 and comparator[powered=true]. Swapping the gold for iron gives 0, and back to gold gives 11.
  • python3 tools/parity.py redstone block_update: both pass. The other affected harnesses run in CI.
  • tools/pr_ready.py --quick: fmt, clippy, Python tests and doc tests pass. horizon-client --test lan_bot fails 13 of 15 locally (minecraft:dialog registry data); main fails the same 13 on this machine, so it isn't this change. The native hook catalog tests (11) pass.

🤖 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/5520 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/analog-output` --- ### 📝 Commits (1) - [`acfac25`](https://github.com/horizon-rust/horizon/commit/acfac2569902c5ab893a44e3756b9e2d766ae368) Native mods: a mod block's comparator output ### 📊 Changes **7 files changed** (+181 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+20 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+53 -0) 📝 `crates/horizon-world/src/level/mod.rs` (+17 -0) 📝 `crates/horizon-world/src/level/redstone.rs` (+21 -4) 📝 `crates/horizon-world/src/level/tests.rs` (+61 -0) 📝 `crates/horizon-world/src/level/update.rs` (+1 -4) ➕ `tools/native-hook-fragments/analog_output.json` (+8 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. ## What and why Closes #5497 (part of #4953). A mod block that isn't a container couldn't give a comparator signal. Vanilla asks `BlockBehaviour.hasAnalogOutputSignal` and `getAnalogOutputSignal(state, level, pos, direction)`, so a block can say how full or far along it is (a cake's bites, a composter's level). - **Hooks** (on `GameLevel`, next to `native_block_signal`): - `native_has_analog_output(state, &mut bool)`: the block has an output. - `native_analog_output(dimension, pos, state, face, &mut i32)`: the output, 0 to 15 (clamped). `face` is the side that touches the comparator. - **Helper** `native_update_output_neighbors(dimension, pos)`: `Level.updateNeighbourForOutputSignal`, for an output that changes without the block's state. - **horizon-world:** `LevelAccess` gains `adjust_has_analog_output` and `adjust_analog_output` (pass-through by default). `ComparatorBlock.getInputSignal` (the block in front, and behind a conductor) and `Level.setBlock`'s "new state has an analog output → update comparators" both go through them. So a mod block that changes its own state through `native_set_block`/`native_set_block_property` updates comparators by itself, as in vanilla. - **Fragment:** `tools/native-hook-fragments/analog_output.json`. Bundles need the API number the stamp assigns. ## Kind - [x] feature: something new for players (listed under New in the release notes) ## Vanilla reference `BlockBehaviour.hasAnalogOutputSignal` / `getAnalogOutputSignal`, `ComparatorBlock.getInputSignal`, `Level.markAndNotifyBlock` (`newState.hasAnalogOutputSignal()` → `updateNeighbourForOutputSignal`), `Level.updateNeighbourForOutputSignal`. ## Self-check - New test `level::tests::a_level_can_answer_for_a_blocks_comparator_output`, with a real comparator in the test level: - gold gives nothing by itself; - once the level says gold has an output, placing it powers the comparator; - an output that changes without the block waits for `update_neighbour_for_output_signal`; - behind a conductor it is read, and 40 clamps to 15. - In game, on the server thread, with a throwaway answer in the two hooks (gold → 11; removed before committing): gold + comparator + dust gives `power=11` and `comparator[powered=true]`. Swapping the gold for iron gives 0, and back to gold gives 11. - `python3 tools/parity.py redstone block_update`: both pass. The other affected harnesses run in CI. - `tools/pr_ready.py --quick`: fmt, clippy, Python tests and doc tests pass. `horizon-client --test lan_bot` fails 13 of 15 locally (`minecraft:dialog` registry data); main fails the same 13 on this machine, so it isn't this change. The native hook catalog tests (11) pass. 🤖 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:18:25 +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#6335
No description provided.