Crafting CPU basics.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package appeng.block.crafting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import appeng.client.texture.ExtraTextures;
|
||||
import appeng.tile.crafting.TileCraftingMonitorTile;
|
||||
|
||||
public class BlockCraftingMonitor extends BlockCraftingUnit
|
||||
{
|
||||
|
||||
public BlockCraftingMonitor() {
|
||||
super( BlockCraftingMonitor.class );
|
||||
setTileEntiy( TileCraftingMonitorTile.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int direction, int metadata)
|
||||
{
|
||||
switch (metadata)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
return super.getIcon( 0, 0 );
|
||||
case 0 | FLAG_FORMED:
|
||||
return ExtraTextures.BlockCraftingMonitorFit.getIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item i, CreativeTabs c, List l)
|
||||
{
|
||||
l.add( new ItemStack( this, 1, 0 ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package appeng.block.crafting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import appeng.client.texture.ExtraTextures;
|
||||
import appeng.tile.crafting.TileCraftingStorageTile;
|
||||
|
||||
public class BlockCraftingStorage extends BlockCraftingUnit
|
||||
{
|
||||
|
||||
public BlockCraftingStorage() {
|
||||
super( BlockCraftingStorage.class );
|
||||
setTileEntiy( TileCraftingStorageTile.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int direction, int metadata)
|
||||
{
|
||||
switch (metadata & (~4))
|
||||
{
|
||||
default:
|
||||
|
||||
case 0:
|
||||
return super.getIcon( 0, 0 );
|
||||
case 1:
|
||||
return ExtraTextures.BlockCraftingStorage4k.getIcon();
|
||||
case 2:
|
||||
return ExtraTextures.BlockCraftingStorage16k.getIcon();
|
||||
case 3:
|
||||
return ExtraTextures.BlockCraftingStorage64k.getIcon();
|
||||
|
||||
case 0 | FLAG_FORMED:
|
||||
return ExtraTextures.BlockCraftingStorage1kFit.getIcon();
|
||||
case 1 | FLAG_FORMED:
|
||||
return ExtraTextures.BlockCraftingStorage4kFit.getIcon();
|
||||
case 2 | FLAG_FORMED:
|
||||
return ExtraTextures.BlockCraftingStorage16kFit.getIcon();
|
||||
case 3 | FLAG_FORMED:
|
||||
return ExtraTextures.BlockCraftingStorage64kFit.getIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item i, CreativeTabs c, List l)
|
||||
{
|
||||
l.add( new ItemStack( this, 1, 0 ) );
|
||||
l.add( new ItemStack( this, 1, 1 ) );
|
||||
l.add( new ItemStack( this, 1, 2 ) );
|
||||
l.add( new ItemStack( this, 1, 3 ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package appeng.block.crafting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
@@ -9,9 +8,7 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.client.render.BaseBlockRender;
|
||||
@@ -23,49 +20,42 @@ import appeng.tile.crafting.TileCraftingTile;
|
||||
public class BlockCraftingUnit extends AEBaseBlock
|
||||
{
|
||||
|
||||
public final static int BASE_DAMAGE = 0;
|
||||
public final static int BASE_MONITOR = 1;
|
||||
public final static int BASE_STORAGE = 2;
|
||||
public final static int BASE_ACCELERATOR = 3;
|
||||
public static final int FLAG_FORMED = 8;
|
||||
public static final int FLAG_POWERED = 4;
|
||||
|
||||
static public boolean checkType(int meta, int type)
|
||||
{
|
||||
return (meta & 7) == type;
|
||||
public BlockCraftingUnit(Class<? extends BlockCraftingUnit> childClass) {
|
||||
super( childClass, Material.iron );
|
||||
hasSubtypes = true;
|
||||
setfeature( EnumSet.of( AEFeature.Crafting ) );
|
||||
}
|
||||
|
||||
public BlockCraftingUnit() {
|
||||
super( BlockCraftingUnit.class, Material.iron );
|
||||
hasSubtypes = true;
|
||||
setfeature( EnumSet.of( AEFeature.Crafting ) );
|
||||
this( BlockCraftingUnit.class );
|
||||
setTileEntiy( TileCraftingTile.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamageValue(World w, int x, int y, int z)
|
||||
{
|
||||
int meta = w.getBlockMetadata( x, y, z );
|
||||
return meta & 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int direction, int metadata)
|
||||
{
|
||||
switch (metadata)
|
||||
{
|
||||
case BASE_MONITOR:
|
||||
if ( direction == 0 )
|
||||
return ExtraTextures.BlockCraftingStorageMonitor.getIcon();
|
||||
break;
|
||||
case BASE_STORAGE:
|
||||
return ExtraTextures.BlockCraftingStorage1k.getIcon();
|
||||
case BASE_ACCELERATOR:
|
||||
default:
|
||||
case 0:
|
||||
return super.getIcon( 0, 0 );
|
||||
case 1:
|
||||
return ExtraTextures.BlockCraftingAccelerator.getIcon();
|
||||
case BASE_MONITOR | 8:
|
||||
if ( direction == 0 )
|
||||
return ExtraTextures.BlockCraftingStorageMonitorFit.getIcon();
|
||||
break;
|
||||
case BASE_STORAGE | 8:
|
||||
return ExtraTextures.BlockCraftingStorage1kFit.getIcon();
|
||||
case BASE_ACCELERATOR | 8:
|
||||
return ExtraTextures.BlockCraftingAcceleratorFit.getIcon();
|
||||
case BASE_DAMAGE | 8:
|
||||
case 0 | FLAG_FORMED:
|
||||
return ExtraTextures.BlockCraftingUnitFit.getIcon();
|
||||
case 1 | FLAG_FORMED:
|
||||
return ExtraTextures.BlockCraftingAcceleratorFit.getIcon();
|
||||
}
|
||||
|
||||
return super.getIcon( direction, metadata );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,62 +72,10 @@ public class BlockCraftingUnit extends AEBaseBlock
|
||||
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 ) & 7;
|
||||
if ( ct != null && meta == BASE_STORAGE )
|
||||
{
|
||||
return createStackForBytes( ct.getStorageBytes() );
|
||||
}
|
||||
|
||||
return new ItemStack( this, 1, meta );
|
||||
}
|
||||
|
||||
private ItemStack createStackForBytes(long storageBytes)
|
||||
{
|
||||
ItemStack itemDetails = new ItemStack( this, 1, BASE_STORAGE );
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setLong( "bytes", storageBytes );
|
||||
itemDetails.setTagCompound( tag );
|
||||
return itemDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
|
||||
{
|
||||
ArrayList<ItemStack> out = new ArrayList();
|
||||
|
||||
ItemStack is = getItemStack( world, x, y, z );
|
||||
if ( is != null )
|
||||
out.add( is );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
|
||||
{
|
||||
return getItemStack( world, x, y, z );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item i, CreativeTabs c, List l)
|
||||
{
|
||||
l.add( new ItemStack( this, 1, BASE_DAMAGE ) );
|
||||
l.add( new ItemStack( this, 1, BASE_MONITOR ) );
|
||||
l.add( new ItemStack( this, 1, BASE_ACCELERATOR ) );
|
||||
l.add( createStackForBytes( 1024 ) );
|
||||
l.add( createStackForBytes( 1024 * 4 ) );
|
||||
l.add( createStackForBytes( 1024 * 16 ) );
|
||||
l.add( createStackForBytes( 1024 * 64 ) );
|
||||
l.add( new ItemStack( this, 1, 0 ) );
|
||||
l.add( new ItemStack( this, 1, 1 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getItemBlockClass()
|
||||
{
|
||||
return ItemBlockCraftingUnit.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package appeng.block.crafting;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.block.AEBaseItemBlock;
|
||||
import appeng.core.localization.GuiText;
|
||||
|
||||
public class ItemBlockCraftingUnit extends AEBaseItemBlock
|
||||
{
|
||||
|
||||
public ItemBlockCraftingUnit(Block id) {
|
||||
super( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack is)
|
||||
{
|
||||
switch (is.getItemDamage())
|
||||
{
|
||||
case BlockCraftingUnit.BASE_STORAGE:
|
||||
return "tile.appliedenergistics2.BlockCraftingStorage";
|
||||
case BlockCraftingUnit.BASE_ACCELERATOR:
|
||||
return "tile.appliedenergistics2.BlockCraftingAccelerator";
|
||||
case BlockCraftingUnit.BASE_MONITOR:
|
||||
return "tile.appliedenergistics2.BlockCraftingMonitor";
|
||||
}
|
||||
|
||||
return super.getUnlocalizedName( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack is)
|
||||
{
|
||||
String name = super.getItemStackDisplayName( is );
|
||||
|
||||
long storageBytes = getStorageBytes( is );
|
||||
if ( storageBytes > 0 )
|
||||
return name + " - " + GuiText.Stores.getLocal() + " " + (storageBytes / 1024) + "k";
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public long getStorageBytes(ItemStack is)
|
||||
{
|
||||
NBTTagCompound tag = is.getTagCompound();
|
||||
|
||||
if ( tag != null )
|
||||
{
|
||||
return tag.getLong( "bytes" );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,14 +3,15 @@ package appeng.client.render.blocks;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.block.crafting.BlockCraftingMonitor;
|
||||
import appeng.block.crafting.BlockCraftingUnit;
|
||||
import appeng.block.crafting.ItemBlockCraftingUnit;
|
||||
import appeng.client.render.BaseBlockRender;
|
||||
import appeng.client.render.BusRenderHelper;
|
||||
import appeng.client.render.BusRenderer;
|
||||
@@ -20,6 +21,10 @@ import appeng.tile.crafting.TileCraftingTile;
|
||||
public class RenderBlockCrafting extends BaseBlockRender
|
||||
{
|
||||
|
||||
protected RenderBlockCrafting(boolean useTesr, int range) {
|
||||
super( useTesr, range );
|
||||
}
|
||||
|
||||
public RenderBlockCrafting() {
|
||||
super( false, 20 );
|
||||
}
|
||||
@@ -27,30 +32,7 @@ public class RenderBlockCrafting extends BaseBlockRender
|
||||
@Override
|
||||
public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj)
|
||||
{
|
||||
if ( is.getItemDamage() == BlockCraftingUnit.BASE_STORAGE )
|
||||
{
|
||||
ItemBlockCraftingUnit ibcu = (ItemBlockCraftingUnit) is.getItem();
|
||||
int bytes = (int) ibcu.getStorageBytes( is );
|
||||
final int k = 1024;
|
||||
switch (bytes)
|
||||
{
|
||||
case k:
|
||||
renderer.setOverrideBlockTexture( ExtraTextures.BlockCraftingStorage1k.getIcon() );
|
||||
break;
|
||||
case 4 * k:
|
||||
renderer.setOverrideBlockTexture( ExtraTextures.BlockCraftingStorage4k.getIcon() );
|
||||
break;
|
||||
case 16 * k:
|
||||
renderer.setOverrideBlockTexture( ExtraTextures.BlockCraftingStorage16k.getIcon() );
|
||||
break;
|
||||
case 64 * k:
|
||||
renderer.setOverrideBlockTexture( ExtraTextures.BlockCraftingStorage64k.getIcon() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
renderer.setOverrideBlockTexture( blk.getIcon( 0, is.getItemDamage() ) );
|
||||
|
||||
renderer.setOverrideBlockTexture( blk.getIcon( 0, is.getItemDamage() ) );
|
||||
super.renderInventory( blk, is, renderer, type, obj );
|
||||
renderer.setOverrideBlockTexture( null );
|
||||
}
|
||||
@@ -60,36 +42,18 @@ public class RenderBlockCrafting extends BaseBlockRender
|
||||
{
|
||||
IIcon theIcon = null;
|
||||
boolean formed = false;
|
||||
boolean emitsLight = false;
|
||||
|
||||
TileCraftingTile ct = blk.getTileEntity( w, x, y, z );
|
||||
if ( ct != null && ct.isFormed() )
|
||||
formed = true;
|
||||
|
||||
int meta = w.getBlockMetadata( x, y, z ) & 7;
|
||||
|
||||
if ( meta == BlockCraftingUnit.BASE_STORAGE )
|
||||
{
|
||||
TileCraftingTile tct = (TileCraftingTile) blk.getTileEntity( w, x, y, z );
|
||||
|
||||
final int k = 1024;
|
||||
switch ((int) tct.getStorageBytes())
|
||||
{
|
||||
case k:
|
||||
theIcon = formed ? ExtraTextures.BlockCraftingStorage1kFit.getIcon() : ExtraTextures.BlockCraftingStorage1k.getIcon();
|
||||
break;
|
||||
case 4 * k:
|
||||
theIcon = formed ? ExtraTextures.BlockCraftingStorage4kFit.getIcon() : ExtraTextures.BlockCraftingStorage4k.getIcon();
|
||||
break;
|
||||
case 16 * k:
|
||||
theIcon = formed ? ExtraTextures.BlockCraftingStorage16kFit.getIcon() : ExtraTextures.BlockCraftingStorage16k.getIcon();
|
||||
break;
|
||||
case 64 * k:
|
||||
theIcon = formed ? ExtraTextures.BlockCraftingStorage64kFit.getIcon() : ExtraTextures.BlockCraftingStorage64k.getIcon();
|
||||
break;
|
||||
}
|
||||
formed = true;
|
||||
emitsLight = ct.isPowered();
|
||||
}
|
||||
else
|
||||
theIcon = blk.getIcon( 0, meta | (formed ? 8 : 0) );
|
||||
int meta = w.getBlockMetadata( x, y, z ) & 3;
|
||||
|
||||
boolean isMonitor = blk.getClass() == BlockCraftingMonitor.class;
|
||||
theIcon = blk.getIcon( 0, meta | (formed ? 8 : 0) );
|
||||
|
||||
if ( formed )
|
||||
{
|
||||
@@ -134,7 +98,7 @@ public class RenderBlockCrafting extends BaseBlockRender
|
||||
fso( side, highX, ForgeDirection.EAST ), fso( side, highY, ForgeDirection.UP ), fso( side, highZ, ForgeDirection.SOUTH ) );
|
||||
i.prepareBounds( renderer );
|
||||
|
||||
handleSide( x, y, z, i, renderer, theIcon, side, w );
|
||||
handleSide( blk, meta, x, y, z, i, renderer, theIcon, emitsLight, isMonitor, side, w );
|
||||
}
|
||||
|
||||
i.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
|
||||
@@ -194,14 +158,45 @@ public class RenderBlockCrafting extends BaseBlockRender
|
||||
return def;
|
||||
}
|
||||
|
||||
private void handleSide(int x, int y, int z, BusRenderHelper i, RenderBlocks renderer, IIcon theIcon, ForgeDirection side, IBlockAccess w)
|
||||
private void handleSide(AEBaseBlock blk, int meta, int x, int y, int z, BusRenderHelper i, RenderBlocks renderer, IIcon color, boolean emitsLight,
|
||||
boolean isMonitor, ForgeDirection side, IBlockAccess w)
|
||||
{
|
||||
if ( isConnected( w, x, y, z, side ) )
|
||||
return;
|
||||
|
||||
i.setFacesToRender( EnumSet.of( side ) );
|
||||
i.setTexture( ExtraTextures.BlockCraftingHeatVent.getIcon() );
|
||||
i.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
|
||||
if ( meta == 0 && blk.getClass() == BlockCraftingUnit.class )
|
||||
{
|
||||
i.setTexture( ExtraTextures.BlockCraftingUnitFit.getIcon() );
|
||||
i.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( color == ExtraTextures.BlockCraftingMonitorFit.getIcon() )
|
||||
i.setTexture( ExtraTextures.BlockCraftingMonitorOuter.getIcon() );
|
||||
else
|
||||
i.setTexture( ExtraTextures.BlockCraftingFitSolid.getIcon() );
|
||||
|
||||
i.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
|
||||
if ( color != null )
|
||||
{
|
||||
i.setTexture( color );
|
||||
|
||||
if ( !emitsLight )
|
||||
{
|
||||
i.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
}
|
||||
else
|
||||
{
|
||||
Tessellator.instance.setColorOpaque_F( 1.0f, 1.0f, 1.0f );
|
||||
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
|
||||
i.renderFace( x, y, z, color, side, renderer );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
i.setTexture( ExtraTextures.BlockCraftingUnitRingLong.getIcon() );
|
||||
for (ForgeDirection a : ForgeDirection.VALID_DIRECTIONS)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package appeng.client.render.blocks;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
public class RenderBlockCraftingMonitor extends RenderBlockCrafting
|
||||
{
|
||||
|
||||
public RenderBlockCraftingMonitor() {
|
||||
super( true, 20 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTile(AEBaseBlock block, AEBaseTile tile, Tessellator tess, double x, double y, double z, float f, RenderBlocks renderer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,19 +54,19 @@ public enum ExtraTextures
|
||||
|
||||
BlockWirelessInside("BlockWirelessInside"),
|
||||
|
||||
BlockCraftingAccelerator("BlockCraftingAccelerator"), BlockCraftingStorageMonitor("BlockCraftingStorageMonitor"),
|
||||
BlockCraftingAccelerator("BlockCraftingAccelerator"), BlockCraftingMonitor("BlockCraftingMonitor"),
|
||||
|
||||
BlockCraftingStorage1k("BlockCraftingStorage1k"), BlockCraftingStorage4k("BlockCraftingStorage4k"), BlockCraftingStorage16k("BlockCraftingStorage16k"), BlockCraftingStorage64k(
|
||||
"BlockCraftingStorage64k"),
|
||||
|
||||
BlockCraftingAcceleratorFit("BlockCraftingAcceleratorFit"), BlockCraftingStorageMonitorFit("BlockCraftingStorageMonitorFit"),
|
||||
BlockCraftingAcceleratorFit("BlockCraftingAcceleratorFit"), BlockCraftingMonitorFit("BlockCraftingMonitorFit"),
|
||||
|
||||
BlockCraftingStorage1kFit("BlockCraftingStorage1kFit"), BlockCraftingStorage4kFit("BlockCraftingStorage4kFit"), BlockCraftingStorage16kFit(
|
||||
BlockCraftingStorage1kFit("BlockCraftingStorageFit"), BlockCraftingStorage4kFit("BlockCraftingStorage4kFit"), BlockCraftingStorage16kFit(
|
||||
"BlockCraftingStorage16kFit"), BlockCraftingStorage64kFit("BlockCraftingStorage64kFit"),
|
||||
|
||||
BlockCraftingUnitRing("BlockCraftingUnitRing"), BlockCraftingUnitRingLong("BlockCraftingUnitRingLong"), BlockCraftingUnitFit("BlockCraftingUnitFit"),
|
||||
|
||||
BlockCraftingHeatVent("BlockCraftingHeatVent");
|
||||
BlockCraftingMonitorOuter("BlockCraftingMonitorOuter"), BlockCraftingFitSolid("BlockCraftingFitSolid");
|
||||
|
||||
final private String name;
|
||||
public IIcon IIcon;
|
||||
|
||||
@@ -30,6 +30,8 @@ import appeng.api.networking.ticking.ITickManager;
|
||||
import appeng.api.parts.IPartHelper;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.AEItemDefinition;
|
||||
import appeng.block.crafting.BlockCraftingMonitor;
|
||||
import appeng.block.crafting.BlockCraftingStorage;
|
||||
import appeng.block.crafting.BlockCraftingUnit;
|
||||
import appeng.block.crafting.BlockMolecularAssembler;
|
||||
import appeng.block.grindstone.BlockCrank;
|
||||
@@ -272,9 +274,12 @@ public class Registration
|
||||
blocks.blockMultiPart = addFeature( BlockCableBus.class );
|
||||
|
||||
blocks.blockCraftingUnit = addFeature( BlockCraftingUnit.class );
|
||||
blocks.blockCraftingMonitor = new WrappedDamageItemDefinition( blocks.blockCraftingUnit, BlockCraftingUnit.BASE_MONITOR );
|
||||
blocks.blockCraftingStorage = new WrappedDamageItemDefinition( blocks.blockCraftingUnit, BlockCraftingUnit.BASE_STORAGE );
|
||||
blocks.blockCraftingAccelerator = new WrappedDamageItemDefinition( blocks.blockCraftingUnit, BlockCraftingUnit.BASE_ACCELERATOR );
|
||||
blocks.blockCraftingAccelerator = new WrappedDamageItemDefinition( blocks.blockCraftingUnit, 1 );
|
||||
blocks.blockCraftingMonitor = addFeature( BlockCraftingMonitor.class );
|
||||
blocks.blockCraftingStorage1k = addFeature( BlockCraftingStorage.class );
|
||||
blocks.blockCraftingStorage4k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 1 );
|
||||
blocks.blockCraftingStorage16k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 2 );
|
||||
blocks.blockCraftingStorage64k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 3 );
|
||||
blocks.blockMolecularAssembler = addFeature( BlockMolecularAssembler.class );
|
||||
|
||||
blocks.blockQuartzOre = addFeature( OreQuartz.class );
|
||||
|
||||
Vendored
+60
-6
@@ -2,47 +2,101 @@ package appeng.me.cache;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridCache;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.IGridStorage;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingProvider;
|
||||
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
||||
import appeng.api.networking.events.MENetworkCraftingCpuChange;
|
||||
import appeng.api.networking.events.MENetworkCraftingPatternChange;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.tile.crafting.TileCraftingStorageTile;
|
||||
import appeng.tile.crafting.TileCraftingTile;
|
||||
|
||||
public class CraftingCache implements IGridCache
|
||||
public class CraftingCache implements IGridCache, ICraftingProviderHelper
|
||||
{
|
||||
|
||||
HashSet<CraftingCPUCluster> cpuClusters = new HashSet();
|
||||
HashSet<ICraftingProvider> providers = new HashSet();
|
||||
|
||||
IGrid grid;
|
||||
|
||||
boolean updateList = false;
|
||||
|
||||
public CraftingCache(IGrid g) {
|
||||
grid = g;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
if ( updateList )
|
||||
{
|
||||
updateList = false;
|
||||
updateCPUClusters();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCPUClusters(MENetworkCraftingCpuChange c)
|
||||
{
|
||||
updateList = true;
|
||||
}
|
||||
|
||||
public void updateCPUClusters(MENetworkCraftingPatternChange c)
|
||||
{
|
||||
updatePatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode(IGridNode gridNode, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof TileCraftingTile )
|
||||
updateList = true;
|
||||
if ( machine instanceof ICraftingProvider )
|
||||
{
|
||||
providers.remove( machine );
|
||||
|
||||
updatePatterns();
|
||||
updatePatterns();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode(IGridNode gridNode, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof TileCraftingTile )
|
||||
updateList = true;
|
||||
if ( machine instanceof ICraftingProvider )
|
||||
{
|
||||
providers.add( (ICraftingProvider) machine );
|
||||
updatePatterns();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCPUClusters()
|
||||
{
|
||||
cpuClusters.clear();
|
||||
for (IGridNode cst : grid.getMachines( TileCraftingStorageTile.class ))
|
||||
{
|
||||
TileCraftingStorageTile tile = (TileCraftingStorageTile) cst.getMachine();
|
||||
cpuClusters.add( (CraftingCPUCluster) tile.getCluster() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCraftingOption(ICraftingPatternDetails api)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
updatePatterns();
|
||||
}
|
||||
|
||||
private void updatePatterns()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
for (ICraftingProvider cp : providers)
|
||||
{
|
||||
cp.provideCrafting( this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package appeng.me.cluster.implementations;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkCraftingCpuChange;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.me.cluster.IAECluster;
|
||||
import appeng.me.cluster.IAEMultiBlock;
|
||||
@@ -56,6 +63,22 @@ public class CraftingCPUCalculator extends MBCalculator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<IGridHost> i = c.getTiles();
|
||||
while (i.hasNext())
|
||||
{
|
||||
IGridHost gh = i.next();
|
||||
IGridNode n = gh.getGridNode( ForgeDirection.UNKNOWN );
|
||||
if ( n != null )
|
||||
{
|
||||
IGrid g = n.getGrid();
|
||||
if ( g != null )
|
||||
{
|
||||
g.postEvent( new MENetworkCraftingCpuChange( n ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,6 +96,8 @@ public class CraftingCPUCalculator extends MBCalculator
|
||||
@Override
|
||||
public boolean verifyInternalStructure(World w, WorldCoord min, WorldCoord max)
|
||||
{
|
||||
boolean storage = false;
|
||||
|
||||
for (int x = min.x; x <= max.x; x++)
|
||||
{
|
||||
for (int y = min.y; y <= max.y; y++)
|
||||
@@ -84,11 +109,13 @@ public class CraftingCPUCalculator extends MBCalculator
|
||||
if ( !te.isValid() )
|
||||
return false;
|
||||
|
||||
if ( !storage && te instanceof TileCraftingTile )
|
||||
storage = ((TileCraftingTile) te).getStorageBytes() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return storage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ package appeng.me.cluster.implementations;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkCraftingCpuChange;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.me.cluster.IAECluster;
|
||||
import appeng.tile.crafting.TileCraftingTile;
|
||||
@@ -48,8 +51,21 @@ public class CraftingCPUCluster implements IAECluster
|
||||
return;
|
||||
isDestroyed = true;
|
||||
|
||||
boolean posted = false;
|
||||
|
||||
for (TileCraftingTile r : tiles)
|
||||
{
|
||||
IGridNode n = r.getActionableNode();
|
||||
if ( n != null && posted == false )
|
||||
{
|
||||
IGrid g = n.getGrid();
|
||||
if ( g != null )
|
||||
{
|
||||
g.postEvent( new MENetworkCraftingCpuChange( n ) );
|
||||
posted = true;
|
||||
}
|
||||
}
|
||||
|
||||
r.updateStatus( null );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package appeng.tile.crafting;
|
||||
|
||||
public class TileCraftingMonitorTile extends TileCraftingTile
|
||||
{
|
||||
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStatus()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package appeng.tile.crafting;
|
||||
|
||||
public class TileCraftingStorageTile extends TileCraftingTile
|
||||
{
|
||||
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStorage()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getStorageBytes()
|
||||
{
|
||||
switch (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 3)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
return 1 * 1024;
|
||||
case 1:
|
||||
return 4 * 1024;
|
||||
case 2:
|
||||
return 16 * 1024;
|
||||
case 3:
|
||||
return 64 * 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,23 @@ 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.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.parts.ISimplifiedBundle;
|
||||
import appeng.block.crafting.BlockCraftingUnit;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cluster.IAECluster;
|
||||
import appeng.me.cluster.IAEMultiBlock;
|
||||
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 AENetworkTile implements IAEMultiBlock
|
||||
{
|
||||
|
||||
private long storageBytes = 0;
|
||||
CraftingCPUCluster clust;
|
||||
final CraftingCPUCalculator calc = new CraftingCPUCalculator( this );
|
||||
public ISimplifiedBundle lightCache;
|
||||
@@ -48,31 +43,6 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock
|
||||
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)
|
||||
{
|
||||
if ( storageBytes > 0 )
|
||||
data.setLong( "bytes", storageBytes );
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
storageBytes = data.getLong( "bytes" );
|
||||
}
|
||||
|
||||
public boolean readFromStream(io.netty.buffer.ByteBuf data) throws java.io.IOException
|
||||
{
|
||||
storageBytes = data.readLong();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void writeToStream(io.netty.buffer.ByteBuf data) throws java.io.IOException
|
||||
{
|
||||
data.writeLong( storageBytes );
|
||||
}
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,13 +53,10 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement(ItemStack stack, EntityPlayer player, int side)
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
if ( AEApi.instance().blocks().blockCraftingStorage.sameAsStack( stack ) && stack.hasTagCompound() )
|
||||
{
|
||||
NBTTagCompound data = stack.getTagCompound();
|
||||
storageBytes = data.getLong( "bytes" );
|
||||
}
|
||||
return true;// return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ),
|
||||
// BlockCraftingUnit.BASE_MONITOR );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,11 +69,27 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerStateChage(MENetworkPowerStatusChange ev)
|
||||
{
|
||||
updateMeta();
|
||||
}
|
||||
|
||||
public void updateMeta()
|
||||
{
|
||||
boolean formed = clust != null;
|
||||
boolean power = false;
|
||||
try
|
||||
{
|
||||
power = gridProxy.getEnergy().isNetworkPowered();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
|
||||
int current = worldObj.getBlockMetadata( xCoord, yCoord, zCoord );
|
||||
int newmeta = (current & 7) | (formed ? 8 : 0);
|
||||
int newmeta = (current & 3) | (formed ? 8 : 0) | (power ? 4 : 0);
|
||||
|
||||
if ( current != newmeta )
|
||||
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, newmeta, 3 );
|
||||
@@ -135,9 +118,9 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock
|
||||
return true;
|
||||
}
|
||||
|
||||
public long getStorageBytes()
|
||||
public boolean isPowered()
|
||||
{
|
||||
return storageBytes;
|
||||
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 4) == 4;
|
||||
}
|
||||
|
||||
public boolean isFormed()
|
||||
@@ -145,19 +128,24 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock
|
||||
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 8) == 8;
|
||||
}
|
||||
|
||||
public boolean isStorage()
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ), BlockCraftingUnit.BASE_STORAGE );
|
||||
return worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) == 1;
|
||||
}
|
||||
|
||||
public boolean isStatus()
|
||||
{
|
||||
return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ), BlockCraftingUnit.BASE_MONITOR );
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAccelerator()
|
||||
public boolean isStorage()
|
||||
{
|
||||
return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ), BlockCraftingUnit.BASE_ACCELERATOR );
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getStorageBytes()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user