diff --git a/src/main/java/appeng/parts/p2p/PartP2PFEPower.java b/src/main/java/appeng/parts/p2p/PartP2PFEPower.java index 80654ff5b..0ac913fcc 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PFEPower.java +++ b/src/main/java/appeng/parts/p2p/PartP2PFEPower.java @@ -133,24 +133,42 @@ public class PartP2PFEPower extends PartP2PTunnel } final int amountPerOutput = maxReceive / outputTunnels; - int overflow = amountPerOutput == 0 ? maxReceive : maxReceive % amountPerOutput; + int overflow = 0; - if (outputs.isEmpty()) - { - for ( PartP2PFEPower o : PartP2PFEPower.this.getOutputs()) + for( PartP2PFEPower o : PartP2PFEPower.this.getOutputs() ) outputs.add( o ); - } - while ( !outputs.isEmpty() ) { + while( !outputs.isEmpty() ) + { PartP2PFEPower target = outputs.poll(); final IEnergyStorage output = target.getAttachedEnergyStorage(); - final int toSend = amountPerOutput + overflow; - final int received = output.receiveEnergy( toSend, simulate ); + final int received = output.receiveEnergy( amountPerOutput, simulate ); - overflow = toSend - received; + overflow += amountPerOutput - received; total += received; } + if( overflow > 0 ) + { + for( PartP2PFEPower o : PartP2PFEPower.this.getOutputs() ) + outputs.add( o ); + + while( !outputs.isEmpty() ) + { + PartP2PFEPower target = outputs.poll(); + final IEnergyStorage output = target.getAttachedEnergyStorage(); + final int received = output.receiveEnergy( overflow, simulate ); + + overflow -= received; + total += received; + if( overflow == 0 ) + { + outputs.clear(); + break; + } + } + } + if( !simulate ) { PartP2PFEPower.this.queueTunnelDrain( PowerUnits.RF, total ); diff --git a/src/main/java/appeng/parts/p2p/PartP2PGTCEPower.java b/src/main/java/appeng/parts/p2p/PartP2PGTCEPower.java index 133b51c7d..c6ae1ef48 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PGTCEPower.java +++ b/src/main/java/appeng/parts/p2p/PartP2PGTCEPower.java @@ -164,6 +164,7 @@ public class PartP2PGTCEPower extends PartP2PTunnel if( amperage >= amperesUsed ) { + outputs.clear(); break; } }