2014-02-22 23:14:43 +01:00
|
|
|
package appeng.tile.misc;
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import appeng.api.implementations.IPowerChannelState;
|
|
|
|
import appeng.api.networking.GridFlags;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.grid.AENetworkTile;
|
2014-02-23 07:55:46 +01:00
|
|
|
import appeng.util.Platform;
|
2014-02-22 23:14:43 +01:00
|
|
|
|
|
|
|
public class TileQuartzGrowthAccelerator extends AENetworkTile implements IPowerChannelState
|
|
|
|
{
|
|
|
|
|
|
|
|
public boolean hasPower = false;
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void onPower(MENetworkPowerStatusChange ch)
|
|
|
|
{
|
|
|
|
markForUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return AECableType.COVERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TileChargerHandler extends AETileEventHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
public TileChargerHandler() {
|
|
|
|
super( TileEventType.NETWORK );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean readFromStream(ByteBuf data) throws IOException
|
|
|
|
{
|
|
|
|
boolean hadPower = hasPower;
|
|
|
|
hasPower = data.readBoolean();
|
|
|
|
return hasPower != hadPower;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToStream(ByteBuf data) throws IOException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
data.writeBoolean( gridProxy.getEnergy().isNetworkPowered() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
data.writeBoolean( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
public TileQuartzGrowthAccelerator() {
|
|
|
|
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
|
|
|
gridProxy.setFlags( GridFlags.CANNOT_CARRY );
|
2014-02-23 07:55:46 +01:00
|
|
|
gridProxy.setIdlePowerUsage( 8 );
|
2014-02-22 23:14:43 +01:00
|
|
|
addNewHandler( new TileChargerHandler() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
|
|
|
{
|
|
|
|
super.setOrientation( inForward, inUp );
|
|
|
|
gridProxy.setValidSides( EnumSet.of( getUp(), getUp().getOpposite() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPowered()
|
|
|
|
{
|
2014-02-23 07:55:46 +01:00
|
|
|
if ( Platform.isServer() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return gridProxy.getEnergy().isNetworkPowered();
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 23:14:43 +01:00
|
|
|
return hasPower;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isActive()
|
|
|
|
{
|
2014-02-23 07:55:46 +01:00
|
|
|
return isPowered();
|
2014-02-22 23:14:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|