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

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
@ -12,6 +13,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderBlockCrafting;
import appeng.core.features.AEFeature;
import appeng.tile.crafting.TileCraftingTile;
@ -23,6 +26,11 @@ public class BlockCraftingUnit extends AEBaseBlock
public final static int BASE_STORAGE = 2;
public final static int BASE_ACCELERATOR = 3;
static public boolean checkType(int meta, int type)
{
return (meta & 7) == type;
}
public BlockCraftingUnit() {
super( BlockCraftingUnit.class, Material.iron );
hasSubtypes = true;
@ -30,11 +38,25 @@ public class BlockCraftingUnit extends AEBaseBlock
setTileEntiy( TileCraftingTile.class );
}
@Override
protected Class<? extends BaseBlockRender> getRenderer()
{
return RenderBlockCrafting.class;
}
@Override
public void onNeighborBlockChange(World w, int x, int y, int z, Block junk)
{
TileCraftingTile cp = getTileEntity( w, x, y, z );
if ( cp != null )
cp.updateMultiBlock();
}
public ItemStack getItemStack(World world, int x, int y, int z)
{
TileCraftingTile ct = getTileEntity( world, x, y, z );
int meta = world.getBlockMetadata( x, y, z );
int meta = world.getBlockMetadata( x, y, z ) & 7;
if ( ct != null && meta == BASE_STORAGE )
{
return createStackForBytes( ct.getStorageBytes() );

View file

@ -9,7 +9,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderQuartzGlass;
import appeng.client.render.blocks.RenderBlockAssembler;
import appeng.core.features.AEFeature;
import appeng.core.sync.GuiBridge;
import appeng.tile.crafting.TileMolecularAssembler;
@ -32,7 +32,7 @@ public class BlockMolecularAssembler extends AEBaseBlock
@SideOnly(Side.CLIENT)
public Class<? extends BaseBlockRender> getRenderer()
{
return RenderQuartzGlass.class;
return RenderBlockAssembler.class;
}
@Override

View file

@ -0,0 +1,34 @@
package appeng.client.render.blocks;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
public class RenderBlockAssembler extends BaseBlockRender
{
public RenderBlockAssembler() {
super( false, 20 );
}
@Override
public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj)
{
renderer.setOverrideBlockTexture( blk.getIcon( 0, 0 ) );
super.renderInventory( blk, is, renderer, type, obj );
renderer.setOverrideBlockTexture( null );
}
@Override
public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer)
{
renderer.overrideBlockTexture = blk.getIcon( 0, 0 );
boolean out = renderer.renderStandardBlock( blk, x, y, z );
renderer.overrideBlockTexture = null;
return out;
}
}

View file

@ -0,0 +1,48 @@
package appeng.client.render.blocks;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.texture.ExtraTextures;
import appeng.tile.crafting.TileCraftingTile;
public class RenderBlockCrafting extends BaseBlockRender
{
public RenderBlockCrafting() {
super( false, 20 );
}
@Override
public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj)
{
renderer.setOverrideBlockTexture( blk.getIcon( 0, 0 ) );
super.renderInventory( blk, is, renderer, type, obj );
renderer.setOverrideBlockTexture( null );
}
@Override
public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer)
{
TileCraftingTile ct = blk.getTileEntity( world, x, y, z );
if ( ct != null && ct.isFormed() )
{
renderer.overrideBlockTexture = ExtraTextures.BlockControllerConflict.getIcon();
boolean out = renderer.renderStandardBlock( blk, x, y, z );
renderer.overrideBlockTexture = null;
return out;
}
else
{
renderer.overrideBlockTexture = blk.getIcon( 0, 0 );
boolean out = renderer.renderStandardBlock( blk, x, y, z );
renderer.overrideBlockTexture = null;
return out;
}
}
}

View file

@ -7,7 +7,6 @@ import appeng.me.cluster.IAECluster;
import appeng.me.cluster.IAEMultiBlock;
import appeng.me.cluster.MBCalculator;
import appeng.tile.crafting.TileCraftingTile;
import appeng.tile.qnb.TileQuantumBridge;
public class CraftingCPUCalculator extends MBCalculator
{
@ -22,19 +21,41 @@ public class CraftingCPUCalculator extends MBCalculator
@Override
public boolean isValidTile(TileEntity te)
{
return te instanceof TileQuantumBridge;
return te instanceof TileCraftingTile;
}
@Override
public boolean checkMultiblockScale(WorldCoord min, WorldCoord max)
{
if ( max.x - min.x > 8 )
return false;
if ( max.y - min.y > 8 )
return false;
if ( max.z - min.z > 8 )
return false;
return true;
}
@Override
public void updateTiles(IAECluster cl, World w, WorldCoord min, WorldCoord max)
{
CraftingCPUCluster c = (CraftingCPUCluster) cl;
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++)
{
TileCraftingTile te = (TileCraftingTile) w.getTileEntity( x, y, z );
te.updateStatus( c );
c.addTile( te );
}
}
}
}
@Override
@ -52,7 +73,6 @@ public class CraftingCPUCalculator extends MBCalculator
@Override
public boolean verifyInternalStructure(World w, WorldCoord min, WorldCoord max)
{
for (int x = min.x; x <= max.x; x++)
{
for (int y = min.y; y <= max.y; y++)

View file

@ -6,6 +6,7 @@ import java.util.LinkedList;
import appeng.api.networking.IGridHost;
import appeng.api.util.WorldCoord;
import appeng.me.cluster.IAECluster;
import appeng.tile.crafting.TileCraftingTile;
public class CraftingCPUCluster implements IAECluster
{
@ -14,12 +15,16 @@ public class CraftingCPUCluster implements IAECluster
public WorldCoord max;
public boolean isDestroyed = false;
private LinkedList<IGridHost> tiles = new LinkedList();
private LinkedList<TileCraftingTile> tiles = new LinkedList();
int accelerator = 0;
private LinkedList<TileCraftingTile> storage = new LinkedList<TileCraftingTile>();
private LinkedList<TileCraftingTile> status = new LinkedList<TileCraftingTile>();
@Override
public Iterator<IGridHost> getTiles()
{
return tiles.iterator();
return (Iterator) tiles.iterator();
}
public CraftingCPUCluster(WorldCoord _min, WorldCoord _max) {
@ -30,7 +35,10 @@ public class CraftingCPUCluster implements IAECluster
@Override
public void updateStatus(boolean updateGrid)
{
for (TileCraftingTile r : tiles)
{
r.updateMeta();
}
}
@Override
@ -40,6 +48,22 @@ public class CraftingCPUCluster implements IAECluster
return;
isDestroyed = true;
for (TileCraftingTile r : tiles)
{
r.updateStatus( null );
}
}
public void addTile(TileCraftingTile te)
{
tiles.add( te );
if ( te.isStorage() )
storage.add( te );
else if ( te.isStatus() )
status.add( te );
else if ( te.isAccelerator() )
accelerator++;
}
}

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 );
}
}

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 );
}