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.me.cluster.implementations;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraft.block.Block;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.World;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IBlockDefinition;
|
|
|
|
import appeng.api.definitions.IBlocks;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.util.WorldCoord;
|
|
|
|
import appeng.me.cluster.IAECluster;
|
|
|
|
import appeng.me.cluster.IAEMultiBlock;
|
|
|
|
import appeng.me.cluster.MBCalculator;
|
|
|
|
import appeng.tile.qnb.TileQuantumBridge;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public class QuantumCalculator extends MBCalculator
|
|
|
|
{
|
|
|
|
|
2014-07-23 21:20:47 +02:00
|
|
|
final private TileQuantumBridge tqb;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public QuantumCalculator( IAEMultiBlock t )
|
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
super( t );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tqb = (TileQuantumBridge) t;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean checkMultiblockScale( WorldCoord min, WorldCoord max )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( max.x - min.x + 1 ) * ( max.y - min.y + 1 ) * ( max.z - min.z + 1 ) == 9 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
int ones = ( ( max.x - min.x ) == 0 ? 1 : 0 ) + ( ( max.y - min.y ) == 0 ? 1 : 0 ) + ( ( max.z - min.z ) == 0 ? 1 : 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
int threes = ( ( max.x - min.x ) == 2 ? 1 : 0 ) + ( ( max.y - min.y ) == 2 ? 1 : 0 ) + ( ( max.z - min.z ) == 2 ? 1 : 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
return ones == 1 && threes == 2;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IAECluster createCluster( World w, WorldCoord min, WorldCoord max )
|
|
|
|
{
|
|
|
|
return new QuantumCluster( min, max );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean verifyInternalStructure( World w, WorldCoord min, WorldCoord max )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
byte num = 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = min.x; x <= max.x; x++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int y = min.y; y <= max.y; y++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int z = min.z; z <= max.z; z++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
IAEMultiBlock te = (IAEMultiBlock) w.getTileEntity( x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !te.isValid() )
|
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
num++;
|
2015-04-03 08:54:31 +02:00
|
|
|
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
|
|
|
if( num == 5 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.isBlockAtLocation( w, x, y, z, blocks.quantumLink() ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.isBlockAtLocation( w, x, y, z, blocks.quantumRing() ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disconnect()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.tqb.disconnect( true );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void updateTiles( IAECluster cl, World w, WorldCoord min, WorldCoord max )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
byte num = 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
byte ringNum = 0;
|
|
|
|
QuantumCluster c = (QuantumCluster) cl;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = min.x; x <= max.x; x++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int y = min.y; y <= max.y; y++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int z = min.z; z <= max.z; z++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
TileQuantumBridge te = (TileQuantumBridge) w.getTileEntity( x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
byte flags;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
num++;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( num == 5 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
flags = num;
|
|
|
|
c.setCenter( te );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( num == 1 || num == 3 || num == 7 || num == 9 )
|
|
|
|
flags = (byte) ( this.tqb.corner | num );
|
|
|
|
else
|
|
|
|
flags = num;
|
|
|
|
c.Ring[ringNum] = te;
|
|
|
|
ringNum++;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
te.updateStatus( c, flags, true );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValidTile( TileEntity te )
|
|
|
|
{
|
|
|
|
return te instanceof TileQuantumBridge;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
private boolean isBlockAtLocation( IBlockAccess w, int x, int y, int z, IBlockDefinition def )
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Block block : def.maybeBlock().asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
return block == w.getBlock( x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|