[PR #5687] [MERGED] Native mods: draw items in mod block entities, read their block state's properties #6436

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5687
Author: @ErikKalikas
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @levzzz5154

Base: main ← Head: mod-block-entity-draw-item-helpers


📝 Commits (4)

  • dcec52b Native mods: native_draw_item and native_block_state_property for drawing block entities
  • 7cb0086 Native mods: native_draw_item takes an owner, as a shelf's items have
  • 63bc913 Native mods: name ItemStackRenderState.submit, what a campfire draws its items with
  • a5937ef Merge remote-tracking branch 'upstream/main' into mod-block-entity-draw-item-helpers

📊 Changes

3 files changed (+72 additions, -5 deletions)

View changed files

📝 crates/horizon-client/src/game/native_block_entity_draw.rs (+58 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+6 -5)
➕ tools/native-hook-fragments/block_entity_draw_item.json (+8 -0)

📄 Description

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

What and why

Fixes #5669, the follow-up promised to @reservedbytes in #5562. Two helpers for native_block_entity_submit:

  • native_draw_item(draw, stack, display, owner_yaw, seed) draws an item stack under draw's pose, as a campfire's or a shelf's is drawn in the world (ItemModelResolver.updateForTopItem and ItemStackRenderState.submit, through resolve_item and submit_item_world as campfire.rs does), in the model's display transform. With owner_yaw the block entity is the item's owner, as ShelfRenderer passes its ShelfBlockEntity (position() is the block's centre, getVisualRotationYInDegrees() its facing), so a compass on it points to its target; None is a campfire's null. False for an empty stack or one with no model. Its docs say the client's copy of a block entity has no item slots (the update tag merges into nbt), so a mod sends the stacks it draws in native_block_entity_update_tag and reads them from entity.nbt (@reservedbytes's review).
  • native_block_state_property(state, key) reads a property of the hook's state (a machine's facing) from the registry, without a world lookup, so it is cheap each frame.

Helper-only: no new hook, a fragment of its own (block_entity_draw_item.json, empty hooks), since block_entity_submit has no number yet.

Checked in game (server thread, a content mod with two blocks, temporary code in the hooks, not committed): a diamond drawn over a machine on the enchanting_table template; two compasses over it, the one with an owner turned to the world spawn (the client has it at 160, 78, 160; the needle is the same in four frames a few seconds apart, as CompassAngleState gives an owner other than the local player no wobble), the one without pointing straight up; and facing read as Some("east") on a block on the furnace template, None on the machine. Over the furnace-shaped block the diamond is dark: draw.light is the block's own light (LevelRenderer.getLightCoords), 0 inside an opaque block, as #5562 documents; a mod that draws above its block sets draw.light itself.

Also on a dedicated server (horizon-client --dedicated --nogui with the same content mod, one game joined with --server, the same temporary code): both sides made the block entities, the client drew the two compasses and the diamond (native_draw_item true for all three), read facing as Some("east"), and had the server's spawn for the compass.

No unit test: both are thin calls into code that has its own (resolve_item, submit_item_world, the block registry), and a test would need a whole Game.

Note: the in-game check needed a local fix for #5678 (current main panics on the first frame with water and clouds in view); that fix is not in this PR.

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

ItemModelResolver.updateForTopItem and ItemStackRenderState.submit (as CampfireRenderer and ShelfRenderer draw their items), ShelfBlockEntity.position and getVisualRotationYInDegrees (the owner), BlockState.getValue. No harness: the helpers reuse the item and block-state code the vanilla renderers already use.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on kased-h610mkddr4, against upstream/main at 3099586bb, 4 min 11 s)

