Skip to content

Conversation

@Rover656
Copy link
Member

@Rover656 Rover656 commented Jan 27, 2026

Description

Removes energy throttling for energy inputs and makes machines that output energy do so evenly.

Closes #1225

Breaking Changes

Generator blocks will now always output energy by default, something that used to be the case but broke when we started to rewrite machines. This is now the desired behaviour.

Checklist

  • My code follows the style guidelines of this project (.editorconfig, most IDEs will use this for you).
  • I have made corresponding changes to the documentation.
  • My changes are ready for review from a contributor.

Summary by CodeRabbit

  • Configuration Changes

    • Removed the energy input throttling option, simplifying machine energy behaviour.
  • New Features

    • Added a reusable utility to distribute energy evenly across multiple sides.
    • Exposed per-side push/pull checks for energy I/O modes.
  • Improvements

    • Centralised and standardised side-agnostic energy distribution across machines.
    • Made resource distribution overridable to allow customised machine behaviour.

✏️ Tip: You can customize this high-level summary in your review settings.

@Rover656 Rover656 added Type-Enhancement New feature or enhancement to existing feature. Area-Backend Backend work not usually visible to players. MC-1.21.1 labels Jan 27, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

Walkthrough

Adds per-IOMode push/pull checks, removes energy input throttling, centralises machine energy distribution into TransferUtil.distributeEnergyEvenly, makes distributeResources overridable, and updates callers and storages to use the new distribution and drop input-throttling logic.

Changes

Cohort / File(s) Summary
API: Energy I/O
enderio/src/main/java/com/enderio/enderio/api/io/energy/EnergyIOMode.java
Added canPush(IOMode) and canPull(IOMode) methods that validate direction viability, connection ability and (optionally) delegate to the provided IOMode.
Configuration
enderio/src/main/java/com/enderio/enderio/config/machines/common/EnergyConfig.java
Removed THROTTLE_ENERGY_INPUT config field and its builder initialization (throttle option deleted).
Centralised Transfer Utility
enderio/src/main/java/com/enderio/enderio/foundation/io/TransferUtil.java
New distributeEnergyEvenly(Level, BlockPos, Function<Direction,Boolean>) method and internal EnergyStoragePair record to collect compatible sender/receiver pairs and distribute energy evenly.
Machine distribution refactor
enderio/src/main/java/com/enderio/enderio/foundation/block/entity/PoweredMachineBlockEntity.java, enderio/src/main/java/com/enderio/enderio/foundation/block/entity/legacy/LegacyPoweredMachineBlockEntity.java
Replaced per-side manual push logic with calls to TransferUtil.distributeEnergyEvenly(...); energy push eligibility now resolved via energyIOMode.canPush(getIOMode(dir)).
Energy storage: remove throttling
enderio/src/main/java/com/enderio/enderio/foundation/energy/PoweredMachineEnergyStorage.java, enderio/src/main/java/com/enderio/enderio/foundation/io/energy/MachineEnergyStorage.java
Removed runtime input-throttling logic that previously capped maxReceive based on config; receiveEnergy now uses raw maxReceive.
Inheritance tweak
enderio/src/main/java/com/enderio/enderio/foundation/block/entity/MachineBlockEntity.java
Removed final from distributeResources() allowing subclasses to override distribution behaviour.
Conduit distribution logic
enderio/src/main/java/com/enderio/enderio/content/conduits/type/energy/EnergyConduitTicker.java
Minor sorting and sharing refactor: uses Comparator.comparingInt and Guava Ints.saturatedCast to compute per-handler share amounts.

Sequence Diagram(s)

sequenceDiagram
  participant Machine as MachineBlockEntity
  participant Transfer as TransferUtil
  participant Level as Level/World
  participant Neighbor as NeighborBlockEntity

  Machine->>Transfer: distributeEnergyEvenly(level, pos, canPushTo)
  Transfer->>Level: inspect adjacent positions
  loop directions where canPushTo(dir) == true
    Transfer->>Machine: obtain self IEnergyStorage for dir
    Transfer->>Neighbor: obtain neighbour IEnergyStorage for dir
    alt both handlers present and compatible
      Transfer->>Transfer: record EnergyStoragePair(self, receiver)
    end
  end
  Transfer->>Transfer: compute total available energy from primary self handler
  loop distribute until exhausted or receivers full
    Transfer->>Neighbor: insert share into receiver
    Transfer->>Machine: extract actual transferred energy from source
    Transfer->>Transfer: update remainingEnergy and receiver state
  end
  Transfer-->>Machine: complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nudged the cables in the night,
Shared currents danced in soft moonlight,
The meadow’s stores now flow in line,
No throttles block the steady shine,
Hooray — the grid hums warm and bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarises the main changes: removing energy throttling and implementing even energy distribution across machines.
Description check ✅ Passed The description covers the main changes, links the related issue, documents breaking changes, and completes the checklist template with necessary sections.
Linked Issues check ✅ Passed The PR fully addresses the objectives from #1225: removes energy input throttling, implements even energy distribution for power-producing blocks, and ensures machine push behaviour distributes evenly.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objectives of removing throttling and implementing even energy distribution; no extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
enderio/src/main/java/com/enderio/enderio/foundation/block/entity/legacy/LegacyPoweredMachineBlockEntity.java (1)

