2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-02-22 23:14:43 +01:00
|
|
|
package appeng.tile.misc;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-02-22 23:14:43 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
2014-12-29 21:59:05 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2014-02-22 23:14:43 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-02-22 23:14:43 +01:00
|
|
|
import appeng.api.implementations.IPowerChannelState;
|
2014-09-10 02:44:30 +02:00
|
|
|
import appeng.api.implementations.tiles.ICrystalGrowthAccelerator;
|
2014-02-22 23:14:43 +01:00
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.me.GridAccessException;
|
2014-08-28 09:39:52 +02:00
|
|
|
import appeng.tile.TileEvent;
|
2014-02-22 23:14:43 +01:00
|
|
|
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
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-10 02:44:30 +02:00
|
|
|
public class TileQuartzGrowthAccelerator extends AENetworkTile implements IPowerChannelState, ICrystalGrowthAccelerator
|
2014-02-22 23:14:43 +01:00
|
|
|
{
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private boolean hasPower = false;
|
2014-02-22 23:14:43 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public TileQuartzGrowthAccelerator()
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getProxy().setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
|
|
|
this.getProxy().setFlags();
|
|
|
|
this.getProxy().setIdlePowerUsage( 8 );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-22 23:14:43 +01:00
|
|
|
@MENetworkEventSubscribe
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onPower( final MENetworkPowerStatusChange ch )
|
2014-02-22 23:14:43 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.markForUpdate();
|
2014-02-22 23:14:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public AECableType getCableConnectionType( final ForgeDirection dir )
|
2014-02-22 23:14:43 +01:00
|
|
|
{
|
|
|
|
return AECableType.COVERED;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.NETWORK_READ )
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean readFromStream_TileQuartzGrowthAccelerator( final ByteBuf data )
|
2014-02-22 23:14:43 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
final boolean hadPower = this.isPowered();
|
|
|
|
this.setPowered( data.readBoolean() );
|
|
|
|
return this.isPowered() != hadPower;
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
2014-02-22 23:14:43 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.NETWORK_WRITE )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void writeToStream_TileQuartzGrowthAccelerator( final ByteBuf data )
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
|
|
|
try
|
2014-02-22 23:14:43 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
data.writeBoolean( this.getProxy().getEnergy().isNetworkPowered() );
|
2014-02-22 23:14:43 +01:00
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final GridAccessException e )
|
2014-02-22 23:14:43 +01:00
|
|
|
{
|
2014-08-28 09:39:52 +02:00
|
|
|
data.writeBoolean( false );
|
2014-02-22 23:14:43 +01:00
|
|
|
}
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
2014-02-22 23:14:43 +01:00
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void setOrientation( final ForgeDirection inForward, final ForgeDirection inUp )
|
2014-02-22 23:14:43 +01:00
|
|
|
{
|
|
|
|
super.setOrientation( inForward, inUp );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getProxy().setValidSides( EnumSet.of( this.getUp(), this.getUp().getOpposite() ) );
|
2014-02-22 23:14:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPowered()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isServer() )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getProxy().getEnergy().isNetworkPowered();
|
2014-02-23 07:55:46 +01:00
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final GridAccessException e )
|
2014-02-23 07:55:46 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.hasPower;
|
2014-02-22 23:14:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isActive()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.isPowered();
|
2014-02-22 23:14:43 +01:00
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
|
|
|
|
private void setPowered( final boolean hasPower )
|
|
|
|
{
|
|
|
|
this.hasPower = hasPower;
|
|
|
|
}
|
2014-02-22 23:14:43 +01:00
|
|
|
}
|