Working Towards Crafing CPU MultiBlock

This commit is contained in:
AlgorithmX2
2014-05-13 21:42:14 -05:00
parent 25a588f303
commit 6a8fafa58d
8 changed files with 305 additions and 17 deletions
+85 -6
View File
@@ -1,21 +1,51 @@
package appeng.tile.crafting;
import java.util.EnumSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.networking.GridFlags;
import appeng.block.crafting.BlockCraftingUnit;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.IAEMultiBlock;
import appeng.tile.AEBaseTile;
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.events.AETileEventHandler;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkTile;
public class TileCraftingTile extends AEBaseTile implements IAEMultiBlock
public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock
{
private long storageBytes = 0;
CraftingCPUCluster clust;
final CraftingCPUCalculator calc = new CraftingCPUCalculator( this );
@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() {
gridProxy.setFlags( GridFlags.MULTIBLOCK, GridFlags.REQUIRE_CHANNEL );
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
addNewHandler( new AETileEventHandler( TileEventType.NETWORK, TileEventType.WORLD_NBT ) {
public void writeToNBT(NBTTagCompound data)
@@ -43,6 +73,13 @@ public class TileCraftingTile extends AEBaseTile implements IAEMultiBlock
} );
}
@Override
public void onReady()
{
super.onReady();
updateMultiBlock();
}
@Override
public void onPlacement(ItemStack stack, EntityPlayer player, int side)
{
@@ -55,6 +92,30 @@ public class TileCraftingTile extends AEBaseTile implements IAEMultiBlock
@Override
public void disconnect()
{
if ( clust != null )
{
clust.destroy();
updateMeta();
}
}
public void updateMeta()
{
boolean formed = clust != null;
int current = worldObj.getBlockMetadata( xCoord, yCoord, zCoord );
int newmeta = (current & 7) | (formed ? 8 : 0);
if ( current != newmeta )
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, newmeta, 3 );
if ( isFormed() )
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
else
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
}
private void dropAndBreak()
{
// TODO Auto-generated method stub
@@ -63,15 +124,13 @@ public class TileCraftingTile extends AEBaseTile implements IAEMultiBlock
@Override
public IAECluster getCluster()
{
// TODO Auto-generated method stub
return null;
return clust;
}
@Override
public boolean isValid()
{
// TODO Auto-generated method stub
return false;
return true;
}
public long getStorageBytes()
@@ -79,4 +138,24 @@ public class TileCraftingTile extends AEBaseTile implements IAEMultiBlock
return storageBytes;
}
public boolean isFormed()
{
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 8) == 8;
}
public boolean isStorage()
{
return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ), BlockCraftingUnit.BASE_STORAGE );
}
public boolean isStatus()
{
return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ), BlockCraftingUnit.BASE_MONITOR );
}
public boolean isAccelerator()
{
return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ), BlockCraftingUnit.BASE_ACCELERATOR );
}
}
+63 -2
View File
@@ -56,18 +56,39 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
private ICraftingPatternDetails myPlan = null;
private double progress = 0;
private boolean isAwake = false;
private boolean forcePlan = false;
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table, ForgeDirection where)
{
if ( myPattern == null )
{
boolean isEmpty = true;
for (int x = 0; x < inv.getSizeInventory(); x++)
isEmpty = inv.getStackInSlot( x ) == null && isEmpty;
if ( isEmpty )
{
forcePlan = true;
myPlan = patternDetails;
pushDirection = where;
for (int x = 0; x < table.getSizeInventory(); x++)
inv.setInventorySlotContents( x, table.getStackInSlot( x ) );
updateSleepyness();
return true;
}
}
return false;
}
private void recalculatePlan()
{
ItemStack is = inv.getStackInSlot( 10 );
if ( forcePlan )
return;
boolean wasEnabled = isAwake;
ItemStack is = inv.getStackInSlot( 10 );
if ( is != null && is.getItem() instanceof ItemEncodedPattern )
{
@@ -89,6 +110,12 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
myPattern = null;
}
updateSleepyness();
}
private void updateSleepyness()
{
boolean wasEnabled = isAwake;
isAwake = myPlan != null && hasMats() || canPush();
if ( wasEnabled != isAwake )
{
@@ -132,6 +159,17 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
@Override
public void writeToNBT(NBTTagCompound data)
{
if ( forcePlan )
{
ItemStack pattern = myPlan.getPattern();
if ( pattern != null )
{
NBTTagCompound pdata = new NBTTagCompound();
pattern.writeToNBT( pdata );
data.setTag( "myPlan", pdata );
}
}
upgrades.writeToNBT( data, "upgrades" );
inv.writeToNBT( data, "inv" );
settings.writeToNBT( data );
@@ -140,6 +178,23 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
@Override
public void readFromNBT(NBTTagCompound data)
{
if ( data.hasKey( "myPlan" ) )
{
ItemStack myPat = ItemStack.loadItemStackFromNBT( data.getCompoundTag( "myPlan" ) );
if ( myPat != null && myPat.getItem() instanceof ItemEncodedPattern )
{
World w = getWorldObj();
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
ICraftingPatternDetails ph = iep.getPatternForItem( is, w );
if ( ph != null )
{
forcePlan = true;
myPlan = ph;
}
}
}
upgrades.readFromNBT( data, "upgrades" );
inv.readFromNBT( data, "inv" );
settings.readFromNBT( data );
@@ -340,6 +395,12 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
else
output = pushTo( output, pushDirection );
if ( output == null && forcePlan )
{
forcePlan = false;
recalculatePlan();
}
inv.setInventorySlotContents( 9, output );
}