Applied-Energistics-2-tiler.../tile/crafting/TileCraftingTile.java

168 lines
3.5 KiB
Java
Raw Normal View History

package appeng.tile.crafting;
2014-05-14 04:42:14 +02:00
import java.util.EnumSet;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.IPowerChannelState;
2014-05-14 04:42:14 +02:00
import appeng.api.networking.GridFlags;
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;
import appeng.api.parts.ISimplifiedBundle;
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;
import appeng.util.Platform;
public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IPowerChannelState
{
2014-05-14 04:42:14 +02:00
CraftingCPUCluster clust;
final CraftingCPUCalculator calc = new CraftingCPUCalculator( this );
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() );
}
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-14 04:42:14 +02:00
@Override
public void onReady()
{
super.onReady();
updateMultiBlock();
}
@Override
2014-05-18 05:19:23 +02:00
public boolean canBeRotated()
{
2014-05-18 05:19:23 +02:00
return true;// return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ),
// BlockCraftingUnit.BASE_MONITOR );
}
@Override
public void disconnect(boolean update)
2014-05-14 04:42:14 +02:00
{
if ( clust != null )
{
clust.destroy();
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();
}
@MENetworkEventSubscribe
public void ChannelChangesd(MENetworkChannelsChanged ev)
{
updateMeta();
}
2014-05-14 04:42:14 +02:00
public void updateMeta()
{
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;
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 )
{
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, newmeta, 2 );
2014-05-14 04:42:14 +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()
{
// TODO Auto-generated method stub
}
@Override
public IAECluster getCluster()
{
2014-05-14 04:42:14 +02:00
return clust;
}
@Override
public boolean isValid()
{
2014-05-14 04:42:14 +02:00
return true;
}
@Override
2014-05-18 05:19:23 +02:00
public boolean isPowered()
{
2014-05-18 05:19:23 +02:00
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 4) == 4;
}
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
}
@Override
public boolean isActive()
{
if ( Platform.isServer() )
return gridProxy.isActive();
return isPowered() && isFormed();
}
}