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-05-09 06:10:12 +02:00
|
|
|
package appeng.me.cluster.implementations;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.util.BlockPos;
|
2014-05-09 06:10:12 +02:00
|
|
|
import net.minecraft.world.World;
|
2014-05-18 05:19:23 +02:00
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.events.MENetworkCraftingCpuChange;
|
2015-06-16 02:44:59 +02:00
|
|
|
import appeng.api.util.AEPartLocation;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.api.util.WorldCoord;
|
|
|
|
import appeng.me.cluster.IAECluster;
|
|
|
|
import appeng.me.cluster.IAEMultiBlock;
|
|
|
|
import appeng.me.cluster.MBCalculator;
|
|
|
|
import appeng.tile.crafting.TileCraftingTile;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
public class CraftingCPUCalculator extends MBCalculator
|
|
|
|
{
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2014-07-23 21:20:47 +02:00
|
|
|
final TileCraftingTile tqb;
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public CraftingCPUCalculator( IAEMultiBlock t )
|
|
|
|
{
|
2014-05-09 06:10:12 +02:00
|
|
|
super( t );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tqb = (TileCraftingTile) t;
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean checkMultiblockScale( WorldCoord min, WorldCoord max )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( max.x - min.x > 16 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-14 04:42:14 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-14 04:42:14 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( max.y - min.y > 16 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-14 04:42:14 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-14 04:42:14 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( max.z - min.z > 16 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-14 04:42:14 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-14 04:42:14 +02:00
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IAECluster createCluster( World w, WorldCoord min, WorldCoord max )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return new CraftingCPUCluster( min, max );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean verifyInternalStructure( World w, WorldCoord min, WorldCoord max )
|
|
|
|
{
|
|
|
|
boolean storage = false;
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = min.x; x <= max.x; x++ )
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int y = min.y; y <= max.y; y++ )
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int z = min.z; z <= max.z; z++ )
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
IAEMultiBlock te = (IAEMultiBlock) w.getTileEntity( new BlockPos( x, y, z ) );
|
2014-05-18 05:19:23 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !te.isValid() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-02 03:53:32 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !storage && te instanceof TileCraftingTile )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
storage = ( (TileCraftingTile) te ).getStorageBytes() > 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-18 05:19:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return storage;
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disconnect()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tqb.disconnect( true );
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void updateTiles( IAECluster cl, World w, WorldCoord min, WorldCoord max )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
CraftingCPUCluster c = (CraftingCPUCluster) cl;
|
2014-05-18 05:19:23 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = min.x; x <= max.x; x++ )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int y = min.y; y <= max.y; y++ )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int z = min.z; z <= max.z; z++ )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
TileCraftingTile te = (TileCraftingTile) w.getTileEntity( new BlockPos( x, y, z ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
te.updateStatus( c );
|
|
|
|
c.addTile( te );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
c.done();
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
Iterator<IGridHost> i = c.getTiles();
|
|
|
|
while( i.hasNext() )
|
|
|
|
{
|
|
|
|
IGridHost gh = i.next();
|
2015-06-16 02:44:59 +02:00
|
|
|
IGridNode n = gh.getGridNode( AEPartLocation.INTERNAL );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( n != null )
|
|
|
|
{
|
|
|
|
IGrid g = n.getGrid();
|
|
|
|
if( g != null )
|
|
|
|
{
|
|
|
|
g.postEvent( new MENetworkCraftingCpuChange( n ) );
|
|
|
|
return;
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean isValidTile( TileEntity te )
|
|
|
|
{
|
|
|
|
return te instanceof TileCraftingTile;
|
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|