Applied-Energistics-2-tiler.../src/main/java/appeng/tile/misc/TileQuartzGrowthAccelerator.java

114 lines
3 KiB
Java
Raw Normal View History

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>.
*/
package appeng.tile.misc;
import java.util.EnumSet;
2014-12-29 21:59:05 +01:00
import io.netty.buffer.ByteBuf;
import net.minecraftforge.common.util.ForgeDirection;
2014-12-29 21:59:05 +01:00
import appeng.api.implementations.IPowerChannelState;
import appeng.api.implementations.tiles.ICrystalGrowthAccelerator;
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;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkTile;
import appeng.util.Platform;
public class TileQuartzGrowthAccelerator extends AENetworkTile implements IPowerChannelState, ICrystalGrowthAccelerator
{
public boolean hasPower = false;
@MENetworkEventSubscribe
public void onPower(MENetworkPowerStatusChange ch)
{
2014-12-29 15:13:47 +01:00
this.markForUpdate();
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir)
{
return AECableType.COVERED;
}
2014-08-28 09:39:52 +02:00
@TileEvent(TileEventType.NETWORK_READ)
2014-10-04 08:08:28 +02:00
public boolean readFromStream_TileQuartzGrowthAccelerator(ByteBuf data)
{
2014-12-29 15:13:47 +01:00
boolean hadPower = this.hasPower;
this.hasPower = data.readBoolean();
return this.hasPower != hadPower;
2014-08-28 09:39:52 +02:00
}
2014-08-28 09:39:52 +02:00
@TileEvent(TileEventType.NETWORK_WRITE)
2014-10-04 08:08:28 +02:00
public void writeToStream_TileQuartzGrowthAccelerator(ByteBuf data)
2014-08-28 09:39:52 +02:00
{
try
{
2014-12-29 15:13:47 +01:00
data.writeBoolean( this.gridProxy.getEnergy().isNetworkPowered() );
}
2014-08-28 09:39:52 +02:00
catch (GridAccessException e)
{
2014-08-28 09:39:52 +02:00
data.writeBoolean( false );
}
2014-08-28 09:39:52 +02:00
}
public TileQuartzGrowthAccelerator() {
2014-12-29 15:13:47 +01:00
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
this.gridProxy.setFlags();
this.gridProxy.setIdlePowerUsage( 8 );
}
@Override
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
{
super.setOrientation( inForward, inUp );
2014-12-29 15:13:47 +01:00
this.gridProxy.setValidSides( EnumSet.of( this.getUp(), this.getUp().getOpposite() ) );
}
@Override
public boolean isPowered()
{
if ( Platform.isServer() )
{
try
{
2014-12-29 15:13:47 +01:00
return this.gridProxy.getEnergy().isNetworkPowered();
}
catch (GridAccessException e)
{
return false;
}
}
2014-12-29 15:13:47 +01:00
return this.hasPower;
}
@Override
public boolean isActive()
{
2014-12-29 15:13:47 +01:00
return this.isPowered();
}
}