[PR #5151] [MERGED] Native mods: read and change item entities near a block (API next) #6103

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5151
Author: @levzzz5154
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @levzzz5154

Base: main ← Head: mods/native-item-entities


📝 Commits (3)

  • fc9326b Native mods: read and change item entities near a block
  • 9021ffb Merge remote-tracking branch 'hr/main' into mods/native-item-entities
  • 0d2a9d8 Docs: API 41 stays bundles' data files

📊 Changes

2 files changed (+90 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game/native_hooks.rs (+83 -1)
📝 docs/native-mods.md (+7 -0)

📄 Description

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

What and why

Fixes #5150. Part of #4953 and #3911 (Mods). NATIVE_HOOKS_API 40 → 41 (API next: the number is set at merge; #5140 and #5146 ask for the next one too).

Two server helpers (not hook points, so no catalog entry), for machines that pick up dropped items as a hopper does:

  • native_item_entities(dimension, min, max) -> Vec<NativeItemEntity>: the item entities whose box meets min..max, in the level's order. Each comes with its entity id, position, stack and pickup delay. This is vanilla's Level.getEntitiesOfClass(ItemEntity.class, box, ENTITY_STILL_ALIVE) with AABB.intersects, the test Horizon's hopper (suck_item_entities) already uses.
  • native_set_item_entity(dimension, id, stack) -> bool: replaces one's stack (ItemEntity.setItem). An empty stack removes it (setItem(EMPTY) then discard), as HopperBlockEntity.addItem does with what it takes. Players see it through the entity tracker, as with the hopper.

Both act on the level in place, as native_set_block does. A mod's block-entity and level-tick hooks run with their level in place. On a client of a server the list is empty and writes return false.

Kind

  • feature: something new for players (listed under New in the release notes)
  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

26.3's HopperBlockEntity:

  • getItemsAtAndAbove is level.getEntitiesOfClass(ItemEntity.class, aabb, EntitySelector.ENTITY_STILL_ALIVE).
  • addItem(Container, ItemEntity) does entity.setItem(result), or setItem(ItemStack.EMPTY) and discard() when the result is empty.

Other projects' code

none

Tested in the game

A throwaway native_tick probe (removed before the commit) runs on the server's Game every 40 ticks. It lists the item entities in the column [-1, -64, -1]..[2, 320, 2] and takes one item from each with native_set_item_entity. It also asks for the Nether (not in place) and writes to minecraft:nope. Items come from /summon item … {PickupDelay:32767}. Fresh mktemp -d homes, HORIZON_NO_AUDIO=1, --profile fast.

Run Server log What the client sees (horizon-ctl entities 64 item)
Single player: diamond ×3 at (0.5, 0.5), iron ×1 at (1.5, 1.5), gold ×2 at (5.5, 5.5), outside the box tick 40: 2 entities: diamond 3→2, iron 1→0 (removed). Tick 80: diamond 2→1. Tick 120: diamond 1→0 (removed). Then 0 entities. Nether: 0 every time; nope write: false diamond 2, gold 2 → diamond 1, gold 2 → gold 2 only. Gold untouched
Dedicated (--dedicated --nogui), console summon, client Alex at (4, 4) diamond 3→2→1→removed over ticks 240–320; gold never listed Alex: gold 2, diamond 1 → gold 2 → gold 2
The clients' own Game lists nothing, writes nothing

Unit: native_hooks::tests pass.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at 01bbb4c65, 54 s)

Check Result
Scope ✅ 2 files, +90 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (25 s)
rustfmt ✅ (5 s)
clippy ✅ (11 s)
tests: horizon-client ✅ 1340 passed (12 s)
doc tests ✅ 0 passed (1 s)
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses

🤖 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/5151 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/native-item-entities` --- ### 📝 Commits (3) - [`fc9326b`](https://github.com/horizon-rust/horizon/commit/fc9326b05eeedc301f8a51ea3b765dc6e1b0750b) Native mods: read and change item entities near a block - [`9021ffb`](https://github.com/horizon-rust/horizon/commit/9021ffb4f52d00e2ea2316f4f67244ba5ba4cde4) Merge remote-tracking branch 'hr/main' into mods/native-item-entities - [`0d2a9d8`](https://github.com/horizon-rust/horizon/commit/0d2a9d8402bf7270a3f350850a95df7ae1a26d2c) Docs: API 41 stays bundles' data files ### 📊 Changes **2 files changed** (+90 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/native_hooks.rs` (+83 -1) 📝 `docs/native-mods.md` (+7 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. ## What and why Fixes #5150. Part of #4953 and #3911 (Mods). `NATIVE_HOOKS_API` 40 → 41 (**API next**: the number is set at merge; #5140 and #5146 ask for the next one too). Two server helpers (not hook points, so no catalog entry), for machines that pick up dropped items as a hopper does: - **`native_item_entities(dimension, min, max) -> Vec<NativeItemEntity>`**: the item entities whose box meets `min..max`, in the level's order. Each comes with its entity id, position, stack and pickup delay. This is vanilla's `Level.getEntitiesOfClass(ItemEntity.class, box, ENTITY_STILL_ALIVE)` with `AABB.intersects`, the test Horizon's hopper (`suck_item_entities`) already uses. - **`native_set_item_entity(dimension, id, stack) -> bool`**: replaces one's stack (`ItemEntity.setItem`). An empty stack removes it (`setItem(EMPTY)` then `discard`), as `HopperBlockEntity.addItem` does with what it takes. Players see it through the entity tracker, as with the hopper. Both act on the level in place, as `native_set_block` does. A mod's block-entity and level-tick hooks run with their level in place. On a client of a server the list is empty and writes return false. ## Kind - [x] feature: something new for players (listed under New in the release notes) - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference 26.3's `HopperBlockEntity`: - `getItemsAtAndAbove` is `level.getEntitiesOfClass(ItemEntity.class, aabb, EntitySelector.ENTITY_STILL_ALIVE)`. - `addItem(Container, ItemEntity)` does `entity.setItem(result)`, or `setItem(ItemStack.EMPTY)` and `discard()` when the result is empty. ## Other projects' code none ## Tested in the game A throwaway `native_tick` probe (removed before the commit) runs on the server's `Game` every 40 ticks. It lists the item entities in the column `[-1, -64, -1]..[2, 320, 2]` and takes one item from each with `native_set_item_entity`. It also asks for the Nether (not in place) and writes to `minecraft:nope`. Items come from `/summon item … {PickupDelay:32767}`. Fresh `mktemp -d` homes, `HORIZON_NO_AUDIO=1`, `--profile fast`. | Run | Server log | What the client sees (`horizon-ctl entities 64 item`) | |---|---|---| | Single player: diamond ×3 at (0.5, 0.5), iron ×1 at (1.5, 1.5), gold ×2 at (5.5, 5.5), outside the box | tick 40: 2 entities: diamond 3→2, iron 1→0 (removed). Tick 80: diamond 2→1. Tick 120: diamond 1→0 (removed). Then 0 entities. Nether: 0 every time; `nope` write: false | diamond 2, gold 2 → diamond 1, gold 2 → gold 2 only. Gold untouched | | Dedicated (`--dedicated --nogui`), console `summon`, client Alex at (4, 4) | diamond 3→2→1→removed over ticks 240–320; gold never listed | Alex: gold 2, diamond 1 → gold 2 → gold 2 | | The clients' own `Game` | lists nothing, writes nothing | | Unit: `native_hooks::tests` pass. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at 01bbb4c65, 54 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +90 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (25 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (11 s) | | tests: horizon-client | ✅ 1340 passed (12 s) | | doc tests | ✅ 0 passed (1 s) | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | 🤖 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:11:41 +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#6103
No description provided.