[PR #4055] [MERGED] Native mods: item slots for mod block entities (hoppers, comparators, drops) #5387

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4055
Author: @Sylviromi
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: native-mod-inventories


📝 Commits (6)

  • f57fe83 Native mods: item slots for mod block entities (hoppers, comparators, drops)
  • 99791ea Merge branch 'native-mod-block-entities' into native-mod-inventories
  • 027aef4 Merge branch 'native-mod-block-entities' into native-mod-inventories
  • 4459fe3 Native mods: a mod's own Items stays its own
  • 14d7f03 Native mods: item slots are API 5
  • 5edf728 Merge main; item slots for mod block entities are API 16; a block entity that breaks its own block drops its contents

📊 Changes

10 files changed (+283 additions, -34 deletions)

View changed files

📝 crates/horizon-client-render/src/block_entities.rs (+11 -1)
📝 crates/horizon-client-render/src/chunk/block_entity.rs (+16 -2)
📝 crates/horizon-client-render/src/containers.rs (+8 -8)
📝 crates/horizon-client/src/game/block_entity_ticks.rs (+2 -0)
📝 crates/horizon-client/src/game/machines.rs (+79 -12)
📝 crates/horizon-client/src/game/native_hooks.rs (+93 -8)
📝 crates/horizon-client/src/game/spill.rs (+21 -1)
📝 crates/horizon-client/src/save.rs (+45 -2)
📝 docs/native-mods.md (+3 -0)
📝 native-hooks.json (+5 -0)

📄 Description

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

Stacked on #3996: review only the last commit (f57fe836c, +220 −32 over #3996's branch).

What and why

Fixes #4034. Part of #3911 (Mods): item slots for mod block entities, gap "V, inventories" in #1854 (124 of ATM10's 307 code mods).

  • native_block_entity_container(block, &mut Option<ModContainer>) (new hook point, API 5): a mod block's block entity is a container, said as a WorldlyContainer says it, as data: the slot count (at most 256, Slot is a byte), the slots each face reaches (getSlotsForFace), and the slots hoppers may put into (canPlaceItemThroughFace) and take from (canTakeItemThroughFace). Asked once per mod block when the ticking table is built, kept by block state beside it (BlockEntities::mod_container), so the container code reaches it through the world and needs no hook calls.
  • The container code vanilla's blocks use (game/machines.rs): a Mod block entity with a container is Kind::Mod, so hoppers push and pull through its faces, droppers insert, and comparators read it (AbstractContainerMenu.getRedstoneSignalFromContainer).
  • Drops: breaking the block drops its slots (BaseContainerBlockEntity.preRemoveSideEffects → Containers.dropContents).
  • Saves: the slots are the block entity's Items (ContainerHelper), taken out of the mod's compound on load and put back on save. They grow to the container's count when first used and never shrink, so items a mod no longer has room for stay saved.
  • The tick hook gets the slots: native_block_entity_tick(pos, id, nbt, slots: &mut [Option<ItemStack>]), so a machine moves items between them. This changes #3996's hook before it is released (API 4 → 5).

Out of scope: menus (opening a screen on the block) and client sync (#4028).

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 (the native mod API), shaped after WorldlyContainer (getSlotsForFace, canPlaceItemThroughFace, canTakeItemThroughFace), HopperBlockEntity, ContainerHelper.saveAllItems/loadAllItems and Containers.dropContents. Without a mod nothing changes: vanilla's containers never get Kind::Mod.

Self-check

New tests: mod_container_tests::mod_container_slots_by_face, and mod_block_entity_round_trips now checks that Items become slots and save back equal. catalog_matches_hook_points covers the new hook (in native-hooks.json).

pr_ready (tools/pr_ready.py --quick, against origin/main at 829c4021a, 2 min 25 s; the scope includes #3996)

Check Result
Scope ✅ 14 files, +373 −26
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 475 passed (33 s)
rustfmt ✅ (7 s)
clippy ✅ (43 s)
tests: horizon-client, horizon-client-render ❌ 688 passed, 1 failed: the axolotl test of #3840 (runs only with prepared resources; passes in CI)
doc tests ✅ (2 s)
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses

Proof: a 3-slot machine mod

The test mod of #3996, built with horizon-mixins 0d6b103 on this branch: testmachine:counter now has three slots like a furnace's (input from the top, slot 0; from the sides, slot 1; output from the bottom, slot 2), and every 10 ticks its tick moves one item from slot 0 to slot 2. Driven through horizon-ctl (offscreen, single player on the server thread, scratch homes):

Step Result
A hopper above with 64 iron ore, a hopper below, 6 s above 44 left; machine [{Slot:0b, count:4}]; below 14
Hoppers removed, save and quit (machine [{Slot:0b, count:3}, {Slot:2b, count:1}] just before)
Reopen machine [{Slot:2b, count:4}]: kept, and the tick finished moving them
Mine the machine one item entity, 4 iron ore; "The target block is not a block entity"

Not covered: comparators and droppers against a mod container (same code path as hoppers, not run), LAN guests and dedicated servers.

🤖 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/4055 **Author:** [@Sylviromi](https://github.com/Sylviromi) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `native-mod-inventories` --- ### 📝 Commits (6) - [`f57fe83`](https://github.com/horizon-rust/horizon/commit/f57fe836c40b80c81e0235ca10ec3964b9a1de8d) Native mods: item slots for mod block entities (hoppers, comparators, drops) - [`99791ea`](https://github.com/horizon-rust/horizon/commit/99791ea225045c5188e18e6a19eacda1030aaaf1) Merge branch 'native-mod-block-entities' into native-mod-inventories - [`027aef4`](https://github.com/horizon-rust/horizon/commit/027aef4b3b150d5c12394c21570899fa8ec1fbc6) Merge branch 'native-mod-block-entities' into native-mod-inventories - [`4459fe3`](https://github.com/horizon-rust/horizon/commit/4459fe39891e7a2e84bf44373289197fb609d586) Native mods: a mod's own Items stays its own - [`14d7f03`](https://github.com/horizon-rust/horizon/commit/14d7f036c3d5c35dc29ed8f370e4e5ad0c294c53) Native mods: item slots are API 5 - [`5edf728`](https://github.com/horizon-rust/horizon/commit/5edf728ee3a36c042bb049e041aa0eb63f366729) Merge main; item slots for mod block entities are API 16; a block entity that breaks its own block drops its contents ### 📊 Changes **10 files changed** (+283 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/block_entities.rs` (+11 -1) 📝 `crates/horizon-client-render/src/chunk/block_entity.rs` (+16 -2) 📝 `crates/horizon-client-render/src/containers.rs` (+8 -8) 📝 `crates/horizon-client/src/game/block_entity_ticks.rs` (+2 -0) 📝 `crates/horizon-client/src/game/machines.rs` (+79 -12) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+93 -8) 📝 `crates/horizon-client/src/game/spill.rs` (+21 -1) 📝 `crates/horizon-client/src/save.rs` (+45 -2) 📝 `docs/native-mods.md` (+3 -0) 📝 `native-hooks.json` (+5 -0) </details> ### 📄 Description > 🤖 Opened by Sylviromi's AI agent (Claude Code, Claude Opus 5.5), not by Sylviromi personally. **Stacked on #3996: review only the last commit** (`f57fe836c`, +220 −32 over #3996's branch). ## What and why Fixes #4034. Part of #3911 (Mods): item slots for mod block entities, gap "V, inventories" in #1854 (124 of ATM10's 307 code mods). - **`native_block_entity_container(block, &mut Option<ModContainer>)`** (new hook point, API 5): a mod block's block entity is a container, said as a `WorldlyContainer` says it, as data: the slot count (at most 256, `Slot` is a byte), the slots each face reaches (`getSlotsForFace`), and the slots hoppers may put into (`canPlaceItemThroughFace`) and take from (`canTakeItemThroughFace`). Asked once per mod block when the ticking table is built, kept by block state beside it (`BlockEntities::mod_container`), so the container code reaches it through the world and needs no hook calls. - **The container code vanilla's blocks use** (`game/machines.rs`): a `Mod` block entity with a container is `Kind::Mod`, so hoppers push and pull through its faces, droppers insert, and comparators read it (`AbstractContainerMenu.getRedstoneSignalFromContainer`). - **Drops**: breaking the block drops its slots (`BaseContainerBlockEntity.preRemoveSideEffects` → `Containers.dropContents`). - **Saves**: the slots are the block entity's `Items` (`ContainerHelper`), taken out of the mod's compound on load and put back on save. They grow to the container's count when first used and never shrink, so items a mod no longer has room for stay saved. - **The tick hook gets the slots**: `native_block_entity_tick(pos, id, nbt, slots: &mut [Option<ItemStack>])`, so a machine moves items between them. This changes #3996's hook before it is released (API 4 → 5). Out of scope: menus (opening a screen on the block) and client sync (#4028). ## 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 (the native mod API), shaped after `WorldlyContainer` (`getSlotsForFace`, `canPlaceItemThroughFace`, `canTakeItemThroughFace`), `HopperBlockEntity`, `ContainerHelper.saveAllItems`/`loadAllItems` and `Containers.dropContents`. Without a mod nothing changes: vanilla's containers never get `Kind::Mod`. ## Self-check New tests: `mod_container_tests::mod_container_slots_by_face`, and `mod_block_entity_round_trips` now checks that `Items` become slots and save back equal. `catalog_matches_hook_points` covers the new hook (in `native-hooks.json`). **pr_ready** (`tools/pr_ready.py --quick`, against origin/main at 829c4021a, 2 min 25 s; the scope includes #3996) | Check | Result | | --- | --- | | Scope | ✅ 14 files, +373 −26 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 475 passed (33 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (43 s) | | tests: horizon-client, horizon-client-render | ❌ 688 passed, 1 failed: the axolotl test of #3840 (runs only with prepared resources; passes in CI) | | doc tests | ✅ (2 s) | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | ## Proof: a 3-slot machine mod The test mod of #3996, built with horizon-mixins `0d6b103` on this branch: `testmachine:counter` now has three slots like a furnace's (input from the top, slot 0; from the sides, slot 1; output from the bottom, slot 2), and every 10 ticks its tick moves one item from slot 0 to slot 2. Driven through `horizon-ctl` (offscreen, single player on the server thread, scratch homes): | Step | Result | | --- | --- | | A hopper above with 64 iron ore, a hopper below, 6 s | above 44 left; machine `[{Slot:0b, count:4}]`; below 14 | | Hoppers removed, save and quit (machine `[{Slot:0b, count:3}, {Slot:2b, count:1}]` just before) | | | Reopen | machine `[{Slot:2b, count:4}]`: kept, and the tick finished moving them | | Mine the machine | one item entity, 4 iron ore; "The target block is not a block entity" | Not covered: comparators and droppers against a mod container (same code path as hoppers, not run), LAN guests and dedicated servers. 🤖 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 05:12:14 +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#5387
No description provided.