Fixed Energy Laser Relays causing endless power loss when transferring very small amounts of RF

Closes #375
This commit is contained in:
Ellpeck 2016-11-19 10:08:47 +01:00
parent 8f92cc5170
commit 483d20ff99

View file

@ -154,20 +154,32 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
IEnergyReceiver iReceiver = (IEnergyReceiver)tile; IEnergyReceiver iReceiver = (IEnergyReceiver)tile;
if(iReceiver.canConnectEnergy(opp)){ if(iReceiver.canConnectEnergy(opp)){
int theoreticalReceived = iReceiver.receiveEnergy(opp, Math.min(amountPer, lowestCap), true); int theoreticalReceived = iReceiver.receiveEnergy(opp, Math.min(amountPer, lowestCap), true);
if(theoreticalReceived > 0){
int deduct = this.calcDeduction(theoreticalReceived, highestLoss); int deduct = this.calcDeduction(theoreticalReceived, highestLoss);
if(deduct >= theoreticalReceived){ //Happens with small numbers
deduct = 0;
}
transmitted += iReceiver.receiveEnergy(opp, theoreticalReceived-deduct, simulate); transmitted += iReceiver.receiveEnergy(opp, theoreticalReceived-deduct, simulate);
transmitted += deduct; transmitted += deduct;
} }
} }
}
else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){ else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){
ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp); ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp);
if(cap != null){ if(cap != null){
int theoreticalReceived = (int)cap.givePower(Math.min(amountPer, lowestCap), true); int theoreticalReceived = (int)cap.givePower(Math.min(amountPer, lowestCap), true);
if(theoreticalReceived > 0){
int deduct = this.calcDeduction(theoreticalReceived, highestLoss); int deduct = this.calcDeduction(theoreticalReceived, highestLoss);
if(deduct >= theoreticalReceived){ //Happens with small numbers
deduct = 0;
}
transmitted += cap.givePower(theoreticalReceived-deduct, simulate); transmitted += cap.givePower(theoreticalReceived-deduct, simulate);
transmitted += deduct; transmitted += deduct;
} }
} }
}
//If everything that could be transmitted was transmitted //If everything that could be transmitted was transmitted
if(transmitted >= maxTransfer){ if(transmitted >= maxTransfer){