[PR #5512] [MERGED] Native mods: a mod block decides if it can stay where it is #6328

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5512
Author: @PzmuV1517
Created: 10/31/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: mods/can-survive


📝 Commits (2)

  • b1f3afc Native mods: a mod block decides if it can stay where it is
  • 4eb27f4 Piston head: a neighbour change asks can_survive, so a mod's answer counts

📊 Changes

7 files changed (+244 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+16 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+39 -0)
📝 crates/horizon-world/src/level/hooks.rs (+1 -1)
📝 crates/horizon-world/src/level/mod.rs (+25 -0)
📝 crates/horizon-world/src/level/survive.rs (+9 -1)
📝 crates/horizon-world/src/level/tests.rs (+140 -0)
➕ tools/native-hook-fragments/can_survive.json (+14 -0)

📄 Description

What and why

Fixes #5486. Part of #4953.

A mod block couldn't answer vanilla's canSurvive, so a mod plant couldn't say which blocks it grows on, or pop off when the block under it goes. This adds two hooks on GameLevel, both on an authoritative server, both through LevelAccess as native_update_shape (#4899) is:

  • native_can_survive(dimension, pos, state, survives) answers BlockState.canSurvive before the block's own rule. The level asks it wherever vanilla does: as a block is placed (BlockItem.canPlace: Some(false) refuses the spot), from the shape update of a block whose template checks it (a plant, a torch, a sign: Some(false) breaks it with its drops when a neighbour changes), and every other caller of can_survive. state may not be in the world yet (it is being placed), so a mod decides from state.
  • native_may_place_on(dimension, state, ground, ground_pos, may) answers VegetationBlock.mayPlaceOn: the blocks a mod plant (a content block whose template is a vanilla plant, such as a crop) can stand on. Its template's canSurvive asks it, so the plant is refused elsewhere and pops off when its ground changes.

A mod answers only for its own blocks and leaves the answer empty otherwise; the level is read-only. A mod block whose template doesn't check canSurvive in its shape update (a plain block) can break itself through native_update_shape, as before.

Without a mod nothing changes: the two LevelAccess defaults do nothing and the game's are an empty inline hook behind native_authoritative. The deprecated in-frame path fires neither. The hooks come in a fragment (tools/native-hook-fragments/can_survive.json); the API number is stamped after merge.

Tested in the game

With a test copy of this branch whose hooks answer for vanilla blocks (dandelions stand on stone only; glass can't be placed above y 100), not committed. Blocks placed as a player through horizon-ctl place:

Check Server thread (single player) Dedicated server (--dedicated, a client joined)
A dandelion placed on stone (vanilla refuses) ✅ placed ✅ placed
A dandelion on dirt (vanilla allows) ✅ refused ✅ refused
Its stone set to cobblestone ✅ pops off, drops a dandelion ✅ pops off
Glass at y 90 / y 111 ✅ placed / refused ✅ placed / refused

No panics or errors in either log. On the dedicated server the console checked each block (execute if block).

survive_hooks_answer_for_the_block (horizon-world) covers the same in the level: mayPlaceOn lets a dandelion onto stone, its shape update breaks it with its drops when the ground changes, canSurvive answered either way wins over the block's rule, and without an answer the block's own rule runs. It fails with the hook taken out.

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

BlockBehaviour.canSurvive, BlockItem.canPlace, VegetationBlock.mayPlaceOn, VegetationBlock.updateShape. Names from NeoForge's public API: none (NeoForge overrides these methods in a block subclass).

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on Mac, against origin/main at ef0dd81a1, 6 min 52 s)

Check Result
Scope ✅ 6 files, +243 −1
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ✅ 510 passed (22 s)
rustfmt ✅ (4 s)
Rust ⚠️ 1.98.1 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with rustup update
clippy ✅ (1 min 59 s)
tests: horizon-client, horizon-world ❌ 1552 passed, 13 failed (4 min 20 s). All 13 are tests/lan_bot.rs, which asserts that minecraft:dialog's registry data is sent without its entries to a client that knows the vanilla pack; they fail the same way on main at ef0dd81a1
doc tests ✅ 0 passed (3 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 ➖ 336 affected, to run in CI (--quick)
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/5512 **Author:** [@PzmuV1517](https://github.com/PzmuV1517) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `mods/can-survive` --- ### 📝 Commits (2) - [`b1f3afc`](https://github.com/horizon-rust/horizon/commit/b1f3afcd9a0f7a2905797097a92590a0030cd310) Native mods: a mod block decides if it can stay where it is - [`4eb27f4`](https://github.com/horizon-rust/horizon/commit/4eb27f42164cd81d4b91dac06ad24340cbce3e4f) Piston head: a neighbour change asks can_survive, so a mod's answer counts ### 📊 Changes **7 files changed** (+244 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+16 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+39 -0) 📝 `crates/horizon-world/src/level/hooks.rs` (+1 -1) 📝 `crates/horizon-world/src/level/mod.rs` (+25 -0) 📝 `crates/horizon-world/src/level/survive.rs` (+9 -1) 📝 `crates/horizon-world/src/level/tests.rs` (+140 -0) ➕ `tools/native-hook-fragments/can_survive.json` (+14 -0) </details> ### 📄 Description ## What and why Fixes #5486. Part of #4953. A mod block couldn't answer vanilla's `canSurvive`, so a mod plant couldn't say which blocks it grows on, or pop off when the block under it goes. This adds two hooks on `GameLevel`, both on an authoritative server, both through `LevelAccess` as `native_update_shape` (#4899) is: - **`native_can_survive(dimension, pos, state, survives)`** answers `BlockState.canSurvive` before the block's own rule. The level asks it wherever vanilla does: as a block is placed (`BlockItem.canPlace`: `Some(false)` refuses the spot), from the shape update of a block whose template checks it (a plant, a torch, a sign: `Some(false)` breaks it with its drops when a neighbour changes), and every other caller of `can_survive`. `state` may not be in the world yet (it is being placed), so a mod decides from `state`. - **`native_may_place_on(dimension, state, ground, ground_pos, may)`** answers `VegetationBlock.mayPlaceOn`: the blocks a mod plant (a content block whose template is a vanilla plant, such as a crop) can stand on. Its template's `canSurvive` asks it, so the plant is refused elsewhere and pops off when its ground changes. A mod answers only for its own blocks and leaves the answer empty otherwise; the level is read-only. A mod block whose template doesn't check `canSurvive` in its shape update (a plain block) can break itself through `native_update_shape`, as before. Without a mod nothing changes: the two `LevelAccess` defaults do nothing and the game's are an empty inline hook behind `native_authoritative`. The deprecated in-frame path fires neither. The hooks come in a fragment (`tools/native-hook-fragments/can_survive.json`); the API number is stamped after merge. ## Tested in the game With a test copy of this branch whose hooks answer for vanilla blocks (dandelions stand on stone only; glass can't be placed above y 100), not committed. Blocks placed as a player through `horizon-ctl place`: | Check | Server thread (single player) | Dedicated server (`--dedicated`, a client joined) | | --- | --- | --- | | A dandelion placed on stone (vanilla refuses) | ✅ placed | ✅ placed | | A dandelion on dirt (vanilla allows) | ✅ refused | ✅ refused | | Its stone set to cobblestone | ✅ pops off, drops a dandelion | ✅ pops off | | Glass at y 90 / y 111 | ✅ placed / refused | ✅ placed / refused | No panics or errors in either log. On the dedicated server the console checked each block (`execute if block`). `survive_hooks_answer_for_the_block` (horizon-world) covers the same in the level: `mayPlaceOn` lets a dandelion onto stone, its shape update breaks it with its drops when the ground changes, `canSurvive` answered either way wins over the block's rule, and without an answer the block's own rule runs. It fails with the hook taken out. ## 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 `BlockBehaviour.canSurvive`, `BlockItem.canPlace`, `VegetationBlock.mayPlaceOn`, `VegetationBlock.updateShape`. Names from NeoForge's public API: none (NeoForge overrides these methods in a block subclass). ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on Mac, against origin/main at ef0dd81a1, 6 min 52 s) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +243 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ✅ 510 passed (22 s) | | rustfmt | ✅ (4 s) | | Rust | ⚠️ 1.98.1 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with `rustup update` | | clippy | ✅ (1 min 59 s) | | tests: horizon-client, horizon-world | ❌ 1552 passed, 13 failed (4 min 20 s). All 13 are `tests/lan_bot.rs`, which asserts that `minecraft:dialog`'s registry data is sent without its entries to a client that knows the vanilla pack; they fail the same way on main at ef0dd81a1 | | doc tests | ✅ 0 passed (3 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 | ➖ 336 affected, to run in CI (--quick) | | 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 06:18:18 +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#6328
No description provided.