Check Result
Scope ✅ 3 files, +72 −5
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed (21 s)
rustfmt ✅ (5 s)
clippy ✅ (47 s)
tests: horizon-client ✅ 1646 passed (2 min 54 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 ➖ 278 affected, to run in CI (--quick): blending, datafix, datapack_worldgen, decorated_region, decoration, decoration_region, dedicated_server, delta, density, disk, dispenser, dynamic_support and 266 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Screenshots

Diamond over the machine:

screenshot

Two frames side by side; in each, the compass without an owner is on the left (straight up), the one with an owner on the right (turned to the spawn):

screenshot

🤖 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/5687 **Author:** [@ErikKalikas](https://github.com/ErikKalikas) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mod-block-entity-draw-item-helpers` --- ### 📝 Commits (4) - [`dcec52b`](https://github.com/horizon-rust/horizon/commit/dcec52b07ea265c1e05bf2d26c58fec063781f7a) Native mods: native_draw_item and native_block_state_property for drawing block entities - [`7cb0086`](https://github.com/horizon-rust/horizon/commit/7cb008681f042a2047f2fcf92efa2823b2475d71) Native mods: native_draw_item takes an owner, as a shelf's items have - [`63bc913`](https://github.com/horizon-rust/horizon/commit/63bc913369750c2a944d2155472e2ea5e22ec661) Native mods: name ItemStackRenderState.submit, what a campfire draws its items with - [`a5937ef`](https://github.com/horizon-rust/horizon/commit/a5937ef68204bf2386b7bc85fa26133a66ebf237) Merge remote-tracking branch 'upstream/main' into mod-block-entity-draw-item-helpers ### 📊 Changes **3 files changed** (+72 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/native_block_entity_draw.rs` (+58 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+6 -5) ➕ `tools/native-hook-fragments/block_entity_draw_item.json` (+8 -0) </details> ### 📄 Description > 🤖 Opened by ErikKalikas's AI agent (Claude Code, Claude Opus 5.5), not by ErikKalikas personally. ## What and why Fixes #5669, the follow-up promised to @reservedbytes in #5562. Two helpers for `native_block_entity_submit`: - `native_draw_item(draw, stack, display, owner_yaw, seed)` draws an item stack under `draw`'s pose, as a campfire's or a shelf's is drawn in the world (`ItemModelResolver.updateForTopItem` and `ItemStackRenderState.submit`, through `resolve_item` and `submit_item_world` as `campfire.rs` does), in the model's `display` transform. With `owner_yaw` the block entity is the item's owner, as `ShelfRenderer` passes its `ShelfBlockEntity` (`position()` is the block's centre, `getVisualRotationYInDegrees()` its facing), so a compass on it points to its target; `None` is a campfire's `null`. False for an empty stack or one with no model. Its docs say the client's copy of a block entity has no item slots (the update tag merges into `nbt`), so a mod sends the stacks it draws in `native_block_entity_update_tag` and reads them from `entity.nbt` (@reservedbytes's review). - `native_block_state_property(state, key)` reads a property of the hook's `state` (a machine's `facing`) from the registry, without a world lookup, so it is cheap each frame. Helper-only: no new hook, a fragment of its own (`block_entity_draw_item.json`, empty `hooks`), since `block_entity_submit` has no number yet. **Checked in game** (server thread, a content mod with two blocks, temporary code in the hooks, not committed): a diamond drawn over a machine on the `enchanting_table` template; two compasses over it, the one with an owner turned to the world spawn (the client has it at 160, 78, 160; the needle is the same in four frames a few seconds apart, as `CompassAngleState` gives an owner other than the local player no wobble), the one without pointing straight up; and `facing` read as `Some("east")` on a block on the `furnace` template, `None` on the machine. Over the furnace-shaped block the diamond is dark: `draw.light` is the block's own light (`LevelRenderer.getLightCoords`), 0 inside an opaque block, as #5562 documents; a mod that draws above its block sets `draw.light` itself. **Also on a dedicated server** (`horizon-client --dedicated --nogui` with the same content mod, one game joined with `--server`, the same temporary code): both sides made the block entities, the client drew the two compasses and the diamond (`native_draw_item` true for all three), read `facing` as `Some("east")`, and had the server's spawn for the compass. No unit test: both are thin calls into code that has its own (`resolve_item`, `submit_item_world`, the block registry), and a test would need a whole `Game`. Note: the in-game check needed a local fix for #5678 (current main panics on the first frame with water and clouds in view); that fix is not in this PR. ## 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 `ItemModelResolver.updateForTopItem` and `ItemStackRenderState.submit` (as `CampfireRenderer` and `ShelfRenderer` draw their items), `ShelfBlockEntity.position` and `getVisualRotationYInDegrees` (the owner), `BlockState.getValue`. No harness: the helpers reuse the item and block-state code the vanilla renderers already use. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on kased-h610mkddr4, against upstream/main at 3099586bb, 4 min 11 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +72 −5 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed (21 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (47 s) | | tests: horizon-client | ✅ 1646 passed (2 min 54 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 | ➖ 278 affected, to run in CI (--quick): blending, datafix, datapack_worldgen, decorated_region, decoration, decoration_region, dedicated_server, delta, density, disk, dispenser, dynamic_support and 266 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## Screenshots Diamond over the machine: <img width="1280" height="720" alt="screenshot" src="https://github.com/user-attachments/assets/c37d013a-bed4-4bef-a7b2-c2056922811b" /> Two frames side by side; in each, the compass without an owner is on the left (straight up), the one with an owner on the right (turned to the spawn): <img width="800" height="260" alt="screenshot" src="https://github.com/user-attachments/assets/e4298d34-ad45-4fc3-b6c4-b8cff9636d49" /> 🤖 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:20:34 +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#6436
No description provided.