diff --git a/src/main/java/appeng/block/AEBaseBlock.java b/src/main/java/appeng/block/AEBaseBlock.java index 85e84764b..c19e96f60 100644 --- a/src/main/java/appeng/block/AEBaseBlock.java +++ b/src/main/java/appeng/block/AEBaseBlock.java @@ -18,12 +18,14 @@ package appeng.block; + import java.util.ArrayList; import java.util.EnumSet; import java.util.List; -import appeng.client.texture.FlippableIcon; +import com.google.common.base.Optional; import com.google.common.collect.Lists; + import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; @@ -48,6 +50,12 @@ import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.ReflectionHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + import appeng.api.implementations.items.IMemoryCard; import appeng.api.implementations.items.MemoryCardMessages; import appeng.api.implementations.tiles.IColorableTile; @@ -58,10 +66,13 @@ import appeng.block.networking.BlockCableBus; import appeng.client.render.BaseBlockRender; import appeng.client.render.BlockRenderInfo; import appeng.client.render.WorldRender; +import appeng.client.texture.FlippableIcon; import appeng.client.texture.MissingIcon; +import appeng.core.features.AEBlockFeatureHandler; import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; +import appeng.core.features.FeatureNameExtractor; import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; import appeng.core.features.ItemStackSrc; import appeng.helpers.AEGlassMaterial; import appeng.helpers.ICustomCollision; @@ -71,144 +82,26 @@ import appeng.tile.storage.TileSkyChest; import appeng.util.LookDirection; import appeng.util.Platform; import appeng.util.SettingsFrom; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.ReflectionHelper; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; + public class AEBaseBlock extends BlockContainer implements IAEFeature { - private final String featureFullName; - private final String featureSubName; - private AEFeatureHandler feature; - - private Class tileEntityType = null; + private final Optional featureSubName; + @SideOnly( Side.CLIENT ) + public IIcon renderIcon; protected boolean isOpaque = true; protected boolean isFullSize = true; protected boolean hasSubtypes = false; protected boolean isInventory = false; - - @SideOnly(Side.CLIENT) - public IIcon renderIcon; - - @SideOnly(Side.CLIENT) + @SideOnly( Side.CLIENT ) BlockRenderInfo renderInfo; + private IFeatureHandler handler; + private Class tileEntityType = null; - @Override - public String toString() + protected AEBaseBlock( Class c, Material mat ) { - return featureFullName; - } - - @SideOnly(Side.CLIENT) - protected Class getRenderer() - { - return BaseBlockRender.class; - } - - @Override - @SideOnly(Side.CLIENT) - public int getRenderType() - { - return WorldRender.instance.getRenderId(); - } - - @SideOnly(Side.CLIENT) - private FlippableIcon optionalIcon(IIconRegister ir, String Name, IIcon substitute) - { - // if the input is an flippable IIcon find the original. - while (substitute instanceof FlippableIcon) - substitute = ((FlippableIcon) substitute).getOriginal(); - - if ( substitute != null ) - { - try - { - ResourceLocation resLoc = new ResourceLocation( Name ); - resLoc = new ResourceLocation( resLoc.getResourceDomain(), String.format( "%s/%s%s", "textures/blocks", - resLoc.getResourcePath(), ".png" ) ); - - IResource res = Minecraft.getMinecraft().getResourceManager().getResource( resLoc ); - if ( res != null ) - return new FlippableIcon( ir.registerIcon( Name ) ); - } - catch (Throwable e) - { - return new FlippableIcon( substitute ); - } - } - - return new FlippableIcon( ir.registerIcon( Name ) ); - } - - @Override - @SideOnly(Side.CLIENT) - public void registerBlockIcons(IIconRegister iconRegistry) - { - BlockRenderInfo info = getRendererInstance(); - FlippableIcon topIcon; - FlippableIcon bottomIcon; - FlippableIcon sideIcon; - FlippableIcon eastIcon; - FlippableIcon westIcon; - FlippableIcon southIcon; - FlippableIcon northIcon; - - this.blockIcon = topIcon = optionalIcon( iconRegistry, this.getTextureName(), null ); - bottomIcon = optionalIcon( iconRegistry, this.getTextureName() + "Bottom", topIcon ); - sideIcon = optionalIcon( iconRegistry, this.getTextureName() + "Side", topIcon ); - eastIcon = optionalIcon( iconRegistry, this.getTextureName() + "East", sideIcon ); - westIcon = optionalIcon( iconRegistry, this.getTextureName() + "West", sideIcon ); - southIcon = optionalIcon( iconRegistry, this.getTextureName() + "Front", sideIcon ); - northIcon = optionalIcon( iconRegistry, this.getTextureName() + "Back", sideIcon ); - - info.updateIcons( bottomIcon, topIcon, northIcon, southIcon, eastIcon, westIcon ); - } - - public void registerNoIcons() - { - BlockRenderInfo info = getRendererInstance(); - FlippableIcon i = new FlippableIcon( new MissingIcon( this ) ); - info.updateIcons( i, i, i, i, i, i ); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(int direction, int metadata) - { - if ( renderIcon != null ) - return renderIcon; - - return getRendererInstance().getTexture( ForgeDirection.getOrientation( direction ) ); - } - - public IIcon unmappedGetIcon(IBlockAccess w, int x, int y, int z, int s) - { - return super.getIcon( w, x, y, z, s ); - } - - @Override - public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s) - { - return getIcon( mapRotation( w, x, y, z, s ), w.getBlockMetadata( x, y, z ) ); - } - - protected void setTileEntity(Class c) - { - AEBaseTile.registerTileItem( c, new ItemStackSrc( this, 0 ) ); - GameRegistry.registerTileEntity( tileEntityType = c, featureFullName ); - isInventory = IInventory.class.isAssignableFrom( c ); - setTileProvider( hasBlockTileEntity() ); - } - - protected void setFeature(EnumSet f) - { - feature = new AEFeatureHandler( f, this, featureSubName ); - } - - protected AEBaseBlock(Class c, Material mat) { - this( c, mat, null ); + this( c, mat, Optional. absent() ); setLightOpacity( 255 ); setLightLevel( 0 ); setHardness( 2.2F ); @@ -216,13 +109,8 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature setHarvestLevel( "pickaxe", 0 ); } - // update Block value. - private void setTileProvider(boolean b) + protected AEBaseBlock( Class c, Material mat, Optional subName ) { - ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" ); - } - - protected AEBaseBlock(Class c, Material mat, String subName) { super( mat ); if ( mat == AEGlassMaterial.instance ) @@ -234,23 +122,60 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature else setStepSound( Block.soundTypeMetal ); - featureFullName = AEFeatureHandler.getName( c, subName ); + featureFullName = new FeatureNameExtractor( c, subName ).get(); featureSubName = subName; } @Override - final public AEFeatureHandler feature() + public String toString() { - return feature; + return featureFullName; } - public boolean isOpaque() + public void registerNoIcons() { - return isOpaque; + BlockRenderInfo info = getRendererInstance(); + FlippableIcon i = new FlippableIcon( new MissingIcon( this ) ); + info.updateIcons( i, i, i, i, i, i ); + } + + public IIcon unmappedGetIcon( IBlockAccess w, int x, int y, int z, int s ) + { + return super.getIcon( w, x, y, z, s ); + } + + protected void setTileEntity( Class c ) + { + AEBaseTile.registerTileItem( c, new ItemStackSrc( this, 0 ) ); + GameRegistry.registerTileEntity( tileEntityType = c, featureFullName ); + isInventory = IInventory.class.isAssignableFrom( c ); + setTileProvider( hasBlockTileEntity() ); + } + + // update Block value. + private void setTileProvider( boolean b ) + { + ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" ); + } + + protected void setFeature( EnumSet f ) + { + this.handler = new AEBlockFeatureHandler( f, this, this.featureSubName ); } @Override - final public boolean isOpaqueCube() + final public IFeatureHandler handler() + { + return handler; + } + + @Override + public void postInit() + { + // override! + } + + public boolean isOpaque() { return isOpaque; } @@ -262,293 +187,78 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature } @Override - final public boolean isNormalCube(IBlockAccess world, int x, int y, int z) + @SideOnly( Side.CLIENT ) + public int getRenderType() { - return isFullSize; - } - - public boolean hasBlockTileEntity() - { - return tileEntityType != null; - } - - public Class getTileEntityClass() - { - return tileEntityType; - } - - @SideOnly(Side.CLIENT) - public void setRenderStateByMeta(int itemDamage) - { - - } - - @SideOnly(Side.CLIENT) - public BlockRenderInfo getRendererInstance() - { - if ( renderInfo != null ) - return renderInfo; - - try - { - return renderInfo = new BlockRenderInfo( getRenderer().newInstance() ); - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } + return WorldRender.instance.getRenderId(); } @Override - final public TileEntity createNewTileEntity(World var1, int var2) + public IIcon getIcon( IBlockAccess w, int x, int y, int z, int s ) { - if ( hasBlockTileEntity() ) - { - try - { - return tileEntityType.newInstance(); - } - catch (Throwable e) - { - throw new RuntimeException( e ); - } - } - return null; - } - - public T getTileEntity(IBlockAccess w, int x, int y, int z) - { - if ( !hasBlockTileEntity() ) - return null; - - TileEntity te = w.getTileEntity( x, y, z ); - if ( tileEntityType.isInstance( te ) ) - return (T) te; - - return null; - } - - protected boolean hasCustomRotation() - { - return false; - } - - protected void customRotateBlock(IOrientable rotatable, ForgeDirection axis) - { - + return getIcon( mapRotation( w, x, y, z, s ), w.getBlockMetadata( x, y, z ) ); } @Override - final public boolean rotateBlock(World w, int x, int y, int z, ForgeDirection axis) + @SideOnly( Side.CLIENT ) + public IIcon getIcon( int direction, int metadata ) { - IOrientable rotatable = null; + if ( renderIcon != null ) + return renderIcon; - if ( hasBlockTileEntity() ) - { - rotatable = (AEBaseTile) getTileEntity( w, x, y, z ); - } - else if ( this instanceof IOrientableBlock ) - { - rotatable = ((IOrientableBlock) this).getOrientable( w, x, y, z ); - } - - if ( rotatable != null && rotatable.canBeRotated() ) - { - if ( hasCustomRotation() ) - { - customRotateBlock( rotatable, axis ); - return true; - } - else - { - ForgeDirection forward = rotatable.getForward(); - ForgeDirection up = rotatable.getUp(); - - for (int rs = 0; rs < 4; rs++) - { - forward = Platform.rotateAround( forward, axis ); - up = Platform.rotateAround( up, axis ); - - if ( this.isValidOrientation( w, x, y, z, forward, up ) ) - { - rotatable.setOrientation( forward, up ); - return true; - } - } - } - } - - return super.rotateBlock( w, x, y, z, axis ); - } - - public ForgeDirection mapRotation(IOrientable ori, ForgeDirection dir) - { - // case DOWN: return bottomIcon; - // case UP: return blockIcon; - // case NORTH: return northIcon; - // case SOUTH: return southIcon; - // case WEST: return sideIcon; - // case EAST: return sideIcon; - - ForgeDirection forward = ori.getForward(); - ForgeDirection up = ori.getUp(); - ForgeDirection west = ForgeDirection.UNKNOWN; - - if ( forward == null || up == null ) - return dir; - - int west_x = forward.offsetY * up.offsetZ - forward.offsetZ * up.offsetY; - int west_y = forward.offsetZ * up.offsetX - forward.offsetX * up.offsetZ; - int west_z = forward.offsetX * up.offsetY - forward.offsetY * up.offsetX; - - for (ForgeDirection dx : ForgeDirection.VALID_DIRECTIONS) - if ( dx.offsetX == west_x && dx.offsetY == west_y && dx.offsetZ == west_z ) - west = dx; - - if ( dir.equals( forward ) ) - return ForgeDirection.SOUTH; - if ( dir.equals( forward.getOpposite() ) ) - return ForgeDirection.NORTH; - - if ( dir.equals( up ) ) - return ForgeDirection.UP; - if ( dir.equals( up.getOpposite() ) ) - return ForgeDirection.DOWN; - - if ( dir.equals( west ) ) - return ForgeDirection.WEST; - if ( dir.equals( west.getOpposite() ) ) - return ForgeDirection.EAST; - - return ForgeDirection.UNKNOWN; - } - - int mapRotation(IBlockAccess w, int x, int y, int z, int s) - { - IOrientable ori = null; - - if ( hasBlockTileEntity() ) - { - ori = (AEBaseTile) getTileEntity( w, x, y, z ); - } - else if ( this instanceof IOrientableBlock ) - { - ori = ((IOrientableBlock) this).getOrientable( w, x, y, z ); - } - - if ( ori != null && ori.canBeRotated() ) - { - return mapRotation( ori, ForgeDirection.getOrientation( s ) ).ordinal(); - } - - return s; + return getRendererInstance().getTexture( ForgeDirection.getOrientation( direction ) ); } @Override - final public ForgeDirection[] getValidRotations(World w, int x, int y, int z) - { - if ( hasBlockTileEntity() ) - { - AEBaseTile obj = getTileEntity( w, x, y, z ); - if ( obj != null && obj.canBeRotated() ) - { - return ForgeDirection.VALID_DIRECTIONS; - } - } - - return new ForgeDirection[0]; - } - - @Override - public void breakBlock(World w, int x, int y, int z, Block a, int b) - { - AEBaseTile te = getTileEntity( w, x, y, z ); - if ( te != null ) - { - ArrayList drops = new ArrayList(); - if ( te.dropItems() ) - te.getDrops( w, x, y, z, drops ); - else - te.getNoDrops( w, x, y, z, drops ); - - // Cry ;_; ... - Platform.spawnDrops( w, x, y, z, drops ); - } - - super.breakBlock( w, x, y, z, a, b ); - if ( te != null ) - w.setTileEntity( x, y, z, null ); - } - - @Override - public MovingObjectPosition collisionRayTrace(World w, int x, int y, int z, Vec3 a, Vec3 b) + @SuppressWarnings( "unchecked" ) + // NOTE: WAS FINAL, changed for Immibis + public void addCollisionBoxesToList( World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e ) { ICustomCollision collisionHandler = null; if ( this instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) this; + collisionHandler = ( ICustomCollision ) this; else { AEBaseTile te = getTileEntity( w, x, y, z ); if ( te instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) te; + collisionHandler = ( ICustomCollision ) te; } - if ( collisionHandler != null ) + if ( collisionHandler != null && bb != null ) { - Iterable bbs = collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, true ); - MovingObjectPosition br = null; - - double lastDist = 0; - - for (AxisAlignedBB bb : bbs) + List tmp = new ArrayList(); + collisionHandler.addCollidingBlockToList( w, x, y, z, bb, tmp, e ); + for ( AxisAlignedBB b : tmp ) { - setBlockBounds( (float) bb.minX, (float) bb.minY, (float) bb.minZ, (float) bb.maxX, (float) bb.maxY, (float) bb.maxZ ); - - MovingObjectPosition r = super.collisionRayTrace( w, x, y, z, a, b ); - - setBlockBounds( 0, 0, 0, 1, 1, 1 ); - - if ( r != null ) - { - double xLen = (a.xCoord - r.hitVec.xCoord); - double yLen = (a.yCoord - r.hitVec.yCoord); - double zLen = (a.zCoord - r.hitVec.zCoord); - - double thisDist = xLen * xLen + yLen * yLen + zLen * zLen; - if ( br == null || lastDist > thisDist ) - { - lastDist = thisDist; - br = r; - } - } + b.minX += x; + b.minY += y; + b.minZ += z; + b.maxX += x; + b.maxY += y; + b.maxZ += z; + if ( bb.intersectsWith( b ) ) + out.add( b ); } - - if ( br != null ) - { - return br; - } - return null; } - - setBlockBounds( 0, 0, 0, 1, 1, 1 ); - return super.collisionRayTrace( w, x, y, z, a, b ); + else + super.addCollisionBoxesToList( w, x, y, z, bb, out, e ); } @Override - @SideOnly(Side.CLIENT) - final public AxisAlignedBB getSelectedBoundingBoxFromPool(World w, int x, int y, int z) + @SideOnly( Side.CLIENT ) + final public AxisAlignedBB getSelectedBoundingBoxFromPool( World w, int x, int y, int z ) { ICustomCollision collisionHandler = null; AxisAlignedBB b = null; if ( this instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) this; + collisionHandler = ( ICustomCollision ) this; else { AEBaseTile te = getTileEntity( w, x, y, z ); if ( te instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) te; + collisionHandler = ( ICustomCollision ) te; } if ( collisionHandler != null ) @@ -563,9 +273,9 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature double lastDist = 0; - for (AxisAlignedBB bb : bbs) + for ( AxisAlignedBB bb : bbs ) { - setBlockBounds( (float) bb.minX, (float) bb.minY, (float) bb.minZ, (float) bb.maxX, (float) bb.maxY, (float) bb.maxZ ); + setBlockBounds( ( float ) bb.minX, ( float ) bb.minY, ( float ) bb.minZ, ( float ) bb.maxX, ( float ) bb.maxY, ( float ) bb.maxZ ); MovingObjectPosition r = super.collisionRayTrace( w, x, y, z, ld.a, ld.b ); @@ -573,9 +283,9 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature if ( r != null ) { - double xLen = (ld.a.xCoord - r.hitVec.xCoord); - double yLen = (ld.a.yCoord - r.hitVec.yCoord); - double zLen = (ld.a.zCoord - r.hitVec.zCoord); + double xLen = ( ld.a.xCoord - r.hitVec.xCoord ); + double yLen = ( ld.a.yCoord - r.hitVec.yCoord ); + double zLen = ( ld.a.zCoord - r.hitVec.zCoord ); double thisDist = xLen * xLen + yLen * yLen + zLen * zLen; if ( br == null || lastDist > thisDist ) @@ -593,7 +303,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature } } - for (AxisAlignedBB bx : collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, false )) + for ( AxisAlignedBB bx : collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, false ) ) { if ( b == null ) b = bx; @@ -618,48 +328,68 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature } @Override - @SuppressWarnings( "unchecked" ) - // NOTE: WAS FINAL, changed for Immibis - public void addCollisionBoxesToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) + final public boolean isOpaqueCube() + { + return isOpaque; + } + + @Override + public MovingObjectPosition collisionRayTrace( World w, int x, int y, int z, Vec3 a, Vec3 b ) { ICustomCollision collisionHandler = null; if ( this instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) this; + collisionHandler = ( ICustomCollision ) this; else { AEBaseTile te = getTileEntity( w, x, y, z ); if ( te instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) te; + collisionHandler = ( ICustomCollision ) te; } - if ( collisionHandler != null && bb != null ) + if ( collisionHandler != null ) { - List tmp = new ArrayList(); - collisionHandler.addCollidingBlockToList( w, x, y, z, bb, tmp, e ); - for (AxisAlignedBB b : tmp) - { - b.minX += x; - b.minY += y; - b.minZ += z; - b.maxX += x; - b.maxY += y; - b.maxZ += z; - if ( bb.intersectsWith( b ) ) - out.add( b ); - } - } - else - super.addCollisionBoxesToList( w, x, y, z, bb, out, e ); - } + Iterable bbs = collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, true ); + MovingObjectPosition br = null; - public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) - { - return false; + double lastDist = 0; + + for ( AxisAlignedBB bb : bbs ) + { + setBlockBounds( ( float ) bb.minX, ( float ) bb.minY, ( float ) bb.minZ, ( float ) bb.maxX, ( float ) bb.maxY, ( float ) bb.maxZ ); + + MovingObjectPosition r = super.collisionRayTrace( w, x, y, z, a, b ); + + setBlockBounds( 0, 0, 0, 1, 1, 1 ); + + if ( r != null ) + { + double xLen = ( a.xCoord - r.hitVec.xCoord ); + double yLen = ( a.yCoord - r.hitVec.yCoord ); + double zLen = ( a.zCoord - r.hitVec.zCoord ); + + double thisDist = xLen * xLen + yLen * yLen + zLen * zLen; + if ( br == null || lastDist > thisDist ) + { + lastDist = thisDist; + br = r; + } + } + } + + if ( br != null ) + { + return br; + } + return null; + } + + setBlockBounds( 0, 0, 0, 1, 1, 1 ); + return super.collisionRayTrace( w, x, y, z, a, b ); } @Override - final public boolean onBlockActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) + final public boolean onBlockActivated( World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ ) { if ( player != null ) { @@ -681,7 +411,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature return false; ItemStack op = new ItemStack( this ); - for (ItemStack ol : drops) + for ( ItemStack ol : drops ) { if ( Platform.isSameItemType( ol, op ) ) { @@ -693,7 +423,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature if ( id.removedByPlayer( w, player, x, y, z, false ) ) { - List l = Lists.newArrayList(drops); + List l = Lists.newArrayList( drops ); Platform.spawnDrops( w, x, y, z, l ); w.setBlockToAir( x, y, z ); } @@ -701,9 +431,9 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature return false; } - if ( is.getItem() instanceof IMemoryCard && !(this instanceof BlockCableBus) ) + if ( is.getItem() instanceof IMemoryCard && !( this instanceof BlockCableBus ) ) { - IMemoryCard memoryCard = (IMemoryCard) is.getItem(); + IMemoryCard memoryCard = ( IMemoryCard ) is.getItem(); if ( player.isSneaking() ) { AEBaseTile t = getTileEntity( w, x, y, z ); @@ -740,35 +470,28 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature return onActivated( w, x, y, z, player, side, hitX, hitY, hitZ ); } - public boolean isValidOrientation(World w, int x, int y, int z, ForgeDirection forward, ForgeDirection up) + public boolean onActivated( World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ ) { - return true; - } - - public String getUnlocalizedName(ItemStack is) - { - return getUnlocalizedName(); - } - - public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips) - { - - } - - public Class getItemBlockClass() - { - return AEBaseItemBlock.class; + return false; } @Override - public void postInit() + public void onBlockPlacedBy( World w, int x, int y, int z, EntityLivingBase player, ItemStack is ) { - // override! + if ( is.hasDisplayName() ) + { + TileEntity te = getTileEntity( w, x, y, z ); + if ( te instanceof AEBaseTile ) + ( ( AEBaseTile ) w.getTileEntity( x, y, z ) ).setName( is.getDisplayName() ); + } } - public boolean hasSubtypes() + @Override + @SideOnly( Side.CLIENT ) + @SuppressWarnings( "unchecked" ) + public final void getSubBlocks( Item item, CreativeTabs tabs, List itemStacks ) { - return hasSubtypes; + this.getCheckedSubBlocks( item, tabs, itemStacks ); } @Override @@ -778,22 +501,125 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature } @Override - public int getComparatorInputOverride(World w, int x, int y, int z, int s) + public int getComparatorInputOverride( World w, int x, int y, int z, int s ) { TileEntity te = getTileEntity( w, x, y, z ); if ( te instanceof IInventory ) - return Container.calcRedstoneFromInventory( (IInventory) te ); + return Container.calcRedstoneFromInventory( ( IInventory ) te ); return 0; } @Override - public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour) + @SideOnly( Side.CLIENT ) + public void registerBlockIcons( IIconRegister iconRegistry ) + { + BlockRenderInfo info = getRendererInstance(); + FlippableIcon topIcon; + FlippableIcon bottomIcon; + FlippableIcon sideIcon; + FlippableIcon eastIcon; + FlippableIcon westIcon; + FlippableIcon southIcon; + FlippableIcon northIcon; + + this.blockIcon = topIcon = optionalIcon( iconRegistry, this.getTextureName(), null ); + bottomIcon = optionalIcon( iconRegistry, this.getTextureName() + "Bottom", topIcon ); + sideIcon = optionalIcon( iconRegistry, this.getTextureName() + "Side", topIcon ); + eastIcon = optionalIcon( iconRegistry, this.getTextureName() + "East", sideIcon ); + westIcon = optionalIcon( iconRegistry, this.getTextureName() + "West", sideIcon ); + southIcon = optionalIcon( iconRegistry, this.getTextureName() + "Front", sideIcon ); + northIcon = optionalIcon( iconRegistry, this.getTextureName() + "Back", sideIcon ); + + info.updateIcons( bottomIcon, topIcon, northIcon, southIcon, eastIcon, westIcon ); + } + + @Override + final public boolean isNormalCube( IBlockAccess world, int x, int y, int z ) + { + return isFullSize; + } + + @Override + final public boolean rotateBlock( World w, int x, int y, int z, ForgeDirection axis ) + { + IOrientable rotatable = null; + + if ( hasBlockTileEntity() ) + { + rotatable = ( AEBaseTile ) getTileEntity( w, x, y, z ); + } + else if ( this instanceof IOrientableBlock ) + { + rotatable = ( ( IOrientableBlock ) this ).getOrientable( w, x, y, z ); + } + + if ( rotatable != null && rotatable.canBeRotated() ) + { + if ( hasCustomRotation() ) + { + customRotateBlock( rotatable, axis ); + return true; + } + else + { + ForgeDirection forward = rotatable.getForward(); + ForgeDirection up = rotatable.getUp(); + + for ( int rs = 0; rs < 4; rs++ ) + { + forward = Platform.rotateAround( forward, axis ); + up = Platform.rotateAround( up, axis ); + + if ( this.isValidOrientation( w, x, y, z, forward, up ) ) + { + rotatable.setOrientation( forward, up ); + return true; + } + } + } + } + + return super.rotateBlock( w, x, y, z, axis ); + } + + protected boolean hasCustomRotation() + { + return false; + } + + protected void customRotateBlock( IOrientable rotatable, ForgeDirection axis ) + { + + } + + public boolean isValidOrientation( World w, int x, int y, int z, ForgeDirection forward, ForgeDirection up ) + { + return true; + } + + @Override + final public ForgeDirection[] getValidRotations( World w, int x, int y, int z ) + { + if ( hasBlockTileEntity() ) + { + AEBaseTile obj = getTileEntity( w, x, y, z ); + if ( obj != null && obj.canBeRotated() ) + { + return ForgeDirection.VALID_DIRECTIONS; + } + } + + return new ForgeDirection[0]; + } + + @Override + public boolean recolourBlock( World world, int x, int y, int z, ForgeDirection side, int colour ) { TileEntity te = getTileEntity( world, x, y, z ); if ( te instanceof IColorableTile ) { - IColorableTile ct = (IColorableTile) te; + IColorableTile ct = ( IColorableTile ) te; AEColor c = ct.getColor(); AEColor newColor = AEColor.values()[colour]; @@ -808,28 +634,208 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature return super.recolourBlock( world, x, y, z, side, colour ); } - @Override - public void onBlockPlacedBy(World w, int x, int y, int z, EntityLivingBase player, ItemStack is) + @SideOnly( Side.CLIENT ) + public BlockRenderInfo getRendererInstance() { - if ( is.hasDisplayName() ) + if ( renderInfo != null ) + return renderInfo; + + try { - TileEntity te = getTileEntity( w, x, y, z ); - if ( te instanceof AEBaseTile ) - ((AEBaseTile) w.getTileEntity( x, y, z )).setName( is.getDisplayName() ); + return renderInfo = new BlockRenderInfo( getRenderer().newInstance() ); + } + catch ( Throwable t ) + { + throw new RuntimeException( t ); } } - @Override - @SideOnly(Side.CLIENT) - @SuppressWarnings("unchecked") - public final void getSubBlocks(Item item, CreativeTabs tabs, List itemStacks) + @SideOnly( Side.CLIENT ) + private FlippableIcon optionalIcon( IIconRegister ir, String Name, IIcon substitute ) { - this.getCheckedSubBlocks( item, tabs, itemStacks ); + // if the input is an flippable IIcon find the original. + while ( substitute instanceof FlippableIcon ) + substitute = ( ( FlippableIcon ) substitute ).getOriginal(); + + if ( substitute != null ) + { + try + { + ResourceLocation resLoc = new ResourceLocation( Name ); + resLoc = new ResourceLocation( resLoc.getResourceDomain(), String.format( "%s/%s%s", "textures/blocks", + resLoc.getResourcePath(), ".png" ) ); + + IResource res = Minecraft.getMinecraft().getResourceManager().getResource( resLoc ); + if ( res != null ) + return new FlippableIcon( ir.registerIcon( Name ) ); + } + catch ( Throwable e ) + { + return new FlippableIcon( substitute ); + } + } + + return new FlippableIcon( ir.registerIcon( Name ) ); } - @SideOnly(Side.CLIENT) - public void getCheckedSubBlocks(Item item, CreativeTabs tabs, List itemStacks) + @SideOnly( Side.CLIENT ) + protected Class getRenderer() + { + return BaseBlockRender.class; + } + + @SideOnly( Side.CLIENT ) + public void getCheckedSubBlocks( Item item, CreativeTabs tabs, List itemStacks ) { super.getSubBlocks( item, tabs, itemStacks ); } + + int mapRotation( IBlockAccess w, int x, int y, int z, int s ) + { + IOrientable ori = null; + + if ( hasBlockTileEntity() ) + { + ori = ( AEBaseTile ) getTileEntity( w, x, y, z ); + } + else if ( this instanceof IOrientableBlock ) + { + ori = ( ( IOrientableBlock ) this ).getOrientable( w, x, y, z ); + } + + if ( ori != null && ori.canBeRotated() ) + { + return mapRotation( ori, ForgeDirection.getOrientation( s ) ).ordinal(); + } + + return s; + } + + public boolean hasBlockTileEntity() + { + return tileEntityType != null; + } + + public T getTileEntity( IBlockAccess w, int x, int y, int z ) + { + if ( !hasBlockTileEntity() ) + return null; + + TileEntity te = w.getTileEntity( x, y, z ); + if ( tileEntityType.isInstance( te ) ) + return ( T ) te; + + return null; + } + + public ForgeDirection mapRotation( IOrientable ori, ForgeDirection dir ) + { + // case DOWN: return bottomIcon; + // case UP: return blockIcon; + // case NORTH: return northIcon; + // case SOUTH: return southIcon; + // case WEST: return sideIcon; + // case EAST: return sideIcon; + + ForgeDirection forward = ori.getForward(); + ForgeDirection up = ori.getUp(); + ForgeDirection west = ForgeDirection.UNKNOWN; + + if ( forward == null || up == null ) + return dir; + + int west_x = forward.offsetY * up.offsetZ - forward.offsetZ * up.offsetY; + int west_y = forward.offsetZ * up.offsetX - forward.offsetX * up.offsetZ; + int west_z = forward.offsetX * up.offsetY - forward.offsetY * up.offsetX; + + for ( ForgeDirection dx : ForgeDirection.VALID_DIRECTIONS ) + if ( dx.offsetX == west_x && dx.offsetY == west_y && dx.offsetZ == west_z ) + west = dx; + + if ( dir.equals( forward ) ) + return ForgeDirection.SOUTH; + if ( dir.equals( forward.getOpposite() ) ) + return ForgeDirection.NORTH; + + if ( dir.equals( up ) ) + return ForgeDirection.UP; + if ( dir.equals( up.getOpposite() ) ) + return ForgeDirection.DOWN; + + if ( dir.equals( west ) ) + return ForgeDirection.WEST; + if ( dir.equals( west.getOpposite() ) ) + return ForgeDirection.EAST; + + return ForgeDirection.UNKNOWN; + } + + public Class getTileEntityClass() + { + return tileEntityType; + } + + @SideOnly( Side.CLIENT ) + public void setRenderStateByMeta( int itemDamage ) + { + + } + + @Override + final public TileEntity createNewTileEntity( World var1, int var2 ) + { + if ( hasBlockTileEntity() ) + { + try + { + return tileEntityType.newInstance(); + } + catch ( Throwable e ) + { + throw new RuntimeException( e ); + } + } + return null; + } + + @Override + public void breakBlock( World w, int x, int y, int z, Block a, int b ) + { + AEBaseTile te = getTileEntity( w, x, y, z ); + if ( te != null ) + { + ArrayList drops = new ArrayList(); + if ( te.dropItems() ) + te.getDrops( w, x, y, z, drops ); + else + te.getNoDrops( w, x, y, z, drops ); + + // Cry ;_; ... + Platform.spawnDrops( w, x, y, z, drops ); + } + + super.breakBlock( w, x, y, z, a, b ); + if ( te != null ) + w.setTileEntity( x, y, z, null ); + } + + public String getUnlocalizedName( ItemStack is ) + { + return getUnlocalizedName(); + } + + public void addInformation( ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips ) + { + + } + + public Class getItemBlockClass() + { + return AEBaseItemBlock.class; + } + + public boolean hasSubtypes() + { + return hasSubtypes; + } } diff --git a/src/main/java/appeng/block/AEBaseStairBlock.java b/src/main/java/appeng/block/AEBaseStairBlock.java new file mode 100644 index 000000000..f809369fb --- /dev/null +++ b/src/main/java/appeng/block/AEBaseStairBlock.java @@ -0,0 +1,60 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block; + + +import java.util.EnumSet; + +import com.google.common.base.Optional; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockStairs; + +import appeng.core.features.AEFeature; +import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; +import appeng.core.features.StairBlockFeatureHandler; + + +public abstract class AEBaseStairBlock extends BlockStairs implements IAEFeature +{ + private final IFeatureHandler features; + + protected AEBaseStairBlock( Block block, int meta, EnumSet features ) + { + super( block, meta ); + + this.features = new StairBlockFeatureHandler( features, this, Optional. absent() ); + this.setBlockName( block.getUnlocalizedName() ); + + this.setLightOpacity( 0 ); + } + + @Override + public IFeatureHandler handler() + { + return this.features; + } + + @Override + public void postInit() + { + // Override to do stuff + } +} diff --git a/src/main/java/appeng/block/AEDecorativeBlock.java b/src/main/java/appeng/block/AEDecorativeBlock.java index 73d7b2e35..9e9def7eb 100644 --- a/src/main/java/appeng/block/AEDecorativeBlock.java +++ b/src/main/java/appeng/block/AEDecorativeBlock.java @@ -18,21 +18,17 @@ package appeng.block; + import net.minecraft.block.material.Material; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; + public class AEDecorativeBlock extends AEBaseBlock { - - protected AEDecorativeBlock(Class c, Material mat) { - super( c, mat ); - } - - @Override - public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s) + public AEDecorativeBlock( Class c, Material mat ) { - return super.unmappedGetIcon( w, x, y, z, s ); + super( c, mat ); } @Override @@ -41,4 +37,9 @@ public class AEDecorativeBlock extends AEBaseBlock return 0; } + @Override + public IIcon getIcon( IBlockAccess w, int x, int y, int z, int s ) + { + return super.unmappedGetIcon( w, x, y, z, s ); + } } diff --git a/src/main/java/appeng/block/solids/BlockFluix.java b/src/main/java/appeng/block/solids/BlockFluix.java index 227743c78..6e62f8715 100644 --- a/src/main/java/appeng/block/solids/BlockFluix.java +++ b/src/main/java/appeng/block/solids/BlockFluix.java @@ -18,18 +18,20 @@ package appeng.block.solids; + import java.util.EnumSet; import net.minecraft.block.material.Material; + import appeng.block.AEDecorativeBlock; import appeng.core.features.AEFeature; + public class BlockFluix extends AEDecorativeBlock { - - public BlockFluix() { + public BlockFluix() + { super( BlockFluix.class, Material.rock ); setFeature( EnumSet.of( AEFeature.DecorativeQuartzBlocks ) ); } - } diff --git a/src/main/java/appeng/block/stair/ChiseledQuartzStairBlock.java b/src/main/java/appeng/block/stair/ChiseledQuartzStairBlock.java new file mode 100644 index 000000000..e8d622a1a --- /dev/null +++ b/src/main/java/appeng/block/stair/ChiseledQuartzStairBlock.java @@ -0,0 +1,35 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block.stair; + + +import java.util.EnumSet; + +import appeng.block.AEBaseStairBlock; +import appeng.block.solids.BlockQuartzChiseled; +import appeng.core.features.AEFeature; + + +public class ChiseledQuartzStairBlock extends AEBaseStairBlock +{ + public ChiseledQuartzStairBlock( BlockQuartzChiseled block ) + { + super( block, 0, EnumSet.of( AEFeature.Core ) ); + } +} diff --git a/src/main/java/appeng/block/stair/FluixStairBlock.java b/src/main/java/appeng/block/stair/FluixStairBlock.java new file mode 100644 index 000000000..87a34f090 --- /dev/null +++ b/src/main/java/appeng/block/stair/FluixStairBlock.java @@ -0,0 +1,36 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block.stair; + + +import java.util.EnumSet; + +import net.minecraft.block.Block; + +import appeng.block.AEBaseStairBlock; +import appeng.core.features.AEFeature; + + +public class FluixStairBlock extends AEBaseStairBlock +{ + public FluixStairBlock( Block block ) + { + super( block, 0, EnumSet.of( AEFeature.Core ) ); + } +} diff --git a/src/main/java/appeng/block/stair/QuartzPillarStairBlock.java b/src/main/java/appeng/block/stair/QuartzPillarStairBlock.java new file mode 100644 index 000000000..1433a1c56 --- /dev/null +++ b/src/main/java/appeng/block/stair/QuartzPillarStairBlock.java @@ -0,0 +1,35 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block.stair; + + +import java.util.EnumSet; + +import appeng.block.AEBaseStairBlock; +import appeng.block.solids.BlockQuartzPillar; +import appeng.core.features.AEFeature; + + +public class QuartzPillarStairBlock extends AEBaseStairBlock +{ + public QuartzPillarStairBlock( BlockQuartzPillar block ) + { + super( block, 0, EnumSet.of( AEFeature.Core ) ); + } +} diff --git a/src/main/java/appeng/block/stair/QuartzStairBlock.java b/src/main/java/appeng/block/stair/QuartzStairBlock.java new file mode 100644 index 000000000..b91845839 --- /dev/null +++ b/src/main/java/appeng/block/stair/QuartzStairBlock.java @@ -0,0 +1,35 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block.stair; + + +import java.util.EnumSet; + +import appeng.block.AEBaseStairBlock; +import appeng.block.solids.BlockQuartz; +import appeng.core.features.AEFeature; + + +public class QuartzStairBlock extends AEBaseStairBlock +{ + public QuartzStairBlock( BlockQuartz block ) + { + super( block, 0, EnumSet.of( AEFeature.Core ) ); + } +} diff --git a/src/main/java/appeng/block/stair/SkyStoneBlockStairBlock.java b/src/main/java/appeng/block/stair/SkyStoneBlockStairBlock.java new file mode 100644 index 000000000..4eeb0aace --- /dev/null +++ b/src/main/java/appeng/block/stair/SkyStoneBlockStairBlock.java @@ -0,0 +1,36 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block.stair; + + +import java.util.EnumSet; + +import net.minecraft.block.Block; + +import appeng.block.AEBaseStairBlock; +import appeng.core.features.AEFeature; + + +public class SkyStoneBlockStairBlock extends AEBaseStairBlock +{ + public SkyStoneBlockStairBlock( Block block, Integer meta ) + { + super( block, meta, EnumSet.of( AEFeature.Core ) ); + } +} diff --git a/src/main/java/appeng/block/stair/SkyStoneBrickStairBlock.java b/src/main/java/appeng/block/stair/SkyStoneBrickStairBlock.java new file mode 100644 index 000000000..7b6881ed5 --- /dev/null +++ b/src/main/java/appeng/block/stair/SkyStoneBrickStairBlock.java @@ -0,0 +1,36 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block.stair; + + +import java.util.EnumSet; + +import net.minecraft.block.Block; + +import appeng.block.AEBaseStairBlock; +import appeng.core.features.AEFeature; + + +public class SkyStoneBrickStairBlock extends AEBaseStairBlock +{ + public SkyStoneBrickStairBlock( Block block, Integer meta ) + { + super( block, meta, EnumSet.of( AEFeature.Core ) ); + } +} \ No newline at end of file diff --git a/src/main/java/appeng/block/stair/SkyStoneSmallBrickStairBlock.java b/src/main/java/appeng/block/stair/SkyStoneSmallBrickStairBlock.java new file mode 100644 index 000000000..e5a0b1802 --- /dev/null +++ b/src/main/java/appeng/block/stair/SkyStoneSmallBrickStairBlock.java @@ -0,0 +1,36 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block.stair; + + +import java.util.EnumSet; + +import net.minecraft.block.Block; + +import appeng.block.AEBaseStairBlock; +import appeng.core.features.AEFeature; + + +public class SkyStoneSmallBrickStairBlock extends AEBaseStairBlock +{ + public SkyStoneSmallBrickStairBlock( Block block, int meta ) + { + super( block, meta, EnumSet.of( AEFeature.Core ) ); + } +} \ No newline at end of file diff --git a/src/main/java/appeng/block/stair/SkyStoneStairBlock.java b/src/main/java/appeng/block/stair/SkyStoneStairBlock.java new file mode 100644 index 000000000..8d8b70e6b --- /dev/null +++ b/src/main/java/appeng/block/stair/SkyStoneStairBlock.java @@ -0,0 +1,36 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.block.stair; + + +import java.util.EnumSet; + +import net.minecraft.block.Block; + +import appeng.block.AEBaseStairBlock; +import appeng.core.features.AEFeature; + + +public class SkyStoneStairBlock extends AEBaseStairBlock +{ + public SkyStoneStairBlock( Block block, Integer meta ) + { + super( block, meta, EnumSet.of( AEFeature.Core ) ); + } +} diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index d482e473d..3f98fb1b0 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -18,9 +18,13 @@ package appeng.core; -import java.lang.reflect.Constructor; + import java.lang.reflect.Field; +import com.google.common.base.Optional; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; + import net.minecraft.item.crafting.CraftingManager; import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.world.biome.BiomeGenBase; @@ -29,6 +33,14 @@ import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.RecipeSorter.Category; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.common.registry.VillagerRegistry; + import appeng.api.AEApi; import appeng.api.config.Upgrades; import appeng.api.definitions.Blocks; @@ -90,6 +102,14 @@ import appeng.block.solids.OreQuartzCharged; import appeng.block.spatial.BlockMatrixFrame; import appeng.block.spatial.BlockSpatialIOPort; import appeng.block.spatial.BlockSpatialPylon; +import appeng.block.stair.ChiseledQuartzStairBlock; +import appeng.block.stair.FluixStairBlock; +import appeng.block.stair.QuartzPillarStairBlock; +import appeng.block.stair.QuartzStairBlock; +import appeng.block.stair.SkyStoneBlockStairBlock; +import appeng.block.stair.SkyStoneBrickStairBlock; +import appeng.block.stair.SkyStoneSmallBrickStairBlock; +import appeng.block.stair.SkyStoneStairBlock; import appeng.block.storage.BlockChest; import appeng.block.storage.BlockDrive; import appeng.block.storage.BlockIOPort; @@ -184,17 +204,9 @@ import appeng.recipes.ores.OreDictionaryHandler; import appeng.spatial.BiomeGenStorage; import appeng.spatial.StorageWorldProvider; import appeng.tile.AEBaseTile; +import appeng.util.ClassInstantiation; import appeng.util.Platform; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; - -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.common.registry.VillagerRegistry; public class Registration { @@ -202,6 +214,7 @@ public class Registration final public static Registration instance = new Registration(); public final RecipeHandler recipeHandler; + final private Multimap featuresToEntities = ArrayListMultimap.create(); public BiomeGenBase storageBiome; private Registration() @@ -209,9 +222,7 @@ public class Registration recipeHandler = new RecipeHandler(); } - final private Multimap featuresToEntities = ArrayListMultimap.create(); - - public void PreInit(FMLPreInitializationEvent event) + public void PreInit( FMLPreInitializationEvent event ) { registerSpatial( false ); @@ -248,23 +259,23 @@ public class Registration AEItemDefinition materialItem = addFeature( ItemMultiMaterial.class ); Class materialClass = materials.getClass(); - for (MaterialType mat : MaterialType.values()) + for ( MaterialType mat : MaterialType.values() ) { try { if ( mat == MaterialType.InvalidType ) - ((ItemMultiMaterial) materialItem.item()).createMaterial( mat ); + ( ( ItemMultiMaterial ) materialItem.item() ).createMaterial( mat ); else { Field f = materialClass.getField( "material" + mat.name() ); - IStackSrc is = ((ItemMultiMaterial) materialItem.item()).createMaterial( mat ); + IStackSrc is = ( ( ItemMultiMaterial ) materialItem.item() ).createMaterial( mat ); if ( is != null ) f.set( materials, new DamagedItemDefinition( is ) ); else f.set( materials, new NullItemDefinition() ); } } - catch (Throwable err) + catch ( Throwable err ) { AELog.severe( "Error creating material: " + mat.name() ); throw new RuntimeException( err ); @@ -274,19 +285,19 @@ public class Registration AEItemDefinition partItem = addFeature( ItemMultiPart.class ); Class partClass = parts.getClass(); - for (PartType type : PartType.values()) + for ( PartType type : PartType.values() ) { try { if ( type == PartType.InvalidType ) - ((ItemMultiPart) partItem.item()).createPart( type, null ); + ( ( ItemMultiPart ) partItem.item() ).createPart( type, null ); else { Field f = partClass.getField( "part" + type.name() ); Enum variants[] = type.getVariants(); if ( variants == null ) { - ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, null ); + ItemStackSrc is = ( ( ItemMultiPart ) partItem.item() ).createPart( type, null ); if ( is != null ) f.set( parts, new DamagedItemDefinition( is ) ); else @@ -298,11 +309,11 @@ public class Registration { ColoredItemDefinition def = new ColoredItemDefinition(); - for (Enum v : variants) + for ( Enum v : variants ) { - ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, v ); + ItemStackSrc is = ( ( ItemMultiPart ) partItem.item() ).createPart( type, v ); if ( is != null ) - def.add( (AEColor) v, is ); + def.add( ( AEColor ) v, is ); } f.set( parts, def ); @@ -310,7 +321,7 @@ public class Registration } } } - catch (Throwable err) + catch ( Throwable err ) { AELog.severe( "Error creating part: " + type.name() ); throw new RuntimeException( err ); @@ -424,7 +435,7 @@ public class Registration items.itemLumenPaintBall = lumenPaintBall = new ColoredItemDefinition(); AEItemDefinition pb = addFeature( ItemPaintBall.class ); - for (AEColor c : AEColor.values()) + for ( AEColor c : AEColor.values() ) { if ( c != AEColor.Transparent ) { @@ -433,6 +444,17 @@ public class Registration } } + // stairs + this.addFeature( SkyStoneStairBlock.class, blocks.blockSkyStone.block(), 0 ); + this.addFeature( SkyStoneBlockStairBlock.class, blocks.blockSkyStone.block(), 1 ); + this.addFeature( SkyStoneBrickStairBlock.class, blocks.blockSkyStone.block(), 2 ); + this.addFeature( SkyStoneSmallBrickStairBlock.class, blocks.blockSkyStone.block(), 3 ); + this.addFeature( FluixStairBlock.class, blocks.blockFluix.block() ); + this.addFeature( QuartzStairBlock.class, blocks.blockQuartz.block() ); + this.addFeature( ChiseledQuartzStairBlock.class, blocks.blockQuartzChiseled.block() ); + this.addFeature( QuartzPillarStairBlock.class, blocks.blockQuartzPillar.block() ); + + // unsupported developer tools addFeature( ToolEraser.class ); addFeature( ToolMeteoritePlacer.class ); addFeature( ToolDebugCard.class ); @@ -443,96 +465,71 @@ public class Registration addFeature( BlockCubeGenerator.class ); } - private AEItemDefinition addFeature(Class c, Object... Args) + private void registerSpatial( boolean force ) { + if ( !AEConfig.instance.isFeatureEnabled( AEFeature.SpatialIO ) ) + return; - try + AEConfig config = AEConfig.instance; + + if ( storageBiome == null ) { - java.lang.reflect.Constructor[] con = c.getConstructors(); - Object obj = null; - - for (Constructor conItem : con) + if ( force && config.storageBiomeID == -1 ) { - Class paramTypes[] = conItem.getParameterTypes(); - if ( paramTypes.length == Args.length ) - { - boolean valid = true; + config.storageBiomeID = Platform.findEmpty( BiomeGenBase.getBiomeGenArray() ); + if ( config.storageBiomeID == -1 ) + throw new RuntimeException( "Biome Array is full, please free up some Biome ID's or disable spatial." ); - for (int idx = 0; idx < paramTypes.length; idx++) - { - Class cz = Args[idx].getClass(); - if ( !isClassMatch( paramTypes[idx], cz, Args[idx] ) ) - valid = false; - } - - if ( valid ) - { - obj = conItem.newInstance( Args ); - break; - } - } + storageBiome = new BiomeGenStorage( config.storageBiomeID ); + config.save(); } - if ( obj instanceof IAEFeature ) - { - IAEFeature feature = (IAEFeature) obj; - - for (AEFeature f : feature.feature().getFeatures()) - featuresToEntities.put( f, c ); - - feature.feature().register(); - - feature.postInit(); - - return feature.feature(); - } - else if ( obj == null ) - throw new RuntimeException( "No valid constructor found." ); - else - throw new RuntimeException( "Non AE Feature Registered" ); - + if ( !force && config.storageBiomeID != -1 ) + storageBiome = new BiomeGenStorage( config.storageBiomeID ); } - catch (Throwable e) + + if ( config.storageProviderID != -1 ) { - throw new RuntimeException( "Error with Feature: " + c.getName(), e ); + DimensionManager.registerProviderType( config.storageProviderID, StorageWorldProvider.class, false ); + } + + if ( config.storageProviderID == -1 && force ) + { + config.storageProviderID = -11; + + while ( !DimensionManager.registerProviderType( config.storageProviderID, StorageWorldProvider.class, false ) ) + config.storageProviderID--; + + config.save(); } } - private boolean isClassMatch(Class expected, Class got, Object value) + private AEItemDefinition addFeature( Class featureClass, Object... args ) { - if ( value == null && !expected.isPrimitive() ) - return true; + ClassInstantiation instantiation = new ClassInstantiation( featureClass, args ); + Optional instance = instantiation.get(); - expected = condense( expected, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class ); - got = condense( got, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class ); - - if ( expected == got || expected.isAssignableFrom( got ) ) - return true; - - return false; - } - - private Class condense(Class expected, Class... wrappers) - { - if ( expected.isPrimitive() ) + if ( instance.isPresent() ) { - for (Class clz : wrappers) + IAEFeature feature = instance.get(); + + for ( AEFeature f : feature.handler().getFeatures() ) { - try - { - if ( expected == clz.getField( "TYPE" ).get( null ) ) - return clz; - } - catch (Throwable t) - { - AELog.error( t ); - } + this.featuresToEntities.put( f, featureClass ); } + + feature.handler().register(); + feature.postInit(); + + return feature.handler().getDefinition(); + } + else + { + throw new RuntimeException( "Error with Feature: " + featureClass.getName() ); } - return expected; } - public void Init(FMLInitializationEvent event) + public void Init( FMLInitializationEvent event ) { // Perform ore camouflage! ItemMultiMaterial.instance.makeUnique(); @@ -600,19 +597,19 @@ public class Registration CraftingManager.getInstance().getRecipeList().add( new FacadeRecipe() ); } - public void PostInit(FMLPostInitializationEvent event) + public void PostInit( FMLPostInitializationEvent event ) { registerSpatial( true ); // default settings.. - ((P2PTunnelRegistry) AEApi.instance().registries().p2pTunnel()).configure(); + ( ( P2PTunnelRegistry ) AEApi.instance().registries().p2pTunnel() ).configure(); // add to localization.. PlayerMessages.values(); GuiText.values(); Api.instance.partHelper.initFMPSupport(); - ((BlockCableBus) AEApi.instance().blocks().blockMultiPart.block()).setupTile(); + ( ( BlockCableBus ) AEApi.instance().blocks().blockMultiPart.block() ).setupTile(); // Interface Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partInterface.stack( 1 ), 1 ); @@ -679,7 +676,7 @@ public class Registration // Inscriber Upgrades.SPEED.registerItem( AEApi.instance().blocks().blockInscriber.stack( 1 ), 3 ); - AEApi.instance().registries().wireless().registerWirelessHandler( (IWirelessTermHandler) AEApi.instance().items().itemWirelessTerminal.item() ); + AEApi.instance().registries().wireless().registerWirelessHandler( ( IWirelessTermHandler ) AEApi.instance().items().itemWirelessTerminal.item() ); if ( AEConfig.instance.isFeatureEnabled( AEFeature.ChestLoot ) ) { @@ -738,19 +735,19 @@ public class Registration /** * world gen */ - for (WorldGenType type : WorldGenType.values()) + for ( WorldGenType type : WorldGenType.values() ) { AEApi.instance().registries().worldgen().disableWorldGenForProviderID( type, StorageWorldProvider.class ); - //nether + // nether AEApi.instance().registries().worldgen().disableWorldGenForDimension( type, -1 ); - //end + // end AEApi.instance().registries().worldgen().disableWorldGenForDimension( type, 1 ); } - //whitelist from config - for(int dimension : AEConfig.instance.meteoriteDimensionWhitelist) + // whitelist from config + for ( int dimension : AEConfig.instance.meteoriteDimensionWhitelist ) { AEApi.instance().registries().worldgen().enableWorldGenForDimension( WorldGenType.Meteorites, dimension ); } @@ -761,43 +758,4 @@ public class Registration OreDictionaryHandler.instance.bakeRecipes(); } - private void registerSpatial(boolean force) - { - if ( !AEConfig.instance.isFeatureEnabled( AEFeature.SpatialIO ) ) - return; - - AEConfig config = AEConfig.instance; - - if ( storageBiome == null ) - { - if ( force && config.storageBiomeID == -1 ) - { - config.storageBiomeID = Platform.findEmpty( BiomeGenBase.getBiomeGenArray() ); - if ( config.storageBiomeID == -1 ) - throw new RuntimeException( "Biome Array is full, please free up some Biome ID's or disable spatial." ); - - storageBiome = new BiomeGenStorage( config.storageBiomeID ); - config.save(); - } - - if ( !force && config.storageBiomeID != -1 ) - storageBiome = new BiomeGenStorage( config.storageBiomeID ); - } - - if ( config.storageProviderID != -1 ) - { - DimensionManager.registerProviderType( config.storageProviderID, StorageWorldProvider.class, false ); - } - - if ( config.storageProviderID == -1 && force ) - { - config.storageProviderID = -11; - - while (!DimensionManager.registerProviderType( config.storageProviderID, StorageWorldProvider.class, false )) - config.storageProviderID--; - - config.save(); - } - } - } diff --git a/src/main/java/appeng/core/features/AEBlockDefinition.java b/src/main/java/appeng/core/features/AEBlockDefinition.java new file mode 100644 index 000000000..fd00804b7 --- /dev/null +++ b/src/main/java/appeng/core/features/AEBlockDefinition.java @@ -0,0 +1,43 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import net.minecraft.tileentity.TileEntity; + +import appeng.block.AEBaseBlock; + + +public class AEBlockDefinition extends BlockDefinition +{ + private final AEBaseBlock block; + + public AEBlockDefinition( AEBaseBlock block, boolean enabled ) + { + super( block, enabled ); + + this.block = block; + } + + @Override + public Class entity() + { + return this.block.getTileEntityClass(); + } +} diff --git a/src/main/java/appeng/core/features/AEBlockFeatureHandler.java b/src/main/java/appeng/core/features/AEBlockFeatureHandler.java new file mode 100644 index 000000000..b3d3df94d --- /dev/null +++ b/src/main/java/appeng/core/features/AEBlockFeatureHandler.java @@ -0,0 +1,91 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import java.util.EnumSet; + +import com.google.common.base.Optional; + +import cpw.mods.fml.common.registry.GameRegistry; + +import appeng.api.util.AEItemDefinition; +import appeng.block.AEBaseBlock; +import appeng.block.AEBaseItemBlock; +import appeng.core.CommonHelper; +import appeng.core.CreativeTab; +import appeng.util.Platform; + + +public class AEBlockFeatureHandler implements IFeatureHandler +{ + private final EnumSet features; + private final AEBaseBlock featured; + private final FeatureNameExtractor extractor; + private final boolean enabled; + private final AEBlockDefinition definition; + + public AEBlockFeatureHandler( EnumSet features, AEBaseBlock featured, Optional subName ) + { + this.features = features; + this.featured = featured; + this.extractor = new FeatureNameExtractor( featured.getClass(), subName ); + this.enabled = new FeaturedActiveChecker( features ).get(); + this.definition = new AEBlockDefinition( featured, this.enabled ); + } + + @Override + public boolean isFeatureAvailable() + { + return this.enabled; + } + + @Override + public EnumSet getFeatures() + { + return this.features; + } + + @Override + public AEItemDefinition getDefinition() + { + return this.definition; + } + + @Override + public void register() + { + if ( this.enabled ) + { + String name = this.extractor.get(); + this.featured.setCreativeTab( CreativeTab.instance ); + this.featured.setBlockName( /* "tile." */"appliedenergistics2." + name ); + this.featured.setBlockTextureName( "appliedenergistics2:" + name ); + + if ( Platform.isClient() ) + { + CommonHelper.proxy.bindTileEntitySpecialRenderer( this.featured.getTileEntityClass(), this.featured ); + } + + Class itemBlockClass = this.featured.getItemBlockClass(); + + GameRegistry.registerBlock( this.featured, itemBlockClass, "tile." + name ); + } + } +} diff --git a/src/main/java/appeng/core/features/AEFeatureHandler.java b/src/main/java/appeng/core/features/AEFeatureHandler.java index 8c7485902..b7ae31dc1 100644 --- a/src/main/java/appeng/core/features/AEFeatureHandler.java +++ b/src/main/java/appeng/core/features/AEFeatureHandler.java @@ -18,13 +18,18 @@ package appeng.core.features; + import java.util.EnumSet; import net.minecraft.block.Block; +import net.minecraft.block.BlockStairs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; + +import cpw.mods.fml.common.registry.GameRegistry; + import appeng.api.util.AEItemDefinition; import appeng.block.AEBaseBlock; import appeng.block.AEBaseItemBlock; @@ -34,7 +39,7 @@ import appeng.core.CreativeTab; import appeng.core.CreativeTabFacade; import appeng.items.parts.ItemFacade; import appeng.util.Platform; -import cpw.mods.fml.common.registry.GameRegistry; + public class AEFeatureHandler implements AEItemDefinition { @@ -46,8 +51,10 @@ public class AEFeatureHandler implements AEItemDefinition private Item ItemData; private Block BlockData; + private BlockStairs stairData; - public AEFeatureHandler(EnumSet features, IAEFeature feature, String subName) { + public AEFeatureHandler( EnumSet features, IAEFeature feature, String subName ) + { this.features = features; this.feature = feature; this.subName = subName; @@ -58,13 +65,86 @@ public class AEFeatureHandler implements AEItemDefinition if ( isFeatureAvailable() ) { if ( feature instanceof Item ) - initItem( (Item) feature ); - if ( feature instanceof Block ) - initBlock( (Block) feature ); + { + initItem( ( Item ) feature ); + } + else if ( this.feature instanceof BlockStairs ) + { + this.initStairBlock( ( BlockStairs ) this.feature ); + } + else if ( feature instanceof Block ) + { + initBlock( ( Block ) feature ); + } } } - public static String getName(Class o, String subName) + public boolean isFeatureAvailable() + { + boolean enabled = true; + + for ( AEFeature f : features ) + enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); + + return enabled; + } + + private void initItem( Item i ) + { + ItemData = i; + + String name = getName( i.getClass(), subName ); + i.setTextureName( "appliedenergistics2:" + name ); + i.setUnlocalizedName( /* "item." */"appliedenergistics2." + name ); + + if ( i instanceof ItemFacade ) + i.setCreativeTab( CreativeTabFacade.instance ); + else + i.setCreativeTab( CreativeTab.instance ); + + if ( name.equals( "ItemMaterial" ) ) + name = "ItemMultiMaterial"; + else if ( name.equals( "ItemPart" ) ) + name = "ItemMultiPart"; + + GameRegistry.registerItem( i, "item." + name ); + } + + private void initStairBlock( BlockStairs stair ) + { + this.stairData = stair; + + String name = getName( stair.getClass(), subName ); + stair.setCreativeTab( CreativeTab.instance ); + stair.setBlockName( /* "tile." */"appliedenergistics2." + name ); + stair.setBlockTextureName( "appliedenergistics2:" + name ); + + GameRegistry.registerBlock( stair, "tile." + name ); + } + + private void initBlock( Block b ) + { + BlockData = b; + + String name = getName( b.getClass(), subName ); + b.setCreativeTab( CreativeTab.instance ); + b.setBlockName( /* "tile." */"appliedenergistics2." + name ); + b.setBlockTextureName( "appliedenergistics2:" + name ); + + if ( Platform.isClient() && BlockData instanceof AEBaseBlock ) + { + AEBaseBlock bb = ( AEBaseBlock ) b; + CommonHelper.proxy.bindTileEntitySpecialRenderer( bb.getTileEntityClass(), bb ); + } + + Class itemBlock = AEBaseItemBlock.class; + if ( b instanceof AEBaseBlock ) + itemBlock = ( ( AEBaseBlock ) b ).getItemBlockClass(); + + GameRegistry.registerBlock( b, itemBlock, "tile." + name ); + } + + public static String getName( Class o, String subName ) { String name = o.getSimpleName(); @@ -91,76 +171,42 @@ public class AEFeatureHandler implements AEItemDefinition return name; } - private void initItem(Item i) - { - ItemData = i; - - String name = getName( i.getClass(), subName ); - i.setTextureName( "appliedenergistics2:" + name ); - i.setUnlocalizedName( /* "item." */"appliedenergistics2." + name ); - - if ( i instanceof ItemFacade ) - i.setCreativeTab( CreativeTabFacade.instance ); - else - i.setCreativeTab( CreativeTab.instance ); - - if ( name.equals( "ItemMaterial" ) ) - name = "ItemMultiMaterial"; - else if ( name.equals( "ItemPart" ) ) - name = "ItemMultiPart"; - - GameRegistry.registerItem( i, "item." + name ); - } - - private void initBlock(Block b) - { - BlockData = b; - - String name = getName( b.getClass(), subName ); - b.setCreativeTab( CreativeTab.instance ); - b.setBlockName( /* "tile." */"appliedenergistics2." + name ); - b.setBlockTextureName( "appliedenergistics2:" + name ); - - if ( Platform.isClient() && BlockData instanceof AEBaseBlock ) - { - AEBaseBlock bb = (AEBaseBlock) b; - CommonHelper.proxy.bindTileEntitySpecialRenderer( bb.getTileEntityClass(), bb ); - } - - Class itemBlock = AEBaseItemBlock.class; - if ( b instanceof AEBaseBlock ) - itemBlock = ((AEBaseBlock) b).getItemBlockClass(); - - GameRegistry.registerBlock( b, itemBlock, "tile." + name ); - } - public EnumSet getFeatures() { return features.clone(); } - public boolean isFeatureAvailable() - { - boolean enabled = true; - - for (AEFeature f : features) - enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); - - return enabled; - } - @Override public Block block() { return BlockData; } + @Override + public Item item() + { + if ( this.ItemData != null ) + { + return this.ItemData; + } + else if ( this.BlockData != null ) + { + return Item.getItemFromBlock( this.BlockData ); + } + else if ( this.stairData != null ) + { + return Item.getItemFromBlock( this.stairData ); + } + + return null; + } + @Override public Class entity() { if ( BlockData instanceof AEBaseBlock ) { - AEBaseBlock bb = (AEBaseBlock) BlockData; + AEBaseBlock bb = ( AEBaseBlock ) BlockData; return bb.getTileEntityClass(); } @@ -168,15 +214,7 @@ public class AEFeatureHandler implements AEItemDefinition } @Override - public Item item() - { - if ( ItemData == null && BlockData != null ) - return Item.getItemFromBlock( BlockData ); - return ItemData; - } - - @Override - public ItemStack stack(int stackSize) + public ItemStack stack( int stackSize ) { if ( isFeatureAvailable() ) { @@ -190,11 +228,12 @@ public class AEFeatureHandler implements AEItemDefinition rv.stackSize = stackSize; return rv; } + return null; } @Override - public boolean sameAsStack(ItemStack is) + public boolean sameAsStack( ItemStack is ) { return isFeatureAvailable() && Platform.isSameItemType( is, stack( 1 ) ); } @@ -214,7 +253,7 @@ public class AEFeatureHandler implements AEItemDefinition * @return true if feature is available and the blocks are equal */ @Override - public boolean sameAsBlock(IBlockAccess world, int x, int y, int z) + public boolean sameAsBlock( IBlockAccess world, int x, int y, int z ) { return isFeatureAvailable() && BlockData != null && world.getBlock( x, y, z ) == BlockData; } diff --git a/src/main/java/appeng/core/features/BlockDefinition.java b/src/main/java/appeng/core/features/BlockDefinition.java new file mode 100644 index 000000000..6b638a002 --- /dev/null +++ b/src/main/java/appeng/core/features/BlockDefinition.java @@ -0,0 +1,83 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; + +import appeng.api.util.AEItemDefinition; +import appeng.util.Platform; + + +public class BlockDefinition implements AEItemDefinition +{ + private final Block block; + private final boolean enabled; + + public BlockDefinition( Block block, boolean enabled ) + { + this.block = block; + this.enabled = enabled; + } + + @Override + public Block block() + { + return this.block; + } + + @Override + public Item item() + { + return Item.getItemFromBlock( this.block ); + } + + @Override + public Class entity() + { + return null; + } + + @Override + public ItemStack stack( int stackSize ) + { + if ( this.enabled ) + { + return new ItemStack( this.block ); + } + + return null; + } + + @Override + public boolean sameAsStack( ItemStack comparableItem ) + { + return this.enabled && Platform.isSameItemType( comparableItem, this.stack( 1 ) ); + } + + @Override + public boolean sameAsBlock( IBlockAccess world, int x, int y, int z ) + { + return this.enabled && world.getBlock( x, y, z ) == this.block; + } +} diff --git a/src/main/java/appeng/core/features/FeatureNameExtractor.java b/src/main/java/appeng/core/features/FeatureNameExtractor.java new file mode 100644 index 000000000..b047244e4 --- /dev/null +++ b/src/main/java/appeng/core/features/FeatureNameExtractor.java @@ -0,0 +1,72 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import com.google.common.base.Optional; + + +public class FeatureNameExtractor +{ + private Class clazz; + private Optional subName; + + public FeatureNameExtractor( Class clazz, Optional subName ) + { + this.clazz = clazz; + this.subName = subName; + } + + public String get() + { + String name = this.clazz.getSimpleName(); + + if ( name.startsWith( "ItemMultiPart" ) ) + { + name = name.replace( "ItemMultiPart", "ItemPart" ); + } + else if ( name.startsWith( "ItemMultiMaterial" ) ) + { + name = name.replace( "ItemMultiMaterial", "ItemMaterial" ); + } + + if ( this.subName.isPresent() ) + { + final String subName = this.subName.get(); + // simple hack to allow me to do get nice names for these without + // mode code outside of AEBaseItem + if ( subName.startsWith( "P2PTunnel" ) ) + { + return "ItemPart.P2PTunnel"; + } + else if ( subName.equals( "CertusQuartzTools" ) ) + { + return name.replace( "Quartz", "CertusQuartz" ); + } + else if ( subName.equals( "NetherQuartzTools" ) ) + { + return name.replace( "Quartz", "NetherQuartz" ); + } + + name += "." + subName; + } + + return name; + } +} diff --git a/src/main/java/appeng/core/features/FeaturedActiveChecker.java b/src/main/java/appeng/core/features/FeaturedActiveChecker.java new file mode 100644 index 000000000..d5cb26b29 --- /dev/null +++ b/src/main/java/appeng/core/features/FeaturedActiveChecker.java @@ -0,0 +1,48 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import java.util.EnumSet; + +import appeng.core.AEConfig; + + +public class FeaturedActiveChecker +{ + private EnumSet features; + + public FeaturedActiveChecker( EnumSet features ) + { + this.features = features; + } + + public boolean get() + { + for ( AEFeature f : this.features ) + { + if ( !AEConfig.instance.isFeatureEnabled( f ) ) + { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/appeng/core/features/IAEFeature.java b/src/main/java/appeng/core/features/IAEFeature.java index ce54d30f9..c819f1e76 100644 --- a/src/main/java/appeng/core/features/IAEFeature.java +++ b/src/main/java/appeng/core/features/IAEFeature.java @@ -18,11 +18,10 @@ package appeng.core.features; + public interface IAEFeature { - - public AEFeatureHandler feature(); + IFeatureHandler handler(); void postInit(); - } diff --git a/src/main/java/appeng/core/features/IFeatureHandler.java b/src/main/java/appeng/core/features/IFeatureHandler.java new file mode 100644 index 000000000..ae0ae042d --- /dev/null +++ b/src/main/java/appeng/core/features/IFeatureHandler.java @@ -0,0 +1,36 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import java.util.EnumSet; + +import appeng.api.util.AEItemDefinition; + + +public interface IFeatureHandler +{ + boolean isFeatureAvailable(); + + EnumSet getFeatures(); + + AEItemDefinition getDefinition(); + + void register(); +} diff --git a/src/main/java/appeng/core/features/ItemDefinition.java b/src/main/java/appeng/core/features/ItemDefinition.java new file mode 100644 index 000000000..31dad13d7 --- /dev/null +++ b/src/main/java/appeng/core/features/ItemDefinition.java @@ -0,0 +1,85 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; + +import appeng.api.util.AEItemDefinition; +import appeng.util.Platform; + + +public class ItemDefinition implements AEItemDefinition +{ + private final Item item; + private final boolean enabled; + + public ItemDefinition( Item item, boolean enabled ) + { + this.item = item; + this.enabled = enabled; + } + + @Override + public Block block() + { + return null; + } + + @Override + public Item item() + { + return this.item; + } + + @Override + public Class entity() + { + return null; + } + + @Override + public ItemStack stack( int stackSize ) + { + if ( this.enabled ) + { + return new ItemStack( this.item ); + } + else + { + return null; + } + } + + @Override + public boolean sameAsStack( ItemStack comparableItem ) + { + return this.enabled && Platform.isSameItemType( comparableItem, this.stack( 1 ) ); + } + + @Override + public boolean sameAsBlock( IBlockAccess world, int x, int y, int z ) + { + return false; + } +} diff --git a/src/main/java/appeng/core/features/ItemFeatureHandler.java b/src/main/java/appeng/core/features/ItemFeatureHandler.java new file mode 100644 index 000000000..ac27ce0ad --- /dev/null +++ b/src/main/java/appeng/core/features/ItemFeatureHandler.java @@ -0,0 +1,98 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import java.util.EnumSet; + +import com.google.common.base.Optional; + +import net.minecraft.item.Item; + +import cpw.mods.fml.common.registry.GameRegistry; + +import appeng.api.util.AEItemDefinition; +import appeng.core.CreativeTab; +import appeng.core.CreativeTabFacade; +import appeng.items.parts.ItemFacade; + + +public class ItemFeatureHandler implements IFeatureHandler +{ + private final EnumSet features; + private final Item item; + private final FeatureNameExtractor extractor; + private final boolean enabled; + private final ItemDefinition definition; + + public ItemFeatureHandler( EnumSet features, Item item, IAEFeature featured, Optional subName ) + { + this.features = features; + this.item = item; + this.extractor = new FeatureNameExtractor( featured.getClass(), subName ); + this.enabled = new FeaturedActiveChecker( features ).get(); + this.definition = new ItemDefinition( item, this.enabled ); + } + + @Override + public boolean isFeatureAvailable() + { + return this.enabled; + } + + @Override + public EnumSet getFeatures() + { + return this.features; + } + + @Override + public AEItemDefinition getDefinition() + { + return this.definition; + } + + @Override + public void register() + { + String name = this.extractor.get(); + this.item.setTextureName( "appliedenergistics2:" + name ); + this.item.setUnlocalizedName( /* "item." */"appliedenergistics2." + name ); + + if ( this.item instanceof ItemFacade ) + { + this.item.setCreativeTab( CreativeTabFacade.instance ); + } + else + { + this.item.setCreativeTab( CreativeTab.instance ); + } + + if ( name.equals( "ItemMaterial" ) ) + { + name = "ItemMultiMaterial"; + } + else if ( name.equals( "ItemPart" ) ) + { + name = "ItemMultiPart"; + } + + GameRegistry.registerItem( this.item, "item." + name ); + } +} diff --git a/src/main/java/appeng/core/features/StairBlockFeatureHandler.java b/src/main/java/appeng/core/features/StairBlockFeatureHandler.java new file mode 100644 index 000000000..cc74dc907 --- /dev/null +++ b/src/main/java/appeng/core/features/StairBlockFeatureHandler.java @@ -0,0 +1,79 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.core.features; + + +import java.util.EnumSet; + +import com.google.common.base.Optional; + +import net.minecraft.block.BlockStairs; + +import cpw.mods.fml.common.registry.GameRegistry; + +import appeng.api.util.AEItemDefinition; +import appeng.core.CreativeTab; + + +public class StairBlockFeatureHandler implements IFeatureHandler +{ + private final EnumSet features; + private final BlockStairs stairs; + private final FeatureNameExtractor extractor; + private final boolean enabled; + private final BlockDefinition definition; + + public StairBlockFeatureHandler( EnumSet features, BlockStairs stairs, Optional subName ) + { + this.features = features; + this.stairs = stairs; + this.extractor = new FeatureNameExtractor( stairs.getClass(), subName ); + this.enabled = new FeaturedActiveChecker( features ).get(); + this.definition = new BlockDefinition( stairs, this.enabled ); + } + + @Override + public boolean isFeatureAvailable() + { + return this.enabled; + } + + @Override + public EnumSet getFeatures() + { + return this.features; + } + + @Override + public AEItemDefinition getDefinition() + { + return this.definition; + } + + @Override + public void register() + { + String name = this.extractor.get(); + this.stairs.setCreativeTab( CreativeTab.instance ); + this.stairs.setBlockName( "appliedenergistics2." + name ); + this.stairs.setBlockTextureName( "appliedenergistics2:" + name ); + + GameRegistry.registerBlock( this.stairs, "tile." + name ); + } +} diff --git a/src/main/java/appeng/items/AEBaseItem.java b/src/main/java/appeng/items/AEBaseItem.java index 89b0db73b..42fe36e81 100644 --- a/src/main/java/appeng/items/AEBaseItem.java +++ b/src/main/java/appeng/items/AEBaseItem.java @@ -22,54 +22,47 @@ package appeng.items; import java.util.EnumSet; import java.util.List; +import com.google.common.base.Optional; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; +import appeng.core.features.FeatureNameExtractor; import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; +import appeng.core.features.ItemFeatureHandler; public class AEBaseItem extends Item implements IAEFeature { - final String featureFullName; - final String featureSubName; - AEFeatureHandler feature; + private final String fullName; + private final Optional subName; + private IFeatureHandler feature; + + public AEBaseItem( Class c ) + { + this( c, Optional. absent() ); + canRepair = false; + } + + public AEBaseItem( Class c, Optional subName ) + { + this.subName = subName; + this.fullName = new FeatureNameExtractor( c, subName ).get(); + } @Override public String toString() { - return featureFullName; + return this.fullName; } @Override - public AEFeatureHandler feature() + public IFeatureHandler handler() { - return feature; - } - - public void setFeature( EnumSet f ) - { - feature = new AEFeatureHandler( f, this, featureSubName ); - } - - public AEBaseItem( Class c ) - { - this( c, null ); - canRepair = false; - } - - public AEBaseItem( Class c, String subName ) - { - featureSubName = subName; - featureFullName = AEFeatureHandler.getName( c, subName ); - } - - @Override - public boolean isBookEnchantable( ItemStack itemstack1, ItemStack itemstack2 ) - { - return false; + return this.feature; } @Override @@ -78,6 +71,11 @@ public class AEBaseItem extends Item implements IAEFeature // override! } + public void setFeature( EnumSet f ) + { + this.feature = new ItemFeatureHandler( f, this, this, this.subName ); + } + @Override @SuppressWarnings( "unchecked" ) public final void addInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) @@ -85,6 +83,12 @@ public class AEBaseItem extends Item implements IAEFeature this.addCheckedInformation( stack, player, lines, displayAdditionalInformation ); } + @Override + public boolean isBookEnchantable( ItemStack itemstack1, ItemStack itemstack2 ) + { + return false; + } + public void addCheckedInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) { super.addInformation( stack, player, lines, displayAdditionalInformation ); diff --git a/src/main/java/appeng/items/storage/ItemBasicStorageCell.java b/src/main/java/appeng/items/storage/ItemBasicStorageCell.java index 5c32c8ef3..1270fa89b 100644 --- a/src/main/java/appeng/items/storage/ItemBasicStorageCell.java +++ b/src/main/java/appeng/items/storage/ItemBasicStorageCell.java @@ -23,6 +23,8 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; +import com.google.common.base.Optional; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; @@ -59,13 +61,13 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II final int perType; final double idleDrain; - public ItemBasicStorageCell( MaterialType whichCell, int Kilobytes ) + public ItemBasicStorageCell( MaterialType whichCell, int kilobytes ) { - super( ItemBasicStorageCell.class, Kilobytes + "k" ); + super( ItemBasicStorageCell.class, Optional.of( kilobytes + "k" ) ); this.setFeature( EnumSet.of( AEFeature.StorageCells ) ); this.setMaxStackSize( 1 ); - this.totalBytes = Kilobytes * 1024; + this.totalBytes = kilobytes * 1024; this.component = whichCell; switch ( this.component ) @@ -169,6 +171,18 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II return this.idleDrain; } + @Override + public String getUnlocalizedGroupName( Set others, ItemStack is ) + { + return GuiText.StorageCells.getUnlocalized(); + } + + @Override + public boolean isEditable( ItemStack is ) + { + return true; + } + @Override public IInventory getUpgradesInventory( ItemStack is ) { @@ -202,15 +216,10 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II } @Override - public String getUnlocalizedGroupName( Set others, ItemStack is ) + public ItemStack onItemRightClick( ItemStack stack, World world, EntityPlayer player ) { - return GuiText.StorageCells.getUnlocalized(); - } - - @Override - public boolean isEditable( ItemStack is ) - { - return true; + disassembleDrive( stack, world, player ); + return stack; } private boolean disassembleDrive( ItemStack stack, World world, EntityPlayer player ) @@ -248,28 +257,21 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II return false; } - @Override - public ItemStack onItemRightClick( ItemStack stack, World world, EntityPlayer player ) - { - disassembleDrive( stack, world, player ); - return stack; - } - @Override public boolean onItemUseFirst( ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) { return disassembleDrive( stack, world, player ); } - @Override - public boolean hasContainerItem( ItemStack stack ) - { - return AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting ); - } - @Override public ItemStack getContainerItem( ItemStack itemStack ) { return AEApi.instance().materials().materialEmptyStorageCell.stack( 1 ); } + + @Override + public boolean hasContainerItem( ItemStack stack ) + { + return AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting ); + } } diff --git a/src/main/java/appeng/items/storage/ItemSpatialStorageCell.java b/src/main/java/appeng/items/storage/ItemSpatialStorageCell.java index 42770f6fb..4046822ff 100644 --- a/src/main/java/appeng/items/storage/ItemSpatialStorageCell.java +++ b/src/main/java/appeng/items/storage/ItemSpatialStorageCell.java @@ -18,14 +18,18 @@ package appeng.items.storage; + import java.util.EnumSet; import java.util.List; +import com.google.common.base.Optional; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; + import appeng.api.implementations.TransitionResult; import appeng.api.implementations.items.ISpatialStorageCell; import appeng.api.util.WorldCoord; @@ -38,14 +42,16 @@ import appeng.spatial.StorageHelper; import appeng.spatial.StorageWorldProvider; import appeng.util.Platform; + public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell { final MaterialType component; final int maxRegion; - public ItemSpatialStorageCell(MaterialType whichCell, int spatialScale) { - super( ItemSpatialStorageCell.class, spatialScale + "Cubed" ); + public ItemSpatialStorageCell( MaterialType whichCell, int spatialScale ) + { + super( ItemSpatialStorageCell.class, Optional.of( spatialScale + "Cubed" ) ); setFeature( EnumSet.of( AEFeature.SpatialIO ) ); setMaxStackSize( 1 ); maxRegion = spatialScale; @@ -53,7 +59,7 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag } @Override - public void addCheckedInformation(ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) + public void addCheckedInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) { WorldCoord wc = getStoredSize( stack ); if ( wc.x > 0 ) @@ -61,19 +67,19 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag } @Override - public boolean isSpatialStorage(ItemStack is) + public boolean isSpatialStorage( ItemStack is ) { return true; } @Override - public int getMaxStoredDim(ItemStack is) + public int getMaxStoredDim( ItemStack is ) { return maxRegion; } @Override - public World getWorld(ItemStack is) + public World getWorld( ItemStack is ) { if ( is.hasTagCompound() ) { @@ -97,21 +103,8 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag return null; } - private void setStoredSize(ItemStack is, int targetX, int targetY, int targetZ) - { - if ( is.hasTagCompound() ) - { - NBTTagCompound c = is.getTagCompound(); - int dim = c.getInteger( "StorageDim" ); - c.setInteger( "sizeX", targetX ); - c.setInteger( "sizeY", targetY ); - c.setInteger( "sizeZ", targetZ ); - WorldSettings.getInstance().setStoredSize( dim, targetX, targetY, targetZ ); - } - } - @Override - public WorldCoord getStoredSize(ItemStack is) + public WorldCoord getStoredSize( ItemStack is ) { if ( is.hasTagCompound() ) { @@ -128,12 +121,12 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag } @Override - public WorldCoord getMin(ItemStack is) + public WorldCoord getMin( ItemStack is ) { World w = getWorld( is ); if ( w != null ) { - NBTTagCompound info = (NBTTagCompound) w.getWorldInfo().getAdditionalProperty( "storageCell" ); + NBTTagCompound info = ( NBTTagCompound ) w.getWorldInfo().getAdditionalProperty( "storageCell" ); if ( info != null ) { return new WorldCoord( info.getInteger( "minX" ), info.getInteger( "minY" ), info.getInteger( "minZ" ) ); @@ -143,12 +136,12 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag } @Override - public WorldCoord getMax(ItemStack is) + public WorldCoord getMax( ItemStack is ) { World w = getWorld( is ); if ( w != null ) { - NBTTagCompound info = (NBTTagCompound) w.getWorldInfo().getAdditionalProperty( "storageCell" ); + NBTTagCompound info = ( NBTTagCompound ) w.getWorldInfo().getAdditionalProperty( "storageCell" ); if ( info != null ) { return new WorldCoord( info.getInteger( "maxX" ), info.getInteger( "maxY" ), info.getInteger( "maxZ" ) ); @@ -157,18 +150,8 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag return new WorldCoord( 0, 0, 0 ); } - public World createNewWorld(ItemStack is) - { - NBTTagCompound c = Platform.openNbtData( is ); - int newDim = DimensionManager.getNextFreeDimId(); - c.setInteger( "StorageDim", newDim ); - WorldSettings.getInstance().addStorageCellDim( newDim ); - DimensionManager.initDimension( newDim ); - return DimensionManager.getWorld( newDim ); - } - @Override - public TransitionResult doSpatialTransition(ItemStack is, World w, WorldCoord min, WorldCoord max, boolean doTransition) + public TransitionResult doSpatialTransition( ItemStack is, World w, WorldCoord min, WorldCoord max, boolean doTransition ) { WorldCoord scale = getStoredSize( is ); @@ -180,7 +163,7 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag int floorBuffer = 64; World destination = getWorld( is ); - if ( (scale.x == 0 && scale.y == 0 && scale.z == 0) || (scale.x == targetX && scale.y == targetY && scale.z == targetZ) ) + if ( ( scale.x == 0 && scale.y == 0 && scale.z == 0 ) || ( scale.x == targetX && scale.y == targetY && scale.z == targetZ ) ) { if ( targetX <= maxSize && targetY <= maxSize && targetZ <= maxSize ) { @@ -198,4 +181,27 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag return new TransitionResult( false, 0 ); } + public World createNewWorld( ItemStack is ) + { + NBTTagCompound c = Platform.openNbtData( is ); + int newDim = DimensionManager.getNextFreeDimId(); + c.setInteger( "StorageDim", newDim ); + WorldSettings.getInstance().addStorageCellDim( newDim ); + DimensionManager.initDimension( newDim ); + return DimensionManager.getWorld( newDim ); + } + + private void setStoredSize( ItemStack is, int targetX, int targetY, int targetZ ) + { + if ( is.hasTagCompound() ) + { + NBTTagCompound c = is.getTagCompound(); + int dim = c.getInteger( "StorageDim" ); + c.setInteger( "sizeX", targetX ); + c.setInteger( "sizeY", targetY ); + c.setInteger( "sizeZ", targetZ ); + WorldSettings.getInstance().setStoredSize( dim, targetX, targetY, targetZ ); + } + } + } diff --git a/src/main/java/appeng/items/tools/ToolNetworkTool.java b/src/main/java/appeng/items/tools/ToolNetworkTool.java index 7244dca00..8cd55b007 100644 --- a/src/main/java/appeng/items/tools/ToolNetworkTool.java +++ b/src/main/java/appeng/items/tools/ToolNetworkTool.java @@ -18,8 +18,11 @@ package appeng.items.tools; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -28,6 +31,9 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.tools.IToolWrench; + import appeng.api.implementations.guiobjects.IGuiItem; import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.items.IAEWrench; @@ -46,14 +52,15 @@ import appeng.items.AEBaseItem; import appeng.items.contents.NetworkToolViewer; import appeng.transformer.annotations.integration.Interface; import appeng.util.Platform; -import buildcraft.api.tools.IToolWrench; -@Interface(iface = "buildcraft.api.tools.IToolWrench", iname = "BC") + +@Interface( iface = "buildcraft.api.tools.IToolWrench", iname = "BC" ) public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolWrench { - public ToolNetworkTool() { - super( ToolNetworkTool.class, null ); + public ToolNetworkTool() + { + super( ToolNetworkTool.class, Optional. absent() ); this.setFeature( EnumSet.of( AEFeature.NetworkTool ) ); this.setMaxStackSize( 1 ); @@ -61,14 +68,14 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, } @Override - public IGuiItemObject getGuiObject(ItemStack is, World world, int x, int y, int z) + public IGuiItemObject getGuiObject( ItemStack is, World world, int x, int y, int z ) { TileEntity te = world.getTileEntity( x, y, z ); - return new NetworkToolViewer( is, (IGridHost) (te instanceof IGridHost ? te : null) ); + return new NetworkToolViewer( is, ( IGridHost ) ( te instanceof IGridHost ? te : null ) ); } @Override - public ItemStack onItemRightClick(ItemStack it, World w, EntityPlayer p) + public ItemStack onItemRightClick( ItemStack it, World w, EntityPlayer p ) { if ( Platform.isClient() ) { @@ -93,20 +100,20 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, } @Override - public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + public boolean onItemUseFirst( ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) { MovingObjectPosition mop = new MovingObjectPosition( x, y, z, side, Vec3.createVectorHelper( hitX, hitY, hitZ ) ); TileEntity te = world.getTileEntity( x, y, z ); if ( te instanceof IPartHost ) { - SelectedPart part = ((IPartHost) te).selectPart( mop.hitVec ); + SelectedPart part = ( ( IPartHost ) te ).selectPart( mop.hitVec ); if ( part.part != null ) { - if ( part.part instanceof INetworkToolAgent && !((INetworkToolAgent) part.part).showNetworkInfo( mop ) ) + if ( part.part instanceof INetworkToolAgent && !( ( INetworkToolAgent ) part.part ).showNetworkInfo( mop ) ) return false; } } - else if ( te instanceof INetworkToolAgent && !((INetworkToolAgent) te).showNetworkInfo( mop ) ) + else if ( te instanceof INetworkToolAgent && !( ( INetworkToolAgent ) te ).showNetworkInfo( mop ) ) { return false; } @@ -118,7 +125,13 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, return true; } - public boolean serverSideToolLogic(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + @Override + public boolean doesSneakBypassUse( World world, int x, int y, int z, EntityPlayer player ) + { + return true; + } + + public boolean serverSideToolLogic( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) { if ( side >= 0 ) { @@ -129,7 +142,7 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, if ( b != null && !p.isSneaking() ) { TileEntity te = w.getTileEntity( x, y, z ); - if ( !(te instanceof IGridHost) ) + if ( !( te instanceof IGridHost ) ) { if ( b.rotateBlock( w, x, y, z, ForgeDirection.getOrientation( side ) ) ) { @@ -164,25 +177,19 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, } @Override - public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) + public boolean canWrench( ItemStack is, EntityPlayer player, int x, int y, int z ) { return true; } @Override - public boolean canWrench(ItemStack is, EntityPlayer player, int x, int y, int z) + public boolean canWrench( EntityPlayer player, int x, int y, int z ) { return true; } @Override - public boolean canWrench(EntityPlayer player, int x, int y, int z) - { - return true; - } - - @Override - public void wrenchUsed(EntityPlayer player, int x, int y, int z) + public void wrenchUsed( EntityPlayer player, int x, int y, int z ) { player.swingItem(); } diff --git a/src/main/java/appeng/items/tools/powered/ToolChargedStaff.java b/src/main/java/appeng/items/tools/powered/ToolChargedStaff.java index 501126d98..b4497c223 100644 --- a/src/main/java/appeng/items/tools/powered/ToolChargedStaff.java +++ b/src/main/java/appeng/items/tools/powered/ToolChargedStaff.java @@ -18,11 +18,15 @@ package appeng.items.tools.powered; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; + import appeng.core.AEConfig; import appeng.core.features.AEFeature; import appeng.core.sync.packets.PacketLightning; @@ -30,28 +34,30 @@ import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.server.ServerHelper; import appeng.util.Platform; + public class ToolChargedStaff extends AEBasePoweredItem { - public ToolChargedStaff() { - super( ToolChargedStaff.class, null ); + public ToolChargedStaff() + { + super( ToolChargedStaff.class, Optional. absent() ); setFeature( EnumSet.of( AEFeature.ChargedStaff, AEFeature.PoweredTools ) ); maxStoredPower = AEConfig.instance.chargedStaffBattery; } @Override - public boolean hitEntity(ItemStack item, EntityLivingBase target, EntityLivingBase hitter) + public boolean hitEntity( ItemStack item, EntityLivingBase target, EntityLivingBase hitter ) { if ( this.getAECurrentPower( item ) > 300 ) { extractAEPower( item, 300 ); if ( Platform.isServer() ) { - for (int x = 0; x < 2; x++) + for ( int x = 0; x < 2; x++ ) { - float dx = (float) (Platform.getRandomFloat() * target.width + target.boundingBox.minX); - float dy = (float) (Platform.getRandomFloat() * target.height + target.boundingBox.minY); - float dz = (float) (Platform.getRandomFloat() * target.width + target.boundingBox.minZ); + float dx = ( float ) ( Platform.getRandomFloat() * target.width + target.boundingBox.minX ); + float dy = ( float ) ( Platform.getRandomFloat() * target.height + target.boundingBox.minY ); + float dz = ( float ) ( Platform.getRandomFloat() * target.width + target.boundingBox.minZ ); ServerHelper.proxy.sendToAllNearExcept( null, dx, dy, dz, 32.0, target.worldObj, new PacketLightning( dx, dy, dz ) ); } } diff --git a/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java b/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java index cce6e182b..1395d3a9c 100644 --- a/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java +++ b/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.google.common.base.Optional; + import net.minecraft.block.Block; import net.minecraft.block.BlockDispenser; import net.minecraft.entity.player.EntityPlayer; @@ -97,7 +99,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe public ToolColorApplicator() { - super( ToolColorApplicator.class, null ); + super( ToolColorApplicator.class, Optional. absent() ); setFeature( EnumSet.of( AEFeature.ColorApplicator, AEFeature.PoweredTools ) ); maxStoredPower = AEConfig.instance.colorApplicatorBattery; if ( Platform.isClient() ) @@ -111,125 +113,6 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() ); } - public ItemStack getColor( ItemStack is ) - { - NBTTagCompound c = is.getTagCompound(); - if ( c != null && c.hasKey( "color" ) ) - { - NBTTagCompound color = c.getCompoundTag( "color" ); - ItemStack oldColor = ItemStack.loadItemStackFromNBT( color ); - if ( oldColor != null ) - return oldColor; - } - - return findNextColor( is, null, 0 ); - } - - public AEColor getColorFromItem( ItemStack paintBall ) - { - if ( paintBall == null ) - return null; - - if ( paintBall.getItem() instanceof ItemSnowball ) - return AEColor.Transparent; - - if ( paintBall.getItem() instanceof ItemPaintBall ) - { - ItemPaintBall ipb = ( ItemPaintBall ) paintBall.getItem(); - return ipb.getColor( paintBall ); - } - else - { - int[] id = OreDictionary.getOreIDs( paintBall ); - - for ( int oreID : id ) - { - if ( oreToColor.containsKey( oreID ) ) - return oreToColor.get( oreID ); - } - } - - return null; - } - - public AEColor getActiveColor( ItemStack tol ) - { - return getColorFromItem( getColor( tol ) ); - } - - private ItemStack findNextColor( ItemStack is, ItemStack anchor, int scrollOffset ) - { - ItemStack newColor = null; - - IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS ); - if ( inv != null ) - { - IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() ); - if ( anchor == null ) - { - IAEItemStack firstItem = itemList.getFirstItem(); - if ( firstItem != null ) - newColor = firstItem.getItemStack(); - } - else - { - LinkedList list = new LinkedList(); - - for ( IAEItemStack i : itemList ) - list.add( i ); - - Collections.sort( list, new Comparator(){ - - @Override - public int compare( IAEItemStack a, IAEItemStack b ) - { - return ItemSorters.compareInt( a.getItemDamage(), b.getItemDamage() ); - } - - } ); - - if ( list.size() <= 0 ) - return null; - - IAEItemStack where = list.getFirst(); - int cycles = 1 + list.size(); - - while ( cycles > 0 && !where.equals( anchor ) ) - { - list.addLast( list.removeFirst() ); - cycles--; - where = list.getFirst(); - } - - if ( scrollOffset > 0 ) - list.addLast( list.removeFirst() ); - - if ( scrollOffset < 0 ) - list.addFirst( list.removeLast() ); - - return list.get( 0 ).getItemStack(); - } - } - - if ( newColor != null ) - setColor( is, newColor ); - - return newColor; - } - - public void setColor( ItemStack is, ItemStack newColor ) - { - NBTTagCompound data = Platform.openNbtData( is ); - if ( newColor == null ) - data.removeTag( "color" ); - else - { - NBTTagCompound color = new NBTTagCompound(); - newColor.writeToNBT( color ); - data.setTag( "color", color ); - } - } - @Override public boolean onItemUse( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) { @@ -309,6 +192,138 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe return false; } + @Override + public String getItemStackDisplayName( ItemStack par1ItemStack ) + { + String extra = GuiText.Empty.getLocal(); + + AEColor selected = getActiveColor( par1ItemStack ); + + if ( selected != null && Platform.isClient() ) + extra = Platform.gui_localize( selected.unlocalizedName ); + + return super.getItemStackDisplayName( par1ItemStack ) + " - " + extra; + } + + public AEColor getActiveColor( ItemStack tol ) + { + return getColorFromItem( getColor( tol ) ); + } + + public AEColor getColorFromItem( ItemStack paintBall ) + { + if ( paintBall == null ) + return null; + + if ( paintBall.getItem() instanceof ItemSnowball ) + return AEColor.Transparent; + + if ( paintBall.getItem() instanceof ItemPaintBall ) + { + ItemPaintBall ipb = ( ItemPaintBall ) paintBall.getItem(); + return ipb.getColor( paintBall ); + } + else + { + int[] id = OreDictionary.getOreIDs( paintBall ); + + for ( int oreID : id ) + { + if ( oreToColor.containsKey( oreID ) ) + return oreToColor.get( oreID ); + } + } + + return null; + } + + public ItemStack getColor( ItemStack is ) + { + NBTTagCompound c = is.getTagCompound(); + if ( c != null && c.hasKey( "color" ) ) + { + NBTTagCompound color = c.getCompoundTag( "color" ); + ItemStack oldColor = ItemStack.loadItemStackFromNBT( color ); + if ( oldColor != null ) + return oldColor; + } + + return findNextColor( is, null, 0 ); + } + + private ItemStack findNextColor( ItemStack is, ItemStack anchor, int scrollOffset ) + { + ItemStack newColor = null; + + IMEInventory inv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS ); + if ( inv != null ) + { + IItemList itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() ); + if ( anchor == null ) + { + IAEItemStack firstItem = itemList.getFirstItem(); + if ( firstItem != null ) + newColor = firstItem.getItemStack(); + } + else + { + LinkedList list = new LinkedList(); + + for ( IAEItemStack i : itemList ) + list.add( i ); + + Collections.sort( list, new Comparator(){ + + @Override + public int compare( IAEItemStack a, IAEItemStack b ) + { + return ItemSorters.compareInt( a.getItemDamage(), b.getItemDamage() ); + } + + } ); + + if ( list.size() <= 0 ) + return null; + + IAEItemStack where = list.getFirst(); + int cycles = 1 + list.size(); + + while ( cycles > 0 && !where.equals( anchor ) ) + { + list.addLast( list.removeFirst() ); + cycles--; + where = list.getFirst(); + } + + if ( scrollOffset > 0 ) + list.addLast( list.removeFirst() ); + + if ( scrollOffset < 0 ) + list.addFirst( list.removeLast() ); + + return list.get( 0 ).getItemStack(); + } + } + + if ( newColor != null ) + setColor( is, newColor ); + + return newColor; + } + + public void setColor( ItemStack is, ItemStack newColor ) + { + NBTTagCompound data = Platform.openNbtData( is ); + if ( newColor == null ) + data.removeTag( "color" ); + else + { + NBTTagCompound color = new NBTTagCompound(); + newColor.writeToNBT( color ); + data.setTag( "color", color ); + } + } + private boolean recolourBlock( Block blk, ForgeDirection side, World w, int x, int y, int z, ForgeDirection orientation, AEColor newColor, EntityPlayer p ) { if ( blk == Blocks.carpet ) @@ -376,19 +391,6 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe } } - @Override - public String getItemStackDisplayName( ItemStack par1ItemStack ) - { - String extra = GuiText.Empty.getLocal(); - - AEColor selected = getActiveColor( par1ItemStack ); - - if ( selected != null && Platform.isClient() ) - extra = Platform.gui_localize( selected.unlocalizedName ); - - return super.getItemStackDisplayName( par1ItemStack ) + " - " + extra; - } - @Override public void addCheckedInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) { @@ -458,6 +460,24 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe return true; } + @Override + public double getIdleDrain() + { + return 0.5; + } + + @Override + public String getUnlocalizedGroupName( Set others, ItemStack is ) + { + return GuiText.StorageCells.getUnlocalized(); + } + + @Override + public boolean isEditable( ItemStack is ) + { + return true; + } + @Override public IInventory getUpgradesInventory( ItemStack is ) { @@ -484,30 +504,12 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe } } - @Override - public String getUnlocalizedGroupName( Set others, ItemStack is ) - { - return GuiText.StorageCells.getUnlocalized(); - } - @Override public void setFuzzyMode( ItemStack is, FuzzyMode fzMode ) { Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); } - @Override - public boolean isEditable( ItemStack is ) - { - return true; - } - - @Override - public double getIdleDrain() - { - return 0.5; - } - @Override public void onWheel( ItemStack is, boolean up ) { diff --git a/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java b/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java index 47d97881c..e2cc6eaf3 100644 --- a/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java +++ b/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java @@ -18,11 +18,14 @@ package appeng.items.tools.powered; + import java.util.ArrayList; import java.util.EnumSet; import java.util.Hashtable; import java.util.List; +import com.google.common.base.Optional; + import net.minecraft.block.Block; import net.minecraft.block.BlockDispenser; import net.minecraft.block.BlockTNT; @@ -39,6 +42,7 @@ import net.minecraft.util.MovingObjectPosition.MovingObjectType; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; + import appeng.api.util.DimensionalCoord; import appeng.block.misc.BlockTinyTNT; import appeng.core.AEConfig; @@ -49,116 +53,16 @@ import appeng.items.tools.powered.powersink.AEBasePoweredItem; import appeng.util.InWorldToolOperationResult; import appeng.util.Platform; + public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool { - static class Combo - { - - final public Block blk; - final public int meta; - - public Combo(Block b, int m) { - blk = b; - meta = m; - } - - @Override - public int hashCode() - { - return blk.hashCode() ^ meta; - } - - @Override - public boolean equals(Object obj) - { - if ( obj == null ) - return false; - if ( getClass() != obj.getClass() ) - return false; - Combo other = (Combo) obj; - return blk == other.blk && meta == other.meta; - } - - } - static private Hashtable heatUp; static private Hashtable coolDown; - static public void heat(Block BlockID, int Metadata, World w, int x, int y, int z) + public ToolEntropyManipulator() { - InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) ); - - if ( r == null ) - { - r = heatUp.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) ); - } - - if ( r.BlockItem != null ) - { - w.setBlock( x, y, z, Block.getBlockFromItem( r.BlockItem.getItem() ), r.BlockItem.getItemDamage(), 3 ); - } - else - { - w.setBlock( x, y, z, Platform.air, 0, 3 ); - } - - if ( r.Drops != null ) - { - Platform.spawnDrops( w, x, y, z, r.Drops ); - } - } - - static public boolean canHeat(Block BlockID, int Metadata) - { - InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) ); - - if ( r == null ) - { - r = heatUp.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) ); - } - - return r != null; - } - - static public void cool(Block BlockID, int Metadata, World w, int x, int y, int z) - { - InWorldToolOperationResult r = coolDown.get( new Combo( BlockID, Metadata ) ); - - if ( r == null ) - { - r = coolDown.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) ); - } - - if ( r.BlockItem != null ) - { - w.setBlock( x, y, z, Block.getBlockFromItem( r.BlockItem.getItem() ), r.BlockItem.getItemDamage(), 3 ); - } - else - { - w.setBlock( x, y, z, Platform.air, 0, 3 ); - } - - if ( r.Drops != null ) - { - Platform.spawnDrops( w, x, y, z, r.Drops ); - } - } - - static public boolean canCool(Block BlockID, int Metadata) - { - InWorldToolOperationResult r = coolDown.get( new Combo( BlockID, Metadata ) ); - - if ( r == null ) - { - r = coolDown.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) ); - } - - return r != null; - } - - public ToolEntropyManipulator() { - super( ToolEntropyManipulator.class, null ); + super( ToolEntropyManipulator.class, Optional. absent() ); setFeature( EnumSet.of( AEFeature.EntropyManipulator, AEFeature.PoweredTools ) ); maxStoredPower = AEConfig.instance.entropyManipulatorBattery; @@ -188,8 +92,111 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() ); } + static public void heat( Block BlockID, int Metadata, World w, int x, int y, int z ) + { + InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) ); + + if ( r == null ) + { + r = heatUp.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) ); + } + + if ( r.BlockItem != null ) + { + w.setBlock( x, y, z, Block.getBlockFromItem( r.BlockItem.getItem() ), r.BlockItem.getItemDamage(), 3 ); + } + else + { + w.setBlock( x, y, z, Platform.air, 0, 3 ); + } + + if ( r.Drops != null ) + { + Platform.spawnDrops( w, x, y, z, r.Drops ); + } + } + + static class Combo + { + + final public Block blk; + final public int meta; + + public Combo( Block b, int m ) + { + blk = b; + meta = m; + } + + @Override + public int hashCode() + { + return blk.hashCode() ^ meta; + } + + @Override + public boolean equals( Object obj ) + { + if ( obj == null ) + return false; + if ( getClass() != obj.getClass() ) + return false; + Combo other = ( Combo ) obj; + return blk == other.blk && meta == other.meta; + } + + } + + static public boolean canHeat( Block BlockID, int Metadata ) + { + InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) ); + + if ( r == null ) + { + r = heatUp.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) ); + } + + return r != null; + } + + static public void cool( Block BlockID, int Metadata, World w, int x, int y, int z ) + { + InWorldToolOperationResult r = coolDown.get( new Combo( BlockID, Metadata ) ); + + if ( r == null ) + { + r = coolDown.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) ); + } + + if ( r.BlockItem != null ) + { + w.setBlock( x, y, z, Block.getBlockFromItem( r.BlockItem.getItem() ), r.BlockItem.getItemDamage(), 3 ); + } + else + { + w.setBlock( x, y, z, Platform.air, 0, 3 ); + } + + if ( r.Drops != null ) + { + Platform.spawnDrops( w, x, y, z, r.Drops ); + } + } + + static public boolean canCool( Block BlockID, int Metadata ) + { + InWorldToolOperationResult r = coolDown.get( new Combo( BlockID, Metadata ) ); + + if ( r == null ) + { + r = coolDown.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) ); + } + + return r != null; + } + @Override - public boolean hitEntity(ItemStack item, EntityLivingBase target, EntityLivingBase hitter) + public boolean hitEntity( ItemStack item, EntityLivingBase target, EntityLivingBase hitter ) { if ( this.getAECurrentPower( item ) > 1600 ) { @@ -201,7 +208,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT } @Override - public ItemStack onItemRightClick(ItemStack item, World w, EntityPlayer p) + public ItemStack onItemRightClick( ItemStack item, World w, EntityPlayer p ) { MovingObjectPosition target = this.getMovingObjectPositionFromPlayer( w, p, true ); @@ -229,7 +236,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT } @Override - public boolean onItemUse(ItemStack item, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + public boolean onItemUse( ItemStack item, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) { if ( this.getAECurrentPower( item ) > 1600 ) { @@ -253,14 +260,14 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT if ( Blk instanceof BlockTNT ) { w.setBlock( x, y, z, Platform.air, 0, 3 ); - ((BlockTNT) Blk).func_150114_a( w, x, y, z, 1, p ); + ( ( BlockTNT ) Blk ).func_150114_a( w, x, y, z, 1, p ); return true; } if ( Blk instanceof BlockTinyTNT ) { w.setBlock( x, y, z, Platform.air, 0, 3 ); - ((BlockTinyTNT) Blk).startFuse( w, x, y, z, p ); + ( ( BlockTinyTNT ) Blk ).startFuse( w, x, y, z, p ); return true; } @@ -276,7 +283,7 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT boolean hasFurnaceable = false; boolean canFurnaceable = true; - for (ItemStack i : stack) + for ( ItemStack i : stack ) { ItemStack result = FurnaceRecipes.smelting().getSmeltingResult( i ); diff --git a/src/main/java/appeng/items/tools/powered/ToolMassCannon.java b/src/main/java/appeng/items/tools/powered/ToolMassCannon.java index 536045628..222ab018a 100644 --- a/src/main/java/appeng/items/tools/powered/ToolMassCannon.java +++ b/src/main/java/appeng/items/tools/powered/ToolMassCannon.java @@ -18,9 +18,12 @@ package appeng.items.tools.powered; + import java.util.EnumSet; import java.util.List; +import com.google.common.base.Optional; + import net.minecraft.block.Block; import net.minecraft.block.BlockDispenser; import net.minecraft.entity.Entity; @@ -39,6 +42,7 @@ import net.minecraft.util.MovingObjectPosition.MovingObjectType; import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; + import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; @@ -73,11 +77,13 @@ import appeng.me.storage.CellInventoryHandler; import appeng.tile.misc.TilePaint; import appeng.util.Platform; + public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell { - public ToolMassCannon() { - super( ToolMassCannon.class, null ); + public ToolMassCannon() + { + super( ToolMassCannon.class, Optional. absent() ); setFeature( EnumSet.of( AEFeature.MatterCannon, AEFeature.PoweredTools ) ); maxStoredPower = AEConfig.instance.matterCannonBattery; } @@ -90,7 +96,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell } @Override - public void addCheckedInformation(ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) + public void addCheckedInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) { super.addCheckedInformation( stack, player, lines, displayAdditionalInformation ); @@ -98,7 +104,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell if ( cdi instanceof CellInventoryHandler ) { - ICellInventory cd = ((ICellInventoryHandler) cdi).getCellInv(); + ICellInventory cd = ( ( ICellInventoryHandler ) cdi ).getCellInv(); if ( cd != null ) { lines.add( cd.getUsedBytes() + " " + GuiText.Of.getLocal() + " " + cd.getTotalBytes() + " " + GuiText.BytesUsed.getLocal() ); @@ -108,13 +114,13 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell } @Override - public ItemStack onItemRightClick(ItemStack item, World w, EntityPlayer p) + public ItemStack onItemRightClick( ItemStack item, World w, EntityPlayer p ) { if ( this.getAECurrentPower( item ) > 1600 ) { int shots = 1; - CellUpgrades cu = (CellUpgrades) getUpgradesInventory( item ); + CellUpgrades cu = ( CellUpgrades ) getUpgradesInventory( item ); if ( cu != null ) shots += cu.getInstalledUpgrades( Upgrades.SPEED ); @@ -125,8 +131,8 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell IAEStack aeAmmo = itemList.getFirstItem(); if ( aeAmmo instanceof IAEItemStack ) { - shots = Math.min( shots, (int) aeAmmo.getStackSize() ); - for (int sh = 0; sh < shots; sh++) + shots = Math.min( shots, ( int ) aeAmmo.getStackSize() ); + for ( int sh = 0; sh < shots; sh++ ) { extractAEPower( item, 1600 ); @@ -134,7 +140,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell return item; aeAmmo.setStackSize( 1 ); - ItemStack ammo = ((IAEItemStack) aeAmmo).getItemStack(); + ItemStack ammo = ( ( IAEItemStack ) aeAmmo ).getItemStack(); if ( ammo == null ) return item; @@ -144,14 +150,14 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell return item; float f = 1.0F; - float f1 = p.prevRotationPitch + (p.rotationPitch - p.prevRotationPitch) * f; - float f2 = p.prevRotationYaw + (p.rotationYaw - p.prevRotationYaw) * f; - double d0 = p.prevPosX + (p.posX - p.prevPosX) * f; - double d1 = p.prevPosY + (p.posY - p.prevPosY) * f + 1.62D - p.yOffset; - double d2 = p.prevPosZ + (p.posZ - p.prevPosZ) * f; + float f1 = p.prevRotationPitch + ( p.rotationPitch - p.prevRotationPitch ) * f; + float f2 = p.prevRotationYaw + ( p.rotationYaw - p.prevRotationYaw ) * f; + double d0 = p.prevPosX + ( p.posX - p.prevPosX ) * f; + double d1 = p.prevPosY + ( p.posY - p.prevPosY ) * f + 1.62D - p.yOffset; + double d2 = p.prevPosZ + ( p.posZ - p.prevPosZ ) * f; Vec3 vec3 = Vec3.createVectorHelper( d0, d1, d2 ); - float f3 = MathHelper.cos( -f2 * 0.017453292F - (float) Math.PI ); - float f4 = MathHelper.sin( -f2 * 0.017453292F - (float) Math.PI ); + float f3 = MathHelper.cos( -f2 * 0.017453292F - ( float ) Math.PI ); + float f4 = MathHelper.sin( -f2 * 0.017453292F - ( float ) Math.PI ); float f5 = -MathHelper.cos( -f1 * 0.017453292F ); float f6 = MathHelper.sin( -f1 * 0.017453292F ); float f7 = f4 * f5; @@ -165,7 +171,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell float penetration = AEApi.instance().registries().matterCannon().getPenetration( ammo ); // 196.96655f; if ( penetration <= 0 ) { - ItemStack type = ((IAEItemStack) aeAmmo).getItemStack(); + ItemStack type = ( ( IAEItemStack ) aeAmmo ).getItemStack(); if ( type.getItem() instanceof ItemPaintBall ) { shootPaintBalls( type, w, p, vec3, vec31, direction, d0, d1, d2 ); @@ -190,7 +196,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell return item; } - private void shootPaintBalls(ItemStack type, World w, EntityPlayer p, Vec3 vec3, Vec3 vec31, Vec3 direction, double d0, double d1, double d2) + private void shootPaintBalls( ItemStack type, World w, EntityPlayer p, Vec3 vec3, Vec3 vec31, Vec3 direction, double d0, double d1, double d2 ) { AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ), Math.min( vec3.zCoord, vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ), @@ -201,11 +207,11 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell double closest = 9999999.0D; int l; - for (l = 0; l < list.size(); ++l) + for ( l = 0; l < list.size(); ++l ) { - Entity entity1 = (Entity) list.get( l ); + Entity entity1 = ( Entity ) list.get( l ); - if ( !entity1.isDead && entity1 != p && !(entity1 instanceof EntityItem) ) + if ( !entity1.isDead && entity1 != p && !( entity1 instanceof EntityItem ) ) { if ( entity1.isEntityAlive() ) { @@ -246,18 +252,18 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell try { - CommonHelper.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, (float) direction.xCoord, - (float) direction.yCoord, (float) direction.zCoord, (byte) (pos == null ? 32 : pos.hitVec.squareDistanceTo( vec ) + 1) ) ); + CommonHelper.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, ( float ) direction.xCoord, + ( float ) direction.yCoord, ( float ) direction.zCoord, ( byte ) ( pos == null ? 32 : pos.hitVec.squareDistanceTo( vec ) + 1 ) ) ); } - catch (Exception err) + catch ( Exception err ) { AELog.error( err ); } if ( pos != null && type != null && type.getItem() instanceof ItemPaintBall ) { - ItemPaintBall ipb = (ItemPaintBall) type.getItem(); + ItemPaintBall ipb = ( ItemPaintBall ) type.getItem(); AEColor col = ipb.getColor( type ); // boolean lit = ipb.isLumen( type ); @@ -270,7 +276,7 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell if ( pos.entityHit instanceof EntitySheep ) { - EntitySheep sh = (EntitySheep) pos.entityHit; + EntitySheep sh = ( EntitySheep ) pos.entityHit; sh.setFleeceColor( col.ordinal() ); } @@ -300,17 +306,17 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell pos.hitVec.xCoord -= x; pos.hitVec.yCoord -= y; pos.hitVec.zCoord -= z; - ((TilePaint) te).addBlot( type, side.getOpposite(), pos.hitVec ); + ( ( TilePaint ) te ).addBlot( type, side.getOpposite(), pos.hitVec ); } } } } - private void standardAmmo(float penetration, World w, EntityPlayer p, Vec3 vec3, Vec3 vec31, Vec3 direction, double d0, double d1, double d2) + private void standardAmmo( float penetration, World w, EntityPlayer p, Vec3 vec3, Vec3 vec31, Vec3 direction, double d0, double d1, double d2 ) { boolean hasDestroyedSomething = true; - while (penetration > 0 && hasDestroyedSomething) + while ( penetration > 0 && hasDestroyedSomething ) { hasDestroyedSomething = false; @@ -323,11 +329,11 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell double closest = 9999999.0D; int l; - for (l = 0; l < list.size(); ++l) + for ( l = 0; l < list.size(); ++l ) { - Entity entity1 = (Entity) list.get( l ); + Entity entity1 = ( Entity ) list.get( l ); - if ( !entity1.isDead && entity1 != p && !(entity1 instanceof EntityItem) ) + if ( !entity1.isDead && entity1 != p && !( entity1 instanceof EntityItem ) ) { if ( entity1.isEntityAlive() ) { @@ -367,11 +373,11 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell try { - CommonHelper.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, (float) direction.xCoord, - (float) direction.yCoord, (float) direction.zCoord, (byte) (pos == null ? 32 : pos.hitVec.squareDistanceTo( vec ) + 1) ) ); + CommonHelper.proxy.sendToAllNearExcept( null, d0, d1, d2, 128, w, new PacketMatterCannon( d0, d1, d2, ( float ) direction.xCoord, + ( float ) direction.yCoord, ( float ) direction.zCoord, ( byte ) ( pos == null ? 32 : pos.hitVec.squareDistanceTo( vec ) + 1 ) ) ); } - catch (Exception err) + catch ( Exception err ) { AELog.error( err ); } @@ -383,10 +389,10 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell if ( pos.typeOfHit == MovingObjectType.ENTITY ) { - int dmg = (int) Math.ceil( penetration / 20.0f ); + int dmg = ( int ) Math.ceil( penetration / 20.0f ); if ( pos.entityHit instanceof EntityLivingBase ) { - EntityLivingBase el = (EntityLivingBase) pos.entityHit; + EntityLivingBase el = ( EntityLivingBase ) pos.entityHit; penetration -= dmg; el.knockBack( p, 0, -direction.xCoord, -direction.zCoord ); // el.knockBack( p, 0, vec3.xCoord, @@ -434,81 +440,63 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell } @Override - public boolean storableInStorageCell() + public boolean isEditable( ItemStack is ) { return true; } @Override - public boolean isStorageCell(ItemStack i) - { - return true; - } - - @Override - public double getIdleDrain() - { - return 0.5; - } - - @Override - public IInventory getUpgradesInventory(ItemStack is) + public IInventory getUpgradesInventory( ItemStack is ) { return new CellUpgrades( is, 4 ); } @Override - public IInventory getConfigInventory(ItemStack is) + public IInventory getConfigInventory( ItemStack is ) { return new CellConfig( is ); } @Override - public FuzzyMode getFuzzyMode(ItemStack is) + public FuzzyMode getFuzzyMode( ItemStack is ) { String fz = Platform.openNbtData( is ).getString( "FuzzyMode" ); try { return FuzzyMode.valueOf( fz ); } - catch (Throwable t) + catch ( Throwable t ) { return FuzzyMode.IGNORE_ALL; } } @Override - public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) + public void setFuzzyMode( ItemStack is, FuzzyMode fzMode ) { Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); } @Override - public boolean isEditable(ItemStack is) - { - return true; - } - - @Override - public int getBytes(ItemStack cellItem) + public int getBytes( ItemStack cellItem ) { return 512; } @Override - public int BytePerType(ItemStack cell) + public int BytePerType( ItemStack cell ) { return 8; } @Override - public int getTotalTypes(ItemStack cellItem) + public int getTotalTypes( ItemStack cellItem ) { return 1; } @Override - public boolean isBlackListed(ItemStack cellItem, IAEItemStack requestedAddition) + public boolean isBlackListed( ItemStack cellItem, IAEItemStack requestedAddition ) { float pen = AEApi.instance().registries().matterCannon().getPenetration( requestedAddition.getItemStack() ); if ( pen > 0 ) @@ -519,4 +507,22 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell return true; } + + @Override + public boolean storableInStorageCell() + { + return true; + } + + @Override + public boolean isStorageCell( ItemStack i ) + { + return true; + } + + @Override + public double getIdleDrain() + { + return 0.5; + } } diff --git a/src/main/java/appeng/items/tools/powered/ToolPortableCell.java b/src/main/java/appeng/items/tools/powered/ToolPortableCell.java index 12b7302b3..30141a348 100644 --- a/src/main/java/appeng/items/tools/powered/ToolPortableCell.java +++ b/src/main/java/appeng/items/tools/powered/ToolPortableCell.java @@ -23,6 +23,8 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; +import com.google.common.base.Optional; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -56,7 +58,7 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell, { public ToolPortableCell() { - super( ToolPortableCell.class, null ); + super( ToolPortableCell.class, Optional. absent() ); setFeature( EnumSet.of( AEFeature.PortableCell, AEFeature.StorageCells, AEFeature.PoweredTools ) ); maxStoredPower = AEConfig.instance.portableCellBattery; } @@ -128,6 +130,18 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell, return 0.5; } + @Override + public String getUnlocalizedGroupName( Set others, ItemStack is ) + { + return GuiText.StorageCells.getUnlocalized(); + } + + @Override + public boolean isEditable( ItemStack is ) + { + return true; + } + @Override public IInventory getUpgradesInventory( ItemStack is ) { @@ -154,24 +168,12 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell, } } - @Override - public String getUnlocalizedGroupName( Set others, ItemStack is ) - { - return GuiText.StorageCells.getUnlocalized(); - } - @Override public void setFuzzyMode( ItemStack is, FuzzyMode fzMode ) { Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); } - @Override - public boolean isEditable( ItemStack is ) - { - return true; - } - @Override public IGuiItemObject getGuiObject( ItemStack is, World w, int x, int y, int z ) { diff --git a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java index 148ef7d55..ff72edea1 100644 --- a/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java +++ b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java @@ -18,14 +18,18 @@ package appeng.items.tools.powered; + import java.util.EnumSet; import java.util.List; +import com.google.common.base.Optional; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; import net.minecraft.world.World; + import appeng.api.AEApi; import appeng.api.config.Settings; import appeng.api.config.SortDir; @@ -41,24 +45,26 @@ import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; import appeng.util.Platform; + public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler { - public ToolWirelessTerminal() { - super( ToolWirelessTerminal.class, null ); + public ToolWirelessTerminal() + { + super( ToolWirelessTerminal.class, Optional. absent() ); setFeature( EnumSet.of( AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools ) ); maxStoredPower = AEConfig.instance.wirelessTerminalBattery; } @Override - public ItemStack onItemRightClick(ItemStack item, World w, EntityPlayer player) + public ItemStack onItemRightClick( ItemStack item, World w, EntityPlayer player ) { AEApi.instance().registries().wireless().openWirelessTerminalGui( item, w, player ); return item; } @Override - public void addCheckedInformation(ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) + public void addCheckedInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) { super.addCheckedInformation( stack, player, lines, displayAdditionalInformation ); @@ -80,45 +86,30 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless } @Override - public boolean canHandle(ItemStack is) + public boolean canHandle( ItemStack is ) { return AEApi.instance().items().itemWirelessTerminal.sameAsStack( is ); } @Override - public boolean usePower(EntityPlayer player, double amount, ItemStack is) + public boolean usePower( EntityPlayer player, double amount, ItemStack is ) { return this.extractAEPower( is, amount ) >= amount - 0.5; } @Override - public boolean hasPower(EntityPlayer player, double amt, ItemStack is) + public boolean hasPower( EntityPlayer player, double amt, ItemStack is ) { return getAECurrentPower( is ) >= amt; } @Override - public String getEncryptionKey(ItemStack item) + public IConfigManager getConfigManager( final ItemStack target ) { - NBTTagCompound tag = Platform.openNbtData( item ); - return tag.getString( "encryptionKey" ); - } - - @Override - public void setEncryptionKey(ItemStack item, String encKey, String name) - { - NBTTagCompound tag = Platform.openNbtData( item ); - tag.setString( "encryptionKey", encKey ); - tag.setString( "name", name ); - } - - @Override - public IConfigManager getConfigManager(final ItemStack target) - { - final ConfigManager out = new ConfigManager( new IConfigManagerHost() { + final ConfigManager out = new ConfigManager( new IConfigManagerHost(){ @Override - public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) + public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue ) { NBTTagCompound data = Platform.openNbtData( target ); manager.writeToNBT( data ); @@ -130,8 +121,23 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless out.registerSetting( Settings.VIEW_MODE, ViewItems.ALL ); out.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING ); - out.readFromNBT( (NBTTagCompound) Platform.openNbtData( target ).copy() ); + out.readFromNBT( ( NBTTagCompound ) Platform.openNbtData( target ).copy() ); return out; } + @Override + public String getEncryptionKey( ItemStack item ) + { + NBTTagCompound tag = Platform.openNbtData( item ); + return tag.getString( "encryptionKey" ); + } + + @Override + public void setEncryptionKey( ItemStack item, String encKey, String name ) + { + NBTTagCompound tag = Platform.openNbtData( item ); + tag.setString( "encryptionKey", encKey ); + tag.setString( "name", name ); + } + } diff --git a/src/main/java/appeng/items/tools/powered/powersink/AEBasePoweredItem.java b/src/main/java/appeng/items/tools/powered/powersink/AEBasePoweredItem.java index 35b543a95..b990b4f91 100644 --- a/src/main/java/appeng/items/tools/powered/powersink/AEBasePoweredItem.java +++ b/src/main/java/appeng/items/tools/powered/powersink/AEBasePoweredItem.java @@ -18,11 +18,17 @@ package appeng.items.tools.powered.powersink; + +import com.google.common.base.Optional; + + public class AEBasePoweredItem extends RedstoneFlux { - public AEBasePoweredItem(Class c, String subName) { + public AEBasePoweredItem( Class c, Optional subName ) + { super( c, subName ); - setMaxStackSize( 1 ); + + this.setMaxStackSize( 1 ); } } diff --git a/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java b/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java index 7c2fe0d9e..b287ec3ea 100644 --- a/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java +++ b/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java @@ -18,14 +18,18 @@ package appeng.items.tools.powered.powersink; + import java.text.MessageFormat; import java.util.List; +import com.google.common.base.Optional; + import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; + import appeng.api.config.AccessRestriction; import appeng.api.config.PowerUnits; import appeng.api.implementations.items.IAEItemPowerStorage; @@ -33,24 +37,22 @@ import appeng.core.localization.GuiText; import appeng.items.AEBaseItem; import appeng.util.Platform; + public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage { - private enum batteryOperation - { - STORAGE, INJECT, EXTRACT - } - + final String EnergyVar = "internalCurrentPower"; public double maxStoredPower = 200000; - public AERootPoweredItem(Class c, String subName) { + public AERootPoweredItem( Class c, Optional subName ) + { super( c, subName ); setMaxDamage( 32 ); hasSubtypes = false; } @Override - public void addCheckedInformation(ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) + public void addCheckedInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) { NBTTagCompound tag = stack.getTagCompound(); double internalCurrentPower = 0; @@ -75,9 +77,15 @@ public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage } @Override - public boolean isDamaged(ItemStack stack) + public void getSubItems( Item id, CreativeTabs tab, List list ) { - return true; + super.getSubItems( id, tab, list ); + + ItemStack charged = new ItemStack( this, 1 ); + NBTTagCompound tag = Platform.openNbtData( charged ); + tag.setDouble( "internalCurrentPower", getAEMaxPower( charged ) ); + tag.setDouble( "internalMaxPower", getAEMaxPower( charged ) ); + list.add( charged ); } @Override @@ -87,56 +95,31 @@ public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage } @Override - public void setDamage(ItemStack stack, int damage) + public double getDurabilityForDisplay( ItemStack is ) { - + return 1 - getAECurrentPower( is ) / getAEMaxPower( is ); } - final String EnergyVar = "internalCurrentPower"; - - private double getInternalBattery(ItemStack is, batteryOperation op, double adjustment) + @Override + public boolean isDamaged( ItemStack stack ) { - NBTTagCompound data = Platform.openNbtData( is ); + return true; + } - double currentStorage = data.getDouble( EnergyVar ); - double maxStorage = getAEMaxPower( is ); + @Override + public void setDamage( ItemStack stack, int damage ) + { - switch (op) - { - case INJECT: - currentStorage += adjustment; - if ( currentStorage > maxStorage ) - { - double diff = currentStorage - maxStorage; - data.setDouble( EnergyVar, maxStorage ); - return diff; - } - data.setDouble( EnergyVar, currentStorage ); - return 0; - case EXTRACT: - if ( currentStorage > adjustment ) - { - currentStorage -= adjustment; - data.setDouble( EnergyVar, currentStorage ); - return adjustment; - } - data.setDouble( EnergyVar, 0 ); - return currentStorage; - default: - break; - } - - return currentStorage; } /** * inject external */ - double injectExternalPower(PowerUnits input, ItemStack is, double amount, boolean simulate) + double injectExternalPower( PowerUnits input, ItemStack is, double amount, boolean simulate ) { if ( simulate ) { - int requiredEU = (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( is ) - getAECurrentPower( is ) ); + int requiredEU = ( int ) PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( is ) - getAECurrentPower( is ) ); if ( amount < requiredEU ) return 0; return amount - requiredEU; @@ -149,51 +132,73 @@ public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage } @Override - public double injectAEPower(ItemStack is, double amt) + public double injectAEPower( ItemStack is, double amt ) { return getInternalBattery( is, batteryOperation.INJECT, amt ); } @Override - public double extractAEPower(ItemStack is, double amt) + public double extractAEPower( ItemStack is, double amt ) { return getInternalBattery( is, batteryOperation.EXTRACT, amt ); } + private double getInternalBattery( ItemStack is, batteryOperation op, double adjustment ) + { + NBTTagCompound data = Platform.openNbtData( is ); + + double currentStorage = data.getDouble( EnergyVar ); + double maxStorage = getAEMaxPower( is ); + + switch ( op ) + { + case INJECT: + currentStorage += adjustment; + if ( currentStorage > maxStorage ) + { + double diff = currentStorage - maxStorage; + data.setDouble( EnergyVar, maxStorage ); + return diff; + } + data.setDouble( EnergyVar, currentStorage ); + return 0; + case EXTRACT: + if ( currentStorage > adjustment ) + { + currentStorage -= adjustment; + data.setDouble( EnergyVar, currentStorage ); + return adjustment; + } + data.setDouble( EnergyVar, 0 ); + return currentStorage; + default: + break; + } + + return currentStorage; + } + @Override - public double getAEMaxPower(ItemStack is) + public double getAEMaxPower( ItemStack is ) { return maxStoredPower; } @Override - public double getAECurrentPower(ItemStack is) + public double getAECurrentPower( ItemStack is ) { return getInternalBattery( is, batteryOperation.STORAGE, 0 ); } @Override - public AccessRestriction getPowerFlow(ItemStack is) + public AccessRestriction getPowerFlow( ItemStack is ) { return AccessRestriction.WRITE; } - @Override - public double getDurabilityForDisplay(ItemStack is) + private enum batteryOperation { - return 1 - getAECurrentPower( is ) / getAEMaxPower( is ); - } - - @Override - public void getSubItems(Item id, CreativeTabs tab, List list) - { - super.getSubItems( id, tab, list ); - - ItemStack charged = new ItemStack( this, 1 ); - NBTTagCompound tag = Platform.openNbtData( charged ); - tag.setDouble( "internalCurrentPower", getAEMaxPower( charged ) ); - tag.setDouble( "internalMaxPower", getAEMaxPower( charged ) ); - list.add( charged ); + STORAGE, INJECT, EXTRACT } } diff --git a/src/main/java/appeng/items/tools/powered/powersink/IC2.java b/src/main/java/appeng/items/tools/powered/powersink/IC2.java index c549e2ef1..43e183ce1 100644 --- a/src/main/java/appeng/items/tools/powered/powersink/IC2.java +++ b/src/main/java/appeng/items/tools/powered/powersink/IC2.java @@ -18,27 +18,34 @@ package appeng.items.tools.powered.powersink; -import ic2.api.item.IElectricItemManager; -import ic2.api.item.ISpecialElectricItem; + +import com.google.common.base.Optional; + import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; + +import ic2.api.item.IElectricItemManager; +import ic2.api.item.ISpecialElectricItem; + import appeng.api.config.PowerUnits; import appeng.transformer.annotations.integration.Interface; import appeng.transformer.annotations.integration.InterfaceList; import appeng.transformer.annotations.integration.Method; -@InterfaceList(value = { @Interface(iface = "ic2.api.item.ISpecialElectricItem", iname = "IC2"), - @Interface(iface = "ic2.api.item.IElectricItemManager", iname = "IC2") }) + +@InterfaceList( value = { @Interface( iface = "ic2.api.item.ISpecialElectricItem", iname = "IC2" ), + @Interface( iface = "ic2.api.item.IElectricItemManager", iname = "IC2" ) } ) public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpecialElectricItem { - public IC2(Class c, String subName) { + public IC2( Class c, Optional subName ) + { super( c, subName ); } @Override - public double charge(ItemStack is, double amount, int tier, boolean ignoreTransferLimit, boolean simulate) + public double charge( ItemStack is, double amount, int tier, boolean ignoreTransferLimit, boolean simulate ) { double addedAmt = amount; double limit = getTransferLimit( is ); @@ -46,29 +53,29 @@ public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpe if ( !ignoreTransferLimit && amount > limit ) addedAmt = limit; - return addedAmt - ((int) injectExternalPower( PowerUnits.EU, is, addedAmt, simulate )); + return addedAmt - ( ( int ) injectExternalPower( PowerUnits.EU, is, addedAmt, simulate ) ); } @Override - public double discharge(ItemStack itemStack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate) + public double discharge( ItemStack itemStack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate ) { return 0; } @Override - public double getCharge(ItemStack is) + public double getCharge( ItemStack is ) { - return (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAECurrentPower( is ) ); + return ( int ) PowerUnits.AE.convertTo( PowerUnits.EU, getAECurrentPower( is ) ); } @Override - public boolean canUse(ItemStack is, double amount) + public boolean canUse( ItemStack is, double amount ) { return getCharge( is ) > amount; } @Override - public boolean use(ItemStack is, double amount, EntityLivingBase entity) + public boolean use( ItemStack is, double amount, EntityLivingBase entity ) { if ( canUse( is, amount ) ) { @@ -80,56 +87,56 @@ public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpe } @Override - public void chargeFromArmor(ItemStack itemStack, EntityLivingBase entity) + public void chargeFromArmor( ItemStack itemStack, EntityLivingBase entity ) { // wtf? } @Override - public String getToolTip(ItemStack itemStack) + public String getToolTip( ItemStack itemStack ) { return null; } @Override - public boolean canProvideEnergy(ItemStack itemStack) + public boolean canProvideEnergy( ItemStack itemStack ) { return false; } @Override - public Item getChargedItem(ItemStack itemStack) + public Item getChargedItem( ItemStack itemStack ) { return itemStack.getItem(); } @Override - public Item getEmptyItem(ItemStack itemStack) + public Item getEmptyItem( ItemStack itemStack ) { return itemStack.getItem(); } @Override - public double getMaxCharge(ItemStack itemStack) + public double getMaxCharge( ItemStack itemStack ) { return PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( itemStack ) ); } @Override - public int getTier(ItemStack itemStack) + public int getTier( ItemStack itemStack ) { return 1; } @Override - public double getTransferLimit(ItemStack itemStack) + public double getTransferLimit( ItemStack itemStack ) { return Math.max( 32, getMaxCharge( itemStack ) / 200 ); } @Override - @Method(iname = "IC2") - public IElectricItemManager getManager(ItemStack itemStack) + @Method( iname = "IC2" ) + public IElectricItemManager getManager( ItemStack itemStack ) { return this; } diff --git a/src/main/java/appeng/items/tools/powered/powersink/RedstoneFlux.java b/src/main/java/appeng/items/tools/powered/powersink/RedstoneFlux.java index 9ece13154..73fe858bb 100644 --- a/src/main/java/appeng/items/tools/powered/powersink/RedstoneFlux.java +++ b/src/main/java/appeng/items/tools/powered/powersink/RedstoneFlux.java @@ -18,41 +18,48 @@ package appeng.items.tools.powered.powersink; + +import com.google.common.base.Optional; + import net.minecraft.item.ItemStack; -import appeng.api.config.PowerUnits; -import appeng.transformer.annotations.integration.Interface; + import cofh.api.energy.IEnergyContainerItem; -@Interface(iface = "cofh.api.energy.IEnergyContainerItem", iname = "RFItem") +import appeng.api.config.PowerUnits; +import appeng.transformer.annotations.integration.Interface; + + +@Interface( iface = "cofh.api.energy.IEnergyContainerItem", iname = "RFItem" ) public class RedstoneFlux extends IC2 implements IEnergyContainerItem { - public RedstoneFlux(Class c, String subName) { + public RedstoneFlux( Class c, Optional subName ) + { super( c, subName ); } @Override - public int receiveEnergy(ItemStack is, int maxReceive, boolean simulate) + public int receiveEnergy( ItemStack is, int maxReceive, boolean simulate ) { - return maxReceive - (int) injectExternalPower( PowerUnits.RF, is, maxReceive, simulate ); + return maxReceive - ( int ) injectExternalPower( PowerUnits.RF, is, maxReceive, simulate ); } @Override - public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) + public int extractEnergy( ItemStack container, int maxExtract, boolean simulate ) { return 0; } @Override - public int getEnergyStored(ItemStack is) + public int getEnergyStored( ItemStack is ) { - return (int) PowerUnits.AE.convertTo( PowerUnits.RF, getAECurrentPower( is ) ); + return ( int ) PowerUnits.AE.convertTo( PowerUnits.RF, getAECurrentPower( is ) ); } @Override - public int getMaxEnergyStored(ItemStack is) + public int getMaxEnergyStored( ItemStack is ) { - return (int) PowerUnits.AE.convertTo( PowerUnits.RF, getAEMaxPower( is ) ); + return ( int ) PowerUnits.AE.convertTo( PowerUnits.RF, getAEMaxPower( is ) ); } } diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzAxe.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzAxe.java index a7539b433..2d22ce56c 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzAxe.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzAxe.java @@ -18,36 +18,36 @@ package appeng.items.tools.quartz; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.item.ItemAxe; import net.minecraft.item.ItemStack; + import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; +import appeng.core.features.ItemFeatureHandler; import appeng.util.Platform; + public class ToolQuartzAxe extends ItemAxe implements IAEFeature { + private final AEFeature type; + private final IFeatureHandler feature; - final AEFeature type; - final AEFeatureHandler feature; - - @Override - public AEFeatureHandler feature() + public ToolQuartzAxe( AEFeature Type ) { - return feature; - } - - @Override - public boolean getIsRepairable(ItemStack a, ItemStack b) - { - return Platform.canRepair( type, a, b ); - } - - public ToolQuartzAxe(AEFeature Type) { super( ToolMaterial.IRON ); - feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzAxe ), this, Type.name() ); + this.feature = new ItemFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzAxe ), this, this, Optional.of( Type.name() ) ); + } + + @Override + public IFeatureHandler handler() + { + return this.feature; } @Override @@ -55,4 +55,10 @@ public class ToolQuartzAxe extends ItemAxe implements IAEFeature { // override! } + + @Override + public boolean getIsRepairable( ItemStack a, ItemStack b ) + { + return Platform.canRepair( type, a, b ); + } } diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java index fb19a7008..832682433 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java @@ -18,12 +18,16 @@ package appeng.items.tools.quartz; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; + import appeng.api.implementations.guiobjects.IGuiItem; import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.core.features.AEFeature; @@ -32,20 +36,46 @@ import appeng.items.AEBaseItem; import appeng.items.contents.QuartzKnifeObj; import appeng.util.Platform; + public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem { final AEFeature type; - public ToolQuartzCuttingKnife(AEFeature Type) { - super( ToolQuartzCuttingKnife.class, Type.name() ); + public ToolQuartzCuttingKnife( AEFeature Type ) + { + super( ToolQuartzCuttingKnife.class, Optional.of( Type.name() ) ); + setFeature( EnumSet.of( type = Type, AEFeature.QuartzKnife ) ); setMaxDamage( 50 ); setMaxStackSize( 1 ); } @Override - public boolean getIsRepairable(ItemStack a, ItemStack b) + public boolean onItemUse( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int s, float hitX, float hitY, float hitZ ) + { + if ( Platform.isServer() ) + Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE ); + return true; + } + + @Override + public ItemStack onItemRightClick( ItemStack it, World w, EntityPlayer p ) + { + if ( Platform.isServer() ) + Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE ); + p.swingItem(); + return it; + } + + @Override + public boolean doesContainerItemLeaveCraftingGrid( ItemStack par1ItemStack ) + { + return false; + } + + @Override + public boolean getIsRepairable( ItemStack a, ItemStack b ) { return Platform.canRepair( type, a, b ); } @@ -57,43 +87,20 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem } @Override - public boolean doesContainerItemLeaveCraftingGrid(ItemStack par1ItemStack) - { - return false; - } - - @Override - public boolean hasContainerItem(ItemStack stack) - { - return true; - } - - @Override - public ItemStack onItemRightClick(ItemStack it, World w, EntityPlayer p) - { - if ( Platform.isServer() ) - Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE ); - p.swingItem(); - return it; - } - - @Override - public boolean onItemUse(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int s, float hitX, float hitY, float hitZ) - { - if ( Platform.isServer() ) - Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE ); - return true; - } - - @Override - public ItemStack getContainerItem(ItemStack itemStack) + public ItemStack getContainerItem( ItemStack itemStack ) { itemStack.setItemDamage( itemStack.getItemDamage() + 1 ); return itemStack; } @Override - public IGuiItemObject getGuiObject(ItemStack is, World world, int x, int y, int z) + public boolean hasContainerItem( ItemStack stack ) + { + return true; + } + + @Override + public IGuiItemObject getGuiObject( ItemStack is, World world, int x, int y, int z ) { return new QuartzKnifeObj( is ); } diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzHoe.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzHoe.java index 018cccf6d..7d709b10b 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzHoe.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzHoe.java @@ -18,36 +18,38 @@ package appeng.items.tools.quartz; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; + import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; +import appeng.core.features.ItemFeatureHandler; import appeng.util.Platform; + public class ToolQuartzHoe extends ItemHoe implements IAEFeature { + private final AEFeature feature; + private final IFeatureHandler handler; - final AEFeature type; - final AEFeatureHandler feature; - - @Override - public AEFeatureHandler feature() + public ToolQuartzHoe( AEFeature feature ) { - return feature; - } - - @Override - public boolean getIsRepairable(ItemStack a, ItemStack b) - { - return Platform.canRepair( type, a, b ); - } - - public ToolQuartzHoe(AEFeature Type) { super( ToolMaterial.IRON ); - feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzHoe ), this, Type.name() ); + + this.feature = feature; + this.handler = new ItemFeatureHandler( EnumSet.of( feature, AEFeature.QuartzHoe ), this, this, Optional.of( feature.name() ) ); + } + + @Override + public IFeatureHandler handler() + { + return handler; } @Override @@ -55,4 +57,10 @@ public class ToolQuartzHoe extends ItemHoe implements IAEFeature { // override! } + + @Override + public boolean getIsRepairable( ItemStack a, ItemStack b ) + { + return Platform.canRepair( feature, a, b ); + } } \ No newline at end of file diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzPickaxe.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzPickaxe.java index 508474348..818db3246 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzPickaxe.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzPickaxe.java @@ -18,36 +18,38 @@ package appeng.items.tools.quartz; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; + import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; +import appeng.core.features.ItemFeatureHandler; import appeng.util.Platform; + public class ToolQuartzPickaxe extends ItemPickaxe implements IAEFeature { + private final AEFeature type; + private final IFeatureHandler feature; - final AEFeature type; - final AEFeatureHandler feature; - - @Override - public AEFeatureHandler feature() + public ToolQuartzPickaxe( AEFeature Type ) { - return feature; - } - - @Override - public boolean getIsRepairable(ItemStack a, ItemStack b) - { - return Platform.canRepair( type, a, b ); - } - - public ToolQuartzPickaxe(AEFeature Type) { super( ToolMaterial.IRON ); - feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzPickaxe ), this, Type.name() ); + + this.type = Type; + this.feature = new ItemFeatureHandler( EnumSet.of( Type, AEFeature.QuartzPickaxe ), this, this, Optional.of( Type.name() ) ); + } + + @Override + public IFeatureHandler handler() + { + return this.feature; } @Override @@ -55,4 +57,10 @@ public class ToolQuartzPickaxe extends ItemPickaxe implements IAEFeature { // override! } + + @Override + public boolean getIsRepairable( ItemStack a, ItemStack b ) + { + return Platform.canRepair( type, a, b ); + } } diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzSpade.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzSpade.java index 1d19a2b6c..c912d4e78 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzSpade.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzSpade.java @@ -18,36 +18,37 @@ package appeng.items.tools.quartz; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.item.ItemSpade; import net.minecraft.item.ItemStack; + import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; +import appeng.core.features.ItemFeatureHandler; import appeng.util.Platform; + public class ToolQuartzSpade extends ItemSpade implements IAEFeature { + private final AEFeature type; + private final IFeatureHandler handler; - final AEFeature type; - final AEFeatureHandler feature; - - @Override - public AEFeatureHandler feature() + public ToolQuartzSpade( AEFeature Type ) { - return feature; - } - - @Override - public boolean getIsRepairable(ItemStack a, ItemStack b) - { - return Platform.canRepair( type, a, b ); - } - - public ToolQuartzSpade(AEFeature Type) { super( ToolMaterial.IRON ); - feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSpade ), this, Type.name() ); + + this.handler = new ItemFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSpade ), this, this, Optional.of( Type.name() ) ); + } + + @Override + public IFeatureHandler handler() + { + return handler; } @Override @@ -55,4 +56,10 @@ public class ToolQuartzSpade extends ItemSpade implements IAEFeature { // override! } + + @Override + public boolean getIsRepairable( ItemStack a, ItemStack b ) + { + return Platform.canRepair( type, a, b ); + } } diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzSword.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzSword.java index 3d15b6ec0..a3983f506 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzSword.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzSword.java @@ -18,41 +18,47 @@ package appeng.items.tools.quartz; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; + import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; import appeng.core.features.IAEFeature; +import appeng.core.features.IFeatureHandler; +import appeng.core.features.ItemFeatureHandler; import appeng.util.Platform; + public class ToolQuartzSword extends ItemSword implements IAEFeature { + private final AEFeature type; + private final IFeatureHandler feature; - final AEFeature type; - final AEFeatureHandler feature; + public ToolQuartzSword( AEFeature Type ) + { + super( ToolMaterial.IRON ); + feature = new ItemFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSword ), this, this, Optional.of( Type.name() ) ); + } @Override - public AEFeatureHandler feature() + public IFeatureHandler handler() { return feature; } - @Override - public boolean getIsRepairable(ItemStack a, ItemStack b) - { - return Platform.canRepair( type, a, b ); - } - - public ToolQuartzSword(AEFeature Type) { - super( ToolMaterial.IRON ); - feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSword ), this, Type.name() ); - } - @Override public void postInit() { // override! } + + @Override + public boolean getIsRepairable( ItemStack a, ItemStack b ) + { + return Platform.canRepair( type, a, b ); + } } diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java index 425cb4297..e2d0fc096 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java @@ -18,27 +18,34 @@ package appeng.items.tools.quartz; + import java.util.EnumSet; +import com.google.common.base.Optional; + import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.tools.IToolWrench; + import appeng.api.implementations.items.IAEWrench; import appeng.api.util.DimensionalCoord; import appeng.core.features.AEFeature; import appeng.items.AEBaseItem; import appeng.transformer.annotations.integration.Interface; import appeng.util.Platform; -import buildcraft.api.tools.IToolWrench; -@Interface(iface = "buildcraft.api.tools.IToolWrench", iname = "BC") + +@Interface( iface = "buildcraft.api.tools.IToolWrench", iname = "BC" ) public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolWrench { - public ToolQuartzWrench(AEFeature type) { - super( ToolQuartzWrench.class, type.name() ); + public ToolQuartzWrench( AEFeature type ) + { + super( ToolQuartzWrench.class, Optional.of( type.name() ) ); this.setFeature( EnumSet.of( type, AEFeature.QuartzWrench ) ); this.setMaxStackSize( 1 ); @@ -46,7 +53,7 @@ public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolWren } @Override - public boolean onItemUseFirst(ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + public boolean onItemUseFirst( ItemStack is, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) { Block b = world.getBlock( x, y, z ); if ( b != null && !player.isSneaking() && Platform.hasPermissions( new DimensionalCoord( world, x, y, z ), player ) ) @@ -67,25 +74,25 @@ public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolWren @Override // public boolean shouldPassSneakingClickToBlock(World w, int x, int y, int z) - public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) + public boolean doesSneakBypassUse( World world, int x, int y, int z, EntityPlayer player ) { return true; } @Override - public boolean canWrench(ItemStack is, EntityPlayer player, int x, int y, int z) + public boolean canWrench( ItemStack is, EntityPlayer player, int x, int y, int z ) { return true; } @Override - public boolean canWrench(EntityPlayer player, int x, int y, int z) + public boolean canWrench( EntityPlayer player, int x, int y, int z ) { return true; } @Override - public void wrenchUsed(EntityPlayer player, int x, int y, int z) + public void wrenchUsed( EntityPlayer player, int x, int y, int z ) { player.swingItem(); } diff --git a/src/main/java/appeng/util/ClassInstantiation.java b/src/main/java/appeng/util/ClassInstantiation.java new file mode 100644 index 000000000..05ba655b4 --- /dev/null +++ b/src/main/java/appeng/util/ClassInstantiation.java @@ -0,0 +1,116 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.util; + + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import com.google.common.base.Optional; + +import appeng.core.AELog; + + +public class ClassInstantiation +{ + private final Class template; + private final Object[] args; + + public ClassInstantiation( Class template, Object... args ) + { + this.template = template; + this.args = args; + } + + public Optional get() + { + @SuppressWarnings( "unchecked" ) + Constructor[] constructors = ( Constructor[] ) this.template.getConstructors(); + + for ( Constructor constructor : constructors ) + { + Class[] paramTypes = constructor.getParameterTypes(); + if ( paramTypes.length == args.length ) + { + boolean valid = true; + + for ( int idx = 0; idx < paramTypes.length; idx++ ) + { + Class cz = args[idx].getClass(); + if ( !isClassMatch( paramTypes[idx], cz, args[idx] ) ) + valid = false; + } + + if ( valid ) + { + try + { + return Optional.of( constructor.newInstance( args ) ); + } + catch ( InstantiationException e ) + { + e.printStackTrace(); + } + catch ( IllegalAccessException e ) + { + e.printStackTrace(); + } + catch ( InvocationTargetException e ) + { + e.printStackTrace(); + } + break; + } + } + } + + return Optional.absent(); + } + + private boolean isClassMatch( Class expected, Class got, Object value ) + { + if ( value == null && !expected.isPrimitive() ) + return true; + + expected = condense( expected, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class ); + got = condense( got, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class ); + + return expected == got || expected.isAssignableFrom( got ); + } + + private Class condense( Class expected, Class... wrappers ) + { + if ( expected.isPrimitive() ) + { + for ( Class clz : wrappers ) + { + try + { + if ( expected == clz.getField( "TYPE" ).get( null ) ) + return clz; + } + catch ( Throwable t ) + { + AELog.error( t ); + } + } + } + return expected; + } +}