Applied-Energistics-2-tiler.../src/main/java/appeng/me/cluster/implementations/CraftingCPUCalculator.java

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