[GH-ISSUE #6553] Native mods: energy in an item, Capabilities.Energy.ITEM #2133

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

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

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 ("Energy on items (Capabilities.Energy.ITEM)").

A tech mod's batteries, charged tools and armour, and the slot a machine charges or drains them in, need energy held by an item stack. Horizon has energy in mod blocks (#6330) and fluid in items (#6331), but nothing for energy in items: a mod must invent where a stack keeps its charge, how it stacks, and the rules for putting energy in and taking it out.

Vanilla has no energy, so the contract comes from NeoForge's public docs (capabilities, transactions): Capabilities.Energy.ITEM gives an EnergyHandler for an item, reached through its ItemAccess like Capabilities.FluidHandler.ITEM, so it acts on one item of a stack and may change that item. insert(amount) and extract(amount) each answer how much they moved, between 0 and amount; SimpleEnergyHandler has a capacity and limits on insertion and extraction. In the current API they run in a transaction, and a simulation is a transaction left uncommitted.

Proposed, in the shape of the item fluid helpers (native_item_fluids.rs, #6331) and the block energy buffer (#6330), no new vanilla firing point:

  • Hook native_item_energy_buffer(item, buffer): a mod item declares that it holds energy, with capacity, max_insert and max_extract per call. Asked at each call of the helpers below, as native_item_fluid_tank is.
  • The amount lives in the stack's minecraft:custom_data under horizon_energy (an int, as the block's energy), so it is saved and sent with the stack. An empty item carries nothing, so empty batteries stack with new ones.
  • Helpers that take a stack and change nothing, so they work on any side:
    • native_item_energy(stack): amount, capacity and per-call limits of one item of the stack; none for an item that holds no energy.
    • native_item_energy_insert(stack, amount) and native_item_energy_extract(stack, amount): the amount moved and the single item it becomes. The caller shrinks its stack by one and hands out the result, as with the item fluid helpers; leaving the result unused is the simulation.
  • Energy between a block and an item (a charger slot) can then be the block's native_energy_extract with simulate, the item's insert, and the block's extract of what the item took. A helper for that is a later step.

A mod can already draw the charge with native_item_bar. Server and client alike, since no world state is read. Energy on entities (Capabilities.Energy.ENTITY) is a separate item. API from a fragment.

How to test: give a mod item a buffer in native_item_energy_buffer, fill it from a mod block's buffer (#6330) and check that the amount survives saving, moving between slots and a dedicated server's client, and that empty items stack.

Originally created by @ErikKalikas on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6553 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 ("Energy on items (`Capabilities.Energy.ITEM`)"). A tech mod's batteries, charged tools and armour, and the slot a machine charges or drains them in, need energy held by an item stack. Horizon has energy in mod blocks (#6330) and fluid in items (#6331), but nothing for energy in items: a mod must invent where a stack keeps its charge, how it stacks, and the rules for putting energy in and taking it out. Vanilla has no energy, so the contract comes from NeoForge's public docs (capabilities, transactions): `Capabilities.Energy.ITEM` gives an `EnergyHandler` for an item, reached through its `ItemAccess` like `Capabilities.FluidHandler.ITEM`, so it acts on one item of a stack and may change that item. `insert(amount)` and `extract(amount)` each answer how much they moved, between 0 and `amount`; `SimpleEnergyHandler` has a capacity and limits on insertion and extraction. In the current API they run in a transaction, and a simulation is a transaction left uncommitted. Proposed, in the shape of the item fluid helpers (`native_item_fluids.rs`, #6331) and the block energy buffer (#6330), no new vanilla firing point: - Hook `native_item_energy_buffer(item, buffer)`: a mod item declares that it holds energy, with `capacity`, `max_insert` and `max_extract` per call. Asked at each call of the helpers below, as `native_item_fluid_tank` is. - The amount lives in the stack's `minecraft:custom_data` under `horizon_energy` (an int, as the block's `energy`), so it is saved and sent with the stack. An empty item carries nothing, so empty batteries stack with new ones. - Helpers that take a stack and change nothing, so they work on any side: - `native_item_energy(stack)`: amount, capacity and per-call limits of one item of the stack; none for an item that holds no energy. - `native_item_energy_insert(stack, amount)` and `native_item_energy_extract(stack, amount)`: the amount moved and the single item it becomes. The caller shrinks its stack by one and hands out the result, as with the item fluid helpers; leaving the result unused is the simulation. - Energy between a block and an item (a charger slot) can then be the block's `native_energy_extract` with `simulate`, the item's insert, and the block's extract of what the item took. A helper for that is a later step. A mod can already draw the charge with `native_item_bar`. Server and client alike, since no world state is read. Energy on entities (`Capabilities.Energy.ENTITY`) is a separate item. API from a fragment. **How to test:** give a mod item a buffer in `native_item_energy_buffer`, fill it from a mod block's buffer (#6330) and check that the amount survives saving, moving between slots and a dedicated server's client, and that empty items stack.
Author
Owner

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

/claim

<!-- gh-comment-id:6565167725 --> @ErikKalikas commented on GitHub (Nov 1, 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#2133
No description provided.