[GH-ISSUE #6768] Native mods: items in an item, Capabilities.Item.ITEM #2209

Closed
opened 2026-11-02 15:53:01 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @ErikKalikas on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6768

Originally assigned to: @ErikKalikas on GitHub.

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

Part of #4953 ("Item handler on items (Capabilities.Item.ITEM)").

A tech mod's backpacks, storage cells and toolboxes are items that hold items. Horizon has items in blocks (#5130), fluid in items (#6331) and energy in items (#6596), but nothing for items in items: a mod must invent where a stack keeps its contents, how they are saved and sent, and which items may go in.

NeoForge's contract, from its public docs: Capabilities.Item.ITEM is a ResourceHandler<ItemResource> for "portable backpacks and such", reached through an ItemAccess, so it acts on one item of a stack and may change that item. Vanilla already keeps a container item's contents in the minecraft:container component (ItemContainerContents, the shulker box's), and refuses a shulker box inside one (ShulkerBoxSlot.mayPlace → Item.canFitInsideContainerItems, false for BlockItems of a ShulkerBoxBlock).

Proposed, in the shape of the item fluid and energy helpers (native_item_fluids.rs, native_item_energy.rs), no new vanilla firing point:

  • Hook native_item_container(item, slots): a mod item holds slots slots (clamped to 1..=256, the component's limit). Asked at each call of the helpers below.
  • The contents live in the stack's minecraft:container, as a shulker box item keeps them, so they are saved and sent with the stack. An empty item carries nothing, so it stacks with a new one.
  • Helpers that take a stack and change nothing, so they work on any side:
    • native_item_container_slots(stack): the slots of one item of the stack, empty ones included; none for an item without slots.
    • native_item_container_insert(stack, item): as much of item as fits, topping up equal stacks first and then the first empty slots (the order SimpleContainer.addItem uses), by vanilla's rule above (no shulker box inside); the count that went in and the single container it becomes.
    • native_item_container_extract(stack, slot, max): up to max from slot; what came out and the single container it becomes.
    • The caller shrinks its stack by one and hands out the result, as with the fluid and energy helpers; leaving it unused is the simulation.

Open questions: should vanilla's shulker boxes answer as built-in 27-slot containers, as vanilla's buckets do for fluids in #6331? Bundles hold by weight (BundleContents), not by slot, so they would be a separate item. The hook takes a typed mod API contract in the form #6253 settles.

How to test: give a mod item slots in native_item_container, fill and empty it with the helpers, and check that the contents survive saving, moving between slots and a dedicated server's client, that a shulker box is refused, and that an emptied item stacks with a new one.

Originally created by @ErikKalikas on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6768 Originally assigned to: @ErikKalikas on GitHub. > 🤖 Filed by ErikKalikas's AI agent (Claude Code, Claude Opus 5.5), not by ErikKalikas personally. Part of #4953 ("Item handler on items (`Capabilities.Item.ITEM`)"). A tech mod's backpacks, storage cells and toolboxes are items that hold items. Horizon has items in blocks (#5130), fluid in items (#6331) and energy in items (#6596), but nothing for items in items: a mod must invent where a stack keeps its contents, how they are saved and sent, and which items may go in. NeoForge's contract, from its public docs: `Capabilities.Item.ITEM` is a `ResourceHandler<ItemResource>` for "portable backpacks and such", reached through an `ItemAccess`, so it acts on one item of a stack and may change that item. Vanilla already keeps a container item's contents in the `minecraft:container` component (`ItemContainerContents`, the shulker box's), and refuses a shulker box inside one (`ShulkerBoxSlot.mayPlace` → `Item.canFitInsideContainerItems`, false for `BlockItem`s of a `ShulkerBoxBlock`). Proposed, in the shape of the item fluid and energy helpers (`native_item_fluids.rs`, `native_item_energy.rs`), no new vanilla firing point: - Hook `native_item_container(item, slots)`: a mod item holds `slots` slots (clamped to 1..=256, the component's limit). Asked at each call of the helpers below. - The contents live in the stack's `minecraft:container`, as a shulker box item keeps them, so they are saved and sent with the stack. An empty item carries nothing, so it stacks with a new one. - Helpers that take a stack and change nothing, so they work on any side: - `native_item_container_slots(stack)`: the slots of one item of the stack, empty ones included; none for an item without slots. - `native_item_container_insert(stack, item)`: as much of `item` as fits, topping up equal stacks first and then the first empty slots (the order `SimpleContainer.addItem` uses), by vanilla's rule above (no shulker box inside); the count that went in and the single container it becomes. - `native_item_container_extract(stack, slot, max)`: up to `max` from `slot`; what came out and the single container it becomes. - The caller shrinks its stack by one and hands out the result, as with the fluid and energy helpers; leaving it unused is the simulation. Open questions: should vanilla's shulker boxes answer as built-in 27-slot containers, as vanilla's buckets do for fluids in #6331? Bundles hold by weight (`BundleContents`), not by slot, so they would be a separate item. The hook takes a typed mod API contract in the form #6253 settles. **How to test:** give a mod item slots in `native_item_container`, fill and empty it with the helpers, and check that the contents survive saving, moving between slots and a dedicated server's client, that a shulker box is refused, and that an emptied item stacks with a new one.
Author
Owner

@ErikKalikas commented on GitHub (Nov 2, 2026):

/claim

<!-- gh-comment-id:6568956925 --> @ErikKalikas commented on GitHub (Nov 2, 2026): /claim
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#2209
No description provided.