2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.powersink;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.config.PowerUnits;
|
2014-04-06 08:55:24 +02:00
|
|
|
import appeng.transformer.annotations.integration.Interface;
|
2013-12-27 23:59:59 +01:00
|
|
|
import cofh.api.energy.IEnergyHandler;
|
|
|
|
|
2014-04-06 08:55:24 +02:00
|
|
|
@Interface(iname = "RF", iface = "cofh.api.energy.IEnergyHandler")
|
|
|
|
public abstract class RedstoneFlux extends RotaryCraft implements IEnergyHandler
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
|
|
|
{
|
|
|
|
if ( simulate )
|
|
|
|
{
|
2014-06-04 03:33:04 +02:00
|
|
|
double demand = getExternalPowerDemand( PowerUnits.RF, maxReceive );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( demand > maxReceive )
|
|
|
|
return maxReceive;
|
|
|
|
return (int) Math.floor( maxReceive - demand );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-04 03:33:04 +02:00
|
|
|
int demand = (int) Math.floor( getExternalPowerDemand( PowerUnits.RF, maxReceive ) );
|
2014-06-02 08:33:16 +02:00
|
|
|
|
|
|
|
int ignored = 0;
|
|
|
|
int insertAmt = maxReceive;
|
|
|
|
|
|
|
|
if ( insertAmt > demand )
|
|
|
|
{
|
|
|
|
ignored = insertAmt - demand;
|
|
|
|
insertAmt = demand;
|
|
|
|
}
|
|
|
|
|
|
|
|
double overFlow = injectExternalPower( PowerUnits.RF, insertAmt );
|
2013-12-27 23:59:59 +01:00
|
|
|
double ox = Math.floor( overFlow );
|
|
|
|
internalCurrentPower += PowerUnits.RF.convertTo( PowerUnits.AE, overFlow - ox );
|
2014-06-02 08:33:16 +02:00
|
|
|
return maxReceive - ((int) ox + ignored);
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-07 01:09:31 +02:00
|
|
|
final public boolean canConnectEnergy(ForgeDirection from)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return internalCanAcceptPower && getPowerSides().contains( from );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public int getEnergyStored(ForgeDirection from)
|
|
|
|
{
|
|
|
|
return (int) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, getAECurrentPower() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public int getMaxEnergyStored(ForgeDirection from)
|
|
|
|
{
|
|
|
|
return (int) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, getAEMaxPower() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|