[PR #5707] [MERGED] Native mods: keep a mod block entity's geometry while it doesn't change #6447

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

📋 Pull Request Information

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

Base: main ← Head: mod-block-entity-keep


📝 Commits (3)

  • 6e96e6f Native mods: keep a mod block entity's geometry while it doesn't change
  • 4ef0afc Merge remote-tracking branch 'hr/main' into pr-5707
  • c3af108 Clear kept mod block entity geometry with the world; say what keep() freezes

📊 Changes

5 files changed (+239 additions, -4 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+5 -0)
📝 crates/horizon-client/src/game/native_block_entity_draw.rs (+222 -4)
📝 crates/horizon-client/src/game/packs.rs (+2 -0)
📝 crates/horizon-client/src/game/remote.rs (+2 -0)
➕ tools/native-hook-fragments/block_entity_keep.json (+8 -0)

📄 Description

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

What and why

Fixes #5671 (part of #4953). Since #5562, native_block_entity_submit and native_block_entity_render_bounding_box run every frame for every mod block entity in view, so a base of a few thousand idle machines calls the mod thousands of times a frame to rebuild geometry that has not changed.

draw.keep() inside native_block_entity_submit keeps what that call drew. The game keeps the vertices relative to the block, as SignTexts keeps a sign's text in block_entity_render.rs, with the bounds, and draws the block from them, moved to the camera, without calling either hook until something it was drawn with changes:

  • the dimension, the block state or the block's light,
  • the block entity (ModBlockEntity: what the server sent, so native_block_entity_sync redraws it),
  • the atlas: apply_staged_pack forgets everything on a resource reload.

A kept machine still goes through the frustum test (with its kept bounds), the shader-pack span and the occlusion cull each frame. A machine that is not kept is drawn every frame as before, so a mod can keep a machine while idle and stop keeping it while it runs. What is not drawn for 100 ticks is swept, as signs' text is.

Opt-in, helper-only (a method on BlockEntityDraw, a fragment of its own with empty hooks): nothing changes for a mod that doesn't call it. Everything is now drawn relative to the block and moved to the camera afterwards (one add per vertex), so kept and fresh geometry go through one path.

Checked in game (server thread, a content mod's block on the enchanting_table template, temporary code in the hooks that draws a box with native_draw_cube, not committed): over the same run the hook was called more than 512 times without keep() and once with it, and the kept box stays on its block when the camera moves (screenshot: two camera positions, one hook call). The box looks the same with and without keep(); the only pixel differences between the two runs are the clouds, which moved.

Also on a dedicated server (horizon-client --dedicated --nogui with the same content mod, one game joined with --server, the same temporary code): more than 1024 hook calls without keep() and one with it, and the kept box stays on its block from two camera positions.

Tests: kept geometry is reused while dimension, state, light, position and block entity stay, and dropped when any changes, replaced when kept again, forgotten when drawn without keep(); the sweep drops only what was not drawn in its last 100 ticks. Both fail when the block entity comparison is removed.

Conflicts with #5687 in two lines (a BlockEntityDraw field each, one line each in the loop); I'll rebase whichever lands second.

Not in scope: instanced drawing of many moving parts, the separate #4953 line; this only stops redrawing parts that don't move. The in-game check needed a local fix for #5678 (main panics on the first frame with clouds in view), 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

Horizon-only: vanilla has no such cache (BlockEntityRenderer.submit runs each frame). It follows Horizon's own SignTexts (sign text laid out once, moved to the camera).

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on kased-h610mkddr4, against upstream/main at ae4e28774, 2 min 43 s)

Check Result
Scope ✅ 4 files, +234 −4
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed (21 s)
rustfmt ✅ (5 s)
clippy ✅ (8 s)
tests: horizon-client ✅ 1635 passed (2 min 6 s)
doc tests ✅ 0 passed (1 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

Kept box from two camera positions, one hook call:

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/5707 **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-keep` --- ### 📝 Commits (3) - [`6e96e6f`](https://github.com/horizon-rust/horizon/commit/6e96e6f975f94b2cd72150b480b1c43f5009bd04) Native mods: keep a mod block entity's geometry while it doesn't change - [`4ef0afc`](https://github.com/horizon-rust/horizon/commit/4ef0afc99c24aefc4ced44064e2c1842a78813e1) Merge remote-tracking branch 'hr/main' into pr-5707 - [`c3af108`](https://github.com/horizon-rust/horizon/commit/c3af1089127a5218ad9b9d872e9b68e7403de20b) Clear kept mod block entity geometry with the world; say what keep() freezes ### 📊 Changes **5 files changed** (+239 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+5 -0) 📝 `crates/horizon-client/src/game/native_block_entity_draw.rs` (+222 -4) 📝 `crates/horizon-client/src/game/packs.rs` (+2 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+2 -0) ➕ `tools/native-hook-fragments/block_entity_keep.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 #5671 (part of #4953). Since #5562, `native_block_entity_submit` and `native_block_entity_render_bounding_box` run every frame for every mod block entity in view, so a base of a few thousand idle machines calls the mod thousands of times a frame to rebuild geometry that has not changed. `draw.keep()` inside `native_block_entity_submit` keeps what that call drew. The game keeps the vertices relative to the block, as `SignTexts` keeps a sign's text in `block_entity_render.rs`, with the bounds, and draws the block from them, moved to the camera, without calling either hook until something it was drawn with changes: - the dimension, the block state or the block's light, - the block entity (`ModBlockEntity`: what the server sent, so `native_block_entity_sync` redraws it), - the atlas: `apply_staged_pack` forgets everything on a resource reload. A kept machine still goes through the frustum test (with its kept bounds), the shader-pack span and the occlusion cull each frame. A machine that is not kept is drawn every frame as before, so a mod can keep a machine while idle and stop keeping it while it runs. What is not drawn for 100 ticks is swept, as signs' text is. Opt-in, helper-only (a method on `BlockEntityDraw`, a fragment of its own with empty `hooks`): nothing changes for a mod that doesn't call it. Everything is now drawn relative to the block and moved to the camera afterwards (one add per vertex), so kept and fresh geometry go through one path. **Checked in game** (server thread, a content mod's block on the `enchanting_table` template, temporary code in the hooks that draws a box with `native_draw_cube`, not committed): over the same run the hook was called more than 512 times without `keep()` and once with it, and the kept box stays on its block when the camera moves (screenshot: two camera positions, one hook call). The box looks the same with and without `keep()`; the only pixel differences between the two runs are the clouds, which moved. **Also on a dedicated server** (`horizon-client --dedicated --nogui` with the same content mod, one game joined with `--server`, the same temporary code): more than 1024 hook calls without `keep()` and one with it, and the kept box stays on its block from two camera positions. **Tests**: kept geometry is reused while dimension, state, light, position and block entity stay, and dropped when any changes, replaced when kept again, forgotten when drawn without `keep()`; the sweep drops only what was not drawn in its last 100 ticks. Both fail when the block entity comparison is removed. Conflicts with #5687 in two lines (a `BlockEntityDraw` field each, one line each in the loop); I'll rebase whichever lands second. Not in scope: instanced drawing of many moving parts, the separate #4953 line; this only stops redrawing parts that don't move. The in-game check needed a local fix for #5678 (main panics on the first frame with clouds in view), 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 Horizon-only: vanilla has no such cache (`BlockEntityRenderer.submit` runs each frame). It follows Horizon's own `SignTexts` (sign text laid out once, moved to the camera). ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on kased-h610mkddr4, against upstream/main at ae4e28774, 2 min 43 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +234 −4 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed (21 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (8 s) | | tests: horizon-client | ✅ 1635 passed (2 min 6 s) | | doc tests | ✅ 0 passed (1 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 Kept box from two camera positions, one hook call: <img width="640" height="720" alt="screenshot" src="https://github.com/user-attachments/assets/bbf932f6-5d23-420f-aae9-6fca81750091" /> 🤖 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:51 +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#6447
No description provided.