2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.powersink;
|
|
|
|
|
|
|
|
import ic2.api.energy.tile.IEnergySink;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
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-01-28 21:08:51 +01:00
|
|
|
import appeng.core.AppEng;
|
|
|
|
import appeng.integration.abstraction.IIC2;
|
2014-04-06 08:55:24 +02:00
|
|
|
import appeng.transformer.annotations.integration.Interface;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2014-04-06 08:55:24 +02:00
|
|
|
@Interface(iname = "IC2", iface = "ic2.api.energy.tile.IEnergySink")
|
|
|
|
public abstract class IC2 extends MinecraftJoules implements IEnergySink
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
boolean isInIC2 = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
|
|
|
{
|
|
|
|
return internalCanAcceptPower && getPowerSides().contains( direction );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public double demandedEnergyUnits()
|
|
|
|
{
|
|
|
|
return getExternalPowerDemand( PowerUnits.EU );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
|
|
|
|
{
|
|
|
|
// just store the excess in the current block, if I return the waste,
|
|
|
|
// IC2 will just disintegrate it - Oct 20th 2013
|
|
|
|
double overflow = PowerUnits.EU.convertTo( PowerUnits.AE, injectExternalPower( PowerUnits.EU, amount ) );
|
|
|
|
internalCurrentPower += overflow;
|
|
|
|
return 0; // see above comment.
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public int getMaxSafeInput()
|
|
|
|
{
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void invalidate()
|
|
|
|
{
|
|
|
|
super.invalidate();
|
|
|
|
removeFromENet();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChunkUnload()
|
|
|
|
{
|
|
|
|
super.onChunkUnload();
|
|
|
|
removeFromENet();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReady()
|
|
|
|
{
|
|
|
|
super.onReady();
|
|
|
|
addToENet();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setPowerSides(EnumSet<ForgeDirection> sides)
|
|
|
|
{
|
|
|
|
super.setPowerSides( sides );
|
|
|
|
removeFromENet();
|
|
|
|
addToENet();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
final private void addToENet()
|
|
|
|
{
|
2014-01-28 21:51:44 +01:00
|
|
|
if ( AppEng.instance.isIntegrationEnabled( "IC2" ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-28 21:51:44 +01:00
|
|
|
IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( "IC2" );
|
|
|
|
if ( !isInIC2 && Platform.isServer() && ic2Integration != null )
|
|
|
|
{
|
|
|
|
ic2Integration.addToEnergyNet( this );
|
|
|
|
isInIC2 = true;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final private void removeFromENet()
|
|
|
|
{
|
2014-01-28 21:51:44 +01:00
|
|
|
if ( AppEng.instance.isIntegrationEnabled( "IC2" ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-28 21:51:44 +01:00
|
|
|
IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( "IC2" );
|
|
|
|
if ( isInIC2 && Platform.isServer() && ic2Integration != null )
|
|
|
|
{
|
|
|
|
ic2Integration.removeFromEnergyNet( this );
|
|
|
|
isInIC2 = false;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|