2014-05-09 06:10:12 +02:00
|
|
|
package appeng.tile.crafting;
|
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-05-23 04:43:15 +02:00
|
|
|
import appeng.api.implementations.IPowerChannelState;
|
2014-05-14 04:42:14 +02:00
|
|
|
import appeng.api.networking.GridFlags;
|
2014-05-23 04:43:15 +02:00
|
|
|
import appeng.api.networking.events.MENetworkChannelsChanged;
|
2014-05-18 05:19:23 +02:00
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
2014-05-15 16:34:38 +02:00
|
|
|
import appeng.api.parts.ISimplifiedBundle;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.me.cluster.IAECluster;
|
|
|
|
import appeng.me.cluster.IAEMultiBlock;
|
2014-05-14 04:42:14 +02:00
|
|
|
import appeng.me.cluster.implementations.CraftingCPUCalculator;
|
|
|
|
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
|
|
|
import appeng.me.helpers.AENetworkProxy;
|
|
|
|
import appeng.me.helpers.AENetworkProxyMultiblock;
|
|
|
|
import appeng.tile.grid.AENetworkTile;
|
2014-05-23 04:43:15 +02:00
|
|
|
import appeng.util.Platform;
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2014-05-23 04:43:15 +02:00
|
|
|
public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IPowerChannelState
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
CraftingCPUCluster clust;
|
|
|
|
final CraftingCPUCalculator calc = new CraftingCPUCalculator( this );
|
2014-05-15 16:34:38 +02:00
|
|
|
public ISimplifiedBundle lightCache;
|
2014-05-14 04:42:14 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected AENetworkProxy createProxy()
|
|
|
|
{
|
|
|
|
return new AENetworkProxyMultiblock( this, "proxy", getItemFromTile( this ), true );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateStatus(CraftingCPUCluster c)
|
|
|
|
{
|
|
|
|
clust = c;
|
|
|
|
updateMeta();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateMultiBlock()
|
|
|
|
{
|
|
|
|
calc.calculateMultiblock( worldObj, getLocation() );
|
|
|
|
}
|
2014-05-10 07:00:02 +02:00
|
|
|
|
|
|
|
public TileCraftingTile() {
|
2014-05-14 04:42:14 +02:00
|
|
|
gridProxy.setFlags( GridFlags.MULTIBLOCK, GridFlags.REQUIRE_CHANNEL );
|
|
|
|
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
2014-05-10 07:00:02 +02:00
|
|
|
}
|
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
@Override
|
|
|
|
public void onReady()
|
|
|
|
{
|
|
|
|
super.onReady();
|
|
|
|
updateMultiBlock();
|
|
|
|
}
|
|
|
|
|
2014-05-10 07:00:02 +02:00
|
|
|
@Override
|
2014-05-18 05:19:23 +02:00
|
|
|
public boolean canBeRotated()
|
2014-05-10 07:00:02 +02:00
|
|
|
{
|
2014-05-18 05:19:23 +02:00
|
|
|
return true;// return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ),
|
|
|
|
// BlockCraftingUnit.BASE_MONITOR );
|
2014-05-10 07:00:02 +02:00
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
@Override
|
2014-06-18 08:23:37 +02:00
|
|
|
public void disconnect(boolean update)
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
|
|
|
if ( clust != null )
|
|
|
|
{
|
|
|
|
clust.destroy();
|
2014-06-18 08:23:37 +02:00
|
|
|
if ( update )
|
|
|
|
updateMeta();
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void onPowerStateChage(MENetworkPowerStatusChange ev)
|
|
|
|
{
|
|
|
|
updateMeta();
|
|
|
|
}
|
|
|
|
|
2014-05-23 04:43:15 +02:00
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void ChannelChangesd(MENetworkChannelsChanged ev)
|
|
|
|
{
|
|
|
|
updateMeta();
|
|
|
|
}
|
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
public void updateMeta()
|
|
|
|
{
|
2014-05-23 04:43:15 +02:00
|
|
|
if ( !gridProxy.isReady() )
|
|
|
|
return;
|
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
boolean formed = clust != null;
|
2014-05-18 05:19:23 +02:00
|
|
|
boolean power = false;
|
2014-05-23 04:43:15 +02:00
|
|
|
power = gridProxy.isActive();
|
2014-05-18 05:19:23 +02:00
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
int current = worldObj.getBlockMetadata( xCoord, yCoord, zCoord );
|
2014-05-18 05:19:23 +02:00
|
|
|
int newmeta = (current & 3) | (formed ? 8 : 0) | (power ? 4 : 0);
|
2014-05-14 04:42:14 +02:00
|
|
|
|
|
|
|
if ( current != newmeta )
|
2014-05-19 03:05:03 +02:00
|
|
|
{
|
2014-05-23 04:43:15 +02:00
|
|
|
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, newmeta, 2 );
|
2014-05-14 04:42:14 +02:00
|
|
|
|
2014-05-19 03:05:03 +02:00
|
|
|
if ( isFormed() )
|
|
|
|
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
|
|
|
|
else
|
|
|
|
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
|
|
|
}
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void dropAndBreak()
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAECluster getCluster()
|
|
|
|
{
|
2014-05-14 04:42:14 +02:00
|
|
|
return clust;
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValid()
|
|
|
|
{
|
2014-05-14 04:42:14 +02:00
|
|
|
return true;
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
2014-05-23 04:43:15 +02:00
|
|
|
@Override
|
2014-05-18 05:19:23 +02:00
|
|
|
public boolean isPowered()
|
2014-05-10 07:00:02 +02:00
|
|
|
{
|
2014-05-18 05:19:23 +02:00
|
|
|
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 4) == 4;
|
2014-05-10 07:00:02 +02:00
|
|
|
}
|
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
public boolean isFormed()
|
|
|
|
{
|
|
|
|
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 8) == 8;
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
public boolean isAccelerator()
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
2014-06-20 09:07:52 +02:00
|
|
|
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 3) == 1;
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isStatus()
|
|
|
|
{
|
2014-05-18 05:19:23 +02:00
|
|
|
return false;
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
public boolean isStorage()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getStorageBytes()
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
2014-05-18 05:19:23 +02:00
|
|
|
return 0;
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
|
2014-05-23 04:43:15 +02:00
|
|
|
@Override
|
|
|
|
public boolean isActive()
|
|
|
|
{
|
|
|
|
if ( Platform.isServer() )
|
|
|
|
return gridProxy.isActive();
|
|
|
|
return isPowered() && isFormed();
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|