[GH-ISSUE #6227] Native mods: energy handler on blocks, Capabilities.Energy.BLOCK #2024

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

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

Originally assigned to: @levzzz5154 on GitHub.

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

Part of #4953 ("Energy handler on blocks (Capabilities.Energy.BLOCK)").

A tech mod's generators, cables and machines pass energy between blocks. Horizon has item handlers (#5130) and fluid handlers (#5188, #5203) on blocks, but nothing for energy: a mod must invent its own storage, its own saving and its own transfer rules.

Vanilla has no energy, so the contract comes from NeoForge's javadoc: Capabilities.Energy.BLOCK is a sided EnergyHandler (formerly IEnergyStorage): getAmountAsLong/getCapacityAsLong, insert(amount) and extract(amount) each answer how much they moved, between 0 and amount; SimpleEnergyHandler has a capacity, a per-call maxInsert and maxExtract, saves the amount as the int energy, and EnergyHandlerUtil.move(from, to, amount) asks the source what it can give, offers that to the target, takes back exactly what the target accepted, and does nothing if the source can't give that.

Proposed, in the shape of the fluid handler (machines/native_fluids.rs), no new vanilla firing point:

  • Hook native_block_entity_energy(block, energy): a mod block declares its buffer as a ModEnergyBuffer: capacity, max_insert and max_extract per call, and the faces a fill may come through and a drain may leave by. Asked once for each mod block when the ticking table is built, like native_block_entity_fluids.
  • The amount lives in the block entity's saved compound under energy (an int, as SimpleEnergyHandler.serialize), so it survives restarts and the block's own tick reads and writes it.
  • Helpers on the server (never on a client's copy), for the level in place:
    • native_energy(dimension, pos, face): amount, capacity, per-call limits and whether this face may fill or drain.
    • native_energy_insert(pos, face, amount, simulate) and native_energy_extract(dimension, pos, face, amount, simulate): the amount moved, simulate changing nothing (the old IEnergyStorage contract).
    • native_move_energy(dimension, from, from_face, to, to_face, max): EnergyHandlerUtil.move's rule between two blocks; the amount moved.

Server side only (the single player's server thread and a dedicated server). Energy on items and entities (Capabilities.Energy.ITEM/.ENTITY) are separate items. API from a fragment.

Originally created by @levzzz5154 on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6227 Originally assigned to: @levzzz5154 on GitHub. > 🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. Part of #4953 ("Energy handler on blocks (`Capabilities.Energy.BLOCK`)"). A tech mod's generators, cables and machines pass energy between blocks. Horizon has item handlers (#5130) and fluid handlers (#5188, #5203) on blocks, but nothing for energy: a mod must invent its own storage, its own saving and its own transfer rules. Vanilla has no energy, so the contract comes from NeoForge's javadoc: `Capabilities.Energy.BLOCK` is a sided `EnergyHandler` (formerly `IEnergyStorage`): `getAmountAsLong`/`getCapacityAsLong`, `insert(amount)` and `extract(amount)` each answer how much they moved, between 0 and `amount`; `SimpleEnergyHandler` has a capacity, a per-call `maxInsert` and `maxExtract`, saves the amount as the int `energy`, and `EnergyHandlerUtil.move(from, to, amount)` asks the source what it can give, offers that to the target, takes back exactly what the target accepted, and does nothing if the source can't give that. Proposed, in the shape of the fluid handler (`machines/native_fluids.rs`), no new vanilla firing point: - Hook `native_block_entity_energy(block, energy)`: a mod block declares its buffer as a `ModEnergyBuffer`: `capacity`, `max_insert` and `max_extract` per call, and the faces a fill may come through and a drain may leave by. Asked once for each mod block when the ticking table is built, like `native_block_entity_fluids`. - The amount lives in the block entity's saved compound under `energy` (an int, as `SimpleEnergyHandler.serialize`), so it survives restarts and the block's own tick reads and writes it. - Helpers on the server (never on a client's copy), for the level in place: - `native_energy(dimension, pos, face)`: amount, capacity, per-call limits and whether this face may fill or drain. - `native_energy_insert(pos, face, amount, simulate)` and `native_energy_extract(dimension, pos, face, amount, simulate)`: the amount moved, `simulate` changing nothing (the old `IEnergyStorage` contract). - `native_move_energy(dimension, from, from_face, to, to_face, max)`: `EnergyHandlerUtil.move`'s rule between two blocks; the amount moved. Server side only (the single player's server thread and a dedicated server). Energy on items and entities (`Capabilities.Energy.ITEM`/`.ENTITY`) are separate items. API from a fragment.
Author
Owner

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

/claim

<!-- gh-comment-id:6561914462 --> @levzzz5154 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#2024
No description provided.