[PR #4872] [MERGED] feat(mods): native mods can change their blocks on random ticks #5905

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

📋 Pull Request Information

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

Base: main ← Head: feat/native-random-tick


📝 Commits (2)

  • c832b61 feat(mods): native mods can change their blocks on random ticks
  • e776e8e Merge hr/main; renumber random-tick hook to API 33; guard the Game property writers, test with_property

📊 Changes

7 files changed (+328 additions, -15 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+16 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+132 -14)
📝 crates/horizon-world/src/level/mod.rs (+16 -0)
📝 crates/horizon-world/src/level/tests.rs (+131 -0)
📝 crates/horizon-world/src/level/tick.rs (+8 -1)
📝 docs/native-mods.md (+20 -0)
📝 native-hooks.json (+5 -0)

📄 Description

What and why

A native mod can't make its blocks grow or change on their own yet (crops, soil, spreading blocks)

native_random_tick fires where ServerLevel.tickChunk random-ticks a block, before BlockState.randomTick, only for blocks that tick randomly
The mod can change the block with the level's native_set_block_property(ticks, pos, key, value, flags), and set handled to skip the block's own random tick
flags is vanilla's setBlock flags, so a mod crop grows with flags::UPDATE_CLIENTS (2) as vanilla's crops do (no neighborChanged, comparators not told), and a block that should tell its neighbours uses UPDATE_ALL
Horizon sends every block write to players whatever the flags, so bits 2, 4 and 8 change nothing yet
The merged Game::native_set_block_property keeps its signature and gets a sibling native_set_block_property_with(..., flags) for block entity ticks (vanilla's brewing stand writes with 2)
If it changes the block without handled, the block's own tick runs on the new state (if it still ticks randomly), not the old one

Server side only: the server thread, a LAN host and dedicated servers
It fires from tickChunk only, not from bone meal, and lava's fluid random tick still runs either way

Without a mod nothing changes: in an optimized build tick_chunk_random is the same code as on main, instruction for instruction
With a mod that handles its crop, a handled tick costs about 1.1 µs, most of it the block write

#4817 adds Game::native_set_block with flags too, for a whole state from Game, this one changes a property and works from the level hook

Named after the vanilla call, like #4302 and #4483
This bumps the hook points API to 23 (renumbered at merge if needed)

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

ServerLevel.tickChunk (the isRandomlyTicking check, then randomTick, then the fluid's tick from the same read)

Self-check

The one failure is a_candle_on_an_uneaten_cake_makes_a_candle_cake (#4780)

Check Result
Scope ✅ 7 files, +297 −15
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ✅ 481 passed (57 s)
rustfmt ✅ (9 s)
clippy ✅ (2 min 30 s)
tests: horizon-client, horizon-world ❌ 1470 passed, 1 failed (6 min 59 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)

🔄 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/4872 **Author:** [@reservedbytes](https://github.com/reservedbytes) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `feat/native-random-tick` --- ### 📝 Commits (2) - [`c832b61`](https://github.com/horizon-rust/horizon/commit/c832b61617bbd05867ca04ee2bc1bdf2281fc38f) feat(mods): native mods can change their blocks on random ticks - [`e776e8e`](https://github.com/horizon-rust/horizon/commit/e776e8e94aa5a5bc6a082cf6322a73b121229430) Merge hr/main; renumber random-tick hook to API 33; guard the Game property writers, test with_property ### 📊 Changes **7 files changed** (+328 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+16 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+132 -14) 📝 `crates/horizon-world/src/level/mod.rs` (+16 -0) 📝 `crates/horizon-world/src/level/tests.rs` (+131 -0) 📝 `crates/horizon-world/src/level/tick.rs` (+8 -1) 📝 `docs/native-mods.md` (+20 -0) 📝 `native-hooks.json` (+5 -0) </details> ### 📄 Description ## What and why A native mod can't make its blocks grow or change on their own yet (crops, soil, spreading blocks) `native_random_tick` fires where `ServerLevel.tickChunk` random-ticks a block, before `BlockState.randomTick`, only for blocks that tick randomly The mod can change the block with the level's `native_set_block_property(ticks, pos, key, value, flags)`, and set `handled` to skip the block's own random tick `flags` is vanilla's `setBlock` flags, so a mod crop grows with `flags::UPDATE_CLIENTS` (2) as vanilla's crops do (no `neighborChanged`, comparators not told), and a block that should tell its neighbours uses `UPDATE_ALL` Horizon sends every block write to players whatever the flags, so bits 2, 4 and 8 change nothing yet The merged `Game::native_set_block_property` keeps its signature and gets a sibling `native_set_block_property_with(..., flags)` for block entity ticks (vanilla's brewing stand writes with 2) If it changes the block without `handled`, the block's own tick runs on the new state (if it still ticks randomly), not the old one Server side only: the server thread, a LAN host and dedicated servers It fires from `tickChunk` only, not from bone meal, and lava's fluid random tick still runs either way Without a mod nothing changes: in an optimized build `tick_chunk_random` is the same code as on main, instruction for instruction With a mod that handles its crop, a handled tick costs about 1.1 µs, most of it the block write #4817 adds `Game::native_set_block` with flags too, for a whole state from `Game`, this one changes a property and works from the level hook Named after the vanilla call, like #4302 and #4483 This bumps the hook points API to 23 (renumbered at merge if needed) ## 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 `ServerLevel.tickChunk` (the `isRandomlyTicking` check, then `randomTick`, then the fluid's tick from the same read) ## Self-check The one failure is `a_candle_on_an_uneaten_cake_makes_a_candle_cake` (#4780) | Check | Result | | --- | --- | | Scope | ✅ 7 files, +297 −15 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ✅ 481 passed (57 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (2 min 30 s) | | tests: horizon-client, horizon-world | ❌ 1470 passed, 1 failed (6 min 59 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) | --- <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:50 +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#5905
No description provided.