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