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>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.spatial;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
2014-12-29 21:59:05 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.GridFlags;
|
|
|
|
import appeng.api.networking.events.MENetworkChannelsChanged;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.me.cluster.IAEMultiBlock;
|
|
|
|
import appeng.me.cluster.implementations.SpatialPylonCalculator;
|
|
|
|
import appeng.me.cluster.implementations.SpatialPylonCluster;
|
|
|
|
import appeng.me.helpers.AENetworkProxy;
|
|
|
|
import appeng.me.helpers.AENetworkProxyMultiblock;
|
2014-08-28 09:39:52 +02:00
|
|
|
import appeng.tile.TileEvent;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.grid.AENetworkTile;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public class TileSpatialPylon extends AENetworkTile implements IAEMultiBlock
|
|
|
|
{
|
|
|
|
|
2015-05-08 22:53:50 +02:00
|
|
|
public static final int DISPLAY_END_MIN = 0x01;
|
|
|
|
public static final int DISPLAY_END_MAX = 0x02;
|
|
|
|
public static final int DISPLAY_MIDDLE = 0x01 + 0x02;
|
|
|
|
public static final int DISPLAY_X = 0x04;
|
|
|
|
public static final int DISPLAY_Y = 0x08;
|
|
|
|
public static final int DISPLAY_Z = 0x04 + 0x08;
|
|
|
|
public static final int MB_STATUS = 0x01 + 0x02 + 0x04 + 0x08;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-05-08 22:53:50 +02:00
|
|
|
public static final int DISPLAY_ENABLED = 0x10;
|
|
|
|
public static final int DISPLAY_POWERED_ENABLED = 0x20;
|
|
|
|
public static final int NET_STATUS = 0x10 + 0x20;
|
2015-10-08 15:42:42 +02:00
|
|
|
|
|
|
|
private final SpatialPylonCalculator calc = new SpatialPylonCalculator( this );
|
|
|
|
private int displayBits = 0;
|
|
|
|
private SpatialPylonCluster cluster;
|
|
|
|
private boolean didHaveLight = false;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public TileSpatialPylon()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL, GridFlags.MULTIBLOCK );
|
|
|
|
this.getProxy().setIdlePowerUsage( 0.5 );
|
|
|
|
this.getProxy().setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
protected AENetworkProxy createProxy()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return new AENetworkProxyMultiblock( this, "proxy", this.getItemFromTile( this ), true );
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void onChunkUnload()
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.disconnect( false );
|
|
|
|
super.onChunkUnload();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReady()
|
|
|
|
{
|
|
|
|
super.onReady();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.onNeighborBlockChange();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void invalidate()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.disconnect( false );
|
|
|
|
super.invalidate();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public void onNeighborBlockChange()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.calc.calculateMultiblock( this.worldObj, this.getLocation() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void disconnect( final boolean b )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.cluster != null )
|
|
|
|
{
|
|
|
|
this.cluster.destroy();
|
|
|
|
this.updateStatus( null );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public SpatialPylonCluster getCluster()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.cluster;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean isValid()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return true;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public void updateStatus( final SpatialPylonCluster c )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.cluster = c;
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getProxy().setValidSides( c == null ? EnumSet.noneOf( ForgeDirection.class ) : EnumSet.allOf( ForgeDirection.class ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
this.recalculateDisplay();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void recalculateDisplay()
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int oldBits = this.displayBits;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.displayBits = 0;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.cluster != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.cluster.getMin().equals( this.getLocation() ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-08-06 18:59:31 +02:00
|
|
|
this.displayBits = DISPLAY_END_MIN;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
else if( this.cluster.getMax().equals( this.getLocation() ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-08-06 18:59:31 +02:00
|
|
|
this.displayBits = DISPLAY_END_MAX;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-08-06 18:59:31 +02:00
|
|
|
this.displayBits = DISPLAY_MIDDLE;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
switch( this.cluster.getCurrentAxis() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case X:
|
2015-08-06 18:59:31 +02:00
|
|
|
this.displayBits |= DISPLAY_X;
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
case Y:
|
2015-08-06 18:59:31 +02:00
|
|
|
this.displayBits |= DISPLAY_Y;
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
case Z:
|
2015-08-06 18:59:31 +02:00
|
|
|
this.displayBits |= DISPLAY_Z;
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.displayBits = 0;
|
|
|
|
break;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.getProxy().getEnergy().isNetworkPowered() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-08-06 18:59:31 +02:00
|
|
|
this.displayBits |= DISPLAY_POWERED_ENABLED;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.cluster.isValid() && this.getProxy().isActive() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-08-06 18:59:31 +02:00
|
|
|
this.displayBits |= DISPLAY_ENABLED;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final GridAccessException e )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
// nothing?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( oldBits != this.displayBits )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.markForUpdate();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void markForUpdate()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
super.markForUpdate();
|
2015-09-25 23:10:56 +02:00
|
|
|
final boolean hasLight = this.getLightValue() > 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasLight != this.didHaveLight )
|
|
|
|
{
|
|
|
|
this.didHaveLight = hasLight;
|
|
|
|
this.worldObj.func_147451_t( this.xCoord, this.yCoord, this.zCoord );
|
|
|
|
// worldObj.updateAllLightTypes( xCoord, yCoord, zCoord );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean canBeRotated()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLightValue()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-08-06 18:59:31 +02:00
|
|
|
if( ( this.displayBits & DISPLAY_POWERED_ENABLED ) == DISPLAY_POWERED_ENABLED )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return 8;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return 0;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.NETWORK_READ )
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean readFromStream_TileSpatialPylon( final ByteBuf data )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final int old = this.displayBits;
|
2015-04-03 08:54:31 +02:00
|
|
|
this.displayBits = data.readByte();
|
|
|
|
return old != this.displayBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
@TileEvent( TileEventType.NETWORK_WRITE )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void writeToStream_TileSpatialPylon( final ByteBuf data )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
data.writeByte( this.displayBits );
|
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
2015-09-25 23:10:56 +02:00
|
|
|
public void powerRender( final MENetworkPowerStatusChange c )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
this.recalculateDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
2015-09-25 23:10:56 +02:00
|
|
|
public void activeRender( final MENetworkChannelsChanged c )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
this.recalculateDisplay();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getDisplayBits()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.displayBits;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|