198-200: shouldPushEnergyTo is dead code and should be integrated into the energy distribution predicate.

The shouldPushEnergyTo(Direction) method and its overrides in SolarPanelBlockEntity and CapacitorBankBlockEntity are never called. The pushEnergy() method uses only energyIOMode.canPush(getIOMode(dir)) in the distribution predicate, bypassing the multiblock check that the Javadoc indicates this method was designed to enforce.

Since subclasses provide meaningful implementations for this check, integrate it into the predicate:

Suggested fix
-        TransferUtil.distributeEnergyEvenly(level, worldPosition, dir -> energyIOMode.canPush(getIOMode(dir)));
+        TransferUtil.distributeEnergyEvenly(level, worldPosition, dir -> energyIOMode.canPush(getIOMode(dir)) && shouldPushEnergyTo(dir));
🧹 Nitpick comments (2)
enderio/src/main/java/com/enderio/enderio/foundation/io/energy/MachineEnergyStorage.java (1)

5-5: Remove unused MachinesConfig import.

The MachinesConfig import on line 5 is unused after throttling logic was removed. Consider removing it to keep imports clean.

Suggested cleanup
-import com.enderio.enderio.config.machines.MachinesConfig;
enderio/src/main/java/com/enderio/enderio/foundation/block/entity/PoweredMachineBlockEntity.java (1)

7-7: Remove the unused IOMode import.

The IOMode type is not directly referenced in this file. Although getIOMode(dir) is called on line 145, the return value is only passed to another method without any explicit type reference to IOMode.

🧹 Suggested removal
-import com.enderio.enderio.api.io.IOMode;

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@enderio/src/main/java/com/enderio/enderio/foundation/io/TransferUtil.java`:
- Around line 151-167: The loop in TransferUtil.java uses integer division
(shareAmount = energyRemaining / toShareWith) which yields 0 for early receivers
when energyRemaining < toShareWith; change the share calculation to use ceiling
division so any remaining energy is distributed as evenly as possible (e.g.,
shareAmount = ceil(energyRemaining / toShareWith)) before calling
transfer.receiver.receiveEnergy, keep using
transfer.self.extractEnergy(inserted, false) and decrement energyRemaining and
toShareWith as before so receivers never get skipped when energy remains.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
enderio/src/main/java/com/enderio/enderio/content/conduits/type/energy/EnergyConduitTicker.java (1)

74-75: Sorting order contradicts the comment.

The comment states "Try to fill smaller buffers first", but Integer.compare(b.right(), a.right()) sorts in descending order, placing handlers with larger receivable capacity first. If the intent is to fill smaller buffers first, the comparator should be Integer.compare(a.right(), b.right()).

Please verify which behaviour is intended and either fix the sort order or correct the comment.

🔧 If filling smaller buffers first is intended
-        // Try to fill smaller buffers first.
-        insertHandlers.sort((a, b) -> Integer.compare(b.right(), a.right()));
+        // Try to fill smaller buffers first.
+        insertHandlers.sort((a, b) -> Integer.compare(a.right(), b.right()));
🔧 If filling larger buffers first is intended
-        // Try to fill smaller buffers first.
+        // Try to fill larger buffers first.
         insertHandlers.sort((a, b) -> Integer.compare(b.right(), a.right()));
🧹 Nitpick comments (1)
enderio/src/main/java/com/enderio/enderio/foundation/io/TransferUtil.java (1)

163-168: Consider handling the case where extraction fails after successful insertion.

The code assumes extractEnergy will always succeed after receiveEnergy succeeds, but if extraction fails (returns less than inserted), energyRemaining would desync from actual available energy.

This is likely a theoretical edge case given the @apiNote assumption of a single shared buffer, but adding a defensive check would improve robustness.

♻️ Optional defensive extraction handling
             int inserted = transfer.receiver.receiveEnergy(shareAmount, false);
             if (inserted > 0) {
-                transfer.self.extractEnergy(inserted, false);
-                energyRemaining -= inserted;
+                int extracted = transfer.self.extractEnergy(inserted, false);
+                energyRemaining -= extracted;
             }

@Rover656 Rover656 force-pushed the feat/remove-energy-throttling branch from 4937c61 to 3253269 Compare January 27, 2026 00:33
@Rover656 Rover656 merged commit e20afd0 into 1.21.1 Jan 27, 2026
5 checks passed
@Rover656 Rover656 deleted the feat/remove-energy-throttling branch January 27, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Backend Backend work not usually visible to players. MC-1.21.1 Type-Enhancement New feature or enhancement to existing feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC] Remove energy input throttling

2 participants