[PR #5516] [MERGED] Native mods: a mod block chooses the state it is placed in #6333

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

📋 Pull Request Information

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

Base: main ← Head: mods/placement-state


📝 Commits (7)

  • 09a67d8 Native mods: a mod block chooses the state it is placed in
  • 6c49483 Native mods: a placement answer must be the placed block's own state
  • 2aec9b4 Native mods: the placement hook's test covers a dispenser too
  • 86165f5 Native mods: the placement fragment's summary is one JSON string
  • 124cd2a Dispenser placement: getRotation is -90 facing up or down
  • c30ebd6 Merge main into #5516 (both sides' level hooks kept)
  • 57ae349 Merge remote-tracking branch 'origin/main' into n5516

📊 Changes

8 files changed (+425 additions, -23 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+15 -2)
📝 crates/horizon-client/src/game/dispenser.rs (+10 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+78 -2)
📝 crates/horizon-world/src/level/falling.rs (+1 -1)
📝 crates/horizon-world/src/level/mod.rs (+20 -1)
📝 crates/horizon-world/src/level/place.rs (+62 -16)
📝 crates/horizon-world/src/level/tests.rs (+229 -0)
➕ tools/native-hook-fragments/placement_state.json (+10 -0)

📄 Description

🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi personally.

Closes #5489. Part of #4953, under Mod block behaviour ("whether a block can stay where it is, bone meal, and the state it is placed in").

What and why

A native mod's block could only be placed in its default state: getStateForPlacement had no way in. Now the level is asked, and the mod block answers:

// The hook a bundle injects (crates/horizon-client/src/game/native_hooks.rs).
pub(super) fn native_state_for_placement(
    &self,
    dimension: LevelDimension,
    state: BlockStateId,          // the block's own default state
    context: &PlacementContext,   // vanilla's BlockPlaceContext
    fluid: FluidState,            // the fluid where the block would go
    answer: &mut Option<Option<BlockStateId>>,
) { }
  • Some(Some(state)): that state is placed.
  • Some(None): refuses the placement, as vanilla's null return does — the block goes nowhere and the stack is kept.
  • left empty: the block's own getStateForPlacement runs, so a mod that answers nothing is untouched.

context is what the issue lists: the clicked face, the placer's rotation (yaw/pitch, so a block can face the player or sit on the clicked face), the clicked position and the click location, whether the clicked block is being replaced, isInside, and the item in hand. fluid is the fluid already in the position the block would go in, which is what a waterlogged block reads.

native_state_with_property(state, key, value) builds the state from the default state the hook is given and one of the block's properties — a content block's own declared state_properties (#5306) included — so a mod does not need an id table.

Kind

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

A native hook is feature like #5469 (mods' own sound events); players see nothing until a mod uses it, so skip-release may suit the maintainer better — their call.

Every placer that goes through vanilla's path

The hook is called in Sim::state_for_placement, the one function that computes getStateForPlacement for every placer: the player's BlockItem.place (use_hand → Behaviours::place_block → Sim::placement) and a dispenser's DirectionalPlaceContext (dispense_shulker_box → directional_can_place + place_block). /setblock, templates and world generation bypass it, as they bypass getStateForPlacement in vanilla. The answer still takes vanilla's canSurvive and isUnobstructed checks, and an id past the state table is refused rather than trusted.

PlacementContext is the renamed, now public Ctx: it was pub(crate), so a LevelAccess hook could not take it. It is the vanilla type the hook is about — BlockPlaceContext after the replaceable-click rule — so it gets a doc comment per field instead of a second, duplicated struct at the boundary.

Vanilla reference

Block.getStateForPlacement(BlockPlaceContext), BlockPlaceContext (getClickedPos, getClickedFace, getClickLocation, isInside, getRotation, isSecondaryUseActive, replacingClickedOnBlock, getItemInHand), Block.canBeReplaced, BlockItem.place, DirectionalPlaceContext/ShulkerBoxDispenseBehavior. No decompiled sources on this machine (no .local/), so the port's existing place.rs, which already follows those methods, was the reference. No harness: level_place (tools/test_level_place_parity.py) covers vanilla's placement and is untouched by a hook that vanilla has no answer for.

Other projects' code

None.

Self-check

pr_ready (tools/pr_ready.py --quick on MacBookPro, against origin/main at 21bddafb2, 1 min 25 s)

Check Result
Scope ✅ 7 files, +415 −22
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 487 run, FAILED (errors=13, skipped=1) (1 min 1 s)
rustfmt ✅ (7 s)
clippy ✅ (1 s)
tests: horizon-client, horizon-world ✅ 1925 passed (12 s)
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 ➖ 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)

The 13 Python errors are this machine's Python 3.9, not this change: tools/lab.py digests with hashlib.file_digest, which arrived in 3.11 (test_lab.TestArtifactTests, test_parity_runner, test_rust_parity, test_block_survival_parity, test_roadmap). No Python file is touched here.

Tests

  • the_level_chooses_the_state_a_block_is_placed_in (crates/horizon-world/src/level/tests.rs) — a LevelAccess that answers for a furnace: its state is what the placement returns, not vanilla's; the hook is handed the block's default state, the position the block would go in (above the clicked stone), the clicked position, the face, the item in hand, and that the click replaced nothing; then clicking water hands it FluidKind::Water and replacingClickedOnBlock, with sneaking; Some(None) returns no state (the placement fails); with no answer the furnace places as vanilla does; a block the hook does not answer for is unaffected; and an id past the state table, or another block's state, is not trusted. A dispenser's DirectionalPlaceContext (directional_can_place then place_block) is driven too: the furnace lands in the hook's state, with the dispenser's own click.
  • a_placement_state_is_built_from_a_blocks_own_properties (native_hooks.rs) — building a state from a block's default state and one of its declared properties keeps the others, and a value the property does not have builds nothing.
  • Not run locally: the level tests need the prepared vanilla data (HORIZON_RESOURCES, or .local/horizon-client/26.3), which this machine does not have, so the_level_chooses_... passes CI only; locally it skips like every other test in that file. The rest ran here: cargo test -p horizon-world --lib (267), cargo test -p horizon-client --lib --bins (1082 + 444), cargo clippy -p horizon-world -p horizon-client --all-targets, cargo fmt --all -- --check.
  • Not tested in game: no prepared resources on this machine, so no server-thread run and no screenshot.

API

Pending fragment tools/native-hook-fragments/placement_state.json (hook state_for_placement, v1) plus the helper native_state_with_property, as #5161 asks: no number is taken here.

🤖 Generated with DeepSeek Harness (deepseek-v4.1-flash)


🔄 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/5516 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `mods/placement-state` --- ### 📝 Commits (7) - [`09a67d8`](https://github.com/horizon-rust/horizon/commit/09a67d8c48415d9d1ff2aa1c0241619c8433dba5) Native mods: a mod block chooses the state it is placed in - [`6c49483`](https://github.com/horizon-rust/horizon/commit/6c494834f562dc38ce6215aa4fb83e7566715e60) Native mods: a placement answer must be the placed block's own state - [`2aec9b4`](https://github.com/horizon-rust/horizon/commit/2aec9b416e734f805d529a1a9506815fd0e38ecc) Native mods: the placement hook's test covers a dispenser too - [`86165f5`](https://github.com/horizon-rust/horizon/commit/86165f575443393e3db12bb5e7d656f8c228b34c) Native mods: the placement fragment's summary is one JSON string - [`124cd2a`](https://github.com/horizon-rust/horizon/commit/124cd2ac33a48144aa83d300a403291925295285) Dispenser placement: getRotation is -90 facing up or down - [`c30ebd6`](https://github.com/horizon-rust/horizon/commit/c30ebd6aaf20c120e458f0f8e98e13fd3e141a47) Merge main into #5516 (both sides' level hooks kept) - [`57ae349`](https://github.com/horizon-rust/horizon/commit/57ae3494b86e0ab2677403044ef2efdc3f2f08f1) Merge remote-tracking branch 'origin/main' into n5516 ### 📊 Changes **8 files changed** (+425 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+15 -2) 📝 `crates/horizon-client/src/game/dispenser.rs` (+10 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+78 -2) 📝 `crates/horizon-world/src/level/falling.rs` (+1 -1) 📝 `crates/horizon-world/src/level/mod.rs` (+20 -1) 📝 `crates/horizon-world/src/level/place.rs` (+62 -16) 📝 `crates/horizon-world/src/level/tests.rs` (+229 -0) ➕ `tools/native-hook-fragments/placement_state.json` (+10 -0) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (DeepSeek Harness, deepseek-v4.1-flash), not by sirrayi personally. Closes #5489. Part of #4953, under **Mod block behaviour** ("whether a block can stay where it is, bone meal, and the state it is placed in"). ## What and why A native mod's block could only be placed in its default state: `getStateForPlacement` had no way in. Now the level is asked, and the mod block answers: ```rust // The hook a bundle injects (crates/horizon-client/src/game/native_hooks.rs). pub(super) fn native_state_for_placement( &self, dimension: LevelDimension, state: BlockStateId, // the block's own default state context: &PlacementContext, // vanilla's BlockPlaceContext fluid: FluidState, // the fluid where the block would go answer: &mut Option<Option<BlockStateId>>, ) { } ``` - `Some(Some(state))`: that state is placed. - `Some(None)`: refuses the placement, as vanilla's `null` return does — the block goes nowhere and the stack is kept. - left empty: the block's own `getStateForPlacement` runs, so a mod that answers nothing is untouched. `context` is what the issue lists: the clicked face, the placer's rotation (yaw/pitch, so a block can face the player or sit on the clicked face), the clicked position and the click location, whether the clicked block is being replaced, `isInside`, and the item in hand. `fluid` is the fluid already in the position the block would go in, which is what a waterlogged block reads. `native_state_with_property(state, key, value)` builds the state from the default state the hook is given and one of the block's properties — a content block's own declared `state_properties` (#5306) included — so a mod does not need an id table. ## Kind - [x] feature: something new for players - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs A native hook is `feature` like #5469 (mods' own sound events); players see nothing until a mod uses it, so `skip-release` may suit the maintainer better — their call. ## Every placer that goes through vanilla's path The hook is called in `Sim::state_for_placement`, the one function that computes `getStateForPlacement` for every placer: the player's `BlockItem.place` (`use_hand` → `Behaviours::place_block` → `Sim::placement`) and a dispenser's `DirectionalPlaceContext` (`dispense_shulker_box` → `directional_can_place` + `place_block`). `/setblock`, templates and world generation bypass it, as they bypass `getStateForPlacement` in vanilla. The answer still takes vanilla's `canSurvive` and `isUnobstructed` checks, and an id past the state table is refused rather than trusted. `PlacementContext` is the renamed, now public `Ctx`: it was `pub(crate)`, so a `LevelAccess` hook could not take it. It is the vanilla type the hook is about — `BlockPlaceContext` after the replaceable-click rule — so it gets a doc comment per field instead of a second, duplicated struct at the boundary. ## Vanilla reference `Block.getStateForPlacement(BlockPlaceContext)`, `BlockPlaceContext` (`getClickedPos`, `getClickedFace`, `getClickLocation`, `isInside`, `getRotation`, `isSecondaryUseActive`, `replacingClickedOnBlock`, `getItemInHand`), `Block.canBeReplaced`, `BlockItem.place`, `DirectionalPlaceContext`/`ShulkerBoxDispenseBehavior`. No decompiled sources on this machine (no `.local/`), so the port's existing `place.rs`, which already follows those methods, was the reference. No harness: `level_place` (`tools/test_level_place_parity.py`) covers vanilla's placement and is untouched by a hook that vanilla has no answer for. ## Other projects' code None. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on MacBookPro, against origin/main at 21bddafb2, 1 min 25 s) | Check | Result | | --- | --- | | Scope | ✅ 7 files, +415 −22 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 487 run, FAILED (errors=13, skipped=1) (1 min 1 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 s) | | tests: horizon-client, horizon-world | ✅ 1925 passed (12 s) | | 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 | ➖ 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) | The 13 Python errors are this machine's Python 3.9, not this change: `tools/lab.py` digests with `hashlib.file_digest`, which arrived in 3.11 (`test_lab.TestArtifactTests`, `test_parity_runner`, `test_rust_parity`, `test_block_survival_parity`, `test_roadmap`). No Python file is touched here. ## Tests - `the_level_chooses_the_state_a_block_is_placed_in` (`crates/horizon-world/src/level/tests.rs`) — a `LevelAccess` that answers for a furnace: its state is what the placement returns, not vanilla's; the hook is handed the block's default state, the position the block would go in (above the clicked stone), the clicked position, the face, the item in hand, and that the click replaced nothing; then clicking water hands it `FluidKind::Water` and `replacingClickedOnBlock`, with sneaking; `Some(None)` returns no state (the placement fails); with no answer the furnace places as vanilla does; a block the hook does not answer for is unaffected; and an id past the state table, or another block's state, is not trusted. A dispenser's `DirectionalPlaceContext` (`directional_can_place` then `place_block`) is driven too: the furnace lands in the hook's state, with the dispenser's own click. - `a_placement_state_is_built_from_a_blocks_own_properties` (`native_hooks.rs`) — building a state from a block's default state and one of its declared properties keeps the others, and a value the property does not have builds nothing. - **Not run locally:** the level tests need the prepared vanilla data (`HORIZON_RESOURCES`, or `.local/horizon-client/26.3`), which this machine does not have, so `the_level_chooses_...` passes CI only; locally it skips like every other test in that file. The rest ran here: `cargo test -p horizon-world --lib` (267), `cargo test -p horizon-client --lib --bins` (1082 + 444), `cargo clippy -p horizon-world -p horizon-client --all-targets`, `cargo fmt --all -- --check`. - **Not tested in game:** no prepared resources on this machine, so no server-thread run and no screenshot. ## API Pending fragment `tools/native-hook-fragments/placement_state.json` (hook `state_for_placement`, v1) plus the helper `native_state_with_property`, as #5161 asks: no number is taken here. 🤖 Generated with DeepSeek Harness (deepseek-v4.1-flash) --- <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:24 +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#6333
No description provided.