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,18 +154,30 @@ 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);
int deduct = this.calcDeduction(theoreticalReceived, highestLoss); if(theoreticalReceived > 0){
transmitted += iReceiver.receiveEnergy(opp, theoreticalReceived-deduct, simulate); int deduct = this.calcDeduction(theoreticalReceived, highestLoss);
transmitted += deduct; if(deduct >= theoreticalReceived){ //Happens with small numbers
deduct = 0;
}
transmitted += iReceiver.receiveEnergy(opp, theoreticalReceived-deduct, simulate);
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);
int deduct = this.calcDeduction(theoreticalReceived, highestLoss); if(theoreticalReceived > 0){
transmitted += cap.givePower(theoreticalReceived-deduct, simulate); int deduct = this.calcDeduction(theoreticalReceived, highestLoss);
transmitted += deduct; if(deduct >= theoreticalReceived){ //Happens with small numbers
deduct = 0;
}
transmitted += cap.givePower(theoreticalReceived-deduct, simulate);
transmitted += deduct;
}
} }
} }