Fixes #3175: Return the correct used amount. (#3176)

This commit is contained in:
yueh 2017-10-26 12:46:49 +02:00 committed by GitHub
parent b82df25c75
commit a725779ff6

View file

@ -85,21 +85,10 @@ class PoweredItemCapabilities implements ICapabilityProvider, IEnergyStorage
@Override @Override
public int receiveEnergy( int maxReceive, boolean simulate ) public int receiveEnergy( int maxReceive, boolean simulate )
{ {
if( simulate ) final double convertedOffer = PowerUnits.RF.convertTo( PowerUnits.AE, maxReceive );
{ final double overflow = this.item.injectAEPower( this.is, convertedOffer, simulate ? Actionable.SIMULATE : Actionable.MODULATE );
final int required = (int) PowerUnits.AE.convertTo( PowerUnits.RF, this.item.getAEMaxPower( this.is ) - this.item.getAECurrentPower( this.is ) );
if( maxReceive < required ) return maxReceive - (int) PowerUnits.AE.convertTo( PowerUnits.RF, overflow );
{
return 0;
}
return maxReceive - required;
}
else
{
final double powerRemainder = this.item.injectAEPower( this.is, PowerUnits.RF.convertTo( PowerUnits.AE, maxReceive ), Actionable.MODULATE );
return maxReceive - (int) PowerUnits.AE.convertTo( PowerUnits.RF, powerRemainder );
}
} }
@Override @Override