diff --git a/.gitmodules b/.gitmodules index c10049b5d..27ce6085c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ -[submodule "api"] - path = api - url = https://github.com/AlgorithmX2/Applied-Energistics-2-API.git + +[submodule "src/main/java/appeng/api"] + path = src/main/java/appeng/api + url = https://github.com/AppliedEnergistics/Applied-Energistics-2-API.git +[submodule "src/main/resources/assets/appliedenergistics2/lang"] + path = src/main/resources/assets/appliedenergistics2/lang + url = https://github.com/AppliedEnergistics/AppliedEnergistics-2-Localization.git diff --git a/src/main/java/appeng/api b/src/main/java/appeng/api new file mode 160000 index 000000000..0656cc696 --- /dev/null +++ b/src/main/java/appeng/api @@ -0,0 +1 @@ +Subproject commit 0656cc696ff1cd841dce89e0b5382ff56279dfae diff --git a/block/AEBaseBlock.java b/src/main/java/appeng/block/AEBaseBlock.java similarity index 96% rename from block/AEBaseBlock.java rename to src/main/java/appeng/block/AEBaseBlock.java index 7c00b6ab6..0b4360cc5 100644 --- a/block/AEBaseBlock.java +++ b/src/main/java/appeng/block/AEBaseBlock.java @@ -1,806 +1,806 @@ -package appeng.block; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; - -import appeng.client.texture.FlippableIcon; -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; -import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.client.resources.IResource; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.IIcon; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.Vec3; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.implementations.items.IMemoryCard; -import appeng.api.implementations.items.MemoryCardMessages; -import appeng.api.implementations.tiles.IColorableTile; -import appeng.api.util.AEColor; -import appeng.api.util.IOrientable; -import appeng.api.util.IOrientableBlock; -import appeng.block.networking.BlockCableBus; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.BlockRenderInfo; -import appeng.client.render.WorldRender; -import appeng.client.texture.MissingIcon; -import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; -import appeng.core.features.IAEFeature; -import appeng.core.features.ItemStackSrc; -import appeng.helpers.AEGlassMaterial; -import appeng.helpers.ICustomCollision; -import appeng.tile.AEBaseTile; -import appeng.tile.networking.TileCableBus; -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 String FeatureFullname; - private String FeatureSubname; - private AEFeatureHandler feature; - - private Class tileEntityType = null; - 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) - BlockRenderInfo renderInfo; - - @Override - public String toString() - { - 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", new Object[] { "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 ); - setLightOpacity( 255 ); - setLightLevel( 0 ); - setHardness( 2.2F ); - setTileProvider( false ); - setHarvestLevel( "pickaxe", 0 ); - } - - // update Block value. - private void setTileProvider(boolean b) - { - ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" ); - } - - protected AEBaseBlock(Class c, Material mat, String subname) { - super( mat ); - - if ( mat == AEGlassMaterial.instance ) - setStepSound( Block.soundTypeGlass ); - else if ( mat == Material.glass ) - setStepSound( Block.soundTypeGlass ); - else if ( mat == Material.rock ) - setStepSound( Block.soundTypeStone ); - else - setStepSound( Block.soundTypeMetal ); - - FeatureFullname = AEFeatureHandler.getName( c, subname ); - FeatureSubname = subname; - } - - @Override - final public AEFeatureHandler feature() - { - return feature; - } - - public boolean isOpaque() - { - return isOpaque; - } - - @Override - final public boolean isOpaqueCube() - { - return isOpaque; - } - - @Override - public boolean renderAsNormalBlock() - { - return isFullSize && isOpaque; - } - - @Override - final public boolean isNormalCube(IBlockAccess world, int x, int y, int z) - { - 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 ); - } - } - - @Override - final public TileEntity createNewTileEntity(World var1, int var2) - { - 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) - { - - } - - @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 ); - } - - 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; - } - - @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) - { - ICustomCollision collisionHandler = null; - - if ( this instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) this; - else - { - AEBaseTile te = getTileEntity( w, x, y, z ); - if ( te instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) te; - } - - if ( collisionHandler != null ) - { - Iterable bbs = collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, true ); - MovingObjectPosition br = null; - - 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 - @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; - else - { - AEBaseTile te = getTileEntity( w, x, y, z ); - if ( te instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) te; - } - - if ( collisionHandler != null ) - { - if ( Platform.isClient() ) - { - EntityPlayer player = Minecraft.getMinecraft().thePlayer; - LookDirection ld = Platform.getPlayerRay( player, Platform.getEyeOffset( player ) ); - - Iterable bbs = collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, Minecraft.getMinecraft().thePlayer, true ); - AxisAlignedBB br = null; - - 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, ld.a, ld.b ); - - setBlockBounds( 0, 0, 0, 1, 1, 1 ); - - 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 thisDist = xLen * xLen + yLen * yLen + zLen * zLen; - if ( br == null || lastDist > thisDist ) - { - lastDist = thisDist; - br = bb; - } - } - } - - if ( br != null ) - { - br.setBounds( br.minX + x, br.minY + y, br.minZ + z, br.maxX + x, br.maxY + y, br.maxZ + z ); - return br; - } - } - - for (AxisAlignedBB bx : collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, false )) - { - if ( b == null ) - b = bx; - else - { - double minX = Math.min( b.minX, bx.minX ); - double minY = Math.min( b.minY, bx.minY ); - double minZ = Math.min( b.minZ, bx.minZ ); - double maxX = Math.max( b.maxX, bx.maxX ); - double maxY = Math.max( b.maxY, bx.maxY ); - double maxZ = Math.max( b.maxZ, bx.maxZ ); - b.setBounds( minX, minY, minZ, maxX, maxY, maxZ ); - } - } - - b.setBounds( b.minX + x, b.minY + y, b.minZ + z, b.maxX + x, b.maxY + y, b.maxZ + z ); - } - else - b = super.getSelectedBoundingBoxFromPool( w, x, y, z ); - - return b; - } - - @Override - // 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; - else - { - AEBaseTile te = getTileEntity( w, x, y, z ); - if ( te instanceof ICustomCollision ) - collisionHandler = (ICustomCollision) te; - } - - if ( collisionHandler != null && bb != 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 ); - } - - @Override - public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) - { - super.onBlockDestroyedByPlayer( par1World, par2, par3, par4, par5 ); - } - - public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) - { - return false; - } - - @Override - 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 ) - { - ItemStack is = player.inventory.getCurrentItem(); - if ( is != null ) - { - if ( Platform.isWrench( player, is, x, y, z ) && player.isSneaking() ) - { - Block id = w.getBlock( x, y, z ); - if ( id != null ) - { - AEBaseTile tile = getTileEntity( w, x, y, z ); - ItemStack[] drops = Platform.getBlockDrops( w, x, y, z ); - - if ( tile == null ) - return false; - - if ( tile instanceof TileCableBus || tile instanceof TileSkyChest ) - return false; - - ItemStack op = new ItemStack( this ); - for (ItemStack ol : drops) - { - if ( Platform.isSameItemType( ol, op ) ) - { - NBTTagCompound tag = tile.downloadSettings( SettingsFrom.DISMANTLE_ITEM ); - if ( tag != null ) - ol.setTagCompound( tag ); - } - } - - if ( id.removedByPlayer( w, player, x, y, z, false ) ) - { - List l = new ArrayList(); - for (ItemStack iss : drops) - l.add( iss ); - Platform.spawnDrops( w, x, y, z, l ); - w.setBlockToAir( x, y, z ); - } - } - return false; - } - - if ( is.getItem() instanceof IMemoryCard && !(this instanceof BlockCableBus) ) - { - IMemoryCard memc = (IMemoryCard) is.getItem(); - if ( player.isSneaking() ) - { - AEBaseTile t = getTileEntity( w, x, y, z ); - if ( t != null ) - { - String name = getUnlocalizedName(); - NBTTagCompound data = t.downloadSettings( SettingsFrom.MEMORY_CARD ); - if ( data != null ) - { - memc.setMemoryCardContents( is, name, data ); - memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED ); - return true; - } - } - } - else - { - String name = memc.getSettingsName( is ); - NBTTagCompound data = memc.getData( is ); - if ( getUnlocalizedName().equals( name ) ) - { - AEBaseTile t = getTileEntity( w, x, y, z ); - t.uploadSettings( SettingsFrom.MEMORY_CARD, data ); - memc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED ); - } - else - memc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE ); - return false; - } - } - } - } - - 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) - { - 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; - } - - @Override - public void postInit() - { - // override! - } - - public boolean hasSubtypes() - { - return hasSubtypes; - } - - public boolean hasComparatorInputOverride() - { - return isInventory; - } - - 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 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; - AEColor c = ct.getColor(); - AEColor newColor = AEColor.values()[colour]; - - if ( c != newColor ) - { - ct.recolourBlock( side, newColor, null ); - return true; - } - return false; - } - - 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) - { - if ( is.hasDisplayName() ) - { - TileEntity te = getTileEntity( w, x, y, z ); - if ( te instanceof AEBaseTile ) - ((AEBaseTile) w.getTileEntity( x, y, z )).setName( is.getDisplayName() ); - } - } - -} +package appeng.block; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import appeng.client.texture.FlippableIcon; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.client.resources.IResource; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Vec3; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.implementations.items.IMemoryCard; +import appeng.api.implementations.items.MemoryCardMessages; +import appeng.api.implementations.tiles.IColorableTile; +import appeng.api.util.AEColor; +import appeng.api.util.IOrientable; +import appeng.api.util.IOrientableBlock; +import appeng.block.networking.BlockCableBus; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.BlockRenderInfo; +import appeng.client.render.WorldRender; +import appeng.client.texture.MissingIcon; +import appeng.core.features.AEFeature; +import appeng.core.features.AEFeatureHandler; +import appeng.core.features.IAEFeature; +import appeng.core.features.ItemStackSrc; +import appeng.helpers.AEGlassMaterial; +import appeng.helpers.ICustomCollision; +import appeng.tile.AEBaseTile; +import appeng.tile.networking.TileCableBus; +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 String FeatureFullname; + private String FeatureSubname; + private AEFeatureHandler feature; + + private Class tileEntityType = null; + 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) + BlockRenderInfo renderInfo; + + @Override + public String toString() + { + 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", new Object[] { "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 ); + setLightOpacity( 255 ); + setLightLevel( 0 ); + setHardness( 2.2F ); + setTileProvider( false ); + setHarvestLevel( "pickaxe", 0 ); + } + + // update Block value. + private void setTileProvider(boolean b) + { + ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" ); + } + + protected AEBaseBlock(Class c, Material mat, String subname) { + super( mat ); + + if ( mat == AEGlassMaterial.instance ) + setStepSound( Block.soundTypeGlass ); + else if ( mat == Material.glass ) + setStepSound( Block.soundTypeGlass ); + else if ( mat == Material.rock ) + setStepSound( Block.soundTypeStone ); + else + setStepSound( Block.soundTypeMetal ); + + FeatureFullname = AEFeatureHandler.getName( c, subname ); + FeatureSubname = subname; + } + + @Override + final public AEFeatureHandler feature() + { + return feature; + } + + public boolean isOpaque() + { + return isOpaque; + } + + @Override + final public boolean isOpaqueCube() + { + return isOpaque; + } + + @Override + public boolean renderAsNormalBlock() + { + return isFullSize && isOpaque; + } + + @Override + final public boolean isNormalCube(IBlockAccess world, int x, int y, int z) + { + 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 ); + } + } + + @Override + final public TileEntity createNewTileEntity(World var1, int var2) + { + 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) + { + + } + + @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 ); + } + + 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; + } + + @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) + { + ICustomCollision collisionHandler = null; + + if ( this instanceof ICustomCollision ) + collisionHandler = (ICustomCollision) this; + else + { + AEBaseTile te = getTileEntity( w, x, y, z ); + if ( te instanceof ICustomCollision ) + collisionHandler = (ICustomCollision) te; + } + + if ( collisionHandler != null ) + { + Iterable bbs = collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, true ); + MovingObjectPosition br = null; + + 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 + @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; + else + { + AEBaseTile te = getTileEntity( w, x, y, z ); + if ( te instanceof ICustomCollision ) + collisionHandler = (ICustomCollision) te; + } + + if ( collisionHandler != null ) + { + if ( Platform.isClient() ) + { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + LookDirection ld = Platform.getPlayerRay( player, Platform.getEyeOffset( player ) ); + + Iterable bbs = collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, Minecraft.getMinecraft().thePlayer, true ); + AxisAlignedBB br = null; + + 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, ld.a, ld.b ); + + setBlockBounds( 0, 0, 0, 1, 1, 1 ); + + 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 thisDist = xLen * xLen + yLen * yLen + zLen * zLen; + if ( br == null || lastDist > thisDist ) + { + lastDist = thisDist; + br = bb; + } + } + } + + if ( br != null ) + { + br.setBounds( br.minX + x, br.minY + y, br.minZ + z, br.maxX + x, br.maxY + y, br.maxZ + z ); + return br; + } + } + + for (AxisAlignedBB bx : collisionHandler.getSelectedBoundingBoxesFromPool( w, x, y, z, null, false )) + { + if ( b == null ) + b = bx; + else + { + double minX = Math.min( b.minX, bx.minX ); + double minY = Math.min( b.minY, bx.minY ); + double minZ = Math.min( b.minZ, bx.minZ ); + double maxX = Math.max( b.maxX, bx.maxX ); + double maxY = Math.max( b.maxY, bx.maxY ); + double maxZ = Math.max( b.maxZ, bx.maxZ ); + b.setBounds( minX, minY, minZ, maxX, maxY, maxZ ); + } + } + + b.setBounds( b.minX + x, b.minY + y, b.minZ + z, b.maxX + x, b.maxY + y, b.maxZ + z ); + } + else + b = super.getSelectedBoundingBoxFromPool( w, x, y, z ); + + return b; + } + + @Override + // 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; + else + { + AEBaseTile te = getTileEntity( w, x, y, z ); + if ( te instanceof ICustomCollision ) + collisionHandler = (ICustomCollision) te; + } + + if ( collisionHandler != null && bb != 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 ); + } + + @Override + public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) + { + super.onBlockDestroyedByPlayer( par1World, par2, par3, par4, par5 ); + } + + public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) + { + return false; + } + + @Override + 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 ) + { + ItemStack is = player.inventory.getCurrentItem(); + if ( is != null ) + { + if ( Platform.isWrench( player, is, x, y, z ) && player.isSneaking() ) + { + Block id = w.getBlock( x, y, z ); + if ( id != null ) + { + AEBaseTile tile = getTileEntity( w, x, y, z ); + ItemStack[] drops = Platform.getBlockDrops( w, x, y, z ); + + if ( tile == null ) + return false; + + if ( tile instanceof TileCableBus || tile instanceof TileSkyChest ) + return false; + + ItemStack op = new ItemStack( this ); + for (ItemStack ol : drops) + { + if ( Platform.isSameItemType( ol, op ) ) + { + NBTTagCompound tag = tile.downloadSettings( SettingsFrom.DISMANTLE_ITEM ); + if ( tag != null ) + ol.setTagCompound( tag ); + } + } + + if ( id.removedByPlayer( w, player, x, y, z, false ) ) + { + List l = new ArrayList(); + for (ItemStack iss : drops) + l.add( iss ); + Platform.spawnDrops( w, x, y, z, l ); + w.setBlockToAir( x, y, z ); + } + } + return false; + } + + if ( is.getItem() instanceof IMemoryCard && !(this instanceof BlockCableBus) ) + { + IMemoryCard memc = (IMemoryCard) is.getItem(); + if ( player.isSneaking() ) + { + AEBaseTile t = getTileEntity( w, x, y, z ); + if ( t != null ) + { + String name = getUnlocalizedName(); + NBTTagCompound data = t.downloadSettings( SettingsFrom.MEMORY_CARD ); + if ( data != null ) + { + memc.setMemoryCardContents( is, name, data ); + memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED ); + return true; + } + } + } + else + { + String name = memc.getSettingsName( is ); + NBTTagCompound data = memc.getData( is ); + if ( getUnlocalizedName().equals( name ) ) + { + AEBaseTile t = getTileEntity( w, x, y, z ); + t.uploadSettings( SettingsFrom.MEMORY_CARD, data ); + memc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED ); + } + else + memc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE ); + return false; + } + } + } + } + + 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) + { + 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; + } + + @Override + public void postInit() + { + // override! + } + + public boolean hasSubtypes() + { + return hasSubtypes; + } + + public boolean hasComparatorInputOverride() + { + return isInventory; + } + + 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 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; + AEColor c = ct.getColor(); + AEColor newColor = AEColor.values()[colour]; + + if ( c != newColor ) + { + ct.recolourBlock( side, newColor, null ); + return true; + } + return false; + } + + 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) + { + if ( is.hasDisplayName() ) + { + TileEntity te = getTileEntity( w, x, y, z ); + if ( te instanceof AEBaseTile ) + ((AEBaseTile) w.getTileEntity( x, y, z )).setName( is.getDisplayName() ); + } + } + +} diff --git a/block/AEBaseItemBlock.java b/src/main/java/appeng/block/AEBaseItemBlock.java similarity index 96% rename from block/AEBaseItemBlock.java rename to src/main/java/appeng/block/AEBaseItemBlock.java index ba965f191..338330389 100644 --- a/block/AEBaseItemBlock.java +++ b/src/main/java/appeng/block/AEBaseItemBlock.java @@ -1,173 +1,173 @@ -package appeng.block; - -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemBlock; -import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraftforge.client.MinecraftForgeClient; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.util.IOrientable; -import appeng.api.util.IOrientableBlock; -import appeng.block.misc.BlockLightDetector; -import appeng.block.misc.BlockSkyCompass; -import appeng.block.networking.BlockWireless; -import appeng.client.render.ItemRenderer; -import appeng.me.helpers.IGridProxyable; -import appeng.tile.AEBaseTile; -import appeng.util.Platform; - -public class AEBaseItemBlock extends ItemBlock -{ - - final AEBaseBlock blockType; - - public AEBaseItemBlock(Block id) { - super( id ); - blockType = (AEBaseBlock) id; - hasSubtypes = blockType.hasSubtypes; - - if ( Platform.isClient() ) - MinecraftForgeClient.registerItemRenderer( this, ItemRenderer.instance ); - } - - @Override - public int getMetadata(int dmg) - { - if ( hasSubtypes ) - return dmg; - return 0; - } - - @Override - public String getUnlocalizedName(ItemStack is) - { - return blockType.getUnlocalizedName( is ); - } - - @Override - public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips) - { - blockType.addInformation( is, player, lines, advancedItemTooltips ); - } - - @Override - public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) - { - ForgeDirection up = ForgeDirection.UNKNOWN; - ForgeDirection forward = ForgeDirection.UNKNOWN; - - IOrientable ori = null; - - if ( blockType.hasBlockTileEntity() ) - { - if ( blockType instanceof BlockLightDetector ) - { - up = ForgeDirection.getOrientation( side ); - if ( up == ForgeDirection.UP || up == ForgeDirection.DOWN ) - forward = ForgeDirection.SOUTH; - else - forward = ForgeDirection.UP; - } - else if ( blockType instanceof BlockWireless || blockType instanceof BlockSkyCompass ) - { - forward = ForgeDirection.getOrientation( side ); - if ( forward == ForgeDirection.UP || forward == ForgeDirection.DOWN ) - up = ForgeDirection.SOUTH; - else - up = ForgeDirection.UP; - } - else - { - up = ForgeDirection.UP; - - byte rotation = (byte) (MathHelper.floor_double( (double) ((player.rotationYaw * 4F) / 360F) + 2.5D ) & 3); - - switch (rotation) - { - default: - case 0: - forward = ForgeDirection.SOUTH; - break; - case 1: - forward = ForgeDirection.WEST; - break; - case 2: - forward = ForgeDirection.NORTH; - break; - case 3: - forward = ForgeDirection.EAST; - break; - } - - if ( player.rotationPitch > 65 ) - { - up = forward.getOpposite(); - forward = ForgeDirection.UP; - } - else if ( player.rotationPitch < -65 ) - { - up = forward.getOpposite(); - forward = ForgeDirection.DOWN; - } - } - } - - if ( blockType instanceof IOrientableBlock ) - { - ori = ((IOrientableBlock) blockType).getOrientable( w, x, y, z ); - up = ForgeDirection.getOrientation( side ); - forward = ForgeDirection.SOUTH; - if ( up.offsetY == 0 ) - forward = ForgeDirection.UP; - - ori.setOrientation( forward, up ); - } - - if ( !blockType.isValidOrientation( w, x, y, z, forward, up ) ) - return false; - - if ( super.placeBlockAt( stack, player, w, x, y, z, side, hitX, hitY, hitZ, metadata ) ) - { - if ( blockType.hasBlockTileEntity() && !(blockType instanceof BlockLightDetector) ) - { - AEBaseTile tile = blockType.getTileEntity( w, x, y, z ); - ori = tile; - - if ( tile == null ) - return true; - - if ( ori.canBeRotated() && !blockType.hasCustomRotation() ) - { - if ( ori.getForward() == null || ori.getUp() == null || // null - tile.getForward() == ForgeDirection.UNKNOWN || ori.getUp() == ForgeDirection.UNKNOWN ) - ori.setOrientation( forward, up ); - } - - if ( tile instanceof IGridProxyable ) - { - ((IGridProxyable) tile).getProxy().setOwner( player ); - } - - tile.onPlacement( stack, player, side ); - } - else if ( blockType instanceof IOrientableBlock ) - { - ori.setOrientation( forward, up ); - } - - return true; - } - return false; - } - - @Override - public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2) - { - return false; - } - -} +package appeng.block; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.util.IOrientable; +import appeng.api.util.IOrientableBlock; +import appeng.block.misc.BlockLightDetector; +import appeng.block.misc.BlockSkyCompass; +import appeng.block.networking.BlockWireless; +import appeng.client.render.ItemRenderer; +import appeng.me.helpers.IGridProxyable; +import appeng.tile.AEBaseTile; +import appeng.util.Platform; + +public class AEBaseItemBlock extends ItemBlock +{ + + final AEBaseBlock blockType; + + public AEBaseItemBlock(Block id) { + super( id ); + blockType = (AEBaseBlock) id; + hasSubtypes = blockType.hasSubtypes; + + if ( Platform.isClient() ) + MinecraftForgeClient.registerItemRenderer( this, ItemRenderer.instance ); + } + + @Override + public int getMetadata(int dmg) + { + if ( hasSubtypes ) + return dmg; + return 0; + } + + @Override + public String getUnlocalizedName(ItemStack is) + { + return blockType.getUnlocalizedName( is ); + } + + @Override + public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips) + { + blockType.addInformation( is, player, lines, advancedItemTooltips ); + } + + @Override + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) + { + ForgeDirection up = ForgeDirection.UNKNOWN; + ForgeDirection forward = ForgeDirection.UNKNOWN; + + IOrientable ori = null; + + if ( blockType.hasBlockTileEntity() ) + { + if ( blockType instanceof BlockLightDetector ) + { + up = ForgeDirection.getOrientation( side ); + if ( up == ForgeDirection.UP || up == ForgeDirection.DOWN ) + forward = ForgeDirection.SOUTH; + else + forward = ForgeDirection.UP; + } + else if ( blockType instanceof BlockWireless || blockType instanceof BlockSkyCompass ) + { + forward = ForgeDirection.getOrientation( side ); + if ( forward == ForgeDirection.UP || forward == ForgeDirection.DOWN ) + up = ForgeDirection.SOUTH; + else + up = ForgeDirection.UP; + } + else + { + up = ForgeDirection.UP; + + byte rotation = (byte) (MathHelper.floor_double( (double) ((player.rotationYaw * 4F) / 360F) + 2.5D ) & 3); + + switch (rotation) + { + default: + case 0: + forward = ForgeDirection.SOUTH; + break; + case 1: + forward = ForgeDirection.WEST; + break; + case 2: + forward = ForgeDirection.NORTH; + break; + case 3: + forward = ForgeDirection.EAST; + break; + } + + if ( player.rotationPitch > 65 ) + { + up = forward.getOpposite(); + forward = ForgeDirection.UP; + } + else if ( player.rotationPitch < -65 ) + { + up = forward.getOpposite(); + forward = ForgeDirection.DOWN; + } + } + } + + if ( blockType instanceof IOrientableBlock ) + { + ori = ((IOrientableBlock) blockType).getOrientable( w, x, y, z ); + up = ForgeDirection.getOrientation( side ); + forward = ForgeDirection.SOUTH; + if ( up.offsetY == 0 ) + forward = ForgeDirection.UP; + + ori.setOrientation( forward, up ); + } + + if ( !blockType.isValidOrientation( w, x, y, z, forward, up ) ) + return false; + + if ( super.placeBlockAt( stack, player, w, x, y, z, side, hitX, hitY, hitZ, metadata ) ) + { + if ( blockType.hasBlockTileEntity() && !(blockType instanceof BlockLightDetector) ) + { + AEBaseTile tile = blockType.getTileEntity( w, x, y, z ); + ori = tile; + + if ( tile == null ) + return true; + + if ( ori.canBeRotated() && !blockType.hasCustomRotation() ) + { + if ( ori.getForward() == null || ori.getUp() == null || // null + tile.getForward() == ForgeDirection.UNKNOWN || ori.getUp() == ForgeDirection.UNKNOWN ) + ori.setOrientation( forward, up ); + } + + if ( tile instanceof IGridProxyable ) + { + ((IGridProxyable) tile).getProxy().setOwner( player ); + } + + tile.onPlacement( stack, player, side ); + } + else if ( blockType instanceof IOrientableBlock ) + { + ori.setOrientation( forward, up ); + } + + return true; + } + return false; + } + + @Override + public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2) + { + return false; + } + +} diff --git a/block/AEBaseItemBlockChargeable.java b/src/main/java/appeng/block/AEBaseItemBlockChargeable.java similarity index 96% rename from block/AEBaseItemBlockChargeable.java rename to src/main/java/appeng/block/AEBaseItemBlockChargeable.java index 42111f74f..770e44c6f 100644 --- a/block/AEBaseItemBlockChargeable.java +++ b/src/main/java/appeng/block/AEBaseItemBlockChargeable.java @@ -1,118 +1,118 @@ -package appeng.block; - -import java.text.MessageFormat; -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import appeng.api.AEApi; -import appeng.api.config.AccessRestriction; -import appeng.api.config.PowerUnits; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.core.localization.GuiText; -import appeng.util.Platform; - -public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEItemPowerStorage -{ - - public AEBaseItemBlockChargeable(Block id) { - super( id ); - } - - @Override - public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips) - { - NBTTagCompound tag = is.getTagCompound(); - double internalCurrentPower = 0; - double internalMaxPower = getMax( is ); - - if ( tag != null ) - { - internalCurrentPower = tag.getDouble( "internalCurrentPower" ); - } - - double percent = internalCurrentPower / internalMaxPower; - - lines.add( GuiText.StoredEnergy.getLocal() + ":" + MessageFormat.format( " {0,number,#} ", internalCurrentPower ) - + Platform.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) ); - - } - - private double getMax(ItemStack is) - { - Block blk = Block.getBlockFromItem( this ); - if ( blk == AEApi.instance().blocks().blockEnergyCell.block() ) - return 200000; - else - return 8 * 200000; - } - - private double getInternal(ItemStack is) - { - NBTTagCompound nbt = Platform.openNbtData( is ); - return nbt.getDouble( "internalCurrentPower" ); - } - - private void setInternal(ItemStack is, double amt) - { - NBTTagCompound nbt = Platform.openNbtData( is ); - nbt.setDouble( "internalCurrentPower", amt ); - } - - @Override - public double injectAEPower(ItemStack is, double amt) - { - double internalCurrentPower = getInternal( is ); - double internalMaxPower = getMax( is ); - internalCurrentPower += amt; - if ( internalCurrentPower > internalMaxPower ) - { - amt = internalCurrentPower - internalMaxPower; - internalCurrentPower = internalMaxPower; - setInternal( is, internalCurrentPower ); - return amt; - } - - setInternal( is, internalCurrentPower ); - return 0; - } - - @Override - public double extractAEPower(ItemStack is, double amt) - { - double internalCurrentPower = getInternal( is ); - if ( internalCurrentPower > amt ) - { - internalCurrentPower -= amt; - setInternal( is, internalCurrentPower ); - return amt; - } - - amt = internalCurrentPower; - setInternal( is, 0 ); - return amt; - } - - @Override - public double getAEMaxPower(ItemStack is) - { - double internalMaxPower = getMax( is ); - return internalMaxPower; - } - - @Override - public double getAECurrentPower(ItemStack is) - { - double internalCurrentPower = getInternal( is ); - return internalCurrentPower; - } - - @Override - public AccessRestriction getPowerFlow(ItemStack is) - { - return AccessRestriction.WRITE; - } - -} +package appeng.block; + +import java.text.MessageFormat; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import appeng.api.AEApi; +import appeng.api.config.AccessRestriction; +import appeng.api.config.PowerUnits; +import appeng.api.implementations.items.IAEItemPowerStorage; +import appeng.core.localization.GuiText; +import appeng.util.Platform; + +public class AEBaseItemBlockChargeable extends AEBaseItemBlock implements IAEItemPowerStorage +{ + + public AEBaseItemBlockChargeable(Block id) { + super( id ); + } + + @Override + public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips) + { + NBTTagCompound tag = is.getTagCompound(); + double internalCurrentPower = 0; + double internalMaxPower = getMax( is ); + + if ( tag != null ) + { + internalCurrentPower = tag.getDouble( "internalCurrentPower" ); + } + + double percent = internalCurrentPower / internalMaxPower; + + lines.add( GuiText.StoredEnergy.getLocal() + ":" + MessageFormat.format( " {0,number,#} ", internalCurrentPower ) + + Platform.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) ); + + } + + private double getMax(ItemStack is) + { + Block blk = Block.getBlockFromItem( this ); + if ( blk == AEApi.instance().blocks().blockEnergyCell.block() ) + return 200000; + else + return 8 * 200000; + } + + private double getInternal(ItemStack is) + { + NBTTagCompound nbt = Platform.openNbtData( is ); + return nbt.getDouble( "internalCurrentPower" ); + } + + private void setInternal(ItemStack is, double amt) + { + NBTTagCompound nbt = Platform.openNbtData( is ); + nbt.setDouble( "internalCurrentPower", amt ); + } + + @Override + public double injectAEPower(ItemStack is, double amt) + { + double internalCurrentPower = getInternal( is ); + double internalMaxPower = getMax( is ); + internalCurrentPower += amt; + if ( internalCurrentPower > internalMaxPower ) + { + amt = internalCurrentPower - internalMaxPower; + internalCurrentPower = internalMaxPower; + setInternal( is, internalCurrentPower ); + return amt; + } + + setInternal( is, internalCurrentPower ); + return 0; + } + + @Override + public double extractAEPower(ItemStack is, double amt) + { + double internalCurrentPower = getInternal( is ); + if ( internalCurrentPower > amt ) + { + internalCurrentPower -= amt; + setInternal( is, internalCurrentPower ); + return amt; + } + + amt = internalCurrentPower; + setInternal( is, 0 ); + return amt; + } + + @Override + public double getAEMaxPower(ItemStack is) + { + double internalMaxPower = getMax( is ); + return internalMaxPower; + } + + @Override + public double getAECurrentPower(ItemStack is) + { + double internalCurrentPower = getInternal( is ); + return internalCurrentPower; + } + + @Override + public AccessRestriction getPowerFlow(ItemStack is) + { + return AccessRestriction.WRITE; + } + +} diff --git a/block/AEDecorativeBlock.java b/src/main/java/appeng/block/AEDecorativeBlock.java similarity index 100% rename from block/AEDecorativeBlock.java rename to src/main/java/appeng/block/AEDecorativeBlock.java diff --git a/block/crafting/BlockCraftingMonitor.java b/src/main/java/appeng/block/crafting/BlockCraftingMonitor.java similarity index 100% rename from block/crafting/BlockCraftingMonitor.java rename to src/main/java/appeng/block/crafting/BlockCraftingMonitor.java diff --git a/block/crafting/BlockCraftingStorage.java b/src/main/java/appeng/block/crafting/BlockCraftingStorage.java similarity index 100% rename from block/crafting/BlockCraftingStorage.java rename to src/main/java/appeng/block/crafting/BlockCraftingStorage.java diff --git a/block/crafting/BlockCraftingUnit.java b/src/main/java/appeng/block/crafting/BlockCraftingUnit.java similarity index 100% rename from block/crafting/BlockCraftingUnit.java rename to src/main/java/appeng/block/crafting/BlockCraftingUnit.java diff --git a/block/crafting/BlockMolecularAssembler.java b/src/main/java/appeng/block/crafting/BlockMolecularAssembler.java similarity index 100% rename from block/crafting/BlockMolecularAssembler.java rename to src/main/java/appeng/block/crafting/BlockMolecularAssembler.java diff --git a/block/crafting/ItemCraftingStorage.java b/src/main/java/appeng/block/crafting/ItemCraftingStorage.java similarity index 100% rename from block/crafting/ItemCraftingStorage.java rename to src/main/java/appeng/block/crafting/ItemCraftingStorage.java diff --git a/block/grindstone/BlockCrank.java b/src/main/java/appeng/block/grindstone/BlockCrank.java similarity index 100% rename from block/grindstone/BlockCrank.java rename to src/main/java/appeng/block/grindstone/BlockCrank.java diff --git a/block/grindstone/BlockGrinder.java b/src/main/java/appeng/block/grindstone/BlockGrinder.java similarity index 100% rename from block/grindstone/BlockGrinder.java rename to src/main/java/appeng/block/grindstone/BlockGrinder.java diff --git a/block/misc/BlockCellWorkbench.java b/src/main/java/appeng/block/misc/BlockCellWorkbench.java similarity index 100% rename from block/misc/BlockCellWorkbench.java rename to src/main/java/appeng/block/misc/BlockCellWorkbench.java diff --git a/block/misc/BlockCharger.java b/src/main/java/appeng/block/misc/BlockCharger.java similarity index 96% rename from block/misc/BlockCharger.java rename to src/main/java/appeng/block/misc/BlockCharger.java index 08e59b43f..869f91303 100644 --- a/block/misc/BlockCharger.java +++ b/src/main/java/appeng/block/misc/BlockCharger.java @@ -1,161 +1,161 @@ -package appeng.block.misc; - -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.Random; - -import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; -import net.minecraft.client.particle.EntityFX; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.blocks.RenderBlockCharger; -import appeng.client.render.effects.LightningFX; -import appeng.core.AEConfig; -import appeng.core.CommonHelper; -import appeng.core.features.AEFeature; -import appeng.helpers.ICustomCollision; -import appeng.tile.AEBaseTile; -import appeng.tile.misc.TileCharger; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class BlockCharger extends AEBaseBlock implements ICustomCollision -{ - - public BlockCharger() { - super( BlockCharger.class, Material.iron ); - setFeature( EnumSet.of( AEFeature.Core ) ); - setTileEntity( TileCharger.class ); - setLightOpacity( 2 ); - isFullSize = isOpaque = false; - } - - @Override - public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) - { - if ( player.isSneaking() ) - return false; - - if ( Platform.isServer() ) - { - TileCharger tc = getTileEntity( w, x, y, z ); - if ( tc != null ) - { - tc.activate( player ); - } - } - - return true; - } - - @Override - protected Class getRenderer() - { - return RenderBlockCharger.class; - } - - @Override - @SideOnly(Side.CLIENT) - public void randomDisplayTick(World w, int x, int y, int z, Random r) - { - if ( !AEConfig.instance.enableEffects ) - return; - - if ( r.nextFloat() < 0.98 ) - return; - - AEBaseTile tile = getTileEntity( w, x, y, z ); - if ( tile instanceof TileCharger ) - { - TileCharger tc = (TileCharger) tile; - if ( AEApi.instance().materials().materialCertusQuartzCrystalCharged.sameAsStack( tc.getStackInSlot( 0 ) ) ) - { - - double xOff = 0.0; - double yOff = 0.0; - double zOff = 0.0; - - for (int bolts = 0; bolts < 3; bolts++) - { - if ( CommonHelper.proxy.shouldAddParticles( r ) ) - { - LightningFX fx = new LightningFX( w, xOff + 0.5 + x, yOff + 0.5 + y, zOff + 0.5 + z, 0.0D, 0.0D, 0.0D ); - Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); - } - } - - } - } - } - - @Override - public Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean isVisual) - { - TileCharger tile = getTileEntity( w, x, y, z ); - if ( tile != null ) - { - double twoPixels = 2.0 / 16.0; - ForgeDirection up = tile.getUp(); - ForgeDirection forward = tile.getForward(); - AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( twoPixels, twoPixels, twoPixels, 1.0 - twoPixels, 1.0 - twoPixels, 1.0 - twoPixels ); - - if ( up.offsetX != 0 ) - { - bb.minX = 0; - bb.maxX = 1; - } - if ( up.offsetY != 0 ) - { - bb.minY = 0; - bb.maxY = 1; - } - if ( up.offsetZ != 0 ) - { - bb.minZ = 0; - bb.maxZ = 1; - } - - switch (forward) - { - case DOWN: - bb.maxY = 1; - break; - case UP: - bb.minY = 0; - break; - case NORTH: - bb.maxZ = 1; - break; - case SOUTH: - bb.minZ = 0; - break; - case EAST: - bb.minX = 0; - break; - case WEST: - bb.maxX = 1; - break; - default: - break; - } - - return Arrays.asList( new AxisAlignedBB[] { bb } ); - } - return Arrays.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( 0.0, 0, 0.0, 1.0, 1.0, 1.0 ) } ); - } - - @Override - public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) - { - out.add( AxisAlignedBB.getBoundingBox( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ) ); - } -} +package appeng.block.misc; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.blocks.RenderBlockCharger; +import appeng.client.render.effects.LightningFX; +import appeng.core.AEConfig; +import appeng.core.CommonHelper; +import appeng.core.features.AEFeature; +import appeng.helpers.ICustomCollision; +import appeng.tile.AEBaseTile; +import appeng.tile.misc.TileCharger; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockCharger extends AEBaseBlock implements ICustomCollision +{ + + public BlockCharger() { + super( BlockCharger.class, Material.iron ); + setFeature( EnumSet.of( AEFeature.Core ) ); + setTileEntity( TileCharger.class ); + setLightOpacity( 2 ); + isFullSize = isOpaque = false; + } + + @Override + public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) + { + if ( player.isSneaking() ) + return false; + + if ( Platform.isServer() ) + { + TileCharger tc = getTileEntity( w, x, y, z ); + if ( tc != null ) + { + tc.activate( player ); + } + } + + return true; + } + + @Override + protected Class getRenderer() + { + return RenderBlockCharger.class; + } + + @Override + @SideOnly(Side.CLIENT) + public void randomDisplayTick(World w, int x, int y, int z, Random r) + { + if ( !AEConfig.instance.enableEffects ) + return; + + if ( r.nextFloat() < 0.98 ) + return; + + AEBaseTile tile = getTileEntity( w, x, y, z ); + if ( tile instanceof TileCharger ) + { + TileCharger tc = (TileCharger) tile; + if ( AEApi.instance().materials().materialCertusQuartzCrystalCharged.sameAsStack( tc.getStackInSlot( 0 ) ) ) + { + + double xOff = 0.0; + double yOff = 0.0; + double zOff = 0.0; + + for (int bolts = 0; bolts < 3; bolts++) + { + if ( CommonHelper.proxy.shouldAddParticles( r ) ) + { + LightningFX fx = new LightningFX( w, xOff + 0.5 + x, yOff + 0.5 + y, zOff + 0.5 + z, 0.0D, 0.0D, 0.0D ); + Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); + } + } + + } + } + } + + @Override + public Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean isVisual) + { + TileCharger tile = getTileEntity( w, x, y, z ); + if ( tile != null ) + { + double twoPixels = 2.0 / 16.0; + ForgeDirection up = tile.getUp(); + ForgeDirection forward = tile.getForward(); + AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( twoPixels, twoPixels, twoPixels, 1.0 - twoPixels, 1.0 - twoPixels, 1.0 - twoPixels ); + + if ( up.offsetX != 0 ) + { + bb.minX = 0; + bb.maxX = 1; + } + if ( up.offsetY != 0 ) + { + bb.minY = 0; + bb.maxY = 1; + } + if ( up.offsetZ != 0 ) + { + bb.minZ = 0; + bb.maxZ = 1; + } + + switch (forward) + { + case DOWN: + bb.maxY = 1; + break; + case UP: + bb.minY = 0; + break; + case NORTH: + bb.maxZ = 1; + break; + case SOUTH: + bb.minZ = 0; + break; + case EAST: + bb.minX = 0; + break; + case WEST: + bb.maxX = 1; + break; + default: + break; + } + + return Arrays.asList( new AxisAlignedBB[] { bb } ); + } + return Arrays.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( 0.0, 0, 0.0, 1.0, 1.0, 1.0 ) } ); + } + + @Override + public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) + { + out.add( AxisAlignedBB.getBoundingBox( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ) ); + } +} diff --git a/block/misc/BlockCondenser.java b/src/main/java/appeng/block/misc/BlockCondenser.java similarity index 100% rename from block/misc/BlockCondenser.java rename to src/main/java/appeng/block/misc/BlockCondenser.java diff --git a/block/misc/BlockInscriber.java b/src/main/java/appeng/block/misc/BlockInscriber.java similarity index 96% rename from block/misc/BlockInscriber.java rename to src/main/java/appeng/block/misc/BlockInscriber.java index e161d0f9a..4e5aeaf54 100644 --- a/block/misc/BlockInscriber.java +++ b/src/main/java/appeng/block/misc/BlockInscriber.java @@ -1,50 +1,50 @@ -package appeng.block.misc; - -import java.util.EnumSet; - -import net.minecraft.block.material.Material; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.blocks.RenderBlockInscriber; -import appeng.core.features.AEFeature; -import appeng.core.sync.GuiBridge; -import appeng.tile.misc.TileInscriber; -import appeng.util.Platform; - -public class BlockInscriber extends AEBaseBlock -{ - - public BlockInscriber() { - super( BlockInscriber.class, Material.iron ); - setFeature( EnumSet.of( AEFeature.Inscriber ) ); - setTileEntity( TileInscriber.class ); - setLightOpacity( 2 ); - isFullSize = isOpaque = false; - } - - @Override - protected Class getRenderer() - { - return RenderBlockInscriber.class; - } - - @Override - public boolean onActivated(World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ) - { - if ( p.isSneaking() ) - return false; - - TileInscriber tg = getTileEntity( w, x, y, z ); - if ( tg != null ) - { - if ( Platform.isServer() ) - Platform.openGUI( p, tg, ForgeDirection.getOrientation( side ), GuiBridge.GUI_INSCRIBER ); - return true; - } - return false; - } - -} +package appeng.block.misc; + +import java.util.EnumSet; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.blocks.RenderBlockInscriber; +import appeng.core.features.AEFeature; +import appeng.core.sync.GuiBridge; +import appeng.tile.misc.TileInscriber; +import appeng.util.Platform; + +public class BlockInscriber extends AEBaseBlock +{ + + public BlockInscriber() { + super( BlockInscriber.class, Material.iron ); + setFeature( EnumSet.of( AEFeature.Inscriber ) ); + setTileEntity( TileInscriber.class ); + setLightOpacity( 2 ); + isFullSize = isOpaque = false; + } + + @Override + protected Class getRenderer() + { + return RenderBlockInscriber.class; + } + + @Override + public boolean onActivated(World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ) + { + if ( p.isSneaking() ) + return false; + + TileInscriber tg = getTileEntity( w, x, y, z ); + if ( tg != null ) + { + if ( Platform.isServer() ) + Platform.openGUI( p, tg, ForgeDirection.getOrientation( side ), GuiBridge.GUI_INSCRIBER ); + return true; + } + return false; + } + +} diff --git a/block/misc/BlockInterface.java b/src/main/java/appeng/block/misc/BlockInterface.java similarity index 100% rename from block/misc/BlockInterface.java rename to src/main/java/appeng/block/misc/BlockInterface.java diff --git a/block/misc/BlockLightDetector.java b/src/main/java/appeng/block/misc/BlockLightDetector.java similarity index 100% rename from block/misc/BlockLightDetector.java rename to src/main/java/appeng/block/misc/BlockLightDetector.java diff --git a/block/misc/BlockPaint.java b/src/main/java/appeng/block/misc/BlockPaint.java similarity index 100% rename from block/misc/BlockPaint.java rename to src/main/java/appeng/block/misc/BlockPaint.java diff --git a/block/misc/BlockQuartzGrowthAccelerator.java b/src/main/java/appeng/block/misc/BlockQuartzGrowthAccelerator.java similarity index 100% rename from block/misc/BlockQuartzGrowthAccelerator.java rename to src/main/java/appeng/block/misc/BlockQuartzGrowthAccelerator.java diff --git a/block/misc/BlockQuartzTorch.java b/src/main/java/appeng/block/misc/BlockQuartzTorch.java similarity index 96% rename from block/misc/BlockQuartzTorch.java rename to src/main/java/appeng/block/misc/BlockQuartzTorch.java index 56c50d68c..433f198a8 100644 --- a/block/misc/BlockQuartzTorch.java +++ b/src/main/java/appeng/block/misc/BlockQuartzTorch.java @@ -1,143 +1,143 @@ -package appeng.block.misc; - -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; -import net.minecraft.client.particle.EntityFX; -import net.minecraft.entity.Entity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.util.IOrientable; -import appeng.api.util.IOrientableBlock; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.blocks.RenderQuartzTorch; -import appeng.client.render.effects.LightningFX; -import appeng.core.AEConfig; -import appeng.core.CommonHelper; -import appeng.core.features.AEFeature; -import appeng.helpers.ICustomCollision; -import appeng.helpers.MetaRotation; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, ICustomCollision -{ - - protected BlockQuartzTorch(Class which) { - super( which, Material.circuits ); - setLightOpacity( 0 ); - isFullSize = isOpaque = false; - } - - public BlockQuartzTorch() { - this( BlockQuartzTorch.class ); - setFeature( EnumSet.of( AEFeature.DecorativeLights ) ); - setLightLevel( 0.9375F ); - } - - @Override - protected Class getRenderer() - { - return RenderQuartzTorch.class; - } - - @Override - public IOrientable getOrientable(final IBlockAccess w, final int x, final int y, final int z) - { - return new MetaRotation( w, x, y, z ); - } - - private void dropTorch(World w, int x, int y, int z) - { - w.func_147480_a( x, y, z, true ); - // w.destroyBlock( x, y, z, true ); - w.markBlockForUpdate( x, y, z ); - } - - @Override - public boolean canPlaceBlockAt(World w, int x, int y, int z) - { - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - if ( canPlaceAt( w, x, y, z, dir ) ) - return true; - return false; - } - - private boolean canPlaceAt(World w, int x, int y, int z, ForgeDirection dir) - { - return w.isSideSolid( x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir.getOpposite(), false ); - } - - @Override - public boolean isValidOrientation(World w, int x, int y, int z, ForgeDirection forward, ForgeDirection up) - { - return canPlaceAt( w, x, y, z, up.getOpposite() ); - } - - @Override - public void onNeighborBlockChange(World w, int x, int y, int z, Block id) - { - ForgeDirection up = getOrientable( w, x, y, z ).getUp(); - if ( !canPlaceAt( w, x, y, z, up.getOpposite() ) ) - dropTorch( w, x, y, z ); - } - - @Override - public Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean isVisual) - { - ForgeDirection up = getOrientable( w, x, y, z ).getUp(); - double xOff = -0.3 * up.offsetX; - double yOff = -0.3 * up.offsetY; - double zOff = -0.3 * up.offsetZ; - return Arrays.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7 ) } ); - } - - @Override - public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) - {/* - * double xOff = -0.15 * getUp().offsetX; double yOff = -0.15 * getUp().offsetY; double zOff = -0.15 * - * getUp().offsetZ; out.add( AxisAlignedBB.getBoundingBox( xOff + (double) x + 0.15, yOff + (double) y + 0.15, zOff - * + (double) z + 0.15,// ahh xOff + (double) x + 0.85, yOff + (double) y + 0.85, zOff + (double) z + 0.85 ) ); - */ - } - - @Override - @SideOnly(Side.CLIENT) - public void randomDisplayTick(World w, int x, int y, int z, Random r) - { - if ( !AEConfig.instance.enableEffects ) - return; - - if ( r.nextFloat() < 0.98 ) - return; - - ForgeDirection up = getOrientable( w, x, y, z ).getUp(); - double xOff = -0.3 * up.offsetX; - double yOff = -0.3 * up.offsetY; - double zOff = -0.3 * up.offsetZ; - for (int bolts = 0; bolts < 3; bolts++) - { - if ( CommonHelper.proxy.shouldAddParticles( r ) ) - { - LightningFX fx = new LightningFX( w, xOff + 0.5 + x, yOff + 0.5 + y, zOff + 0.5 + z, 0.0D, 0.0D, 0.0D ); - - Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); - } - } - } - - @Override - public boolean usesMetadata() - { - return true; - } - -} +package appeng.block.misc; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.util.IOrientable; +import appeng.api.util.IOrientableBlock; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.blocks.RenderQuartzTorch; +import appeng.client.render.effects.LightningFX; +import appeng.core.AEConfig; +import appeng.core.CommonHelper; +import appeng.core.features.AEFeature; +import appeng.helpers.ICustomCollision; +import appeng.helpers.MetaRotation; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, ICustomCollision +{ + + protected BlockQuartzTorch(Class which) { + super( which, Material.circuits ); + setLightOpacity( 0 ); + isFullSize = isOpaque = false; + } + + public BlockQuartzTorch() { + this( BlockQuartzTorch.class ); + setFeature( EnumSet.of( AEFeature.DecorativeLights ) ); + setLightLevel( 0.9375F ); + } + + @Override + protected Class getRenderer() + { + return RenderQuartzTorch.class; + } + + @Override + public IOrientable getOrientable(final IBlockAccess w, final int x, final int y, final int z) + { + return new MetaRotation( w, x, y, z ); + } + + private void dropTorch(World w, int x, int y, int z) + { + w.func_147480_a( x, y, z, true ); + // w.destroyBlock( x, y, z, true ); + w.markBlockForUpdate( x, y, z ); + } + + @Override + public boolean canPlaceBlockAt(World w, int x, int y, int z) + { + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + if ( canPlaceAt( w, x, y, z, dir ) ) + return true; + return false; + } + + private boolean canPlaceAt(World w, int x, int y, int z, ForgeDirection dir) + { + return w.isSideSolid( x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir.getOpposite(), false ); + } + + @Override + public boolean isValidOrientation(World w, int x, int y, int z, ForgeDirection forward, ForgeDirection up) + { + return canPlaceAt( w, x, y, z, up.getOpposite() ); + } + + @Override + public void onNeighborBlockChange(World w, int x, int y, int z, Block id) + { + ForgeDirection up = getOrientable( w, x, y, z ).getUp(); + if ( !canPlaceAt( w, x, y, z, up.getOpposite() ) ) + dropTorch( w, x, y, z ); + } + + @Override + public Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean isVisual) + { + ForgeDirection up = getOrientable( w, x, y, z ).getUp(); + double xOff = -0.3 * up.offsetX; + double yOff = -0.3 * up.offsetY; + double zOff = -0.3 * up.offsetZ; + return Arrays.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7 ) } ); + } + + @Override + public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) + {/* + * double xOff = -0.15 * getUp().offsetX; double yOff = -0.15 * getUp().offsetY; double zOff = -0.15 * + * getUp().offsetZ; out.add( AxisAlignedBB.getBoundingBox( xOff + (double) x + 0.15, yOff + (double) y + 0.15, zOff + * + (double) z + 0.15,// ahh xOff + (double) x + 0.85, yOff + (double) y + 0.85, zOff + (double) z + 0.85 ) ); + */ + } + + @Override + @SideOnly(Side.CLIENT) + public void randomDisplayTick(World w, int x, int y, int z, Random r) + { + if ( !AEConfig.instance.enableEffects ) + return; + + if ( r.nextFloat() < 0.98 ) + return; + + ForgeDirection up = getOrientable( w, x, y, z ).getUp(); + double xOff = -0.3 * up.offsetX; + double yOff = -0.3 * up.offsetY; + double zOff = -0.3 * up.offsetZ; + for (int bolts = 0; bolts < 3; bolts++) + { + if ( CommonHelper.proxy.shouldAddParticles( r ) ) + { + LightningFX fx = new LightningFX( w, xOff + 0.5 + x, yOff + 0.5 + y, zOff + 0.5 + z, 0.0D, 0.0D, 0.0D ); + + Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); + } + } + } + + @Override + public boolean usesMetadata() + { + return true; + } + +} diff --git a/block/misc/BlockSecurity.java b/src/main/java/appeng/block/misc/BlockSecurity.java similarity index 100% rename from block/misc/BlockSecurity.java rename to src/main/java/appeng/block/misc/BlockSecurity.java diff --git a/block/misc/BlockSkyCompass.java b/src/main/java/appeng/block/misc/BlockSkyCompass.java similarity index 100% rename from block/misc/BlockSkyCompass.java rename to src/main/java/appeng/block/misc/BlockSkyCompass.java diff --git a/block/misc/BlockTinyTNT.java b/src/main/java/appeng/block/misc/BlockTinyTNT.java similarity index 100% rename from block/misc/BlockTinyTNT.java rename to src/main/java/appeng/block/misc/BlockTinyTNT.java diff --git a/block/misc/BlockVibrationChamber.java b/src/main/java/appeng/block/misc/BlockVibrationChamber.java similarity index 96% rename from block/misc/BlockVibrationChamber.java rename to src/main/java/appeng/block/misc/BlockVibrationChamber.java index 8b14a202c..607ef0306 100644 --- a/block/misc/BlockVibrationChamber.java +++ b/src/main/java/appeng/block/misc/BlockVibrationChamber.java @@ -1,108 +1,108 @@ -package appeng.block.misc; - -import java.util.EnumSet; -import java.util.Random; - -import net.minecraft.block.material.Material; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.block.AEBaseBlock; -import appeng.client.texture.ExtraBlockTextures; -import appeng.core.AEConfig; -import appeng.core.features.AEFeature; -import appeng.core.sync.GuiBridge; -import appeng.tile.AEBaseTile; -import appeng.tile.misc.TileVibrationChamber; -import appeng.util.Platform; - -public class BlockVibrationChamber extends AEBaseBlock -{ - - public BlockVibrationChamber() { - super( BlockVibrationChamber.class, Material.iron ); - setFeature( EnumSet.of( AEFeature.PowerGen ) ); - setTileEntity( TileVibrationChamber.class ); - setHardness( 4.2F ); - } - - @Override - public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) - { - if ( player.isSneaking() ) - return false; - - if ( Platform.isServer() ) - { - TileVibrationChamber tc = getTileEntity( w, x, y, z ); - if ( tc != null && !player.isSneaking() ) - { - Platform.openGUI( player, tc, ForgeDirection.getOrientation( side ), GuiBridge.GUI_VIBRATIONCHAMBER ); - return true; - } - } - - return true; - } - - @Override - public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s) - { - IIcon ico = super.getIcon( w, x, y, z, s ); - TileVibrationChamber tvc = getTileEntity( w, x, y, z ); - - if ( tvc != null && tvc.isOn && ico == getRendererInstance().getTexture( ForgeDirection.SOUTH ) ) - { - return ExtraBlockTextures.BlockVibrationChamberFrontOn.getIcon(); - } - - return ico; - } - - @Override - public void randomDisplayTick(World w, int x, int y, int z, Random r) - { - if ( !AEConfig.instance.enableEffects ) - return; - - AEBaseTile tile = getTileEntity( w, x, y, z ); - if ( tile instanceof TileVibrationChamber ) - { - TileVibrationChamber tc = (TileVibrationChamber) tile; - if ( tc.isOn ) - { - float f1 = (float) x + 0.5F; - float f2 = (float) y + 0.5F; - float f3 = (float) z + 0.5F; - - ForgeDirection forward = tc.getForward(); - ForgeDirection up = tc.getUp(); - - 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; - - f1 += forward.offsetX * 0.6; - f2 += forward.offsetY * 0.6; - f3 += forward.offsetZ * 0.6; - - float ox = r.nextFloat(); - float oy = r.nextFloat() * 0.2f; - - f1 += up.offsetX * (-0.3 + oy); - f2 += up.offsetY * (-0.3 + oy); - f3 += up.offsetZ * (-0.3 + oy); - - f1 += west_x * (0.3 * ox - 0.15); - f2 += west_y * (0.3 * ox - 0.15); - f3 += west_z * (0.3 * ox - 0.15); - - w.spawnParticle( "smoke", (double) f1, (double) f2, (double) f3, 0.0D, 0.0D, 0.0D ); - w.spawnParticle( "flame", (double) f1, (double) f2, (double) f3, 0.0D, 0.0D, 0.0D ); - } - } - } - -} +package appeng.block.misc; + +import java.util.EnumSet; +import java.util.Random; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.block.AEBaseBlock; +import appeng.client.texture.ExtraBlockTextures; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; +import appeng.core.sync.GuiBridge; +import appeng.tile.AEBaseTile; +import appeng.tile.misc.TileVibrationChamber; +import appeng.util.Platform; + +public class BlockVibrationChamber extends AEBaseBlock +{ + + public BlockVibrationChamber() { + super( BlockVibrationChamber.class, Material.iron ); + setFeature( EnumSet.of( AEFeature.PowerGen ) ); + setTileEntity( TileVibrationChamber.class ); + setHardness( 4.2F ); + } + + @Override + public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) + { + if ( player.isSneaking() ) + return false; + + if ( Platform.isServer() ) + { + TileVibrationChamber tc = getTileEntity( w, x, y, z ); + if ( tc != null && !player.isSneaking() ) + { + Platform.openGUI( player, tc, ForgeDirection.getOrientation( side ), GuiBridge.GUI_VIBRATIONCHAMBER ); + return true; + } + } + + return true; + } + + @Override + public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s) + { + IIcon ico = super.getIcon( w, x, y, z, s ); + TileVibrationChamber tvc = getTileEntity( w, x, y, z ); + + if ( tvc != null && tvc.isOn && ico == getRendererInstance().getTexture( ForgeDirection.SOUTH ) ) + { + return ExtraBlockTextures.BlockVibrationChamberFrontOn.getIcon(); + } + + return ico; + } + + @Override + public void randomDisplayTick(World w, int x, int y, int z, Random r) + { + if ( !AEConfig.instance.enableEffects ) + return; + + AEBaseTile tile = getTileEntity( w, x, y, z ); + if ( tile instanceof TileVibrationChamber ) + { + TileVibrationChamber tc = (TileVibrationChamber) tile; + if ( tc.isOn ) + { + float f1 = (float) x + 0.5F; + float f2 = (float) y + 0.5F; + float f3 = (float) z + 0.5F; + + ForgeDirection forward = tc.getForward(); + ForgeDirection up = tc.getUp(); + + 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; + + f1 += forward.offsetX * 0.6; + f2 += forward.offsetY * 0.6; + f3 += forward.offsetZ * 0.6; + + float ox = r.nextFloat(); + float oy = r.nextFloat() * 0.2f; + + f1 += up.offsetX * (-0.3 + oy); + f2 += up.offsetY * (-0.3 + oy); + f3 += up.offsetZ * (-0.3 + oy); + + f1 += west_x * (0.3 * ox - 0.15); + f2 += west_y * (0.3 * ox - 0.15); + f3 += west_z * (0.3 * ox - 0.15); + + w.spawnParticle( "smoke", (double) f1, (double) f2, (double) f3, 0.0D, 0.0D, 0.0D ); + w.spawnParticle( "flame", (double) f1, (double) f2, (double) f3, 0.0D, 0.0D, 0.0D ); + } + } + } + +} diff --git a/block/networking/BlockCableBus.java b/src/main/java/appeng/block/networking/BlockCableBus.java similarity index 96% rename from block/networking/BlockCableBus.java rename to src/main/java/appeng/block/networking/BlockCableBus.java index 329260698..2b0084d41 100644 --- a/block/networking/BlockCableBus.java +++ b/src/main/java/appeng/block/networking/BlockCableBus.java @@ -1,450 +1,450 @@ -package appeng.block.networking; - -import java.util.EnumSet; -import java.util.List; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.client.particle.EffectRenderer; -import net.minecraft.client.particle.EntityDiggingFX; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import powercrystals.minefactoryreloaded.api.rednet.connectivity.IRedNetConnection; -import powercrystals.minefactoryreloaded.api.rednet.connectivity.RedNetConnectionType; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartHost; -import appeng.api.parts.PartItemStack; -import appeng.api.parts.SelectedPart; -import appeng.api.util.AEColor; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.BusRenderHelper; -import appeng.client.render.blocks.RendererCableBus; -import appeng.client.texture.ExtraBlockTextures; -import appeng.core.AEConfig; -import appeng.core.Api; -import appeng.core.AppEng; -import appeng.core.CommonHelper; -import appeng.core.features.AEFeature; -import appeng.helpers.AEGlassMaterial; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.IFMP; -import appeng.parts.ICableBusContainer; -import appeng.parts.NullCableBusContainer; -import appeng.tile.AEBaseTile; -import appeng.tile.networking.TileCableBus; -import appeng.tile.networking.TileCableBusTESR; -import appeng.transformer.annotations.integration.Interface; -import appeng.transformer.annotations.integration.Method; -import appeng.util.Platform; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@Interface(iface = "powercrystals.minefactoryreloaded.api.rednet.connectivity.IRedNetConnection", iname = "MFR") -public class BlockCableBus extends AEBaseBlock implements IRedNetConnection -{ - - static private ICableBusContainer nullCB = new NullCableBusContainer(); - static public Class noTesrTile; - static public Class tesrTile; - - public T getTileEntity(IBlockAccess w, int x, int y, int z) - { - TileEntity te = w.getTileEntity( x, y, z ); - - if ( noTesrTile.isInstance( te ) ) - return (T) te; - - if ( tesrTile != null && tesrTile.isInstance( te ) ) - return (T) te; - - return null; - } - - public BlockCableBus() { - super( BlockCableBus.class, AEGlassMaterial.instance ); - setFeature( EnumSet.of( AEFeature.Core ) ); - setLightOpacity( 0 ); - isFullSize = isOpaque = false; - } - - @Override - public int getRenderBlockPass() - { - if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) ) - return 1; - return 0; - } - - @SideOnly(Side.CLIENT) - public boolean addHitEffects(World world, MovingObjectPosition target, EffectRenderer effectRenderer) - { - Object pobj = cb( world, target.blockX, target.blockY, target.blockZ ); - if ( pobj instanceof IPartHost ) - { - IPartHost host = (IPartHost) pobj; - - for (ForgeDirection side : ForgeDirection.values()) - { - IPart p = host.getPart( side ); - IIcon ico = getIcon( p ); - - if ( ico == null ) - continue; - - byte b0 = (byte) (Platform.getRandomInt() % 2 == 0 ? 1 : 0); - - for (int i1 = 0; i1 < b0; ++i1) - { - for (int j1 = 0; j1 < b0; ++j1) - { - for (int k1 = 0; k1 < b0; ++k1) - { - double d0 = (double) target.blockX + ((double) i1 + 0.5D) / (double) b0; - double d1 = (double) target.blockY + ((double) j1 + 0.5D) / (double) b0; - double d2 = (double) target.blockZ + ((double) k1 + 0.5D) / (double) b0; - - double dd0 = target.hitVec.xCoord; - double dd1 = target.hitVec.yCoord; - double dd2 = target.hitVec.zCoord; - EntityDiggingFX fx = (new EntityDiggingFX( world, dd0, dd1, dd2, d0 - (double) target.blockX - 0.5D, d1 - (double) target.blockY - - 0.5D, d2 - (double) target.blockZ - 0.5D, this, 0 )).applyColourMultiplier( target.blockX, target.blockY, target.blockZ ); - - fx.setParticleIcon( ico ); - - effectRenderer.addEffect( fx ); - } - } - } - } - } - - return true; - } - - @SideOnly(Side.CLIENT) - public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) - { - Object pobj = cb( world, x, y, z ); - if ( pobj instanceof IPartHost ) - { - IPartHost host = (IPartHost) pobj; - - for (ForgeDirection side : ForgeDirection.values()) - { - IPart p = host.getPart( side ); - IIcon ico = getIcon( p ); - - if ( ico == null ) - continue; - - byte b0 = 3; - - for (int i1 = 0; i1 < b0; ++i1) - { - for (int j1 = 0; j1 < b0; ++j1) - { - for (int k1 = 0; k1 < b0; ++k1) - { - double d0 = (double) x + ((double) i1 + 0.5D) / (double) b0; - double d1 = (double) y + ((double) j1 + 0.5D) / (double) b0; - double d2 = (double) z + ((double) k1 + 0.5D) / (double) b0; - EntityDiggingFX fx = (new EntityDiggingFX( world, d0, d1, d2, d0 - (double) x - 0.5D, d1 - (double) y - 0.5D, d2 - (double) z - - 0.5D, this, meta )).applyColourMultiplier( x, y, z ); - - fx.setParticleIcon( ico ); - - effectRenderer.addEffect( fx ); - } - } - } - } - } - - return true; - } - - private IIcon getIcon(IPart p) - { - if ( p == null ) - return null; - - try - { - IIcon ico = p.getBreakingTexture(); - if ( ico != null ) - return ico; - } - catch (Throwable t) - { - // nothing. - } - - ItemStack is = p.getItemStack( PartItemStack.Network ); - if ( is == null || is.getItem() == null ) - return null; - - return is.getItem().getIcon( is, 0 ); - } - - @Override - public boolean canRenderInPass(int pass) - { - BusRenderHelper.instance.setPass( pass ); - - if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) ) - return true; - - return pass == 0; - } - - @Override - public boolean isLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity) - { - return cb( world, x, y, z ).isLadder( entity ); - } - - @Override - public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour) - { - return recolourBlock( world, x, y, z, side, colour, null ); - } - - public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour, EntityPlayer who) - { - try - { - return cb( world, x, y, z ).recolourBlock( side, AEColor.values()[colour], who ); - } - catch (Throwable t) - { - } - return false; - } - - @Override - public void randomDisplayTick(World world, int x, int y, int z, Random r) - { - cb( world, x, y, z ).randomDisplayTick( world, x, y, z, r ); - } - - @Override - public int getLightValue(IBlockAccess world, int x, int y, int z) - { - Block block = world.getBlock( x, y, z ); - if ( block != null && block != this ) - { - return block.getLightValue( world, x, y, z ); - } - if ( block == null ) - return 0; - return cb( world, x, y, z ).getLightValue(); - } - - @Override - public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) - { - Vec3 v3 = target.hitVec.addVector( -x, -y, -z ); - SelectedPart sp = cb( world, x, y, z ).selectPart( v3 ); - - if ( sp.part != null ) - return sp.part.getItemStack( PartItemStack.Pick ); - else if ( sp.facade != null ) - return sp.facade.getItemStack(); - - return null; - } - - @Override - public boolean isReplaceable(IBlockAccess world, int x, int y, int z) - { - return cb( world, x, y, z ).isEmpty(); - } - - @SuppressWarnings("deprecation") - @Override - public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) - { - if ( player.capabilities.isCreativeMode ) - { - AEBaseTile tile = getTileEntity( world, x, y, z ); - if ( tile != null ) - tile.disableDrops(); - // maybe ray trace? - } - return super.removedByPlayer( world, player, x, y, z ); - } - - @Override - public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s) - { - return getIcon( s, 0 ); - } - - @Override - public IIcon getIcon(int direction, int metadata) - { - IIcon i = super.getIcon( direction, metadata ); - if ( i != null ) - return i; - - return ExtraBlockTextures.BlockQuartzGlassB.getIcon(); - } - - @Override - protected Class getRenderer() - { - return RendererCableBus.class; - } - - @Override - public void registerBlockIcons(IIconRegister iconRegistry) - { - - } - - @Override - public boolean canProvidePower() - { - return true; - } - - @Override - public boolean isSideSolid(IBlockAccess w, int x, int y, int z, ForgeDirection side) - { - return cb( w, x, y, z ).isSolidOnSide( side ); - } - - @Override - public void onNeighborBlockChange(World w, int x, int y, int z, Block meh) - { - cb( w, x, y, z ).onNeighborChanged(); - } - - @Override - public void onNeighborChange(IBlockAccess w, int x, int y, int z, int tileX, int tileY, int tileZ) - { - if ( Platform.isServer() ) - cb( w, x, y, z ).onNeighborChanged(); - } - - @Override - public Item getItemDropped(int i, Random r, int k) - { - return null; - } - - @Override - public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) - { - return cb( w, x, y, z ).activate( player, Vec3.createVectorHelper( hitX, hitY, hitZ ) ); - } - - @Override - public void onEntityCollidedWithBlock(World w, int x, int y, int z, Entity e) - { - cb( w, x, y, z ).onEntityCollision( e ); - } - - @Override - public boolean canConnectRedstone(IBlockAccess w, int x, int y, int z, int side) - { - switch (side) - { - case -1: - case 4: - return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN ) ); - case 0: - return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.NORTH ) ); - case 1: - return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.EAST ) ); - case 2: - return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.SOUTH ) ); - case 3: - return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.WEST ) ); - } - return false; - } - - @Override - public int isProvidingWeakPower(IBlockAccess w, int x, int y, int z, int side) - { - return cb( w, x, y, z ).isProvidingWeakPower( ForgeDirection.getOrientation( side ).getOpposite() ); - } - - @Override - public int isProvidingStrongPower(IBlockAccess w, int x, int y, int z, int side) - { - return cb( w, x, y, z ).isProvidingStrongPower( ForgeDirection.getOrientation( side ).getOpposite() ); - } - - @Override - public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) - { - - } - - public void setupTile() - { - setTileEntity( noTesrTile = Api.instance.partHelper.getCombinedInstance( TileCableBus.class.getName() ) ); - if ( Platform.isClient() ) - { - tesrTile = Api.instance.partHelper.getCombinedInstance( TileCableBusTESR.class.getName() ); - GameRegistry.registerTileEntity( tesrTile, "ClientOnly_TESR_CableBus" ); - CommonHelper.proxy.bindTileEntitySpecialRenderer( tesrTile, this ); - } - } - - private ICableBusContainer cb(IBlockAccess w, int x, int y, int z) - { - TileEntity te = w.getTileEntity( x, y, z ); - ICableBusContainer out = null; - - if ( te instanceof TileCableBus ) - out = ((TileCableBus) te).cb; - - else if ( AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) ) - out = ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).getCableContainer( te ); - - return out == null ? nullCB : out; - } - - /** - * Immibis MB Support. - */ - boolean ImmibisMicroblocks_TransformableBlockMarker = true; - - @Override - @Method(iname = "MFR") - public RedNetConnectionType getConnectionType(World world, int x, int y, int z, ForgeDirection side) - { - return cb( world, x, y, z ).canConnectRedstone( EnumSet.allOf( ForgeDirection.class ) ) ? RedNetConnectionType.CableSingle : RedNetConnectionType.None; - } - - int myColorMultiplier = 0xffffff; - - public void setRenderColor(int color) - { - myColorMultiplier = color; - } - - @Override - public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_) - { - return myColorMultiplier; - } - -} +package appeng.block.networking; + +import java.util.EnumSet; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.client.particle.EffectRenderer; +import net.minecraft.client.particle.EntityDiggingFX; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import powercrystals.minefactoryreloaded.api.rednet.connectivity.IRedNetConnection; +import powercrystals.minefactoryreloaded.api.rednet.connectivity.RedNetConnectionType; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartHost; +import appeng.api.parts.PartItemStack; +import appeng.api.parts.SelectedPart; +import appeng.api.util.AEColor; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.BusRenderHelper; +import appeng.client.render.blocks.RendererCableBus; +import appeng.client.texture.ExtraBlockTextures; +import appeng.core.AEConfig; +import appeng.core.Api; +import appeng.core.AppEng; +import appeng.core.CommonHelper; +import appeng.core.features.AEFeature; +import appeng.helpers.AEGlassMaterial; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.IFMP; +import appeng.parts.ICableBusContainer; +import appeng.parts.NullCableBusContainer; +import appeng.tile.AEBaseTile; +import appeng.tile.networking.TileCableBus; +import appeng.tile.networking.TileCableBusTESR; +import appeng.transformer.annotations.integration.Interface; +import appeng.transformer.annotations.integration.Method; +import appeng.util.Platform; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@Interface(iface = "powercrystals.minefactoryreloaded.api.rednet.connectivity.IRedNetConnection", iname = "MFR") +public class BlockCableBus extends AEBaseBlock implements IRedNetConnection +{ + + static private ICableBusContainer nullCB = new NullCableBusContainer(); + static public Class noTesrTile; + static public Class tesrTile; + + public T getTileEntity(IBlockAccess w, int x, int y, int z) + { + TileEntity te = w.getTileEntity( x, y, z ); + + if ( noTesrTile.isInstance( te ) ) + return (T) te; + + if ( tesrTile != null && tesrTile.isInstance( te ) ) + return (T) te; + + return null; + } + + public BlockCableBus() { + super( BlockCableBus.class, AEGlassMaterial.instance ); + setFeature( EnumSet.of( AEFeature.Core ) ); + setLightOpacity( 0 ); + isFullSize = isOpaque = false; + } + + @Override + public int getRenderBlockPass() + { + if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) ) + return 1; + return 0; + } + + @SideOnly(Side.CLIENT) + public boolean addHitEffects(World world, MovingObjectPosition target, EffectRenderer effectRenderer) + { + Object pobj = cb( world, target.blockX, target.blockY, target.blockZ ); + if ( pobj instanceof IPartHost ) + { + IPartHost host = (IPartHost) pobj; + + for (ForgeDirection side : ForgeDirection.values()) + { + IPart p = host.getPart( side ); + IIcon ico = getIcon( p ); + + if ( ico == null ) + continue; + + byte b0 = (byte) (Platform.getRandomInt() % 2 == 0 ? 1 : 0); + + for (int i1 = 0; i1 < b0; ++i1) + { + for (int j1 = 0; j1 < b0; ++j1) + { + for (int k1 = 0; k1 < b0; ++k1) + { + double d0 = (double) target.blockX + ((double) i1 + 0.5D) / (double) b0; + double d1 = (double) target.blockY + ((double) j1 + 0.5D) / (double) b0; + double d2 = (double) target.blockZ + ((double) k1 + 0.5D) / (double) b0; + + double dd0 = target.hitVec.xCoord; + double dd1 = target.hitVec.yCoord; + double dd2 = target.hitVec.zCoord; + EntityDiggingFX fx = (new EntityDiggingFX( world, dd0, dd1, dd2, d0 - (double) target.blockX - 0.5D, d1 - (double) target.blockY + - 0.5D, d2 - (double) target.blockZ - 0.5D, this, 0 )).applyColourMultiplier( target.blockX, target.blockY, target.blockZ ); + + fx.setParticleIcon( ico ); + + effectRenderer.addEffect( fx ); + } + } + } + } + } + + return true; + } + + @SideOnly(Side.CLIENT) + public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) + { + Object pobj = cb( world, x, y, z ); + if ( pobj instanceof IPartHost ) + { + IPartHost host = (IPartHost) pobj; + + for (ForgeDirection side : ForgeDirection.values()) + { + IPart p = host.getPart( side ); + IIcon ico = getIcon( p ); + + if ( ico == null ) + continue; + + byte b0 = 3; + + for (int i1 = 0; i1 < b0; ++i1) + { + for (int j1 = 0; j1 < b0; ++j1) + { + for (int k1 = 0; k1 < b0; ++k1) + { + double d0 = (double) x + ((double) i1 + 0.5D) / (double) b0; + double d1 = (double) y + ((double) j1 + 0.5D) / (double) b0; + double d2 = (double) z + ((double) k1 + 0.5D) / (double) b0; + EntityDiggingFX fx = (new EntityDiggingFX( world, d0, d1, d2, d0 - (double) x - 0.5D, d1 - (double) y - 0.5D, d2 - (double) z + - 0.5D, this, meta )).applyColourMultiplier( x, y, z ); + + fx.setParticleIcon( ico ); + + effectRenderer.addEffect( fx ); + } + } + } + } + } + + return true; + } + + private IIcon getIcon(IPart p) + { + if ( p == null ) + return null; + + try + { + IIcon ico = p.getBreakingTexture(); + if ( ico != null ) + return ico; + } + catch (Throwable t) + { + // nothing. + } + + ItemStack is = p.getItemStack( PartItemStack.Network ); + if ( is == null || is.getItem() == null ) + return null; + + return is.getItem().getIcon( is, 0 ); + } + + @Override + public boolean canRenderInPass(int pass) + { + BusRenderHelper.instance.setPass( pass ); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) ) + return true; + + return pass == 0; + } + + @Override + public boolean isLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity) + { + return cb( world, x, y, z ).isLadder( entity ); + } + + @Override + public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour) + { + return recolourBlock( world, x, y, z, side, colour, null ); + } + + public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour, EntityPlayer who) + { + try + { + return cb( world, x, y, z ).recolourBlock( side, AEColor.values()[colour], who ); + } + catch (Throwable t) + { + } + return false; + } + + @Override + public void randomDisplayTick(World world, int x, int y, int z, Random r) + { + cb( world, x, y, z ).randomDisplayTick( world, x, y, z, r ); + } + + @Override + public int getLightValue(IBlockAccess world, int x, int y, int z) + { + Block block = world.getBlock( x, y, z ); + if ( block != null && block != this ) + { + return block.getLightValue( world, x, y, z ); + } + if ( block == null ) + return 0; + return cb( world, x, y, z ).getLightValue(); + } + + @Override + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) + { + Vec3 v3 = target.hitVec.addVector( -x, -y, -z ); + SelectedPart sp = cb( world, x, y, z ).selectPart( v3 ); + + if ( sp.part != null ) + return sp.part.getItemStack( PartItemStack.Pick ); + else if ( sp.facade != null ) + return sp.facade.getItemStack(); + + return null; + } + + @Override + public boolean isReplaceable(IBlockAccess world, int x, int y, int z) + { + return cb( world, x, y, z ).isEmpty(); + } + + @SuppressWarnings("deprecation") + @Override + public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) + { + if ( player.capabilities.isCreativeMode ) + { + AEBaseTile tile = getTileEntity( world, x, y, z ); + if ( tile != null ) + tile.disableDrops(); + // maybe ray trace? + } + return super.removedByPlayer( world, player, x, y, z ); + } + + @Override + public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s) + { + return getIcon( s, 0 ); + } + + @Override + public IIcon getIcon(int direction, int metadata) + { + IIcon i = super.getIcon( direction, metadata ); + if ( i != null ) + return i; + + return ExtraBlockTextures.BlockQuartzGlassB.getIcon(); + } + + @Override + protected Class getRenderer() + { + return RendererCableBus.class; + } + + @Override + public void registerBlockIcons(IIconRegister iconRegistry) + { + + } + + @Override + public boolean canProvidePower() + { + return true; + } + + @Override + public boolean isSideSolid(IBlockAccess w, int x, int y, int z, ForgeDirection side) + { + return cb( w, x, y, z ).isSolidOnSide( side ); + } + + @Override + public void onNeighborBlockChange(World w, int x, int y, int z, Block meh) + { + cb( w, x, y, z ).onNeighborChanged(); + } + + @Override + public void onNeighborChange(IBlockAccess w, int x, int y, int z, int tileX, int tileY, int tileZ) + { + if ( Platform.isServer() ) + cb( w, x, y, z ).onNeighborChanged(); + } + + @Override + public Item getItemDropped(int i, Random r, int k) + { + return null; + } + + @Override + public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) + { + return cb( w, x, y, z ).activate( player, Vec3.createVectorHelper( hitX, hitY, hitZ ) ); + } + + @Override + public void onEntityCollidedWithBlock(World w, int x, int y, int z, Entity e) + { + cb( w, x, y, z ).onEntityCollision( e ); + } + + @Override + public boolean canConnectRedstone(IBlockAccess w, int x, int y, int z, int side) + { + switch (side) + { + case -1: + case 4: + return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN ) ); + case 0: + return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.NORTH ) ); + case 1: + return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.EAST ) ); + case 2: + return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.SOUTH ) ); + case 3: + return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.WEST ) ); + } + return false; + } + + @Override + public int isProvidingWeakPower(IBlockAccess w, int x, int y, int z, int side) + { + return cb( w, x, y, z ).isProvidingWeakPower( ForgeDirection.getOrientation( side ).getOpposite() ); + } + + @Override + public int isProvidingStrongPower(IBlockAccess w, int x, int y, int z, int side) + { + return cb( w, x, y, z ).isProvidingStrongPower( ForgeDirection.getOrientation( side ).getOpposite() ); + } + + @Override + public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) + { + + } + + public void setupTile() + { + setTileEntity( noTesrTile = Api.instance.partHelper.getCombinedInstance( TileCableBus.class.getName() ) ); + if ( Platform.isClient() ) + { + tesrTile = Api.instance.partHelper.getCombinedInstance( TileCableBusTESR.class.getName() ); + GameRegistry.registerTileEntity( tesrTile, "ClientOnly_TESR_CableBus" ); + CommonHelper.proxy.bindTileEntitySpecialRenderer( tesrTile, this ); + } + } + + private ICableBusContainer cb(IBlockAccess w, int x, int y, int z) + { + TileEntity te = w.getTileEntity( x, y, z ); + ICableBusContainer out = null; + + if ( te instanceof TileCableBus ) + out = ((TileCableBus) te).cb; + + else if ( AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) ) + out = ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).getCableContainer( te ); + + return out == null ? nullCB : out; + } + + /** + * Immibis MB Support. + */ + boolean ImmibisMicroblocks_TransformableBlockMarker = true; + + @Override + @Method(iname = "MFR") + public RedNetConnectionType getConnectionType(World world, int x, int y, int z, ForgeDirection side) + { + return cb( world, x, y, z ).canConnectRedstone( EnumSet.allOf( ForgeDirection.class ) ) ? RedNetConnectionType.CableSingle : RedNetConnectionType.None; + } + + int myColorMultiplier = 0xffffff; + + public void setRenderColor(int color) + { + myColorMultiplier = color; + } + + @Override + public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_) + { + return myColorMultiplier; + } + +} diff --git a/block/networking/BlockController.java b/src/main/java/appeng/block/networking/BlockController.java similarity index 100% rename from block/networking/BlockController.java rename to src/main/java/appeng/block/networking/BlockController.java diff --git a/block/networking/BlockCreativeEnergyCell.java b/src/main/java/appeng/block/networking/BlockCreativeEnergyCell.java similarity index 100% rename from block/networking/BlockCreativeEnergyCell.java rename to src/main/java/appeng/block/networking/BlockCreativeEnergyCell.java diff --git a/block/networking/BlockDenseEnergyCell.java b/src/main/java/appeng/block/networking/BlockDenseEnergyCell.java similarity index 100% rename from block/networking/BlockDenseEnergyCell.java rename to src/main/java/appeng/block/networking/BlockDenseEnergyCell.java diff --git a/block/networking/BlockEnergyAcceptor.java b/src/main/java/appeng/block/networking/BlockEnergyAcceptor.java similarity index 100% rename from block/networking/BlockEnergyAcceptor.java rename to src/main/java/appeng/block/networking/BlockEnergyAcceptor.java diff --git a/block/networking/BlockEnergyCell.java b/src/main/java/appeng/block/networking/BlockEnergyCell.java similarity index 100% rename from block/networking/BlockEnergyCell.java rename to src/main/java/appeng/block/networking/BlockEnergyCell.java diff --git a/block/networking/BlockWireless.java b/src/main/java/appeng/block/networking/BlockWireless.java similarity index 100% rename from block/networking/BlockWireless.java rename to src/main/java/appeng/block/networking/BlockWireless.java diff --git a/block/qnb/BlockQuantumLinkChamber.java b/src/main/java/appeng/block/qnb/BlockQuantumLinkChamber.java similarity index 100% rename from block/qnb/BlockQuantumLinkChamber.java rename to src/main/java/appeng/block/qnb/BlockQuantumLinkChamber.java diff --git a/block/qnb/BlockQuantumRing.java b/src/main/java/appeng/block/qnb/BlockQuantumRing.java similarity index 100% rename from block/qnb/BlockQuantumRing.java rename to src/main/java/appeng/block/qnb/BlockQuantumRing.java diff --git a/block/solids/BlockFluix.java b/src/main/java/appeng/block/solids/BlockFluix.java similarity index 100% rename from block/solids/BlockFluix.java rename to src/main/java/appeng/block/solids/BlockFluix.java diff --git a/block/solids/BlockQuartz.java b/src/main/java/appeng/block/solids/BlockQuartz.java similarity index 100% rename from block/solids/BlockQuartz.java rename to src/main/java/appeng/block/solids/BlockQuartz.java diff --git a/block/solids/BlockQuartzChiseled.java b/src/main/java/appeng/block/solids/BlockQuartzChiseled.java similarity index 100% rename from block/solids/BlockQuartzChiseled.java rename to src/main/java/appeng/block/solids/BlockQuartzChiseled.java diff --git a/block/solids/BlockQuartzGlass.java b/src/main/java/appeng/block/solids/BlockQuartzGlass.java similarity index 100% rename from block/solids/BlockQuartzGlass.java rename to src/main/java/appeng/block/solids/BlockQuartzGlass.java diff --git a/block/solids/BlockQuartzLamp.java b/src/main/java/appeng/block/solids/BlockQuartzLamp.java similarity index 100% rename from block/solids/BlockQuartzLamp.java rename to src/main/java/appeng/block/solids/BlockQuartzLamp.java diff --git a/block/solids/BlockQuartzPillar.java b/src/main/java/appeng/block/solids/BlockQuartzPillar.java similarity index 100% rename from block/solids/BlockQuartzPillar.java rename to src/main/java/appeng/block/solids/BlockQuartzPillar.java diff --git a/block/solids/BlockSkyStone.java b/src/main/java/appeng/block/solids/BlockSkyStone.java similarity index 100% rename from block/solids/BlockSkyStone.java rename to src/main/java/appeng/block/solids/BlockSkyStone.java diff --git a/block/solids/OreQuartz.java b/src/main/java/appeng/block/solids/OreQuartz.java similarity index 100% rename from block/solids/OreQuartz.java rename to src/main/java/appeng/block/solids/OreQuartz.java diff --git a/block/solids/OreQuartzCharged.java b/src/main/java/appeng/block/solids/OreQuartzCharged.java similarity index 100% rename from block/solids/OreQuartzCharged.java rename to src/main/java/appeng/block/solids/OreQuartzCharged.java diff --git a/block/spatial/BlockMatrixFrame.java b/src/main/java/appeng/block/spatial/BlockMatrixFrame.java similarity index 100% rename from block/spatial/BlockMatrixFrame.java rename to src/main/java/appeng/block/spatial/BlockMatrixFrame.java diff --git a/block/spatial/BlockSpatialIOPort.java b/src/main/java/appeng/block/spatial/BlockSpatialIOPort.java similarity index 100% rename from block/spatial/BlockSpatialIOPort.java rename to src/main/java/appeng/block/spatial/BlockSpatialIOPort.java diff --git a/block/spatial/BlockSpatialPylon.java b/src/main/java/appeng/block/spatial/BlockSpatialPylon.java similarity index 100% rename from block/spatial/BlockSpatialPylon.java rename to src/main/java/appeng/block/spatial/BlockSpatialPylon.java diff --git a/block/storage/BlockChest.java b/src/main/java/appeng/block/storage/BlockChest.java similarity index 100% rename from block/storage/BlockChest.java rename to src/main/java/appeng/block/storage/BlockChest.java diff --git a/block/storage/BlockDrive.java b/src/main/java/appeng/block/storage/BlockDrive.java similarity index 100% rename from block/storage/BlockDrive.java rename to src/main/java/appeng/block/storage/BlockDrive.java diff --git a/block/storage/BlockIOPort.java b/src/main/java/appeng/block/storage/BlockIOPort.java similarity index 100% rename from block/storage/BlockIOPort.java rename to src/main/java/appeng/block/storage/BlockIOPort.java diff --git a/block/storage/BlockSkyChest.java b/src/main/java/appeng/block/storage/BlockSkyChest.java similarity index 100% rename from block/storage/BlockSkyChest.java rename to src/main/java/appeng/block/storage/BlockSkyChest.java diff --git a/client/ClientHelper.java b/src/main/java/appeng/client/ClientHelper.java similarity index 96% rename from client/ClientHelper.java rename to src/main/java/appeng/client/ClientHelper.java index 85b3db347..90e5c36e7 100644 --- a/client/ClientHelper.java +++ b/src/main/java/appeng/client/ClientHelper.java @@ -1,407 +1,407 @@ -package appeng.client; - -import static net.minecraftforge.client.IItemRenderer.ItemRenderType.ENTITY; -import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.BLOCK_3D; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.particle.EntityFX; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; -import net.minecraft.item.ItemBlock; -import net.minecraft.item.ItemStack; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.client.IItemRenderer; -import net.minecraftforge.client.MinecraftForgeClient; -import net.minecraftforge.client.event.MouseEvent; -import net.minecraftforge.client.event.RenderLivingEvent; -import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.common.MinecraftForge; - -import org.lwjgl.opengl.GL11; - -import appeng.api.parts.CableRenderMode; -import appeng.api.util.AEColor; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.TESRWrapper; -import appeng.client.render.WorldRender; -import appeng.client.render.effects.AssemblerFX; -import appeng.client.render.effects.CraftingFx; -import appeng.client.render.effects.EnergyFx; -import appeng.client.render.effects.LightningArcFX; -import appeng.client.render.effects.LightningFX; -import appeng.client.render.effects.VibrantFX; -import appeng.client.texture.CableBusTextures; -import appeng.client.texture.ExtraBlockTextures; -import appeng.client.texture.ExtraItemTextures; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.CommonHelper; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketAssemblerAnimation; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.entity.EntityFloatingItem; -import appeng.entity.EntityTinyTNTPrimed; -import appeng.entity.RenderFloatingItem; -import appeng.entity.RenderTinyTNTPrimed; -import appeng.helpers.IMouseWheelItem; -import appeng.hooks.TickHandler; -import appeng.hooks.TickHandler.PlayerColor; -import appeng.server.ServerHelper; -import appeng.transformer.MissingCoreMod; -import appeng.util.Platform; -import cpw.mods.fml.client.registry.ClientRegistry; -import cpw.mods.fml.client.registry.RenderingRegistry; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; - -public class ClientHelper extends ServerHelper -{ - - private static RenderItem itemRenderer = new RenderItem(); - private static RenderBlocks blockRenderer = new RenderBlocks(); - - @Override - public CableRenderMode getRenderMode() - { - if ( Platform.isServer() ) - return super.getRenderMode(); - - Minecraft mc = Minecraft.getMinecraft(); - EntityPlayer player = mc.thePlayer; - - return renderModeForPlayer( player ); - } - - @Override - public void triggerUpdates() - { - Minecraft mc = Minecraft.getMinecraft(); - if ( mc == null || mc.thePlayer == null || mc.theWorld == null ) - return; - - EntityPlayer player = mc.thePlayer; - - if ( player == null ) - return; - - int x = (int) player.posX; - int y = (int) player.posY; - int z = (int) player.posZ; - - int range = 16 * 16; - - mc.theWorld.markBlockRangeForRenderUpdate( x - range, y - range, z - range, x + range, y + range, z + range ); - } - - @SubscribeEvent - public void postPlayerRender(RenderLivingEvent.Pre p) - { - PlayerColor player = TickHandler.instance.getPlayerColors().get( p.entity.getEntityId() ); - if ( player != null ) - { - AEColor col = player.myColor; - - float r = (float) (0xff & (col.mediumVariant >> 16)); - float g = (float) (0xff & (col.mediumVariant >> 8)); - float b = (float) (0xff & (col.mediumVariant)); - GL11.glColor3f( r / 255.0f, g / 255.0f, b / 255.0f ); - } - } - - @Override - public void doRenderItem(ItemStack itemstack, World w) - { - if ( itemstack != null ) - { - EntityItem entityitem = new EntityItem( w, 0.0D, 0.0D, 0.0D, itemstack ); - entityitem.getEntityItem().stackSize = 1; - - // set all this stuff and then do shit? meh? - entityitem.hoverStart = 0; - entityitem.age = 0; - entityitem.rotationYaw = 0; - - GL11.glPushMatrix(); - GL11.glTranslatef( 0, -0.04F, 0 ); - GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); - // GL11.glDisable( GL11.GL_CULL_FACE ); - - if ( itemstack.isItemEnchanted() || itemstack.getItem().requiresMultipleRenderPasses() ) - { - GL11.glTranslatef( 0.0f, -0.05f, -0.25f ); - GL11.glScalef( 1.0f / 1.5f, 1.0f / 1.5f, 1.0f / 1.5f ); - // GL11.glTranslated( -8.0, -12.2, -10.6 ); - GL11.glScalef( 1.0f, -1.0f, 0.005f ); - // GL11.glScalef( 1.0f , -1.0f, 1.0f ); - - Block block = Block.getBlockFromItem( itemstack.getItem() ); - if ( (itemstack.getItemSpriteNumber() == 0 && block != null && RenderBlocks.renderItemIn3d( block.getRenderType() )) ) - { - GL11.glRotatef( 25.0f, 1.0f, 0.0f, 0.0f ); - GL11.glRotatef( 15.0f, 0.0f, 1.0f, 0.0f ); - GL11.glRotatef( 30.0f, 0.0f, 1.0f, 0.0f ); - } - - IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer( itemstack, ENTITY ); - if ( customRenderer != null && !(itemstack.getItem() instanceof ItemBlock) ) - { - if ( customRenderer.shouldUseRenderHelper( ENTITY, itemstack, BLOCK_3D ) ) - { - GL11.glTranslatef( 0, -0.04F, 0 ); - GL11.glScalef( 0.7f, 0.7f, 0.7f ); - GL11.glRotatef( 35, 1, 0, 0 ); - GL11.glRotatef( 45, 0, 1, 0 ); - GL11.glRotatef( -90, 0, 1, 0 ); - } - } - else if ( itemstack.getItem() instanceof ItemBlock ) - { - GL11.glTranslatef( 0, -0.04F, 0 ); - GL11.glScalef( 1.1f, 1.1f, 1.1f ); - GL11.glRotatef( -90, 0, 1, 0 ); - } - else - { - GL11.glTranslatef( 0, -0.14F, 0 ); - GL11.glScalef( 0.8f, 0.8f, 0.8f ); - } - - RenderItem.renderInFrame = true; - RenderManager.instance.renderEntityWithPosYaw( entityitem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F ); - RenderItem.renderInFrame = false; - } - else - { - GL11.glScalef( 1.0f / 42.0f, 1.0f / 42.0f, 1.0f / 42.0f ); - GL11.glTranslated( -8.0, -10.2, -10.4 ); - GL11.glScalef( 1.0f, 1.0f, 0.005f ); - - RenderItem.renderInFrame = false; - FontRenderer fr = Minecraft.getMinecraft().fontRenderer; - if ( !ForgeHooksClient.renderInventoryItem( blockRenderer, Minecraft.getMinecraft().renderEngine, itemstack, true, 0, (float) 0, (float) 0 ) ) - { - itemRenderer.renderItemIntoGUI( fr, Minecraft.getMinecraft().renderEngine, itemstack, 0, 0, false ); - } - } - - GL11.glPopMatrix(); - } - } - - @Override - public void init() - { - MinecraftForge.EVENT_BUS.register( this ); - } - - @Override - public void postinit() - { - RenderingRegistry.registerBlockHandler( WorldRender.instance ); - RenderManager.instance.entityRenderMap.put( EntityTinyTNTPrimed.class, new RenderTinyTNTPrimed() ); - RenderManager.instance.entityRenderMap.put( EntityFloatingItem.class, new RenderFloatingItem() ); - } - - @SubscribeEvent - public void wheelEvent(MouseEvent me) - { - if ( me.isCanceled() || me.dwheel == 0 ) - return; - - Minecraft mc = Minecraft.getMinecraft(); - EntityPlayer player = mc.thePlayer; - ItemStack is = player.getHeldItem(); - - if ( is != null && is.getItem() instanceof IMouseWheelItem && player.isSneaking() ) - { - try - { - NetworkHandler.instance.sendToServer( new PacketValueConfig( "Item", me.dwheel > 0 ? "WheelUp" : "WheelDown" ) ); - me.setCanceled( true ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - } - - @SubscribeEvent - public void updateTextureSheet(TextureStitchEvent.Pre ev) - { - if ( ev.map.getTextureType() == 1 ) - { - for (ExtraItemTextures et : ExtraItemTextures.values()) - et.registerIcon( ev.map ); - } - - if ( ev.map.getTextureType() == 0 ) - { - for (ExtraBlockTextures et : ExtraBlockTextures.values()) - et.registerIcon( ev.map ); - - for (CableBusTextures cb : CableBusTextures.values()) - cb.registerIcon( ev.map ); - } - } - - @Override - public World getWorld() - { - if ( Platform.isClient() ) - return Minecraft.getMinecraft().theWorld; - else - return super.getWorld(); - } - - @Override - public void bindTileEntitySpecialRenderer(Class tile, AEBaseBlock blk) - { - BaseBlockRender bbr = blk.getRendererInstance().rendererInstance; - if ( bbr.hasTESR && tile != null ) - ClientRegistry.bindTileEntitySpecialRenderer( tile, new TESRWrapper( bbr ) ); - } - - @Override - public List getPlayers() - { - if ( Platform.isClient() ) - { - List o = new ArrayList(); - o.add( Minecraft.getMinecraft().thePlayer ); - return o; - } - else - return super.getPlayers(); - } - - @Override - public void spawnEffect(EffectType effect, World worldObj, double posX, double posY, double posZ, Object o) - { - if ( AEConfig.instance.enableEffects ) - { - switch (effect) - { - case Assembler: - spawnAssembler( worldObj, posX, posY, posZ, o ); - return; - case Vibrant: - spawnVibrant( worldObj, posX, posY, posZ ); - return; - case Crafting: - spawnCrafting( worldObj, posX, posY, posZ ); - return; - case Energy: - spawnEnergy( worldObj, posX, posY, posZ ); - return; - case Lightning: - spawnLightning( worldObj, posX, posY, posZ ); - return; - case LightningArc: - spawnLightningArc( worldObj, posX, posY, posZ, (Vec3) o ); - return; - } - } - } - - private void spawnAssembler(World worldObj, double posX, double posY, double posZ, Object o) - { - PacketAssemblerAnimation paa = (PacketAssemblerAnimation) o; - - AssemblerFX fx = new AssemblerFX( Minecraft.getMinecraft().theWorld, posX, posY, posZ, 0.0D, 0.0D, 0.0D, paa.rate, paa.is ); - Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); - } - - private void spawnVibrant(World w, double x, double y, double z) - { - if ( CommonHelper.proxy.shouldAddParticles( Platform.getRandom() ) ) - { - double d0 = (double) (Platform.getRandomFloat() - 0.5F) * 0.26D; - double d1 = (double) (Platform.getRandomFloat() - 0.5F) * 0.26D; - double d2 = (double) (Platform.getRandomFloat() - 0.5F) * 0.26D; - - VibrantFX fx = new VibrantFX( w, x + d0, y + d1, z + d2, 0.0D, 0.0D, 0.0D ); - Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); - } - } - - private void spawnLightningArc(World worldObj, double posX, double posY, double posZ, Vec3 second) - { - LightningFX fx = new LightningArcFX( worldObj, posX, posY, posZ, second.xCoord, second.yCoord, second.zCoord, 0.0f, 0.0f, 0.0f ); - Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); - } - - private void spawnLightning(World worldObj, double posX, double posY, double posZ) - { - LightningFX fx = new LightningFX( worldObj, posX, posY + 0.3f, posZ, 0.0f, 0.0f, 0.0f ); - Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); - } - - private void spawnEnergy(World w, double posX, double posY, double posZ) - { - float x = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; - float y = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; - float z = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; - - EnergyFx fx = new EnergyFx( w, posX + x, posY + y, posZ + z, Items.diamond ); - - fx.motionX = -x * 0.1; - fx.motionY = -y * 0.1; - fx.motionZ = -z * 0.1; - - Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); - } - - private void spawnCrafting(World w, double posX, double posY, double posZ) - { - float x = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; - float y = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; - float z = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; - - CraftingFx fx = new CraftingFx( w, posX + x, posY + y, posZ + z, Items.diamond ); - - fx.motionX = -x * 0.2; - fx.motionY = -y * 0.2; - fx.motionZ = -z * 0.2; - - Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); - } - - @Override - public boolean shouldAddParticles(Random r) - { - int setting = Minecraft.getMinecraft().gameSettings.particleSetting; - if ( setting == 2 ) - return false; - if ( setting == 0 ) - return true; - return r.nextInt( 2 * (setting + 1) ) == 0; - } - - @Override - public MovingObjectPosition getMOP() - { - return Minecraft.getMinecraft().objectMouseOver; - } - - @Override - public void missingCoreMod() - { - throw new MissingCoreMod(); - } - +package appeng.client; + +import static net.minecraftforge.client.IItemRenderer.ItemRenderType.ENTITY; +import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.BLOCK_3D; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.client.event.MouseEvent; +import net.minecraftforge.client.event.RenderLivingEvent; +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.common.MinecraftForge; + +import org.lwjgl.opengl.GL11; + +import appeng.api.parts.CableRenderMode; +import appeng.api.util.AEColor; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.TESRWrapper; +import appeng.client.render.WorldRender; +import appeng.client.render.effects.AssemblerFX; +import appeng.client.render.effects.CraftingFx; +import appeng.client.render.effects.EnergyFx; +import appeng.client.render.effects.LightningArcFX; +import appeng.client.render.effects.LightningFX; +import appeng.client.render.effects.VibrantFX; +import appeng.client.texture.CableBusTextures; +import appeng.client.texture.ExtraBlockTextures; +import appeng.client.texture.ExtraItemTextures; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.CommonHelper; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketAssemblerAnimation; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.entity.EntityFloatingItem; +import appeng.entity.EntityTinyTNTPrimed; +import appeng.entity.RenderFloatingItem; +import appeng.entity.RenderTinyTNTPrimed; +import appeng.helpers.IMouseWheelItem; +import appeng.hooks.TickHandler; +import appeng.hooks.TickHandler.PlayerColor; +import appeng.server.ServerHelper; +import appeng.transformer.MissingCoreMod; +import appeng.util.Platform; +import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.client.registry.RenderingRegistry; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class ClientHelper extends ServerHelper +{ + + private static RenderItem itemRenderer = new RenderItem(); + private static RenderBlocks blockRenderer = new RenderBlocks(); + + @Override + public CableRenderMode getRenderMode() + { + if ( Platform.isServer() ) + return super.getRenderMode(); + + Minecraft mc = Minecraft.getMinecraft(); + EntityPlayer player = mc.thePlayer; + + return renderModeForPlayer( player ); + } + + @Override + public void triggerUpdates() + { + Minecraft mc = Minecraft.getMinecraft(); + if ( mc == null || mc.thePlayer == null || mc.theWorld == null ) + return; + + EntityPlayer player = mc.thePlayer; + + if ( player == null ) + return; + + int x = (int) player.posX; + int y = (int) player.posY; + int z = (int) player.posZ; + + int range = 16 * 16; + + mc.theWorld.markBlockRangeForRenderUpdate( x - range, y - range, z - range, x + range, y + range, z + range ); + } + + @SubscribeEvent + public void postPlayerRender(RenderLivingEvent.Pre p) + { + PlayerColor player = TickHandler.instance.getPlayerColors().get( p.entity.getEntityId() ); + if ( player != null ) + { + AEColor col = player.myColor; + + float r = (float) (0xff & (col.mediumVariant >> 16)); + float g = (float) (0xff & (col.mediumVariant >> 8)); + float b = (float) (0xff & (col.mediumVariant)); + GL11.glColor3f( r / 255.0f, g / 255.0f, b / 255.0f ); + } + } + + @Override + public void doRenderItem(ItemStack itemstack, World w) + { + if ( itemstack != null ) + { + EntityItem entityitem = new EntityItem( w, 0.0D, 0.0D, 0.0D, itemstack ); + entityitem.getEntityItem().stackSize = 1; + + // set all this stuff and then do shit? meh? + entityitem.hoverStart = 0; + entityitem.age = 0; + entityitem.rotationYaw = 0; + + GL11.glPushMatrix(); + GL11.glTranslatef( 0, -0.04F, 0 ); + GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); + // GL11.glDisable( GL11.GL_CULL_FACE ); + + if ( itemstack.isItemEnchanted() || itemstack.getItem().requiresMultipleRenderPasses() ) + { + GL11.glTranslatef( 0.0f, -0.05f, -0.25f ); + GL11.glScalef( 1.0f / 1.5f, 1.0f / 1.5f, 1.0f / 1.5f ); + // GL11.glTranslated( -8.0, -12.2, -10.6 ); + GL11.glScalef( 1.0f, -1.0f, 0.005f ); + // GL11.glScalef( 1.0f , -1.0f, 1.0f ); + + Block block = Block.getBlockFromItem( itemstack.getItem() ); + if ( (itemstack.getItemSpriteNumber() == 0 && block != null && RenderBlocks.renderItemIn3d( block.getRenderType() )) ) + { + GL11.glRotatef( 25.0f, 1.0f, 0.0f, 0.0f ); + GL11.glRotatef( 15.0f, 0.0f, 1.0f, 0.0f ); + GL11.glRotatef( 30.0f, 0.0f, 1.0f, 0.0f ); + } + + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer( itemstack, ENTITY ); + if ( customRenderer != null && !(itemstack.getItem() instanceof ItemBlock) ) + { + if ( customRenderer.shouldUseRenderHelper( ENTITY, itemstack, BLOCK_3D ) ) + { + GL11.glTranslatef( 0, -0.04F, 0 ); + GL11.glScalef( 0.7f, 0.7f, 0.7f ); + GL11.glRotatef( 35, 1, 0, 0 ); + GL11.glRotatef( 45, 0, 1, 0 ); + GL11.glRotatef( -90, 0, 1, 0 ); + } + } + else if ( itemstack.getItem() instanceof ItemBlock ) + { + GL11.glTranslatef( 0, -0.04F, 0 ); + GL11.glScalef( 1.1f, 1.1f, 1.1f ); + GL11.glRotatef( -90, 0, 1, 0 ); + } + else + { + GL11.glTranslatef( 0, -0.14F, 0 ); + GL11.glScalef( 0.8f, 0.8f, 0.8f ); + } + + RenderItem.renderInFrame = true; + RenderManager.instance.renderEntityWithPosYaw( entityitem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F ); + RenderItem.renderInFrame = false; + } + else + { + GL11.glScalef( 1.0f / 42.0f, 1.0f / 42.0f, 1.0f / 42.0f ); + GL11.glTranslated( -8.0, -10.2, -10.4 ); + GL11.glScalef( 1.0f, 1.0f, 0.005f ); + + RenderItem.renderInFrame = false; + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + if ( !ForgeHooksClient.renderInventoryItem( blockRenderer, Minecraft.getMinecraft().renderEngine, itemstack, true, 0, (float) 0, (float) 0 ) ) + { + itemRenderer.renderItemIntoGUI( fr, Minecraft.getMinecraft().renderEngine, itemstack, 0, 0, false ); + } + } + + GL11.glPopMatrix(); + } + } + + @Override + public void init() + { + MinecraftForge.EVENT_BUS.register( this ); + } + + @Override + public void postinit() + { + RenderingRegistry.registerBlockHandler( WorldRender.instance ); + RenderManager.instance.entityRenderMap.put( EntityTinyTNTPrimed.class, new RenderTinyTNTPrimed() ); + RenderManager.instance.entityRenderMap.put( EntityFloatingItem.class, new RenderFloatingItem() ); + } + + @SubscribeEvent + public void wheelEvent(MouseEvent me) + { + if ( me.isCanceled() || me.dwheel == 0 ) + return; + + Minecraft mc = Minecraft.getMinecraft(); + EntityPlayer player = mc.thePlayer; + ItemStack is = player.getHeldItem(); + + if ( is != null && is.getItem() instanceof IMouseWheelItem && player.isSneaking() ) + { + try + { + NetworkHandler.instance.sendToServer( new PacketValueConfig( "Item", me.dwheel > 0 ? "WheelUp" : "WheelDown" ) ); + me.setCanceled( true ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + } + + @SubscribeEvent + public void updateTextureSheet(TextureStitchEvent.Pre ev) + { + if ( ev.map.getTextureType() == 1 ) + { + for (ExtraItemTextures et : ExtraItemTextures.values()) + et.registerIcon( ev.map ); + } + + if ( ev.map.getTextureType() == 0 ) + { + for (ExtraBlockTextures et : ExtraBlockTextures.values()) + et.registerIcon( ev.map ); + + for (CableBusTextures cb : CableBusTextures.values()) + cb.registerIcon( ev.map ); + } + } + + @Override + public World getWorld() + { + if ( Platform.isClient() ) + return Minecraft.getMinecraft().theWorld; + else + return super.getWorld(); + } + + @Override + public void bindTileEntitySpecialRenderer(Class tile, AEBaseBlock blk) + { + BaseBlockRender bbr = blk.getRendererInstance().rendererInstance; + if ( bbr.hasTESR && tile != null ) + ClientRegistry.bindTileEntitySpecialRenderer( tile, new TESRWrapper( bbr ) ); + } + + @Override + public List getPlayers() + { + if ( Platform.isClient() ) + { + List o = new ArrayList(); + o.add( Minecraft.getMinecraft().thePlayer ); + return o; + } + else + return super.getPlayers(); + } + + @Override + public void spawnEffect(EffectType effect, World worldObj, double posX, double posY, double posZ, Object o) + { + if ( AEConfig.instance.enableEffects ) + { + switch (effect) + { + case Assembler: + spawnAssembler( worldObj, posX, posY, posZ, o ); + return; + case Vibrant: + spawnVibrant( worldObj, posX, posY, posZ ); + return; + case Crafting: + spawnCrafting( worldObj, posX, posY, posZ ); + return; + case Energy: + spawnEnergy( worldObj, posX, posY, posZ ); + return; + case Lightning: + spawnLightning( worldObj, posX, posY, posZ ); + return; + case LightningArc: + spawnLightningArc( worldObj, posX, posY, posZ, (Vec3) o ); + return; + } + } + } + + private void spawnAssembler(World worldObj, double posX, double posY, double posZ, Object o) + { + PacketAssemblerAnimation paa = (PacketAssemblerAnimation) o; + + AssemblerFX fx = new AssemblerFX( Minecraft.getMinecraft().theWorld, posX, posY, posZ, 0.0D, 0.0D, 0.0D, paa.rate, paa.is ); + Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); + } + + private void spawnVibrant(World w, double x, double y, double z) + { + if ( CommonHelper.proxy.shouldAddParticles( Platform.getRandom() ) ) + { + double d0 = (double) (Platform.getRandomFloat() - 0.5F) * 0.26D; + double d1 = (double) (Platform.getRandomFloat() - 0.5F) * 0.26D; + double d2 = (double) (Platform.getRandomFloat() - 0.5F) * 0.26D; + + VibrantFX fx = new VibrantFX( w, x + d0, y + d1, z + d2, 0.0D, 0.0D, 0.0D ); + Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); + } + } + + private void spawnLightningArc(World worldObj, double posX, double posY, double posZ, Vec3 second) + { + LightningFX fx = new LightningArcFX( worldObj, posX, posY, posZ, second.xCoord, second.yCoord, second.zCoord, 0.0f, 0.0f, 0.0f ); + Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); + } + + private void spawnLightning(World worldObj, double posX, double posY, double posZ) + { + LightningFX fx = new LightningFX( worldObj, posX, posY + 0.3f, posZ, 0.0f, 0.0f, 0.0f ); + Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); + } + + private void spawnEnergy(World w, double posX, double posY, double posZ) + { + float x = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; + float y = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; + float z = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; + + EnergyFx fx = new EnergyFx( w, posX + x, posY + y, posZ + z, Items.diamond ); + + fx.motionX = -x * 0.1; + fx.motionY = -y * 0.1; + fx.motionZ = -z * 0.1; + + Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); + } + + private void spawnCrafting(World w, double posX, double posY, double posZ) + { + float x = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; + float y = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; + float z = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f; + + CraftingFx fx = new CraftingFx( w, posX + x, posY + y, posZ + z, Items.diamond ); + + fx.motionX = -x * 0.2; + fx.motionY = -y * 0.2; + fx.motionZ = -z * 0.2; + + Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx ); + } + + @Override + public boolean shouldAddParticles(Random r) + { + int setting = Minecraft.getMinecraft().gameSettings.particleSetting; + if ( setting == 2 ) + return false; + if ( setting == 0 ) + return true; + return r.nextInt( 2 * (setting + 1) ) == 0; + } + + @Override + public MovingObjectPosition getMOP() + { + return Minecraft.getMinecraft().objectMouseOver; + } + + @Override + public void missingCoreMod() + { + throw new MissingCoreMod(); + } + } \ No newline at end of file diff --git a/client/EffectType.java b/src/main/java/appeng/client/EffectType.java similarity index 100% rename from client/EffectType.java rename to src/main/java/appeng/client/EffectType.java diff --git a/client/gui/AEBaseGui.java b/src/main/java/appeng/client/gui/AEBaseGui.java similarity index 100% rename from client/gui/AEBaseGui.java rename to src/main/java/appeng/client/gui/AEBaseGui.java diff --git a/client/gui/AEBaseMEGui.java b/src/main/java/appeng/client/gui/AEBaseMEGui.java similarity index 96% rename from client/gui/AEBaseMEGui.java rename to src/main/java/appeng/client/gui/AEBaseMEGui.java index 6e85703c6..9c1a7027c 100644 --- a/client/gui/AEBaseMEGui.java +++ b/src/main/java/appeng/client/gui/AEBaseMEGui.java @@ -1,103 +1,103 @@ -package appeng.client.gui; - -import java.text.NumberFormat; -import java.util.List; -import java.util.Locale; - -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.me.SlotME; -import appeng.core.AEConfig; - -public abstract class AEBaseMEGui extends AEBaseGui -{ - - public AEBaseMEGui(Container container) { - super( container ); - } - - public List handleItemTooltip(ItemStack stack, int mousex, int mousey, List currenttip) - { - if ( stack != null ) - { - Slot s = getSlot( mousex, mousey ); - if ( s instanceof SlotME ) - { - int BigNumber = AEConfig.instance.useTerminalUseLargeFont() ? 999 : 9999; - - IAEItemStack myStack = null; - - try - { - SlotME theSlotField = (SlotME) s; - myStack = theSlotField.getAEStack(); - } - catch (Throwable ignore) - { - } - - if ( myStack != null ) - { - if ( myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged()) ) - currenttip.add( "\u00a77Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getStackSize() ) ); - - if ( myStack.getCountRequestable() > 0 ) - currenttip.add( "\u00a77Items Requestable: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getCountRequestable() ) ); - } - else if ( stack.stackSize > BigNumber || (stack.stackSize > 1 && stack.isItemDamaged()) ) - { - currenttip.add( "\u00a77Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( stack.stackSize ) ); - } - } - } - return currenttip; - } - - // Vanilla version... - // protected void drawItemStackTooltip(ItemStack stack, int x, int y) - @Override - protected void renderToolTip(ItemStack stack, int x, int y) - { - Slot s = getSlot( x, y ); - if ( s instanceof SlotME && stack != null ) - { - int BigNumber = AEConfig.instance.useTerminalUseLargeFont() ? 999 : 9999; - - IAEItemStack myStack = null; - - try - { - SlotME theSlotField = (SlotME) s; - myStack = theSlotField.getAEStack(); - } - catch (Throwable ignore) - { - } - - if ( myStack != null ) - { - List currenttip = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips ); - - if ( myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged()) ) - currenttip.add( "Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getStackSize() ) ); - - if ( myStack.getCountRequestable() > 0 ) - currenttip.add( "Items Requestable: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getCountRequestable() ) ); - - drawTooltip( x, y, 0, join( currenttip, "\n" ) ); - } - else if ( stack != null && stack.stackSize > BigNumber ) - { - List var4 = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips ); - var4.add( "Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( stack.stackSize ) ); - drawTooltip( x, y, 0, join( var4, "\n" ) ); - return; - } - } - super.renderToolTip( stack, x, y ); - // super.drawItemStackTooltip( stack, x, y ); - } - +package appeng.client.gui; + +import java.text.NumberFormat; +import java.util.List; +import java.util.Locale; + +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.client.me.SlotME; +import appeng.core.AEConfig; + +public abstract class AEBaseMEGui extends AEBaseGui +{ + + public AEBaseMEGui(Container container) { + super( container ); + } + + public List handleItemTooltip(ItemStack stack, int mousex, int mousey, List currenttip) + { + if ( stack != null ) + { + Slot s = getSlot( mousex, mousey ); + if ( s instanceof SlotME ) + { + int BigNumber = AEConfig.instance.useTerminalUseLargeFont() ? 999 : 9999; + + IAEItemStack myStack = null; + + try + { + SlotME theSlotField = (SlotME) s; + myStack = theSlotField.getAEStack(); + } + catch (Throwable ignore) + { + } + + if ( myStack != null ) + { + if ( myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged()) ) + currenttip.add( "\u00a77Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getStackSize() ) ); + + if ( myStack.getCountRequestable() > 0 ) + currenttip.add( "\u00a77Items Requestable: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getCountRequestable() ) ); + } + else if ( stack.stackSize > BigNumber || (stack.stackSize > 1 && stack.isItemDamaged()) ) + { + currenttip.add( "\u00a77Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( stack.stackSize ) ); + } + } + } + return currenttip; + } + + // Vanilla version... + // protected void drawItemStackTooltip(ItemStack stack, int x, int y) + @Override + protected void renderToolTip(ItemStack stack, int x, int y) + { + Slot s = getSlot( x, y ); + if ( s instanceof SlotME && stack != null ) + { + int BigNumber = AEConfig.instance.useTerminalUseLargeFont() ? 999 : 9999; + + IAEItemStack myStack = null; + + try + { + SlotME theSlotField = (SlotME) s; + myStack = theSlotField.getAEStack(); + } + catch (Throwable ignore) + { + } + + if ( myStack != null ) + { + List currenttip = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips ); + + if ( myStack.getStackSize() > BigNumber || (myStack.getStackSize() > 1 && stack.isItemDamaged()) ) + currenttip.add( "Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getStackSize() ) ); + + if ( myStack.getCountRequestable() > 0 ) + currenttip.add( "Items Requestable: " + NumberFormat.getNumberInstance( Locale.US ).format( myStack.getCountRequestable() ) ); + + drawTooltip( x, y, 0, join( currenttip, "\n" ) ); + } + else if ( stack != null && stack.stackSize > BigNumber ) + { + List var4 = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips ); + var4.add( "Items Stored: " + NumberFormat.getNumberInstance( Locale.US ).format( stack.stackSize ) ); + drawTooltip( x, y, 0, join( var4, "\n" ) ); + return; + } + } + super.renderToolTip( stack, x, y ); + // super.drawItemStackTooltip( stack, x, y ); + } + } \ No newline at end of file diff --git a/client/gui/GuiNull.java b/src/main/java/appeng/client/gui/GuiNull.java similarity index 93% rename from client/gui/GuiNull.java rename to src/main/java/appeng/client/gui/GuiNull.java index f23cfea5c..ead16965b 100644 --- a/client/gui/GuiNull.java +++ b/src/main/java/appeng/client/gui/GuiNull.java @@ -1,23 +1,23 @@ -package appeng.client.gui; - -import net.minecraft.inventory.Container; - -public class GuiNull extends AEBaseGui -{ - - public GuiNull(Container container) { - super( container ); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - } - -} +package appeng.client.gui; + +import net.minecraft.inventory.Container; + +public class GuiNull extends AEBaseGui +{ + + public GuiNull(Container container) { + super( container ); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + } + +} diff --git a/client/gui/config/AEConfigGui.java b/src/main/java/appeng/client/gui/config/AEConfigGui.java similarity index 100% rename from client/gui/config/AEConfigGui.java rename to src/main/java/appeng/client/gui/config/AEConfigGui.java diff --git a/client/gui/config/AEConfigGuiFactory.java b/src/main/java/appeng/client/gui/config/AEConfigGuiFactory.java similarity index 100% rename from client/gui/config/AEConfigGuiFactory.java rename to src/main/java/appeng/client/gui/config/AEConfigGuiFactory.java diff --git a/client/gui/implementations/GuiCellWorkbench.java b/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java similarity index 96% rename from client/gui/implementations/GuiCellWorkbench.java rename to src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java index 823e6ae9d..225984db6 100644 --- a/client/gui/implementations/GuiCellWorkbench.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java @@ -1,178 +1,178 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -import org.lwjgl.input.Mouse; - -import appeng.api.config.ActionItems; -import appeng.api.config.CopyMode; -import appeng.api.config.FuzzyMode; -import appeng.api.config.Settings; -import appeng.api.config.Upgrades; -import appeng.api.implementations.items.IUpgradeModule; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiToggleButton; -import appeng.container.implementations.ContainerCellWorkbench; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.tile.misc.TileCellWorkbench; -import appeng.util.Platform; - -public class GuiCellWorkbench extends GuiUpgradeable -{ - - ContainerCellWorkbench ccwb; - TileCellWorkbench tcw; - - GuiImgButton clear; - GuiImgButton partition; - GuiToggleButton copyMode; - - public GuiCellWorkbench(InventoryPlayer inventoryPlayer, TileCellWorkbench te) { - super( new ContainerCellWorkbench( inventoryPlayer, te ) ); - ccwb = (ContainerCellWorkbench) inventorySlots; - ySize = 251; - tcw = te; - } - - @Override - protected boolean drawUpgrades() - { - return ccwb.availableUpgrades() > 0; - } - - @Override - public void initGui() - { - super.initGui(); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - handleButtonVisibility(); - - bindTexture( getBackground() ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, 211 - 34, ySize ); - if ( drawUpgrades() ) - { - if ( ccwb.availableUpgrades() <= 8 ) - { - this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + ccwb.availableUpgrades() * 18 ); - this.drawTexturedModalRect( offsetX + 177, offsetY + (7 + (ccwb.availableUpgrades()) * 18), 177, 151, 35, 7 ); - } - else if ( ccwb.availableUpgrades() <= 16 ) - { - this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + 8 * 18 ); - this.drawTexturedModalRect( offsetX + 177, offsetY + (7 + (8) * 18), 177, 151, 35, 7 ); - - int dx = ccwb.availableUpgrades() - 8; - this.drawTexturedModalRect( offsetX + 177 + 27, offsetY, 186, 0, 35 - 8, 7 + dx * 18 ); - if ( dx == 8 ) - this.drawTexturedModalRect( offsetX + 177 + 27, offsetY + (7 + (dx) * 18), 186, 151, 35 - 8, 7 ); - else - this.drawTexturedModalRect( offsetX + 177 + 27 + 4, offsetY + (7 + (dx) * 18), 186 + 4, 151, 35 - 8, 7 ); - - } - else - { - this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + 8 * 18 ); - this.drawTexturedModalRect( offsetX + 177, offsetY + (7 + (8) * 18), 177, 151, 35, 7 ); - - this.drawTexturedModalRect( offsetX + 177 + 27, offsetY, 186, 0, 35 - 8, 7 + 8 * 18 ); - this.drawTexturedModalRect( offsetX + 177 + 27, offsetY + (7 + (8) * 18), 186, 151, 35 - 8, 7 ); - - int dx = ccwb.availableUpgrades() - 16; - this.drawTexturedModalRect( offsetX + 177 + 27 + 18, offsetY, 186, 0, 35 - 8, 7 + dx * 18 ); - if ( dx == 8 ) - this.drawTexturedModalRect( offsetX + 177 + 27 + 18, offsetY + (7 + (dx) * 18), 186, 151, 35 - 8, 7 ); - else - this.drawTexturedModalRect( offsetX + 177 + 27 + 18 + 4, offsetY + (7 + (dx) * 18), 186 + 4, 151, 35 - 8, 7 ); - } - } - if ( hasToolbox() ) - this.drawTexturedModalRect( offsetX + 178, offsetY + ySize - 90, 178, 161, 68, 68 ); - } - - @Override - protected void actionPerformed(GuiButton btn) - { - try - { - if ( btn == copyMode ) - { - NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "CopyMode" ) ); - } - else if ( btn == partition ) - { - NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Partition" ) ); - } - else if ( btn == clear ) - { - NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Clear" ) ); - } - else if ( btn == fuzzyMode ) - { - boolean backwards = Mouse.isButtonDown( 1 ); - - FuzzyMode fz = (FuzzyMode) fuzzyMode.getCurrentValue(); - fz = Platform.rotateEnum( fz, backwards, Settings.FUZZY_MODE.getPossibleValues() ); - - NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Fuzzy", fz.name() ) ); - } - else - super.actionPerformed( btn ); - } - catch (IOException err) - { - } - } - - @Override - protected void addButtons() - { - clear = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE ); - partition = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH ); - copyMode = new GuiToggleButton( this.guiLeft - 18, guiTop + 48, 11 * 16 + 5, 12 * 16 + 5, GuiText.CopyMode.getLocal(), GuiText.CopyModeDesc.getLocal() ); - fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 68, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); - - buttonList.add( fuzzyMode ); - buttonList.add( partition ); - buttonList.add( clear ); - buttonList.add( copyMode ); - } - - protected void handleButtonVisibility() - { - copyMode.setState( ccwb.copyMode == CopyMode.CLEAR_ON_REMOVE ); - - boolean hasFuzzy = false; - IInventory inv = ccwb.getCellUpgradeInventory(); - for (int x = 0; x < inv.getSizeInventory(); x++) - { - ItemStack is = inv.getStackInSlot( x ); - if ( is != null && is.getItem() instanceof IUpgradeModule ) - { - if ( ((IUpgradeModule) is.getItem()).getType( is ) == Upgrades.FUZZY ) - hasFuzzy = true; - } - } - fuzzyMode.setVisibility( hasFuzzy ); - } - - protected String getBackground() - { - return "guis/cellworkbench.png"; - } - - protected GuiText getName() - { - return GuiText.CellWorkbench; - } -} +package appeng.client.gui.implementations; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import org.lwjgl.input.Mouse; + +import appeng.api.config.ActionItems; +import appeng.api.config.CopyMode; +import appeng.api.config.FuzzyMode; +import appeng.api.config.Settings; +import appeng.api.config.Upgrades; +import appeng.api.implementations.items.IUpgradeModule; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiToggleButton; +import appeng.container.implementations.ContainerCellWorkbench; +import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.tile.misc.TileCellWorkbench; +import appeng.util.Platform; + +public class GuiCellWorkbench extends GuiUpgradeable +{ + + ContainerCellWorkbench ccwb; + TileCellWorkbench tcw; + + GuiImgButton clear; + GuiImgButton partition; + GuiToggleButton copyMode; + + public GuiCellWorkbench(InventoryPlayer inventoryPlayer, TileCellWorkbench te) { + super( new ContainerCellWorkbench( inventoryPlayer, te ) ); + ccwb = (ContainerCellWorkbench) inventorySlots; + ySize = 251; + tcw = te; + } + + @Override + protected boolean drawUpgrades() + { + return ccwb.availableUpgrades() > 0; + } + + @Override + public void initGui() + { + super.initGui(); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + handleButtonVisibility(); + + bindTexture( getBackground() ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, 211 - 34, ySize ); + if ( drawUpgrades() ) + { + if ( ccwb.availableUpgrades() <= 8 ) + { + this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + ccwb.availableUpgrades() * 18 ); + this.drawTexturedModalRect( offsetX + 177, offsetY + (7 + (ccwb.availableUpgrades()) * 18), 177, 151, 35, 7 ); + } + else if ( ccwb.availableUpgrades() <= 16 ) + { + this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + 8 * 18 ); + this.drawTexturedModalRect( offsetX + 177, offsetY + (7 + (8) * 18), 177, 151, 35, 7 ); + + int dx = ccwb.availableUpgrades() - 8; + this.drawTexturedModalRect( offsetX + 177 + 27, offsetY, 186, 0, 35 - 8, 7 + dx * 18 ); + if ( dx == 8 ) + this.drawTexturedModalRect( offsetX + 177 + 27, offsetY + (7 + (dx) * 18), 186, 151, 35 - 8, 7 ); + else + this.drawTexturedModalRect( offsetX + 177 + 27 + 4, offsetY + (7 + (dx) * 18), 186 + 4, 151, 35 - 8, 7 ); + + } + else + { + this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + 8 * 18 ); + this.drawTexturedModalRect( offsetX + 177, offsetY + (7 + (8) * 18), 177, 151, 35, 7 ); + + this.drawTexturedModalRect( offsetX + 177 + 27, offsetY, 186, 0, 35 - 8, 7 + 8 * 18 ); + this.drawTexturedModalRect( offsetX + 177 + 27, offsetY + (7 + (8) * 18), 186, 151, 35 - 8, 7 ); + + int dx = ccwb.availableUpgrades() - 16; + this.drawTexturedModalRect( offsetX + 177 + 27 + 18, offsetY, 186, 0, 35 - 8, 7 + dx * 18 ); + if ( dx == 8 ) + this.drawTexturedModalRect( offsetX + 177 + 27 + 18, offsetY + (7 + (dx) * 18), 186, 151, 35 - 8, 7 ); + else + this.drawTexturedModalRect( offsetX + 177 + 27 + 18 + 4, offsetY + (7 + (dx) * 18), 186 + 4, 151, 35 - 8, 7 ); + } + } + if ( hasToolbox() ) + this.drawTexturedModalRect( offsetX + 178, offsetY + ySize - 90, 178, 161, 68, 68 ); + } + + @Override + protected void actionPerformed(GuiButton btn) + { + try + { + if ( btn == copyMode ) + { + NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "CopyMode" ) ); + } + else if ( btn == partition ) + { + NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Partition" ) ); + } + else if ( btn == clear ) + { + NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Clear" ) ); + } + else if ( btn == fuzzyMode ) + { + boolean backwards = Mouse.isButtonDown( 1 ); + + FuzzyMode fz = (FuzzyMode) fuzzyMode.getCurrentValue(); + fz = Platform.rotateEnum( fz, backwards, Settings.FUZZY_MODE.getPossibleValues() ); + + NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Fuzzy", fz.name() ) ); + } + else + super.actionPerformed( btn ); + } + catch (IOException err) + { + } + } + + @Override + protected void addButtons() + { + clear = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE ); + partition = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH ); + copyMode = new GuiToggleButton( this.guiLeft - 18, guiTop + 48, 11 * 16 + 5, 12 * 16 + 5, GuiText.CopyMode.getLocal(), GuiText.CopyModeDesc.getLocal() ); + fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 68, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); + + buttonList.add( fuzzyMode ); + buttonList.add( partition ); + buttonList.add( clear ); + buttonList.add( copyMode ); + } + + protected void handleButtonVisibility() + { + copyMode.setState( ccwb.copyMode == CopyMode.CLEAR_ON_REMOVE ); + + boolean hasFuzzy = false; + IInventory inv = ccwb.getCellUpgradeInventory(); + for (int x = 0; x < inv.getSizeInventory(); x++) + { + ItemStack is = inv.getStackInSlot( x ); + if ( is != null && is.getItem() instanceof IUpgradeModule ) + { + if ( ((IUpgradeModule) is.getItem()).getType( is ) == Upgrades.FUZZY ) + hasFuzzy = true; + } + } + fuzzyMode.setVisibility( hasFuzzy ); + } + + protected String getBackground() + { + return "guis/cellworkbench.png"; + } + + protected GuiText getName() + { + return GuiText.CellWorkbench; + } +} diff --git a/client/gui/implementations/GuiChest.java b/src/main/java/appeng/client/gui/implementations/GuiChest.java similarity index 96% rename from client/gui/implementations/GuiChest.java rename to src/main/java/appeng/client/gui/implementations/GuiChest.java index fb7bd9d3c..3647cc7c7 100644 --- a/client/gui/implementations/GuiChest.java +++ b/src/main/java/appeng/client/gui/implementations/GuiChest.java @@ -1,67 +1,67 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.container.implementations.ContainerChest; -import appeng.core.AELog; -import appeng.core.localization.GuiText; -import appeng.core.sync.GuiBridge; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.tile.storage.TileChest; - -public class GuiChest extends AEBaseGui -{ - - GuiTabButton priority; - - @Override - protected void actionPerformed(GuiButton par1GuiButton) - { - super.actionPerformed( par1GuiButton ); - - if ( par1GuiButton == priority ) - { - try - { - NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - } - - @Override - public void initGui() - { - super.initGui(); - - buttonList.add( priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), itemRender ) ); - } - - public GuiChest(InventoryPlayer inventoryPlayer, TileChest te) { - super( new ContainerChest( inventoryPlayer, te ) ); - this.ySize = 166; - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/chest.png" ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( GuiText.Chest.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - } - -} +package appeng.client.gui.implementations; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiTabButton; +import appeng.container.implementations.ContainerChest; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.GuiBridge; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketSwitchGuis; +import appeng.tile.storage.TileChest; + +public class GuiChest extends AEBaseGui +{ + + GuiTabButton priority; + + @Override + protected void actionPerformed(GuiButton par1GuiButton) + { + super.actionPerformed( par1GuiButton ); + + if ( par1GuiButton == priority ) + { + try + { + NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + } + + @Override + public void initGui() + { + super.initGui(); + + buttonList.add( priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), itemRender ) ); + } + + public GuiChest(InventoryPlayer inventoryPlayer, TileChest te) { + super( new ContainerChest( inventoryPlayer, te ) ); + this.ySize = 166; + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/chest.png" ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( GuiText.Chest.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + } + +} diff --git a/client/gui/implementations/GuiCondenser.java b/src/main/java/appeng/client/gui/implementations/GuiCondenser.java similarity index 96% rename from client/gui/implementations/GuiCondenser.java rename to src/main/java/appeng/client/gui/implementations/GuiCondenser.java index 80120fb61..aef2349d6 100644 --- a/client/gui/implementations/GuiCondenser.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCondenser.java @@ -1,90 +1,90 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.input.Mouse; - -import appeng.api.config.Settings; -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiProgressBar; -import appeng.client.gui.widgets.GuiProgressBar.Direction; -import appeng.container.implementations.ContainerCondenser; -import appeng.core.AELog; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketConfigButton; -import appeng.tile.misc.TileCondenser; - -public class GuiCondenser extends AEBaseGui -{ - - ContainerCondenser cvc; - GuiProgressBar pb; - GuiImgButton mode; - - public GuiCondenser(InventoryPlayer inventoryPlayer, TileCondenser te) { - super( new ContainerCondenser( inventoryPlayer, te ) ); - cvc = (ContainerCondenser) inventorySlots; - this.ySize = 197; - } - - @Override - protected void actionPerformed(GuiButton btn) - { - super.actionPerformed( btn ); - - boolean backwards = Mouse.isButtonDown( 1 ); - - if ( mode == btn ) - { - try - { - NetworkHandler.instance.sendToServer( new PacketConfigButton( Settings.CONDENSER_OUTPUT, backwards ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - } - - @Override - public void initGui() - { - super.initGui(); - - pb = new GuiProgressBar( "guis/condenser.png", 120 + guiLeft, 25 + guiTop, 178, 25, 6, 18, Direction.VERTICAL ); - pb.TitleName = GuiText.StoredEnergy.getLocal(); - - mode = new GuiImgButton( 128 + guiLeft, 52 + guiTop, Settings.CONDENSER_OUTPUT, cvc.output ); - - this.buttonList.add( pb ); - this.buttonList.add( mode ); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/condenser.png" ); - - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( GuiText.Condenser.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - - mode.set( cvc.output ); - mode.FillVar = "" + cvc.output.requiredPower; - - pb.max = (int) cvc.requiredEnergy; - pb.current = (int) cvc.storedPower; - } - -} +package appeng.client.gui.implementations; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; + +import org.lwjgl.input.Mouse; + +import appeng.api.config.Settings; +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiProgressBar; +import appeng.client.gui.widgets.GuiProgressBar.Direction; +import appeng.container.implementations.ContainerCondenser; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketConfigButton; +import appeng.tile.misc.TileCondenser; + +public class GuiCondenser extends AEBaseGui +{ + + ContainerCondenser cvc; + GuiProgressBar pb; + GuiImgButton mode; + + public GuiCondenser(InventoryPlayer inventoryPlayer, TileCondenser te) { + super( new ContainerCondenser( inventoryPlayer, te ) ); + cvc = (ContainerCondenser) inventorySlots; + this.ySize = 197; + } + + @Override + protected void actionPerformed(GuiButton btn) + { + super.actionPerformed( btn ); + + boolean backwards = Mouse.isButtonDown( 1 ); + + if ( mode == btn ) + { + try + { + NetworkHandler.instance.sendToServer( new PacketConfigButton( Settings.CONDENSER_OUTPUT, backwards ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + } + + @Override + public void initGui() + { + super.initGui(); + + pb = new GuiProgressBar( "guis/condenser.png", 120 + guiLeft, 25 + guiTop, 178, 25, 6, 18, Direction.VERTICAL ); + pb.TitleName = GuiText.StoredEnergy.getLocal(); + + mode = new GuiImgButton( 128 + guiLeft, 52 + guiTop, Settings.CONDENSER_OUTPUT, cvc.output ); + + this.buttonList.add( pb ); + this.buttonList.add( mode ); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/condenser.png" ); + + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( GuiText.Condenser.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + + mode.set( cvc.output ); + mode.FillVar = "" + cvc.output.requiredPower; + + pb.max = (int) cvc.requiredEnergy; + pb.current = (int) cvc.storedPower; + } + +} diff --git a/client/gui/implementations/GuiCraftAmount.java b/src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java similarity index 100% rename from client/gui/implementations/GuiCraftAmount.java rename to src/main/java/appeng/client/gui/implementations/GuiCraftAmount.java diff --git a/client/gui/implementations/GuiCraftConfirm.java b/src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java similarity index 100% rename from client/gui/implementations/GuiCraftConfirm.java rename to src/main/java/appeng/client/gui/implementations/GuiCraftConfirm.java diff --git a/client/gui/implementations/GuiCraftingCPU.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java similarity index 100% rename from client/gui/implementations/GuiCraftingCPU.java rename to src/main/java/appeng/client/gui/implementations/GuiCraftingCPU.java diff --git a/client/gui/implementations/GuiCraftingStatus.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java similarity index 100% rename from client/gui/implementations/GuiCraftingStatus.java rename to src/main/java/appeng/client/gui/implementations/GuiCraftingStatus.java diff --git a/client/gui/implementations/GuiCraftingTerm.java b/src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java similarity index 100% rename from client/gui/implementations/GuiCraftingTerm.java rename to src/main/java/appeng/client/gui/implementations/GuiCraftingTerm.java diff --git a/client/gui/implementations/GuiDrive.java b/src/main/java/appeng/client/gui/implementations/GuiDrive.java similarity index 96% rename from client/gui/implementations/GuiDrive.java rename to src/main/java/appeng/client/gui/implementations/GuiDrive.java index cf1d49200..ec5c41bb8 100644 --- a/client/gui/implementations/GuiDrive.java +++ b/src/main/java/appeng/client/gui/implementations/GuiDrive.java @@ -1,67 +1,67 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.container.implementations.ContainerDrive; -import appeng.core.AELog; -import appeng.core.localization.GuiText; -import appeng.core.sync.GuiBridge; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.tile.storage.TileDrive; - -public class GuiDrive extends AEBaseGui -{ - - GuiTabButton priority; - - @Override - protected void actionPerformed(GuiButton par1GuiButton) - { - super.actionPerformed( par1GuiButton ); - - if ( par1GuiButton == priority ) - { - try - { - NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - } - - @Override - public void initGui() - { - super.initGui(); - - buttonList.add( priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), itemRender ) ); - } - - public GuiDrive(InventoryPlayer inventoryPlayer, TileDrive te) { - super( new ContainerDrive( inventoryPlayer, te ) ); - this.ySize = 199; - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/drive.png" ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( GuiText.Drive.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - } - -} +package appeng.client.gui.implementations; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiTabButton; +import appeng.container.implementations.ContainerDrive; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.GuiBridge; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketSwitchGuis; +import appeng.tile.storage.TileDrive; + +public class GuiDrive extends AEBaseGui +{ + + GuiTabButton priority; + + @Override + protected void actionPerformed(GuiButton par1GuiButton) + { + super.actionPerformed( par1GuiButton ); + + if ( par1GuiButton == priority ) + { + try + { + NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + } + + @Override + public void initGui() + { + super.initGui(); + + buttonList.add( priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), itemRender ) ); + } + + public GuiDrive(InventoryPlayer inventoryPlayer, TileDrive te) { + super( new ContainerDrive( inventoryPlayer, te ) ); + this.ySize = 199; + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/drive.png" ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( GuiText.Drive.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + } + +} diff --git a/client/gui/implementations/GuiFormationPlane.java b/src/main/java/appeng/client/gui/implementations/GuiFormationPlane.java similarity index 100% rename from client/gui/implementations/GuiFormationPlane.java rename to src/main/java/appeng/client/gui/implementations/GuiFormationPlane.java diff --git a/client/gui/implementations/GuiGrinder.java b/src/main/java/appeng/client/gui/implementations/GuiGrinder.java similarity index 96% rename from client/gui/implementations/GuiGrinder.java rename to src/main/java/appeng/client/gui/implementations/GuiGrinder.java index e7c0b0fd4..76c01d0d8 100644 --- a/client/gui/implementations/GuiGrinder.java +++ b/src/main/java/appeng/client/gui/implementations/GuiGrinder.java @@ -1,31 +1,31 @@ -package appeng.client.gui.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import appeng.client.gui.AEBaseGui; -import appeng.container.implementations.ContainerGrinder; -import appeng.core.localization.GuiText; -import appeng.tile.grindstone.TileGrinder; - -public class GuiGrinder extends AEBaseGui -{ - - public GuiGrinder(InventoryPlayer inventoryPlayer, TileGrinder te) { - super( new ContainerGrinder( inventoryPlayer, te ) ); - this.ySize = 176; - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/grinder.png" ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( GuiText.GrindStone.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - } - -} +package appeng.client.gui.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import appeng.client.gui.AEBaseGui; +import appeng.container.implementations.ContainerGrinder; +import appeng.core.localization.GuiText; +import appeng.tile.grindstone.TileGrinder; + +public class GuiGrinder extends AEBaseGui +{ + + public GuiGrinder(InventoryPlayer inventoryPlayer, TileGrinder te) { + super( new ContainerGrinder( inventoryPlayer, te ) ); + this.ySize = 176; + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/grinder.png" ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( GuiText.GrindStone.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + } + +} diff --git a/client/gui/implementations/GuiIOPort.java b/src/main/java/appeng/client/gui/implementations/GuiIOPort.java similarity index 96% rename from client/gui/implementations/GuiIOPort.java rename to src/main/java/appeng/client/gui/implementations/GuiIOPort.java index 29d92b15d..d8901d9a2 100644 --- a/client/gui/implementations/GuiIOPort.java +++ b/src/main/java/appeng/client/gui/implementations/GuiIOPort.java @@ -1,96 +1,96 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.input.Mouse; - -import appeng.api.AEApi; -import appeng.api.config.FullnessMode; -import appeng.api.config.OperationMode; -import appeng.api.config.RedstoneMode; -import appeng.api.config.Settings; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.container.implementations.ContainerIOPort; -import appeng.core.AELog; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketConfigButton; -import appeng.tile.storage.TileIOPort; - -public class GuiIOPort extends GuiUpgradeable -{ - - GuiImgButton fullMode; - GuiImgButton operationMode; - - public GuiIOPort(InventoryPlayer inventoryPlayer, TileIOPort te) { - super( new ContainerIOPort( inventoryPlayer, te ) ); - this.ySize = 166; - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - super.drawBG( offsetX, offsetY, mouseX, mouseY ); - this.drawItem( offsetX + 66 - 8, offsetY + 17, AEApi.instance().items().itemCell1k.stack( 1 ) ); - this.drawItem( offsetX + 94 + 8, offsetY + 17, AEApi.instance().blocks().blockDrive.stack( 1 ) ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( GuiText.IOPort.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - - if ( redstoneMode != null ) - redstoneMode.set( cvb.rsMode ); - - if ( operationMode != null ) - operationMode.set( ((ContainerIOPort) cvb).opMode ); - - if ( fullMode != null ) - fullMode.set( ((ContainerIOPort) cvb).fMode ); - } - - @Override - protected void addButtons() - { - redstoneMode = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE ); - fullMode = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.FULLNESS_MODE, FullnessMode.EMPTY ); - operationMode = new GuiImgButton( this.guiLeft + 80, guiTop + 17, Settings.OPERATION_MODE, OperationMode.EMPTY ); - - buttonList.add( operationMode ); - buttonList.add( redstoneMode ); - buttonList.add( fullMode ); - } - - @Override - protected void actionPerformed(GuiButton btn) - { - super.actionPerformed( btn ); - - boolean backwards = Mouse.isButtonDown( 1 ); - - try - { - if ( btn == fullMode ) - NetworkHandler.instance.sendToServer( new PacketConfigButton( fullMode.getSetting(), backwards ) ); - - if ( btn == operationMode ) - NetworkHandler.instance.sendToServer( new PacketConfigButton( operationMode.getSetting(), backwards ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - - protected String getBackground() - { - return "guis/ioport.png"; - } - -} +package appeng.client.gui.implementations; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; + +import org.lwjgl.input.Mouse; + +import appeng.api.AEApi; +import appeng.api.config.FullnessMode; +import appeng.api.config.OperationMode; +import appeng.api.config.RedstoneMode; +import appeng.api.config.Settings; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.container.implementations.ContainerIOPort; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketConfigButton; +import appeng.tile.storage.TileIOPort; + +public class GuiIOPort extends GuiUpgradeable +{ + + GuiImgButton fullMode; + GuiImgButton operationMode; + + public GuiIOPort(InventoryPlayer inventoryPlayer, TileIOPort te) { + super( new ContainerIOPort( inventoryPlayer, te ) ); + this.ySize = 166; + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + super.drawBG( offsetX, offsetY, mouseX, mouseY ); + this.drawItem( offsetX + 66 - 8, offsetY + 17, AEApi.instance().items().itemCell1k.stack( 1 ) ); + this.drawItem( offsetX + 94 + 8, offsetY + 17, AEApi.instance().blocks().blockDrive.stack( 1 ) ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( GuiText.IOPort.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + + if ( redstoneMode != null ) + redstoneMode.set( cvb.rsMode ); + + if ( operationMode != null ) + operationMode.set( ((ContainerIOPort) cvb).opMode ); + + if ( fullMode != null ) + fullMode.set( ((ContainerIOPort) cvb).fMode ); + } + + @Override + protected void addButtons() + { + redstoneMode = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE ); + fullMode = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.FULLNESS_MODE, FullnessMode.EMPTY ); + operationMode = new GuiImgButton( this.guiLeft + 80, guiTop + 17, Settings.OPERATION_MODE, OperationMode.EMPTY ); + + buttonList.add( operationMode ); + buttonList.add( redstoneMode ); + buttonList.add( fullMode ); + } + + @Override + protected void actionPerformed(GuiButton btn) + { + super.actionPerformed( btn ); + + boolean backwards = Mouse.isButtonDown( 1 ); + + try + { + if ( btn == fullMode ) + NetworkHandler.instance.sendToServer( new PacketConfigButton( fullMode.getSetting(), backwards ) ); + + if ( btn == operationMode ) + NetworkHandler.instance.sendToServer( new PacketConfigButton( operationMode.getSetting(), backwards ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + + protected String getBackground() + { + return "guis/ioport.png"; + } + +} diff --git a/client/gui/implementations/GuiInscriber.java b/src/main/java/appeng/client/gui/implementations/GuiInscriber.java similarity index 100% rename from client/gui/implementations/GuiInscriber.java rename to src/main/java/appeng/client/gui/implementations/GuiInscriber.java diff --git a/client/gui/implementations/GuiInterface.java b/src/main/java/appeng/client/gui/implementations/GuiInterface.java similarity index 100% rename from client/gui/implementations/GuiInterface.java rename to src/main/java/appeng/client/gui/implementations/GuiInterface.java diff --git a/client/gui/implementations/GuiInterfaceTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java similarity index 100% rename from client/gui/implementations/GuiInterfaceTerminal.java rename to src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java diff --git a/client/gui/implementations/GuiLevelEmitter.java b/src/main/java/appeng/client/gui/implementations/GuiLevelEmitter.java similarity index 96% rename from client/gui/implementations/GuiLevelEmitter.java rename to src/main/java/appeng/client/gui/implementations/GuiLevelEmitter.java index 912345100..9db1ba390 100644 --- a/client/gui/implementations/GuiLevelEmitter.java +++ b/src/main/java/appeng/client/gui/implementations/GuiLevelEmitter.java @@ -1,238 +1,238 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.input.Mouse; - -import appeng.api.config.FuzzyMode; -import appeng.api.config.LevelType; -import appeng.api.config.RedstoneMode; -import appeng.api.config.Settings; -import appeng.api.config.Upgrades; -import appeng.api.config.YesNo; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiNumberBox; -import appeng.container.implementations.ContainerLevelEmitter; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketConfigButton; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.parts.automation.PartLevelEmitter; - -public class GuiLevelEmitter extends GuiUpgradeable -{ - - GuiNumberBox level; - - GuiButton plus1, plus10, plus100, plus1000; - GuiButton minus1, minus10, minus100, minus1000; - - GuiImgButton levelMode; - GuiImgButton craftingMode; - - public GuiLevelEmitter(InventoryPlayer inventoryPlayer, PartLevelEmitter te) { - super( new ContainerLevelEmitter( inventoryPlayer, te ) ); - } - - @Override - public void initGui() - { - super.initGui(); - - level = new GuiNumberBox( fontRendererObj, this.guiLeft + 24, this.guiTop + 43, 79, fontRendererObj.FONT_HEIGHT, Long.class ); - level.setEnableBackgroundDrawing( false ); - level.setMaxStringLength( 16 ); - level.setTextColor( 0xFFFFFF ); - level.setVisible( true ); - level.setFocused( true ); - ((ContainerLevelEmitter) inventorySlots).setTextField( level ); - } - - @Override - protected void addButtons() - { - levelMode = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL ); - redstoneMode = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL ); - fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); - craftingMode = new GuiImgButton( this.guiLeft - 18, guiTop + 48, Settings.CRAFT_VIA_REDSTONE, YesNo.NO ); - - int a = AEConfig.instance.levelByStackAmounts( 0 ); - int b = AEConfig.instance.levelByStackAmounts( 1 ); - int c = AEConfig.instance.levelByStackAmounts( 2 ); - int d = AEConfig.instance.levelByStackAmounts( 3 ); - - buttonList.add( plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a ) ); - buttonList.add( plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b ) ); - buttonList.add( plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c ) ); - buttonList.add( plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d ) ); - - buttonList.add( minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a ) ); - buttonList.add( minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b ) ); - buttonList.add( minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c ) ); - buttonList.add( minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d ) ); - - buttonList.add( levelMode ); - buttonList.add( redstoneMode ); - buttonList.add( fuzzyMode ); - buttonList.add( craftingMode ); - } - - @Override - protected void actionPerformed(GuiButton btn) - { - super.actionPerformed( btn ); - - boolean backwards = Mouse.isButtonDown( 1 ); - - try - { - if ( btn == craftingMode ) - NetworkHandler.instance.sendToServer( new PacketConfigButton( craftingMode.getSetting(), backwards ) ); - - if ( btn == levelMode ) - NetworkHandler.instance.sendToServer( new PacketConfigButton( levelMode.getSetting(), backwards ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - - boolean isPlus = btn == plus1 || btn == plus10 || btn == plus100 || btn == plus1000; - boolean isMinus = btn == minus1 || btn == minus10 || btn == minus100 || btn == minus1000; - - if ( isPlus || isMinus ) - addQty( getQty( btn ) ); - } - - private void addQty(long i) - { - try - { - String Out = level.getText(); - - boolean Fixed = false; - while (Out.startsWith( "0" ) && Out.length() > 1) - { - Out = Out.substring( 1 ); - Fixed = true; - } - - if ( Fixed ) - level.setText( Out ); - - if ( Out.length() == 0 ) - Out = "0"; - - long result = Long.parseLong( Out ); - result += i; - if ( result < 0 ) - result = 0; - - level.setText( Out = Long.toString( result ) ); - - NetworkHandler.instance.sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) ); - } - catch (NumberFormatException e) - { - // nope.. - level.setText( "0" ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - - protected void handleButtonVisibility() - { - craftingMode.setVisibility( bc.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 ); - fuzzyMode.setVisibility( bc.getInstalledUpgrades( Upgrades.FUZZY ) > 0 ); - } - - @Override - protected void keyTyped(char character, int key) - { - if ( !this.checkHotbarKeys( key ) ) - { - if ( (key == 211 || key == 205 || key == 203 || key == 14 || Character.isDigit( character )) && level.textboxKeyTyped( character, key ) ) - { - try - { - String Out = level.getText(); - - boolean Fixed = false; - while (Out.startsWith( "0" ) && Out.length() > 1) - { - Out = Out.substring( 1 ); - Fixed = true; - } - - if ( Fixed ) - level.setText( Out ); - - if ( Out.length() == 0 ) - Out = "0"; - - NetworkHandler.instance.sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - else - { - super.keyTyped( character, key ); - } - } - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - boolean notCraftingMode = bc.getInstalledUpgrades( Upgrades.CRAFTING ) == 0; - - // configure enabled status... - level.setEnabled( notCraftingMode ); - plus1.enabled = notCraftingMode; - plus10.enabled = notCraftingMode; - plus100.enabled = notCraftingMode; - plus1000.enabled = notCraftingMode; - minus1.enabled = notCraftingMode; - minus10.enabled = notCraftingMode; - minus100.enabled = notCraftingMode; - minus1000.enabled = notCraftingMode; - levelMode.enabled = notCraftingMode; - redstoneMode.enabled = notCraftingMode; - - super.drawFG( offsetX, offsetY, mouseX, mouseY ); - - if ( craftingMode != null ) - craftingMode.set( ((ContainerLevelEmitter) cvb).cmType ); - - if ( levelMode != null ) - levelMode.set( ((ContainerLevelEmitter) cvb).lvType ); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - super.drawBG( offsetX, offsetY, mouseX, mouseY ); - level.drawTextBox(); - } - - protected String getBackground() - { - return "guis/lvlemitter.png"; - } - - protected GuiText getName() - { - return GuiText.LevelEmitter; - } -} +package appeng.client.gui.implementations; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; + +import org.lwjgl.input.Mouse; + +import appeng.api.config.FuzzyMode; +import appeng.api.config.LevelType; +import appeng.api.config.RedstoneMode; +import appeng.api.config.Settings; +import appeng.api.config.Upgrades; +import appeng.api.config.YesNo; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiNumberBox; +import appeng.container.implementations.ContainerLevelEmitter; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketConfigButton; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.parts.automation.PartLevelEmitter; + +public class GuiLevelEmitter extends GuiUpgradeable +{ + + GuiNumberBox level; + + GuiButton plus1, plus10, plus100, plus1000; + GuiButton minus1, minus10, minus100, minus1000; + + GuiImgButton levelMode; + GuiImgButton craftingMode; + + public GuiLevelEmitter(InventoryPlayer inventoryPlayer, PartLevelEmitter te) { + super( new ContainerLevelEmitter( inventoryPlayer, te ) ); + } + + @Override + public void initGui() + { + super.initGui(); + + level = new GuiNumberBox( fontRendererObj, this.guiLeft + 24, this.guiTop + 43, 79, fontRendererObj.FONT_HEIGHT, Long.class ); + level.setEnableBackgroundDrawing( false ); + level.setMaxStringLength( 16 ); + level.setTextColor( 0xFFFFFF ); + level.setVisible( true ); + level.setFocused( true ); + ((ContainerLevelEmitter) inventorySlots).setTextField( level ); + } + + @Override + protected void addButtons() + { + levelMode = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL ); + redstoneMode = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL ); + fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); + craftingMode = new GuiImgButton( this.guiLeft - 18, guiTop + 48, Settings.CRAFT_VIA_REDSTONE, YesNo.NO ); + + int a = AEConfig.instance.levelByStackAmounts( 0 ); + int b = AEConfig.instance.levelByStackAmounts( 1 ); + int c = AEConfig.instance.levelByStackAmounts( 2 ); + int d = AEConfig.instance.levelByStackAmounts( 3 ); + + buttonList.add( plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a ) ); + buttonList.add( plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b ) ); + buttonList.add( plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c ) ); + buttonList.add( plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d ) ); + + buttonList.add( minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a ) ); + buttonList.add( minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b ) ); + buttonList.add( minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c ) ); + buttonList.add( minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d ) ); + + buttonList.add( levelMode ); + buttonList.add( redstoneMode ); + buttonList.add( fuzzyMode ); + buttonList.add( craftingMode ); + } + + @Override + protected void actionPerformed(GuiButton btn) + { + super.actionPerformed( btn ); + + boolean backwards = Mouse.isButtonDown( 1 ); + + try + { + if ( btn == craftingMode ) + NetworkHandler.instance.sendToServer( new PacketConfigButton( craftingMode.getSetting(), backwards ) ); + + if ( btn == levelMode ) + NetworkHandler.instance.sendToServer( new PacketConfigButton( levelMode.getSetting(), backwards ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + + boolean isPlus = btn == plus1 || btn == plus10 || btn == plus100 || btn == plus1000; + boolean isMinus = btn == minus1 || btn == minus10 || btn == minus100 || btn == minus1000; + + if ( isPlus || isMinus ) + addQty( getQty( btn ) ); + } + + private void addQty(long i) + { + try + { + String Out = level.getText(); + + boolean Fixed = false; + while (Out.startsWith( "0" ) && Out.length() > 1) + { + Out = Out.substring( 1 ); + Fixed = true; + } + + if ( Fixed ) + level.setText( Out ); + + if ( Out.length() == 0 ) + Out = "0"; + + long result = Long.parseLong( Out ); + result += i; + if ( result < 0 ) + result = 0; + + level.setText( Out = Long.toString( result ) ); + + NetworkHandler.instance.sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) ); + } + catch (NumberFormatException e) + { + // nope.. + level.setText( "0" ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + + protected void handleButtonVisibility() + { + craftingMode.setVisibility( bc.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 ); + fuzzyMode.setVisibility( bc.getInstalledUpgrades( Upgrades.FUZZY ) > 0 ); + } + + @Override + protected void keyTyped(char character, int key) + { + if ( !this.checkHotbarKeys( key ) ) + { + if ( (key == 211 || key == 205 || key == 203 || key == 14 || Character.isDigit( character )) && level.textboxKeyTyped( character, key ) ) + { + try + { + String Out = level.getText(); + + boolean Fixed = false; + while (Out.startsWith( "0" ) && Out.length() > 1) + { + Out = Out.substring( 1 ); + Fixed = true; + } + + if ( Fixed ) + level.setText( Out ); + + if ( Out.length() == 0 ) + Out = "0"; + + NetworkHandler.instance.sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + else + { + super.keyTyped( character, key ); + } + } + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + boolean notCraftingMode = bc.getInstalledUpgrades( Upgrades.CRAFTING ) == 0; + + // configure enabled status... + level.setEnabled( notCraftingMode ); + plus1.enabled = notCraftingMode; + plus10.enabled = notCraftingMode; + plus100.enabled = notCraftingMode; + plus1000.enabled = notCraftingMode; + minus1.enabled = notCraftingMode; + minus10.enabled = notCraftingMode; + minus100.enabled = notCraftingMode; + minus1000.enabled = notCraftingMode; + levelMode.enabled = notCraftingMode; + redstoneMode.enabled = notCraftingMode; + + super.drawFG( offsetX, offsetY, mouseX, mouseY ); + + if ( craftingMode != null ) + craftingMode.set( ((ContainerLevelEmitter) cvb).cmType ); + + if ( levelMode != null ) + levelMode.set( ((ContainerLevelEmitter) cvb).lvType ); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + super.drawBG( offsetX, offsetY, mouseX, mouseY ); + level.drawTextBox(); + } + + protected String getBackground() + { + return "guis/lvlemitter.png"; + } + + protected GuiText getName() + { + return GuiText.LevelEmitter; + } +} diff --git a/client/gui/implementations/GuiMAC.java b/src/main/java/appeng/client/gui/implementations/GuiMAC.java similarity index 100% rename from client/gui/implementations/GuiMAC.java rename to src/main/java/appeng/client/gui/implementations/GuiMAC.java diff --git a/client/gui/implementations/GuiMEMonitorable.java b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java similarity index 96% rename from client/gui/implementations/GuiMEMonitorable.java rename to src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java index c2cdbde9a..05fbbd1b9 100644 --- a/client/gui/implementations/GuiMEMonitorable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java @@ -1,472 +1,472 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; -import java.util.List; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -import org.lwjgl.input.Mouse; - -import appeng.api.config.SearchBoxMode; -import appeng.api.config.Settings; -import appeng.api.config.TerminalStyle; -import appeng.api.implementations.guiobjects.IPortableCell; -import appeng.api.implementations.tiles.IMEChest; -import appeng.api.implementations.tiles.IViewCellStorage; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.client.gui.AEBaseMEGui; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiScrollbar; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.client.gui.widgets.ISortSource; -import appeng.client.gui.widgets.MEGuiTextField; -import appeng.client.me.InternalSlotME; -import appeng.client.me.ItemRepo; -import appeng.container.implementations.ContainerMEMonitorable; -import appeng.container.slot.AppEngSlot; -import appeng.container.slot.SlotCraftingMatrix; -import appeng.container.slot.SlotFakeCraftingMatrix; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.AppEng; -import appeng.core.localization.GuiText; -import appeng.core.sync.GuiBridge; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.helpers.WirelessTerminalGuiObject; -import appeng.integration.IntegrationType; -import appeng.parts.reporting.PartTerminal; -import appeng.tile.misc.TileSecurity; -import appeng.util.IConfigManagerHost; -import appeng.util.Platform; - -public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfigManagerHost -{ - - GuiTabButton craftingStatusBtn; - - MEGuiTextField searchField; - private static String memoryText = ""; - - public static int CraftingGridOffsetX; - public static int CraftingGridOffsetY; - - ItemRepo repo; - - GuiText myName; - - int xoffset = 9; - int perRow = 9; - int reservedSpace = 0; - int lowerTextureOffset = 0; - boolean customSortOrder = true; - - int rows = 0; - int maxRows = Integer.MAX_VALUE; - - int standardSize; - - IConfigManager configSrc; - - GuiImgButton ViewBox; - GuiImgButton SortByBox; - GuiImgButton SortDirBox; - - GuiImgButton searchBoxSettings, terminalStyleBox; - boolean viewCell; - - ItemStack myCurrentViewCells[] = new ItemStack[5]; - ContainerMEMonitorable mecontainer; - - public GuiMEMonitorable(InventoryPlayer inventoryPlayer, ITerminalHost te) { - this( inventoryPlayer, te, new ContainerMEMonitorable( inventoryPlayer, te ) ); - } - - public GuiMEMonitorable(InventoryPlayer inventoryPlayer, ITerminalHost te, ContainerMEMonitorable c) { - - super( c ); - myScrollBar = new GuiScrollbar(); - repo = new ItemRepo( myScrollBar, this ); - - xSize = 185; - ySize = 204; - - if ( te instanceof IViewCellStorage ) - xSize += 33; - - standardSize = xSize; - - configSrc = ((IConfigurableObject) inventorySlots).getConfigManager(); - (mecontainer = (ContainerMEMonitorable) inventorySlots).gui = this; - - viewCell = te instanceof IViewCellStorage; - - if ( te instanceof TileSecurity ) - myName = GuiText.Security; - else if ( te instanceof WirelessTerminalGuiObject ) - myName = GuiText.WirelessTerminal; - else if ( te instanceof IPortableCell ) - myName = GuiText.PortableCell; - else if ( te instanceof IMEChest ) - myName = GuiText.Chest; - else if ( te instanceof PartTerminal ) - myName = GuiText.Terminal; - } - - public void postUpdate(List list) - { - for (IAEItemStack is : list) - repo.postUpdate( is ); - - repo.updateView(); - setScrollBar(); - } - - private void setScrollBar() - { - myScrollBar.setTop( 18 ).setLeft( 175 ).setHeight( rows * 18 - 2 ); - myScrollBar.setRange( 0, (repo.size() + perRow - 1) / perRow - rows, Math.max( 1, rows / 6 ) ); - } - - public void re_init() - { - this.buttonList.clear(); - this.initGui(); - } - - @Override - public void onGuiClosed() - { - super.onGuiClosed(); - memoryText = searchField.getText(); - } - - @Override - public void initGui() - { - maxRows = getMaxRows(); - perRow = AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ? 9 : 9 + ((width - standardSize) / 18); - - boolean hasNEI = AppEng.instance.isIntegrationEnabled( IntegrationType.NEI ); - - int NEI = hasNEI ? 0 : 0; - int top = hasNEI ? 22 : 0; - - int magicNumber = 114 + 1; - int extraSpace = height - magicNumber - NEI - top - reservedSpace; - - rows = (int) Math.floor( extraSpace / 18 ); - if ( rows > maxRows ) - { - top += (rows - maxRows) * 18 / 2; - rows = maxRows; - } - - if ( hasNEI ) - rows--; - - if ( rows < 3 ) - rows = 3; - - meSlots.clear(); - for (int y = 0; y < rows; y++) - { - for (int x = 0; x < perRow; x++) - { - meSlots.add( new InternalSlotME( repo, x + y * perRow, xoffset + x * 18, 18 + y * 18 ) ); - } - } - - if ( AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ) - this.xSize = standardSize + ((perRow - 9) * 18); - else - this.xSize = standardSize; - - super.initGui(); - // full size : 204 - // extra slots : 72 - // slot 18 - - this.ySize = magicNumber + rows * 18 + reservedSpace; - // this.guiTop = top; - int unusedSpace = height - ySize; - guiTop = (int) Math.floor( (float) unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f) ); - - int offset = guiTop + 8; - - if ( customSortOrder ) - { - buttonList.add( SortByBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, configSrc.getSetting( Settings.SORT_BY ) ) ); - offset += 20; - } - - if ( viewCell || this instanceof GuiWirelessTerm ) - { - buttonList.add( ViewBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE, configSrc.getSetting( Settings.VIEW_MODE ) ) ); - offset += 20; - } - - buttonList.add( SortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, configSrc.getSetting( Settings.SORT_DIRECTION ) ) ); - offset += 20; - - buttonList.add( searchBoxSettings = new GuiImgButton( this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance.settings - .getSetting( Settings.SEARCH_MODE ) ) ); - offset += 20; - - if ( !(this instanceof GuiMEPortableCell) || this instanceof GuiWirelessTerm ) - { - buttonList.add( terminalStyleBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.TERMINAL_STYLE, AEConfig.instance.settings - .getSetting( Settings.TERMINAL_STYLE ) ) ); - } - - searchField = new MEGuiTextField( fontRendererObj, this.guiLeft + Math.max( 82, xoffset ), this.guiTop + 6, 89, fontRendererObj.FONT_HEIGHT ); - searchField.setEnableBackgroundDrawing( false ); - searchField.setMaxStringLength( 25 ); - searchField.setTextColor( 0xFFFFFF ); - searchField.setVisible( true ); - - if ( viewCell || this instanceof GuiWirelessTerm ) - { - buttonList.add( craftingStatusBtn = new GuiTabButton( this.guiLeft + 170, this.guiTop - 4, 2 + 11 * 16, GuiText.CraftingStatus.getLocal(), - itemRender ) ); - craftingStatusBtn.hideEdge = 13; - } - - // Enum setting = AEConfig.instance.getSetting( "Terminal", SearchBoxMode.class, SearchBoxMode.AUTOSEARCH ); - Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); - searchField.setFocused( SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting ); - - if ( isSubGui() ) - { - searchField.setText( memoryText ); - repo.searchString = memoryText; - repo.updateView(); - setScrollBar(); - } - - CraftingGridOffsetX = Integer.MAX_VALUE; - CraftingGridOffsetY = Integer.MAX_VALUE; - - for (Object s : inventorySlots.inventorySlots) - { - if ( s instanceof AppEngSlot ) - { - if ( ((AppEngSlot) s).xDisplayPosition < 197 ) - repositionSlot( (AppEngSlot) s ); - } - - if ( s instanceof SlotCraftingMatrix || s instanceof SlotFakeCraftingMatrix ) - { - Slot g = (Slot) s; - if ( g.xDisplayPosition > 0 && g.yDisplayPosition > 0 ) - { - CraftingGridOffsetX = Math.min( CraftingGridOffsetX, g.xDisplayPosition ); - CraftingGridOffsetY = Math.min( CraftingGridOffsetY, g.yDisplayPosition ); - } - } - } - - CraftingGridOffsetX -= 25; - CraftingGridOffsetY -= 6; - } - - protected void repositionSlot(AppEngSlot s) - { - s.yDisplayPosition = s.defY + ySize - 78 - 5; - } - - @Override - protected void actionPerformed(GuiButton btn) - { - if ( btn == craftingStatusBtn ) - { - try - { - NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_CRAFTING_STATUS ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - - if ( btn instanceof GuiImgButton ) - { - boolean backwards = Mouse.isButtonDown( 1 ); - - GuiImgButton iBtn = (GuiImgButton) btn; - if ( iBtn.getSetting() != Settings.ACTIONS ) - { - Enum cv = iBtn.getCurrentValue(); - Enum next = Platform.rotateEnum( cv, backwards, iBtn.getSetting().getPossibleValues() ); - - if ( btn == terminalStyleBox ) - AEConfig.instance.settings.putSetting( iBtn.getSetting(), next ); - else if ( btn == searchBoxSettings ) - AEConfig.instance.settings.putSetting( iBtn.getSetting(), next ); - else - { - try - { - NetworkHandler.instance.sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - - iBtn.set( next ); - - if ( next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class ) - re_init(); - } - } - } - - @Override - protected void mouseClicked(int xCoord, int yCoord, int btn) - { - Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); - if ( !(SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting) ) - searchField.mouseClicked( xCoord, yCoord, btn ); - - if ( btn == 1 && searchField.isMouseIn( xCoord, yCoord ) ) - { - searchField.setText( "" ); - repo.searchString = ""; - repo.updateView(); - setScrollBar(); - } - - super.mouseClicked( xCoord, yCoord, btn ); - } - - @Override - protected void keyTyped(char character, int key) - { - if ( !this.checkHotbarKeys( key ) ) - { - if ( character == ' ' && this.searchField.getText().length() == 0 ) - return; - - if ( searchField.textboxKeyTyped( character, key ) ) - { - repo.searchString = this.searchField.getText(); - repo.updateView(); - setScrollBar(); - } - else - { - super.keyTyped( character, key ); - } - } - } - - @Override - public void updateScreen() - { - repo.setPower( mecontainer.hasPower ); - super.updateScreen(); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - int x_width = 197; - - bindTexture( getBackground() ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18 ); - - if ( viewCell || (this instanceof GuiSecurity) ) - this.drawTexturedModalRect( offsetX + x_width, offsetY, x_width, 0, 46, 128 ); - - for (int x = 0; x < rows; x++) - this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18 ); - - this.drawTexturedModalRect( offsetX, offsetY + 16 + rows * 18 + lowerTextureOffset, 0, 106 - 18 - 18, x_width, 99 + reservedSpace - lowerTextureOffset ); - - if ( viewCell ) - { - boolean update = false; - - for (int i = 0; i < 5; i++) - { - if ( myCurrentViewCells[i] != mecontainer.cellView[i].getStack() ) - { - update = true; - myCurrentViewCells[i] = mecontainer.cellView[i].getStack(); - } - } - - if ( update ) - repo.setViewCell( myCurrentViewCells ); - } - - if ( searchField != null ) - searchField.drawTextBox(); - } - - protected String getBackground() - { - return "guis/terminal.png"; - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( myName.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - } - - @Override - public Enum getSortBy() - { - return configSrc.getSetting( Settings.SORT_BY ); - } - - @Override - public Enum getSortDir() - { - return configSrc.getSetting( Settings.SORT_DIRECTION ); - } - - @Override - public Enum getSortDisplay() - { - return configSrc.getSetting( Settings.VIEW_MODE ); - } - - @Override - public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) - { - if ( SortByBox != null ) - SortByBox.set( configSrc.getSetting( Settings.SORT_BY ) ); - - if ( SortDirBox != null ) - SortDirBox.set( configSrc.getSetting( Settings.SORT_DIRECTION ) ); - - if ( ViewBox != null ) - ViewBox.set( configSrc.getSetting( Settings.VIEW_MODE ) ); - - repo.updateView(); - } - - protected boolean isPowered() - { - return repo.hasPower(); - } - - int getMaxRows() - { - return AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) == TerminalStyle.SMALL ? 6 : Integer.MAX_VALUE; - } - -} +package appeng.client.gui.implementations; + +import java.io.IOException; +import java.util.List; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import org.lwjgl.input.Mouse; + +import appeng.api.config.SearchBoxMode; +import appeng.api.config.Settings; +import appeng.api.config.TerminalStyle; +import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.implementations.tiles.IMEChest; +import appeng.api.implementations.tiles.IViewCellStorage; +import appeng.api.storage.ITerminalHost; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.client.gui.AEBaseMEGui; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiScrollbar; +import appeng.client.gui.widgets.GuiTabButton; +import appeng.client.gui.widgets.ISortSource; +import appeng.client.gui.widgets.MEGuiTextField; +import appeng.client.me.InternalSlotME; +import appeng.client.me.ItemRepo; +import appeng.container.implementations.ContainerMEMonitorable; +import appeng.container.slot.AppEngSlot; +import appeng.container.slot.SlotCraftingMatrix; +import appeng.container.slot.SlotFakeCraftingMatrix; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.AppEng; +import appeng.core.localization.GuiText; +import appeng.core.sync.GuiBridge; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketSwitchGuis; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.integration.IntegrationType; +import appeng.parts.reporting.PartTerminal; +import appeng.tile.misc.TileSecurity; +import appeng.util.IConfigManagerHost; +import appeng.util.Platform; + +public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfigManagerHost +{ + + GuiTabButton craftingStatusBtn; + + MEGuiTextField searchField; + private static String memoryText = ""; + + public static int CraftingGridOffsetX; + public static int CraftingGridOffsetY; + + ItemRepo repo; + + GuiText myName; + + int xoffset = 9; + int perRow = 9; + int reservedSpace = 0; + int lowerTextureOffset = 0; + boolean customSortOrder = true; + + int rows = 0; + int maxRows = Integer.MAX_VALUE; + + int standardSize; + + IConfigManager configSrc; + + GuiImgButton ViewBox; + GuiImgButton SortByBox; + GuiImgButton SortDirBox; + + GuiImgButton searchBoxSettings, terminalStyleBox; + boolean viewCell; + + ItemStack myCurrentViewCells[] = new ItemStack[5]; + ContainerMEMonitorable mecontainer; + + public GuiMEMonitorable(InventoryPlayer inventoryPlayer, ITerminalHost te) { + this( inventoryPlayer, te, new ContainerMEMonitorable( inventoryPlayer, te ) ); + } + + public GuiMEMonitorable(InventoryPlayer inventoryPlayer, ITerminalHost te, ContainerMEMonitorable c) { + + super( c ); + myScrollBar = new GuiScrollbar(); + repo = new ItemRepo( myScrollBar, this ); + + xSize = 185; + ySize = 204; + + if ( te instanceof IViewCellStorage ) + xSize += 33; + + standardSize = xSize; + + configSrc = ((IConfigurableObject) inventorySlots).getConfigManager(); + (mecontainer = (ContainerMEMonitorable) inventorySlots).gui = this; + + viewCell = te instanceof IViewCellStorage; + + if ( te instanceof TileSecurity ) + myName = GuiText.Security; + else if ( te instanceof WirelessTerminalGuiObject ) + myName = GuiText.WirelessTerminal; + else if ( te instanceof IPortableCell ) + myName = GuiText.PortableCell; + else if ( te instanceof IMEChest ) + myName = GuiText.Chest; + else if ( te instanceof PartTerminal ) + myName = GuiText.Terminal; + } + + public void postUpdate(List list) + { + for (IAEItemStack is : list) + repo.postUpdate( is ); + + repo.updateView(); + setScrollBar(); + } + + private void setScrollBar() + { + myScrollBar.setTop( 18 ).setLeft( 175 ).setHeight( rows * 18 - 2 ); + myScrollBar.setRange( 0, (repo.size() + perRow - 1) / perRow - rows, Math.max( 1, rows / 6 ) ); + } + + public void re_init() + { + this.buttonList.clear(); + this.initGui(); + } + + @Override + public void onGuiClosed() + { + super.onGuiClosed(); + memoryText = searchField.getText(); + } + + @Override + public void initGui() + { + maxRows = getMaxRows(); + perRow = AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ? 9 : 9 + ((width - standardSize) / 18); + + boolean hasNEI = AppEng.instance.isIntegrationEnabled( IntegrationType.NEI ); + + int NEI = hasNEI ? 0 : 0; + int top = hasNEI ? 22 : 0; + + int magicNumber = 114 + 1; + int extraSpace = height - magicNumber - NEI - top - reservedSpace; + + rows = (int) Math.floor( extraSpace / 18 ); + if ( rows > maxRows ) + { + top += (rows - maxRows) * 18 / 2; + rows = maxRows; + } + + if ( hasNEI ) + rows--; + + if ( rows < 3 ) + rows = 3; + + meSlots.clear(); + for (int y = 0; y < rows; y++) + { + for (int x = 0; x < perRow; x++) + { + meSlots.add( new InternalSlotME( repo, x + y * perRow, xoffset + x * 18, 18 + y * 18 ) ); + } + } + + if ( AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ) + this.xSize = standardSize + ((perRow - 9) * 18); + else + this.xSize = standardSize; + + super.initGui(); + // full size : 204 + // extra slots : 72 + // slot 18 + + this.ySize = magicNumber + rows * 18 + reservedSpace; + // this.guiTop = top; + int unusedSpace = height - ySize; + guiTop = (int) Math.floor( (float) unusedSpace / (unusedSpace < 0 ? 3.8f : 2.0f) ); + + int offset = guiTop + 8; + + if ( customSortOrder ) + { + buttonList.add( SortByBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, configSrc.getSetting( Settings.SORT_BY ) ) ); + offset += 20; + } + + if ( viewCell || this instanceof GuiWirelessTerm ) + { + buttonList.add( ViewBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE, configSrc.getSetting( Settings.VIEW_MODE ) ) ); + offset += 20; + } + + buttonList.add( SortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, configSrc.getSetting( Settings.SORT_DIRECTION ) ) ); + offset += 20; + + buttonList.add( searchBoxSettings = new GuiImgButton( this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance.settings + .getSetting( Settings.SEARCH_MODE ) ) ); + offset += 20; + + if ( !(this instanceof GuiMEPortableCell) || this instanceof GuiWirelessTerm ) + { + buttonList.add( terminalStyleBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.TERMINAL_STYLE, AEConfig.instance.settings + .getSetting( Settings.TERMINAL_STYLE ) ) ); + } + + searchField = new MEGuiTextField( fontRendererObj, this.guiLeft + Math.max( 82, xoffset ), this.guiTop + 6, 89, fontRendererObj.FONT_HEIGHT ); + searchField.setEnableBackgroundDrawing( false ); + searchField.setMaxStringLength( 25 ); + searchField.setTextColor( 0xFFFFFF ); + searchField.setVisible( true ); + + if ( viewCell || this instanceof GuiWirelessTerm ) + { + buttonList.add( craftingStatusBtn = new GuiTabButton( this.guiLeft + 170, this.guiTop - 4, 2 + 11 * 16, GuiText.CraftingStatus.getLocal(), + itemRender ) ); + craftingStatusBtn.hideEdge = 13; + } + + // Enum setting = AEConfig.instance.getSetting( "Terminal", SearchBoxMode.class, SearchBoxMode.AUTOSEARCH ); + Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); + searchField.setFocused( SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting ); + + if ( isSubGui() ) + { + searchField.setText( memoryText ); + repo.searchString = memoryText; + repo.updateView(); + setScrollBar(); + } + + CraftingGridOffsetX = Integer.MAX_VALUE; + CraftingGridOffsetY = Integer.MAX_VALUE; + + for (Object s : inventorySlots.inventorySlots) + { + if ( s instanceof AppEngSlot ) + { + if ( ((AppEngSlot) s).xDisplayPosition < 197 ) + repositionSlot( (AppEngSlot) s ); + } + + if ( s instanceof SlotCraftingMatrix || s instanceof SlotFakeCraftingMatrix ) + { + Slot g = (Slot) s; + if ( g.xDisplayPosition > 0 && g.yDisplayPosition > 0 ) + { + CraftingGridOffsetX = Math.min( CraftingGridOffsetX, g.xDisplayPosition ); + CraftingGridOffsetY = Math.min( CraftingGridOffsetY, g.yDisplayPosition ); + } + } + } + + CraftingGridOffsetX -= 25; + CraftingGridOffsetY -= 6; + } + + protected void repositionSlot(AppEngSlot s) + { + s.yDisplayPosition = s.defY + ySize - 78 - 5; + } + + @Override + protected void actionPerformed(GuiButton btn) + { + if ( btn == craftingStatusBtn ) + { + try + { + NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_CRAFTING_STATUS ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + + if ( btn instanceof GuiImgButton ) + { + boolean backwards = Mouse.isButtonDown( 1 ); + + GuiImgButton iBtn = (GuiImgButton) btn; + if ( iBtn.getSetting() != Settings.ACTIONS ) + { + Enum cv = iBtn.getCurrentValue(); + Enum next = Platform.rotateEnum( cv, backwards, iBtn.getSetting().getPossibleValues() ); + + if ( btn == terminalStyleBox ) + AEConfig.instance.settings.putSetting( iBtn.getSetting(), next ); + else if ( btn == searchBoxSettings ) + AEConfig.instance.settings.putSetting( iBtn.getSetting(), next ); + else + { + try + { + NetworkHandler.instance.sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + + iBtn.set( next ); + + if ( next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class ) + re_init(); + } + } + } + + @Override + protected void mouseClicked(int xCoord, int yCoord, int btn) + { + Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); + if ( !(SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting) ) + searchField.mouseClicked( xCoord, yCoord, btn ); + + if ( btn == 1 && searchField.isMouseIn( xCoord, yCoord ) ) + { + searchField.setText( "" ); + repo.searchString = ""; + repo.updateView(); + setScrollBar(); + } + + super.mouseClicked( xCoord, yCoord, btn ); + } + + @Override + protected void keyTyped(char character, int key) + { + if ( !this.checkHotbarKeys( key ) ) + { + if ( character == ' ' && this.searchField.getText().length() == 0 ) + return; + + if ( searchField.textboxKeyTyped( character, key ) ) + { + repo.searchString = this.searchField.getText(); + repo.updateView(); + setScrollBar(); + } + else + { + super.keyTyped( character, key ); + } + } + } + + @Override + public void updateScreen() + { + repo.setPower( mecontainer.hasPower ); + super.updateScreen(); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + int x_width = 197; + + bindTexture( getBackground() ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18 ); + + if ( viewCell || (this instanceof GuiSecurity) ) + this.drawTexturedModalRect( offsetX + x_width, offsetY, x_width, 0, 46, 128 ); + + for (int x = 0; x < rows; x++) + this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18 ); + + this.drawTexturedModalRect( offsetX, offsetY + 16 + rows * 18 + lowerTextureOffset, 0, 106 - 18 - 18, x_width, 99 + reservedSpace - lowerTextureOffset ); + + if ( viewCell ) + { + boolean update = false; + + for (int i = 0; i < 5; i++) + { + if ( myCurrentViewCells[i] != mecontainer.cellView[i].getStack() ) + { + update = true; + myCurrentViewCells[i] = mecontainer.cellView[i].getStack(); + } + } + + if ( update ) + repo.setViewCell( myCurrentViewCells ); + } + + if ( searchField != null ) + searchField.drawTextBox(); + } + + protected String getBackground() + { + return "guis/terminal.png"; + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( myName.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + } + + @Override + public Enum getSortBy() + { + return configSrc.getSetting( Settings.SORT_BY ); + } + + @Override + public Enum getSortDir() + { + return configSrc.getSetting( Settings.SORT_DIRECTION ); + } + + @Override + public Enum getSortDisplay() + { + return configSrc.getSetting( Settings.VIEW_MODE ); + } + + @Override + public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) + { + if ( SortByBox != null ) + SortByBox.set( configSrc.getSetting( Settings.SORT_BY ) ); + + if ( SortDirBox != null ) + SortDirBox.set( configSrc.getSetting( Settings.SORT_DIRECTION ) ); + + if ( ViewBox != null ) + ViewBox.set( configSrc.getSetting( Settings.VIEW_MODE ) ); + + repo.updateView(); + } + + protected boolean isPowered() + { + return repo.hasPower(); + } + + int getMaxRows() + { + return AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) == TerminalStyle.SMALL ? 6 : Integer.MAX_VALUE; + } + +} diff --git a/client/gui/implementations/GuiMEPortableCell.java b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java similarity index 95% rename from client/gui/implementations/GuiMEPortableCell.java rename to src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java index 05f2ceb64..08550a609 100644 --- a/client/gui/implementations/GuiMEPortableCell.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEPortableCell.java @@ -1,24 +1,24 @@ -package appeng.client.gui.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import appeng.api.implementations.guiobjects.IPortableCell; -import appeng.container.implementations.ContainerMEPortableCell; - -public class GuiMEPortableCell extends GuiMEMonitorable -{ - - public GuiMEPortableCell(InventoryPlayer inventoryPlayer, IPortableCell te) { - super( inventoryPlayer, te, new ContainerMEPortableCell( inventoryPlayer, null ) ); - } - - int defaultGetMaxRows() - { - return super.getMaxRows(); - } - - @Override - int getMaxRows() - { - return 3; - } -} +package appeng.client.gui.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.container.implementations.ContainerMEPortableCell; + +public class GuiMEPortableCell extends GuiMEMonitorable +{ + + public GuiMEPortableCell(InventoryPlayer inventoryPlayer, IPortableCell te) { + super( inventoryPlayer, te, new ContainerMEPortableCell( inventoryPlayer, null ) ); + } + + int defaultGetMaxRows() + { + return super.getMaxRows(); + } + + @Override + int getMaxRows() + { + return 3; + } +} diff --git a/client/gui/implementations/GuiNetworkStatus.java b/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java similarity index 96% rename from client/gui/implementations/GuiNetworkStatus.java rename to src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java index ea5fe4ce6..57fbdb522 100644 --- a/client/gui/implementations/GuiNetworkStatus.java +++ b/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java @@ -1,295 +1,295 @@ -package appeng.client.gui.implementations; - -import java.util.List; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.implementations.guiobjects.INetworkTool; -import appeng.api.storage.data.IAEItemStack; -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiScrollbar; -import appeng.client.gui.widgets.ISortSource; -import appeng.client.me.ItemRepo; -import appeng.client.me.SlotME; -import appeng.container.implementations.ContainerNetworkStatus; -import appeng.core.AEConfig; -import appeng.core.localization.GuiText; -import appeng.util.Platform; - -public class GuiNetworkStatus extends AEBaseGui implements ISortSource -{ - - ItemRepo repo; - GuiImgButton units; - - int rows = 4; - - public GuiNetworkStatus(InventoryPlayer inventoryPlayer, INetworkTool te) { - super( new ContainerNetworkStatus( inventoryPlayer, te ) ); - this.ySize = 153; - this.xSize = 195; - myScrollBar = new GuiScrollbar(); - repo = new ItemRepo( myScrollBar, this ); - repo.rowSize = 5; - } - - @Override - protected void actionPerformed(GuiButton btn) - { - super.actionPerformed( btn ); - - boolean backwards = Mouse.isButtonDown( 1 ); - - if ( btn == units ) - { - AEConfig.instance.nextPowerUnit( backwards ); - units.set( AEConfig.instance.selectedPowerUnit() ); - } - } - - @Override - public void initGui() - { - super.initGui(); - - units = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.POWER_UNITS, AEConfig.instance.selectedPowerUnit() ); - buttonList.add( units ); - } - - public void postUpdate(List list) - { - repo.clear(); - - for (IAEItemStack is : list) - repo.postUpdate( is ); - - repo.updateView(); - setScrollBar(); - } - - private void setScrollBar() - { - int size = repo.size(); - myScrollBar.setTop( 39 ).setLeft( 175 ).setHeight( 78 ); - myScrollBar.setRange( 0, (size + 4) / 5 - rows, 1 ); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/networkstatus.png" ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - int tooltip = -1; - - @Override - public void drawScreen(int mouse_x, int mouse_y, float btn) - { - int x = 0; - int y = 0; - - int gx = (width - xSize) / 2; - int gy = (height - ySize) / 2; - - tooltip = -1; - - for (int z = 0; z <= 4 * 5; z++) - { - int minX = gx + 14 + x * 31; - int minY = gy + 41 + y * 18; - - if ( minX < mouse_x && minX + 28 > mouse_x ) - { - if ( minY < mouse_y && minY + 20 > mouse_y ) - { - tooltip = z; - break; - } - - } - - x++; - - if ( x > 4 ) - { - y++; - x = 0; - } - } - - super.drawScreen( mouse_x, mouse_y, btn ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - ContainerNetworkStatus ns = (ContainerNetworkStatus) inventorySlots; - - fontRendererObj.drawString( GuiText.NetworkDetails.getLocal(), 8, 6, 4210752 ); - - fontRendererObj.drawString( GuiText.StoredPower.getLocal() + ": " + Platform.formatPowerLong( ns.currentPower, false ), 13, 16, 4210752 ); - fontRendererObj.drawString( GuiText.MaxPower.getLocal() + ": " + Platform.formatPowerLong( ns.maxPower, false ), 13, 26, 4210752 ); - - fontRendererObj.drawString( GuiText.PowerInputRate.getLocal() + ": " + Platform.formatPowerLong( ns.avgAddition, true ), 13, 143 - 10, 4210752 ); - fontRendererObj.drawString( GuiText.PowerUsageRate.getLocal() + ": " + Platform.formatPowerLong( ns.powerUsage, true ), 13, 143 - 20, 4210752 ); - - int sectionLength = 30; - - int x = 0; - int y = 0; - int xo = 0 + 12; - int yo = 0 + 42; - int viewStart = 0;// myScrollBar.getCurrentScroll() * 5; - int viewEnd = viewStart + 5 * 4; - - String ToolTip = ""; - int toolPosX = 0; - int toolPosY = 0; - - for (int z = viewStart; z < Math.min( viewEnd, repo.size() ); z++) - { - IAEItemStack refStack = repo.getReferenceItem( z ); - if ( refStack != null ) - { - GL11.glPushMatrix(); - GL11.glScaled( 0.5, 0.5, 0.5 ); - - String str = Long.toString( refStack.getStackSize() ); - if ( refStack.getStackSize() >= 10000 ) - str = Long.toString( refStack.getStackSize() / 1000 ) + "k"; - - int w = fontRendererObj.getStringWidth( str ); - fontRendererObj.drawString( str, (int) ((x * sectionLength + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * 18 + yo + 6) * 2), - 4210752 ); - - GL11.glPopMatrix(); - int posX = x * sectionLength + xo + sectionLength - 18; - int posY = y * 18 + yo; - - if ( tooltip == z - viewStart ) - { - ToolTip = Platform.getItemDisplayName( repo.getItem( z ) ); - - ToolTip = ToolTip + ("\n" + GuiText.Installed.getLocal() + ": " + (refStack.getStackSize())); - if ( refStack.getCountRequestable() > 0 ) - ToolTip = ToolTip + ("\n" + GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( refStack.getCountRequestable(), true )); - - toolPosX = x * sectionLength + xo + sectionLength - 8; - toolPosY = y * 18 + yo; - } - - drawItem( posX, posY, repo.getItem( z ) ); - - x++; - - if ( x > 4 ) - { - y++; - x = 0; - } - } - - } - - if ( tooltip >= 0 && ToolTip.length() > 0 ) - { - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - drawTooltip( toolPosX, toolPosY + 10, 0, ToolTip ); - GL11.glPopAttrib(); - } - - } - - // @Override - NEI - public List handleItemTooltip(ItemStack stack, int mousex, int mousey, List currenttip) - { - if ( stack != null ) - { - Slot s = getSlot( mousex, mousey ); - if ( s instanceof SlotME ) - { - IAEItemStack myStack = null; - - try - { - SlotME theSlotField = (SlotME) s; - myStack = theSlotField.getAEStack(); - } - catch (Throwable ignore) - { - } - - if ( myStack != null ) - { - while (currenttip.size() > 1) - currenttip.remove( 1 ); - - } - } - } - return currenttip; - } - - // Vanilla version... - protected void drawItemStackTooltip(ItemStack stack, int x, int y) - { - Slot s = getSlot( x, y ); - if ( s instanceof SlotME && stack != null ) - { - IAEItemStack myStack = null; - - try - { - SlotME theSlotField = (SlotME) s; - myStack = theSlotField.getAEStack(); - } - catch (Throwable ignore) - { - } - - if ( myStack != null ) - { - List currenttip = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips ); - - while (currenttip.size() > 1) - currenttip.remove( 1 ); - - currenttip.add( GuiText.Installed.getLocal() + ": " + (myStack.getStackSize()) ); - currenttip.add( GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( myStack.getCountRequestable(), true ) ); - - drawTooltip( x, y, 0, join( currenttip, "\n" ) ); - } - } - // super.drawItemStackTooltip( stack, x, y ); - } - - @Override - public Enum getSortBy() - { - return SortOrder.NAME; - } - - @Override - public Enum getSortDir() - { - return SortDir.ASCENDING; - } - - @Override - public Enum getSortDisplay() - { - return ViewItems.ALL; - } -} +package appeng.client.gui.implementations; + +import java.util.List; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; +import appeng.api.implementations.guiobjects.INetworkTool; +import appeng.api.storage.data.IAEItemStack; +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiScrollbar; +import appeng.client.gui.widgets.ISortSource; +import appeng.client.me.ItemRepo; +import appeng.client.me.SlotME; +import appeng.container.implementations.ContainerNetworkStatus; +import appeng.core.AEConfig; +import appeng.core.localization.GuiText; +import appeng.util.Platform; + +public class GuiNetworkStatus extends AEBaseGui implements ISortSource +{ + + ItemRepo repo; + GuiImgButton units; + + int rows = 4; + + public GuiNetworkStatus(InventoryPlayer inventoryPlayer, INetworkTool te) { + super( new ContainerNetworkStatus( inventoryPlayer, te ) ); + this.ySize = 153; + this.xSize = 195; + myScrollBar = new GuiScrollbar(); + repo = new ItemRepo( myScrollBar, this ); + repo.rowSize = 5; + } + + @Override + protected void actionPerformed(GuiButton btn) + { + super.actionPerformed( btn ); + + boolean backwards = Mouse.isButtonDown( 1 ); + + if ( btn == units ) + { + AEConfig.instance.nextPowerUnit( backwards ); + units.set( AEConfig.instance.selectedPowerUnit() ); + } + } + + @Override + public void initGui() + { + super.initGui(); + + units = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.POWER_UNITS, AEConfig.instance.selectedPowerUnit() ); + buttonList.add( units ); + } + + public void postUpdate(List list) + { + repo.clear(); + + for (IAEItemStack is : list) + repo.postUpdate( is ); + + repo.updateView(); + setScrollBar(); + } + + private void setScrollBar() + { + int size = repo.size(); + myScrollBar.setTop( 39 ).setLeft( 175 ).setHeight( 78 ); + myScrollBar.setRange( 0, (size + 4) / 5 - rows, 1 ); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/networkstatus.png" ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + int tooltip = -1; + + @Override + public void drawScreen(int mouse_x, int mouse_y, float btn) + { + int x = 0; + int y = 0; + + int gx = (width - xSize) / 2; + int gy = (height - ySize) / 2; + + tooltip = -1; + + for (int z = 0; z <= 4 * 5; z++) + { + int minX = gx + 14 + x * 31; + int minY = gy + 41 + y * 18; + + if ( minX < mouse_x && minX + 28 > mouse_x ) + { + if ( minY < mouse_y && minY + 20 > mouse_y ) + { + tooltip = z; + break; + } + + } + + x++; + + if ( x > 4 ) + { + y++; + x = 0; + } + } + + super.drawScreen( mouse_x, mouse_y, btn ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + ContainerNetworkStatus ns = (ContainerNetworkStatus) inventorySlots; + + fontRendererObj.drawString( GuiText.NetworkDetails.getLocal(), 8, 6, 4210752 ); + + fontRendererObj.drawString( GuiText.StoredPower.getLocal() + ": " + Platform.formatPowerLong( ns.currentPower, false ), 13, 16, 4210752 ); + fontRendererObj.drawString( GuiText.MaxPower.getLocal() + ": " + Platform.formatPowerLong( ns.maxPower, false ), 13, 26, 4210752 ); + + fontRendererObj.drawString( GuiText.PowerInputRate.getLocal() + ": " + Platform.formatPowerLong( ns.avgAddition, true ), 13, 143 - 10, 4210752 ); + fontRendererObj.drawString( GuiText.PowerUsageRate.getLocal() + ": " + Platform.formatPowerLong( ns.powerUsage, true ), 13, 143 - 20, 4210752 ); + + int sectionLength = 30; + + int x = 0; + int y = 0; + int xo = 0 + 12; + int yo = 0 + 42; + int viewStart = 0;// myScrollBar.getCurrentScroll() * 5; + int viewEnd = viewStart + 5 * 4; + + String ToolTip = ""; + int toolPosX = 0; + int toolPosY = 0; + + for (int z = viewStart; z < Math.min( viewEnd, repo.size() ); z++) + { + IAEItemStack refStack = repo.getReferenceItem( z ); + if ( refStack != null ) + { + GL11.glPushMatrix(); + GL11.glScaled( 0.5, 0.5, 0.5 ); + + String str = Long.toString( refStack.getStackSize() ); + if ( refStack.getStackSize() >= 10000 ) + str = Long.toString( refStack.getStackSize() / 1000 ) + "k"; + + int w = fontRendererObj.getStringWidth( str ); + fontRendererObj.drawString( str, (int) ((x * sectionLength + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * 18 + yo + 6) * 2), + 4210752 ); + + GL11.glPopMatrix(); + int posX = x * sectionLength + xo + sectionLength - 18; + int posY = y * 18 + yo; + + if ( tooltip == z - viewStart ) + { + ToolTip = Platform.getItemDisplayName( repo.getItem( z ) ); + + ToolTip = ToolTip + ("\n" + GuiText.Installed.getLocal() + ": " + (refStack.getStackSize())); + if ( refStack.getCountRequestable() > 0 ) + ToolTip = ToolTip + ("\n" + GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( refStack.getCountRequestable(), true )); + + toolPosX = x * sectionLength + xo + sectionLength - 8; + toolPosY = y * 18 + yo; + } + + drawItem( posX, posY, repo.getItem( z ) ); + + x++; + + if ( x > 4 ) + { + y++; + x = 0; + } + } + + } + + if ( tooltip >= 0 && ToolTip.length() > 0 ) + { + GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + drawTooltip( toolPosX, toolPosY + 10, 0, ToolTip ); + GL11.glPopAttrib(); + } + + } + + // @Override - NEI + public List handleItemTooltip(ItemStack stack, int mousex, int mousey, List currenttip) + { + if ( stack != null ) + { + Slot s = getSlot( mousex, mousey ); + if ( s instanceof SlotME ) + { + IAEItemStack myStack = null; + + try + { + SlotME theSlotField = (SlotME) s; + myStack = theSlotField.getAEStack(); + } + catch (Throwable ignore) + { + } + + if ( myStack != null ) + { + while (currenttip.size() > 1) + currenttip.remove( 1 ); + + } + } + } + return currenttip; + } + + // Vanilla version... + protected void drawItemStackTooltip(ItemStack stack, int x, int y) + { + Slot s = getSlot( x, y ); + if ( s instanceof SlotME && stack != null ) + { + IAEItemStack myStack = null; + + try + { + SlotME theSlotField = (SlotME) s; + myStack = theSlotField.getAEStack(); + } + catch (Throwable ignore) + { + } + + if ( myStack != null ) + { + List currenttip = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips ); + + while (currenttip.size() > 1) + currenttip.remove( 1 ); + + currenttip.add( GuiText.Installed.getLocal() + ": " + (myStack.getStackSize()) ); + currenttip.add( GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( myStack.getCountRequestable(), true ) ); + + drawTooltip( x, y, 0, join( currenttip, "\n" ) ); + } + } + // super.drawItemStackTooltip( stack, x, y ); + } + + @Override + public Enum getSortBy() + { + return SortOrder.NAME; + } + + @Override + public Enum getSortDir() + { + return SortDir.ASCENDING; + } + + @Override + public Enum getSortDisplay() + { + return ViewItems.ALL; + } +} diff --git a/client/gui/implementations/GuiNetworkTool.java b/src/main/java/appeng/client/gui/implementations/GuiNetworkTool.java similarity index 96% rename from client/gui/implementations/GuiNetworkTool.java rename to src/main/java/appeng/client/gui/implementations/GuiNetworkTool.java index ddf4b49dc..7bed6c90a 100644 --- a/client/gui/implementations/GuiNetworkTool.java +++ b/src/main/java/appeng/client/gui/implementations/GuiNetworkTool.java @@ -1,69 +1,69 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import appeng.api.implementations.guiobjects.INetworkTool; -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiToggleButton; -import appeng.container.implementations.ContainerNetworkTool; -import appeng.core.AELog; -import appeng.core.localization.GuiText; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketValueConfig; - -public class GuiNetworkTool extends AEBaseGui -{ - - GuiToggleButton tFacades; - - public GuiNetworkTool(InventoryPlayer inventoryPlayer, INetworkTool te) { - super( new ContainerNetworkTool( inventoryPlayer, te ) ); - this.ySize = 166; - } - - @Override - protected void actionPerformed(GuiButton btn) - { - super.actionPerformed( btn ); - - try - { - if ( btn == tFacades ) - NetworkHandler.instance.sendToServer( new PacketValueConfig( "NetworkTool", "Toggle" ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - - @Override - public void initGui() - { - super.initGui(); - - tFacades = new GuiToggleButton( this.guiLeft - 18, guiTop + 8, 23, 22, GuiText.TransparentFacades.getLocal(), GuiText.TransparentFacadesHint.getLocal() ); - - buttonList.add( tFacades ); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/toolbox.png" ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - if ( tFacades != null ) - tFacades.setState( ((ContainerNetworkTool) inventorySlots).facadeMode ); - - fontRendererObj.drawString( getGuiDisplayName( GuiText.NetworkTool.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - } - -} +package appeng.client.gui.implementations; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import appeng.api.implementations.guiobjects.INetworkTool; +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiToggleButton; +import appeng.container.implementations.ContainerNetworkTool; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketValueConfig; + +public class GuiNetworkTool extends AEBaseGui +{ + + GuiToggleButton tFacades; + + public GuiNetworkTool(InventoryPlayer inventoryPlayer, INetworkTool te) { + super( new ContainerNetworkTool( inventoryPlayer, te ) ); + this.ySize = 166; + } + + @Override + protected void actionPerformed(GuiButton btn) + { + super.actionPerformed( btn ); + + try + { + if ( btn == tFacades ) + NetworkHandler.instance.sendToServer( new PacketValueConfig( "NetworkTool", "Toggle" ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + + @Override + public void initGui() + { + super.initGui(); + + tFacades = new GuiToggleButton( this.guiLeft - 18, guiTop + 8, 23, 22, GuiText.TransparentFacades.getLocal(), GuiText.TransparentFacadesHint.getLocal() ); + + buttonList.add( tFacades ); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/toolbox.png" ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + if ( tFacades != null ) + tFacades.setState( ((ContainerNetworkTool) inventorySlots).facadeMode ); + + fontRendererObj.drawString( getGuiDisplayName( GuiText.NetworkTool.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + } + +} diff --git a/client/gui/implementations/GuiPatternTerm.java b/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java similarity index 100% rename from client/gui/implementations/GuiPatternTerm.java rename to src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java diff --git a/client/gui/implementations/GuiPriority.java b/src/main/java/appeng/client/gui/implementations/GuiPriority.java similarity index 100% rename from client/gui/implementations/GuiPriority.java rename to src/main/java/appeng/client/gui/implementations/GuiPriority.java diff --git a/client/gui/implementations/GuiQNB.java b/src/main/java/appeng/client/gui/implementations/GuiQNB.java similarity index 96% rename from client/gui/implementations/GuiQNB.java rename to src/main/java/appeng/client/gui/implementations/GuiQNB.java index 51ed51184..f9c572910 100644 --- a/client/gui/implementations/GuiQNB.java +++ b/src/main/java/appeng/client/gui/implementations/GuiQNB.java @@ -1,31 +1,31 @@ -package appeng.client.gui.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import appeng.client.gui.AEBaseGui; -import appeng.container.implementations.ContainerQNB; -import appeng.core.localization.GuiText; -import appeng.tile.qnb.TileQuantumBridge; - -public class GuiQNB extends AEBaseGui -{ - - public GuiQNB(InventoryPlayer inventoryPlayer, TileQuantumBridge te) { - super( new ContainerQNB( inventoryPlayer, te ) ); - this.ySize = 166; - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/chest.png" ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( GuiText.QuantumLinkChamber.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - } - -} +package appeng.client.gui.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import appeng.client.gui.AEBaseGui; +import appeng.container.implementations.ContainerQNB; +import appeng.core.localization.GuiText; +import appeng.tile.qnb.TileQuantumBridge; + +public class GuiQNB extends AEBaseGui +{ + + public GuiQNB(InventoryPlayer inventoryPlayer, TileQuantumBridge te) { + super( new ContainerQNB( inventoryPlayer, te ) ); + this.ySize = 166; + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/chest.png" ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( GuiText.QuantumLinkChamber.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + } + +} diff --git a/client/gui/implementations/GuiQuartzKnife.java b/src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java similarity index 100% rename from client/gui/implementations/GuiQuartzKnife.java rename to src/main/java/appeng/client/gui/implementations/GuiQuartzKnife.java diff --git a/client/gui/implementations/GuiSecurity.java b/src/main/java/appeng/client/gui/implementations/GuiSecurity.java similarity index 100% rename from client/gui/implementations/GuiSecurity.java rename to src/main/java/appeng/client/gui/implementations/GuiSecurity.java diff --git a/client/gui/implementations/GuiSkyChest.java b/src/main/java/appeng/client/gui/implementations/GuiSkyChest.java similarity index 100% rename from client/gui/implementations/GuiSkyChest.java rename to src/main/java/appeng/client/gui/implementations/GuiSkyChest.java diff --git a/client/gui/implementations/GuiSpatialIOPort.java b/src/main/java/appeng/client/gui/implementations/GuiSpatialIOPort.java similarity index 97% rename from client/gui/implementations/GuiSpatialIOPort.java rename to src/main/java/appeng/client/gui/implementations/GuiSpatialIOPort.java index 7905624db..725d408f7 100644 --- a/client/gui/implementations/GuiSpatialIOPort.java +++ b/src/main/java/appeng/client/gui/implementations/GuiSpatialIOPort.java @@ -1,71 +1,71 @@ -package appeng.client.gui.implementations; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.input.Mouse; - -import appeng.api.config.Settings; -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.container.implementations.ContainerSpatialIOPort; -import appeng.core.AEConfig; -import appeng.core.localization.GuiText; -import appeng.tile.spatial.TileSpatialIOPort; -import appeng.util.Platform; - -public class GuiSpatialIOPort extends AEBaseGui -{ - - ContainerSpatialIOPort csiop; - GuiImgButton units; - - public GuiSpatialIOPort(InventoryPlayer inventoryPlayer, TileSpatialIOPort te) { - super( new ContainerSpatialIOPort( inventoryPlayer, te ) ); - this.ySize = 199; - csiop = (ContainerSpatialIOPort) inventorySlots; - } - - @Override - protected void actionPerformed(GuiButton btn) - { - super.actionPerformed( btn ); - - boolean backwards = Mouse.isButtonDown( 1 ); - - if ( btn == units ) - { - AEConfig.instance.nextPowerUnit( backwards ); - units.set( AEConfig.instance.selectedPowerUnit() ); - } - } - - @Override - public void initGui() - { - super.initGui(); - - units = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.POWER_UNITS, AEConfig.instance.selectedPowerUnit() ); - buttonList.add( units ); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/spatialio.png" ); - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( GuiText.StoredPower.getLocal() + ": " + Platform.formatPowerLong( csiop.currentPower, false ), 13, 21, 4210752 ); - fontRendererObj.drawString( GuiText.MaxPower.getLocal() + ": " + Platform.formatPowerLong( csiop.maxPower, false ), 13, 31, 4210752 ); - fontRendererObj.drawString( GuiText.RequiredPower.getLocal() + ": " + Platform.formatPowerLong( csiop.reqPower, false ), 13, 78, 4210752 ); - fontRendererObj.drawString( GuiText.Efficiency.getLocal() + ": " + (((float) csiop.eff) / 100) + "%", 13, 88, 4210752 ); - - fontRendererObj.drawString( getGuiDisplayName( GuiText.SpatialIOPort.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96, 4210752 ); - } - -} +package appeng.client.gui.implementations; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; + +import org.lwjgl.input.Mouse; + +import appeng.api.config.Settings; +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.container.implementations.ContainerSpatialIOPort; +import appeng.core.AEConfig; +import appeng.core.localization.GuiText; +import appeng.tile.spatial.TileSpatialIOPort; +import appeng.util.Platform; + +public class GuiSpatialIOPort extends AEBaseGui +{ + + ContainerSpatialIOPort csiop; + GuiImgButton units; + + public GuiSpatialIOPort(InventoryPlayer inventoryPlayer, TileSpatialIOPort te) { + super( new ContainerSpatialIOPort( inventoryPlayer, te ) ); + this.ySize = 199; + csiop = (ContainerSpatialIOPort) inventorySlots; + } + + @Override + protected void actionPerformed(GuiButton btn) + { + super.actionPerformed( btn ); + + boolean backwards = Mouse.isButtonDown( 1 ); + + if ( btn == units ) + { + AEConfig.instance.nextPowerUnit( backwards ); + units.set( AEConfig.instance.selectedPowerUnit() ); + } + } + + @Override + public void initGui() + { + super.initGui(); + + units = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.POWER_UNITS, AEConfig.instance.selectedPowerUnit() ); + buttonList.add( units ); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/spatialio.png" ); + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( GuiText.StoredPower.getLocal() + ": " + Platform.formatPowerLong( csiop.currentPower, false ), 13, 21, 4210752 ); + fontRendererObj.drawString( GuiText.MaxPower.getLocal() + ": " + Platform.formatPowerLong( csiop.maxPower, false ), 13, 31, 4210752 ); + fontRendererObj.drawString( GuiText.RequiredPower.getLocal() + ": " + Platform.formatPowerLong( csiop.reqPower, false ), 13, 78, 4210752 ); + fontRendererObj.drawString( GuiText.Efficiency.getLocal() + ": " + (((float) csiop.eff) / 100) + "%", 13, 88, 4210752 ); + + fontRendererObj.drawString( getGuiDisplayName( GuiText.SpatialIOPort.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96, 4210752 ); + } + +} diff --git a/client/gui/implementations/GuiStorageBus.java b/src/main/java/appeng/client/gui/implementations/GuiStorageBus.java similarity index 96% rename from client/gui/implementations/GuiStorageBus.java rename to src/main/java/appeng/client/gui/implementations/GuiStorageBus.java index d26812593..a20af4179 100644 --- a/client/gui/implementations/GuiStorageBus.java +++ b/src/main/java/appeng/client/gui/implementations/GuiStorageBus.java @@ -1,120 +1,120 @@ -package appeng.client.gui.implementations; - -import java.io.IOException; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.input.Mouse; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.ActionItems; -import appeng.api.config.FuzzyMode; -import appeng.api.config.Settings; -import appeng.api.config.StorageFilter; -import appeng.client.gui.widgets.GuiImgButton; -import appeng.client.gui.widgets.GuiTabButton; -import appeng.container.implementations.ContainerStorageBus; -import appeng.core.AELog; -import appeng.core.localization.GuiText; -import appeng.core.sync.GuiBridge; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketConfigButton; -import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.parts.misc.PartStorageBus; - -public class GuiStorageBus extends GuiUpgradeable -{ - - GuiImgButton rwMode; - GuiImgButton storageFilter; - GuiTabButton priority; - GuiImgButton partition; - GuiImgButton clear; - - public GuiStorageBus(InventoryPlayer inventoryPlayer, PartStorageBus te) { - super( new ContainerStorageBus( inventoryPlayer, te ) ); - this.ySize = 251; - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - super.drawBG( offsetX, offsetY, mouseX, mouseY ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( GuiText.StorageBus.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - - if ( fuzzyMode != null ) - fuzzyMode.set( cvb.fzMode ); - - if ( storageFilter != null ) - storageFilter.set( ((ContainerStorageBus) cvb).storageFilter ); - - if ( rwMode != null ) - rwMode.set( ((ContainerStorageBus) cvb).rwMode ); - } - - @Override - protected void addButtons() - { - clear = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE ); - partition = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH ); - rwMode = new GuiImgButton( this.guiLeft - 18, guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE ); - storageFilter = new GuiImgButton( this.guiLeft - 18, guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY ); - fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); - - buttonList.add( priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), itemRender ) ); - - buttonList.add( storageFilter ); - buttonList.add( fuzzyMode ); - buttonList.add( rwMode ); - buttonList.add( partition ); - buttonList.add( clear ); - } - - @Override - protected void actionPerformed(GuiButton btn) - { - super.actionPerformed( btn ); - - boolean backwards = Mouse.isButtonDown( 1 ); - - try - { - if ( btn == partition ) - NetworkHandler.instance.sendToServer( new PacketValueConfig( "StorageBus.Action", "Partition" ) ); - - else if ( btn == clear ) - NetworkHandler.instance.sendToServer( new PacketValueConfig( "StorageBus.Action", "Clear" ) ); - - else if ( btn == priority ) - NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); - - else if ( btn == fuzzyMode ) - NetworkHandler.instance.sendToServer( new PacketConfigButton( fuzzyMode.getSetting(), backwards ) ); - - else if ( btn == rwMode ) - NetworkHandler.instance.sendToServer( new PacketConfigButton( rwMode.getSetting(), backwards ) ); - - else if ( btn == storageFilter ) - NetworkHandler.instance.sendToServer( new PacketConfigButton( storageFilter.getSetting(), backwards ) ); - - } - catch (IOException e) - { - AELog.error( e ); - } - } - - protected String getBackground() - { - return "guis/storagebus.png"; - } - -} +package appeng.client.gui.implementations; + +import java.io.IOException; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; + +import org.lwjgl.input.Mouse; + +import appeng.api.config.AccessRestriction; +import appeng.api.config.ActionItems; +import appeng.api.config.FuzzyMode; +import appeng.api.config.Settings; +import appeng.api.config.StorageFilter; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiTabButton; +import appeng.container.implementations.ContainerStorageBus; +import appeng.core.AELog; +import appeng.core.localization.GuiText; +import appeng.core.sync.GuiBridge; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketConfigButton; +import appeng.core.sync.packets.PacketSwitchGuis; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.parts.misc.PartStorageBus; + +public class GuiStorageBus extends GuiUpgradeable +{ + + GuiImgButton rwMode; + GuiImgButton storageFilter; + GuiTabButton priority; + GuiImgButton partition; + GuiImgButton clear; + + public GuiStorageBus(InventoryPlayer inventoryPlayer, PartStorageBus te) { + super( new ContainerStorageBus( inventoryPlayer, te ) ); + this.ySize = 251; + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + super.drawBG( offsetX, offsetY, mouseX, mouseY ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( GuiText.StorageBus.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + + if ( fuzzyMode != null ) + fuzzyMode.set( cvb.fzMode ); + + if ( storageFilter != null ) + storageFilter.set( ((ContainerStorageBus) cvb).storageFilter ); + + if ( rwMode != null ) + rwMode.set( ((ContainerStorageBus) cvb).rwMode ); + } + + @Override + protected void addButtons() + { + clear = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE ); + partition = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH ); + rwMode = new GuiImgButton( this.guiLeft - 18, guiTop + 48, Settings.ACCESS, AccessRestriction.READ_WRITE ); + storageFilter = new GuiImgButton( this.guiLeft - 18, guiTop + 68, Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY ); + fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 88, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL ); + + buttonList.add( priority = new GuiTabButton( this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), itemRender ) ); + + buttonList.add( storageFilter ); + buttonList.add( fuzzyMode ); + buttonList.add( rwMode ); + buttonList.add( partition ); + buttonList.add( clear ); + } + + @Override + protected void actionPerformed(GuiButton btn) + { + super.actionPerformed( btn ); + + boolean backwards = Mouse.isButtonDown( 1 ); + + try + { + if ( btn == partition ) + NetworkHandler.instance.sendToServer( new PacketValueConfig( "StorageBus.Action", "Partition" ) ); + + else if ( btn == clear ) + NetworkHandler.instance.sendToServer( new PacketValueConfig( "StorageBus.Action", "Clear" ) ); + + else if ( btn == priority ) + NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_PRIORITY ) ); + + else if ( btn == fuzzyMode ) + NetworkHandler.instance.sendToServer( new PacketConfigButton( fuzzyMode.getSetting(), backwards ) ); + + else if ( btn == rwMode ) + NetworkHandler.instance.sendToServer( new PacketConfigButton( rwMode.getSetting(), backwards ) ); + + else if ( btn == storageFilter ) + NetworkHandler.instance.sendToServer( new PacketConfigButton( storageFilter.getSetting(), backwards ) ); + + } + catch (IOException e) + { + AELog.error( e ); + } + } + + protected String getBackground() + { + return "guis/storagebus.png"; + } + +} diff --git a/client/gui/implementations/GuiUpgradeable.java b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java similarity index 100% rename from client/gui/implementations/GuiUpgradeable.java rename to src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java diff --git a/client/gui/implementations/GuiVibrationChamber.java b/src/main/java/appeng/client/gui/implementations/GuiVibrationChamber.java similarity index 96% rename from client/gui/implementations/GuiVibrationChamber.java rename to src/main/java/appeng/client/gui/implementations/GuiVibrationChamber.java index f645b0ce1..916687644 100644 --- a/client/gui/implementations/GuiVibrationChamber.java +++ b/src/main/java/appeng/client/gui/implementations/GuiVibrationChamber.java @@ -1,66 +1,66 @@ -package appeng.client.gui.implementations; - -import net.minecraft.entity.player.InventoryPlayer; - -import org.lwjgl.opengl.GL11; - -import appeng.client.gui.AEBaseGui; -import appeng.client.gui.widgets.GuiProgressBar; -import appeng.client.gui.widgets.GuiProgressBar.Direction; -import appeng.container.implementations.ContainerVibrationChamber; -import appeng.core.localization.GuiText; -import appeng.tile.misc.TileVibrationChamber; - -public class GuiVibrationChamber extends AEBaseGui -{ - - ContainerVibrationChamber cvc; - GuiProgressBar pb; - - public GuiVibrationChamber(InventoryPlayer inventoryPlayer, TileVibrationChamber te) { - super( new ContainerVibrationChamber( inventoryPlayer, te ) ); - cvc = (ContainerVibrationChamber) inventorySlots; - this.ySize = 166; - } - - @Override - public void initGui() - { - super.initGui(); - - pb = new GuiProgressBar( "guis/vibchamber.png", 99, 36, 176, 14, 6, 18, Direction.VERTICAL ); - this.buttonList.add( pb ); - } - - @Override - public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) - { - bindTexture( "guis/vibchamber.png" ); - pb.xPosition = 99 + guiLeft; - pb.yPosition = 36 + guiTop; - this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); - } - - @Override - public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) - { - fontRendererObj.drawString( getGuiDisplayName( GuiText.VibrationChamber.getLocal() ), 8, 6, 4210752 ); - fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); - - int k = 25; - int l = -15; - - pb.max = 200; - pb.current = cvc.burnProgress > 0 ? cvc.burnSpeed : 0; - pb.FullMsg = (cvc.aePerTick * pb.current / 100) + " ae/t"; - - if ( cvc.burnProgress > 0 ) - { - int i1 = cvc.burnProgress; - bindTexture( "guis/vibchamber.png" ); - GL11.glColor3f( 1, 1, 1 ); - this.drawTexturedModalRect( k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2 ); - } - } - -} +package appeng.client.gui.implementations; + +import net.minecraft.entity.player.InventoryPlayer; + +import org.lwjgl.opengl.GL11; + +import appeng.client.gui.AEBaseGui; +import appeng.client.gui.widgets.GuiProgressBar; +import appeng.client.gui.widgets.GuiProgressBar.Direction; +import appeng.container.implementations.ContainerVibrationChamber; +import appeng.core.localization.GuiText; +import appeng.tile.misc.TileVibrationChamber; + +public class GuiVibrationChamber extends AEBaseGui +{ + + ContainerVibrationChamber cvc; + GuiProgressBar pb; + + public GuiVibrationChamber(InventoryPlayer inventoryPlayer, TileVibrationChamber te) { + super( new ContainerVibrationChamber( inventoryPlayer, te ) ); + cvc = (ContainerVibrationChamber) inventorySlots; + this.ySize = 166; + } + + @Override + public void initGui() + { + super.initGui(); + + pb = new GuiProgressBar( "guis/vibchamber.png", 99, 36, 176, 14, 6, 18, Direction.VERTICAL ); + this.buttonList.add( pb ); + } + + @Override + public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) + { + bindTexture( "guis/vibchamber.png" ); + pb.xPosition = 99 + guiLeft; + pb.yPosition = 36 + guiTop; + this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); + } + + @Override + public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) + { + fontRendererObj.drawString( getGuiDisplayName( GuiText.VibrationChamber.getLocal() ), 8, 6, 4210752 ); + fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 ); + + int k = 25; + int l = -15; + + pb.max = 200; + pb.current = cvc.burnProgress > 0 ? cvc.burnSpeed : 0; + pb.FullMsg = (cvc.aePerTick * pb.current / 100) + " ae/t"; + + if ( cvc.burnProgress > 0 ) + { + int i1 = cvc.burnProgress; + bindTexture( "guis/vibchamber.png" ); + GL11.glColor3f( 1, 1, 1 ); + this.drawTexturedModalRect( k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2 ); + } + } + +} diff --git a/client/gui/implementations/GuiWireless.java b/src/main/java/appeng/client/gui/implementations/GuiWireless.java similarity index 100% rename from client/gui/implementations/GuiWireless.java rename to src/main/java/appeng/client/gui/implementations/GuiWireless.java diff --git a/client/gui/implementations/GuiWirelessTerm.java b/src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java similarity index 100% rename from client/gui/implementations/GuiWirelessTerm.java rename to src/main/java/appeng/client/gui/implementations/GuiWirelessTerm.java diff --git a/client/gui/widgets/GuiImgButton.java b/src/main/java/appeng/client/gui/widgets/GuiImgButton.java similarity index 100% rename from client/gui/widgets/GuiImgButton.java rename to src/main/java/appeng/client/gui/widgets/GuiImgButton.java diff --git a/client/gui/widgets/GuiNumberBox.java b/src/main/java/appeng/client/gui/widgets/GuiNumberBox.java similarity index 95% rename from client/gui/widgets/GuiNumberBox.java rename to src/main/java/appeng/client/gui/widgets/GuiNumberBox.java index dd9ed6dcd..da9fd8c6a 100644 --- a/client/gui/widgets/GuiNumberBox.java +++ b/src/main/java/appeng/client/gui/widgets/GuiNumberBox.java @@ -1,39 +1,39 @@ -package appeng.client.gui.widgets; - -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiTextField; - - -public class GuiNumberBox extends GuiTextField -{ - - final Class type; - - public GuiNumberBox(FontRenderer p_i1032_1_, int p_i1032_2_, int p_i1032_3_, int p_i1032_4_, int p_i1032_5_,Class type) { - super( p_i1032_1_, p_i1032_2_, p_i1032_3_, p_i1032_4_, p_i1032_5_ ); - this.type = type; - } - - @Override - public void writeText(String p_146191_1_) - { - String original = getText(); - super.writeText( p_146191_1_ ); - - try - { - if ( type == int.class || type == Integer.class ) - Integer.parseInt( getText() ); - else if ( type == long.class || type == Long.class ) - Long.parseLong( getText() ); - else if ( type == double.class || type == Double.class ) - Double.parseDouble( getText() ); - } - catch(NumberFormatException e ) - { - setText( original ); - } - } - - -} +package appeng.client.gui.widgets; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiTextField; + + +public class GuiNumberBox extends GuiTextField +{ + + final Class type; + + public GuiNumberBox(FontRenderer p_i1032_1_, int p_i1032_2_, int p_i1032_3_, int p_i1032_4_, int p_i1032_5_,Class type) { + super( p_i1032_1_, p_i1032_2_, p_i1032_3_, p_i1032_4_, p_i1032_5_ ); + this.type = type; + } + + @Override + public void writeText(String p_146191_1_) + { + String original = getText(); + super.writeText( p_146191_1_ ); + + try + { + if ( type == int.class || type == Integer.class ) + Integer.parseInt( getText() ); + else if ( type == long.class || type == Long.class ) + Long.parseLong( getText() ); + else if ( type == double.class || type == Double.class ) + Double.parseDouble( getText() ); + } + catch(NumberFormatException e ) + { + setText( original ); + } + } + + +} diff --git a/client/gui/widgets/GuiProgressBar.java b/src/main/java/appeng/client/gui/widgets/GuiProgressBar.java similarity index 100% rename from client/gui/widgets/GuiProgressBar.java rename to src/main/java/appeng/client/gui/widgets/GuiProgressBar.java diff --git a/client/gui/widgets/GuiScrollbar.java b/src/main/java/appeng/client/gui/widgets/GuiScrollbar.java similarity index 94% rename from client/gui/widgets/GuiScrollbar.java rename to src/main/java/appeng/client/gui/widgets/GuiScrollbar.java index 88c964ace..b0c6c9802 100644 --- a/client/gui/widgets/GuiScrollbar.java +++ b/src/main/java/appeng/client/gui/widgets/GuiScrollbar.java @@ -1,132 +1,132 @@ -package appeng.client.gui.widgets; - -import org.lwjgl.opengl.GL11; - -import appeng.client.gui.AEBaseGui; - -public class GuiScrollbar implements IScrollSource -{ - - private int displayX = 0; - private int displayY = 0; - private int width = 12; - private int height = 16; - private int pageSize = 1; - - private int maxScroll = 0; - private int minScroll = 0; - private int currentScroll = 0; - - private void applyRange() - { - currentScroll = Math.max( Math.min( currentScroll, maxScroll ), minScroll ); - } - - public void draw(AEBaseGui g) - { - g.bindTexture( "minecraft", "gui/container/creative_inventory/tabs.png" ); - GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); - - if ( getRange() == 0 ) - { - g.drawTexturedModalRect( displayX, displayY, 232 + width, 0, width, 15 ); - } - else - { - int offset = (currentScroll - minScroll) * (height - 15) / getRange(); - g.drawTexturedModalRect( displayX, offset + displayY, 232, 0, width, 15 ); - } - } - - public int getRange() - { - return maxScroll - minScroll; - } - - public int getLeft() - { - return displayX; - } - - public int getTop() - { - return displayY; - } - - public int getWidth() - { - return width; - } - - public int getHeight() - { - return height; - } - - public GuiScrollbar setLeft(int v) - { - displayX = v; - return this; - } - - public GuiScrollbar setTop(int v) - { - displayY = v; - return this; - } - - public GuiScrollbar setWidth(int v) - { - width = v; - return this; - } - - public GuiScrollbar setHeight(int v) - { - height = v; - return this; - } - - public void setRange(int min, int max, int pageSize) - { - minScroll = min; - maxScroll = max; - this.pageSize = pageSize; - - if ( minScroll > maxScroll ) - maxScroll = minScroll; - - applyRange(); - } - - @Override - public int getCurrentScroll() - { - return currentScroll; - } - - public void click(AEBaseGui aeBaseGui, int x, int y) - { - if ( getRange() == 0 ) - return; - - if ( x > displayX && x <= displayX + width ) - { - if ( y > displayY && y <= displayY + height ) - { - currentScroll = (y - displayY); - currentScroll = minScroll + ((currentScroll * 2 * getRange() / height)); - currentScroll = (currentScroll + 1) >> 1; - applyRange(); - } - } - } - - public void wheel(int delta) - { - delta = Math.max( Math.min( -delta, 1 ), -1 ); - currentScroll += delta * pageSize; - applyRange(); - } - -} +package appeng.client.gui.widgets; + +import org.lwjgl.opengl.GL11; + +import appeng.client.gui.AEBaseGui; + +public class GuiScrollbar implements IScrollSource +{ + + private int displayX = 0; + private int displayY = 0; + private int width = 12; + private int height = 16; + private int pageSize = 1; + + private int maxScroll = 0; + private int minScroll = 0; + private int currentScroll = 0; + + private void applyRange() + { + currentScroll = Math.max( Math.min( currentScroll, maxScroll ), minScroll ); + } + + public void draw(AEBaseGui g) + { + g.bindTexture( "minecraft", "gui/container/creative_inventory/tabs.png" ); + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + + if ( getRange() == 0 ) + { + g.drawTexturedModalRect( displayX, displayY, 232 + width, 0, width, 15 ); + } + else + { + int offset = (currentScroll - minScroll) * (height - 15) / getRange(); + g.drawTexturedModalRect( displayX, offset + displayY, 232, 0, width, 15 ); + } + } + + public int getRange() + { + return maxScroll - minScroll; + } + + public int getLeft() + { + return displayX; + } + + public int getTop() + { + return displayY; + } + + public int getWidth() + { + return width; + } + + public int getHeight() + { + return height; + } + + public GuiScrollbar setLeft(int v) + { + displayX = v; + return this; + } + + public GuiScrollbar setTop(int v) + { + displayY = v; + return this; + } + + public GuiScrollbar setWidth(int v) + { + width = v; + return this; + } + + public GuiScrollbar setHeight(int v) + { + height = v; + return this; + } + + public void setRange(int min, int max, int pageSize) + { + minScroll = min; + maxScroll = max; + this.pageSize = pageSize; + + if ( minScroll > maxScroll ) + maxScroll = minScroll; + + applyRange(); + } + + @Override + public int getCurrentScroll() + { + return currentScroll; + } + + public void click(AEBaseGui aeBaseGui, int x, int y) + { + if ( getRange() == 0 ) + return; + + if ( x > displayX && x <= displayX + width ) + { + if ( y > displayY && y <= displayY + height ) + { + currentScroll = (y - displayY); + currentScroll = minScroll + ((currentScroll * 2 * getRange() / height)); + currentScroll = (currentScroll + 1) >> 1; + applyRange(); + } + } + } + + public void wheel(int delta) + { + delta = Math.max( Math.min( -delta, 1 ), -1 ); + currentScroll += delta * pageSize; + applyRange(); + } + +} diff --git a/client/gui/widgets/GuiTabButton.java b/src/main/java/appeng/client/gui/widgets/GuiTabButton.java similarity index 100% rename from client/gui/widgets/GuiTabButton.java rename to src/main/java/appeng/client/gui/widgets/GuiTabButton.java diff --git a/client/gui/widgets/GuiToggleButton.java b/src/main/java/appeng/client/gui/widgets/GuiToggleButton.java similarity index 100% rename from client/gui/widgets/GuiToggleButton.java rename to src/main/java/appeng/client/gui/widgets/GuiToggleButton.java diff --git a/client/gui/widgets/IScrollSource.java b/src/main/java/appeng/client/gui/widgets/IScrollSource.java similarity index 92% rename from client/gui/widgets/IScrollSource.java rename to src/main/java/appeng/client/gui/widgets/IScrollSource.java index 928cbe2ef..a69b6969d 100644 --- a/client/gui/widgets/IScrollSource.java +++ b/src/main/java/appeng/client/gui/widgets/IScrollSource.java @@ -1,8 +1,8 @@ -package appeng.client.gui.widgets; - -public interface IScrollSource -{ - - int getCurrentScroll(); - -} +package appeng.client.gui.widgets; + +public interface IScrollSource +{ + + int getCurrentScroll(); + +} diff --git a/client/gui/widgets/ISortSource.java b/src/main/java/appeng/client/gui/widgets/ISortSource.java similarity index 100% rename from client/gui/widgets/ISortSource.java rename to src/main/java/appeng/client/gui/widgets/ISortSource.java diff --git a/client/gui/widgets/ITooltip.java b/src/main/java/appeng/client/gui/widgets/ITooltip.java similarity index 93% rename from client/gui/widgets/ITooltip.java rename to src/main/java/appeng/client/gui/widgets/ITooltip.java index fb2a5ed65..cd6c1b7bc 100644 --- a/client/gui/widgets/ITooltip.java +++ b/src/main/java/appeng/client/gui/widgets/ITooltip.java @@ -1,50 +1,50 @@ -package appeng.client.gui.widgets; - -/** - * AEBaseGui controlled Tooltip Interface. - * - */ -public interface ITooltip -{ - - /** - * returns the tooltip message. - * - * @return - */ - String getMsg(); - - /** - * x Location for the object that triggers the tooltip. - * - * @return xPosition - */ - int xPos(); - - /** - * y Location for the object that triggers the tooltip. - * - * @return yPosition - */ - int yPos(); - - /** - * Width of the object that triggers the tooltip. - * - * @return width - */ - int getWidth(); - - /** - * Height for the object that triggers the tooltip. - * - * @return height - */ - int getHeight(); - - /** - * @return true if button being drawn - */ - boolean isVisible(); - -} +package appeng.client.gui.widgets; + +/** + * AEBaseGui controlled Tooltip Interface. + * + */ +public interface ITooltip +{ + + /** + * returns the tooltip message. + * + * @return + */ + String getMsg(); + + /** + * x Location for the object that triggers the tooltip. + * + * @return xPosition + */ + int xPos(); + + /** + * y Location for the object that triggers the tooltip. + * + * @return yPosition + */ + int yPos(); + + /** + * Width of the object that triggers the tooltip. + * + * @return width + */ + int getWidth(); + + /** + * Height for the object that triggers the tooltip. + * + * @return height + */ + int getHeight(); + + /** + * @return true if button being drawn + */ + boolean isVisible(); + +} diff --git a/client/gui/widgets/MEGuiTextField.java b/src/main/java/appeng/client/gui/widgets/MEGuiTextField.java similarity index 100% rename from client/gui/widgets/MEGuiTextField.java rename to src/main/java/appeng/client/gui/widgets/MEGuiTextField.java diff --git a/client/me/ClientDCInternalInv.java b/src/main/java/appeng/client/me/ClientDCInternalInv.java similarity index 100% rename from client/me/ClientDCInternalInv.java rename to src/main/java/appeng/client/me/ClientDCInternalInv.java diff --git a/client/me/InternalSlotME.java b/src/main/java/appeng/client/me/InternalSlotME.java similarity index 94% rename from client/me/InternalSlotME.java rename to src/main/java/appeng/client/me/InternalSlotME.java index 34455ad8b..4d3fae6d5 100644 --- a/client/me/InternalSlotME.java +++ b/src/main/java/appeng/client/me/InternalSlotME.java @@ -1,36 +1,36 @@ -package appeng.client.me; - -import net.minecraft.item.ItemStack; -import appeng.api.storage.data.IAEItemStack; - -public class InternalSlotME -{ - - private final ItemRepo repo; - - public int offset; - public int xPos; - public int yPos; - - public InternalSlotME(ItemRepo def, int offset, int displayX, int displayY) { - this.repo = def; - this.offset = offset; - this.xPos = displayX; - this.yPos = displayY; - } - - public ItemStack getStack() - { - return repo.getItem( offset ); - } - - public IAEItemStack getAEStack() - { - return repo.getReferenceItem( offset ); - } - - public boolean hasPower() - { - return repo.hasPower(); - } -} +package appeng.client.me; + +import net.minecraft.item.ItemStack; +import appeng.api.storage.data.IAEItemStack; + +public class InternalSlotME +{ + + private final ItemRepo repo; + + public int offset; + public int xPos; + public int yPos; + + public InternalSlotME(ItemRepo def, int offset, int displayX, int displayY) { + this.repo = def; + this.offset = offset; + this.xPos = displayX; + this.yPos = displayY; + } + + public ItemStack getStack() + { + return repo.getItem( offset ); + } + + public IAEItemStack getAEStack() + { + return repo.getReferenceItem( offset ); + } + + public boolean hasPower() + { + return repo.hasPower(); + } +} diff --git a/client/me/ItemRepo.java b/src/main/java/appeng/client/me/ItemRepo.java similarity index 95% rename from client/me/ItemRepo.java rename to src/main/java/appeng/client/me/ItemRepo.java index 7489a09bd..38fe8a61a 100644 --- a/client/me/ItemRepo.java +++ b/src/main/java/appeng/client/me/ItemRepo.java @@ -1,246 +1,246 @@ -package appeng.client.me; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.regex.Pattern; - -import net.minecraft.item.ItemStack; -import appeng.api.AEApi; -import appeng.api.config.SearchBoxMode; -import appeng.api.config.Settings; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.config.YesNo; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.client.gui.widgets.IScrollSource; -import appeng.client.gui.widgets.ISortSource; -import appeng.core.AEConfig; -import appeng.items.storage.ItemViewCell; -import appeng.util.ItemSorters; -import appeng.util.Platform; -import appeng.util.prioitylist.IPartitionList; -import cpw.mods.fml.relauncher.ReflectionHelper; - -public class ItemRepo -{ - - final private IItemList list = AEApi.instance().storage().createItemList(); - final private ArrayList view = new ArrayList(); - final private ArrayList dsp = new ArrayList(); - final private IScrollSource src; - final private ISortSource sortSrc; - - public int rowSize = 9; - - public String searchString = ""; - private String innerSearch = ""; - - public ItemRepo(IScrollSource src, ISortSource sortSrc) - { - this.src = src; - this.sortSrc = sortSrc; - } - - public IAEItemStack getReferenceItem(int idx) - { - idx += src.getCurrentScroll() * rowSize; - - if ( idx >= view.size() ) - return null; - return view.get( idx ); - } - - public ItemStack getItem(int idx) - { - idx += src.getCurrentScroll() * rowSize; - - if ( idx >= dsp.size() ) - return null; - return dsp.get( idx ); - } - - void setSearch(String search) - { - searchString = search == null ? "" : search; - } - - public void postUpdate(IAEItemStack is) - { - IAEItemStack st = list.findPrecise( is ); - - if ( st != null ) - { - st.reset(); - st.add( is ); - } - else - list.add( is ); - } - - IPartitionList myPartitionList; - - public void setViewCell(ItemStack[] list) - { - myPartitionList = ItemViewCell.createFilter( list ); - updateView(); - } - - private String NEIWord = null; - - private void updateNEI(String filter) - { - try - { - if ( NEIWord == null || !NEIWord.equals( filter ) ) - { - Class c = ReflectionHelper.getClass( getClass().getClassLoader(), "codechicken.nei.LayoutManager" ); - Field fldSearchField = c.getField( "searchField" ); - Object searchField = fldSearchField.get( c ); - - Method a = searchField.getClass().getMethod( "setText", String.class ); - Method b = searchField.getClass().getMethod( "onTextChange", String.class ); - - NEIWord = filter; - a.invoke( searchField, new String( filter ) ); - b.invoke( searchField, "" ); - } - } - catch (Throwable ignore) - { - - } - } - - public void updateView() - { - view.clear(); - dsp.clear(); - - view.ensureCapacity( list.size() ); - dsp.ensureCapacity( list.size() ); - - Enum vmode = sortSrc.getSortDisplay(); - Enum mode = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); - if ( mode == SearchBoxMode.NEI_AUTOSEARCH || mode == SearchBoxMode.NEI_MANUAL_SEARCH ) - updateNEI( searchString ); - - innerSearch = searchString; - boolean terminalSearchToolTips = AEConfig.instance.settings.getSetting( Settings.SEARCH_TOOLTIPS ) != YesNo.NO; - // boolean terminalSearchMods = Configuration.instance.settings.getSetting( Settings.SEARCH_MODS ) != YesNo.NO; - - boolean searchMod = false; - if ( innerSearch.startsWith( "@" ) ) - { - searchMod = true; - innerSearch = innerSearch.substring( 1 ); - } - - Pattern m = null; - try - { - m = Pattern.compile( innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE ); - } - catch (Throwable ignore) - { - try - { - m = Pattern.compile( Pattern.quote( innerSearch.toLowerCase() ), Pattern.CASE_INSENSITIVE ); - } - catch (Throwable __) - { - return; - } - } - - boolean notDone = false; - for (IAEItemStack is : list) - { - if ( myPartitionList != null ) - { - if ( !myPartitionList.isListed( is ) ) - continue; - } - - if ( vmode == ViewItems.CRAFTABLE && !is.isCraftable() ) - continue; - - if ( vmode == ViewItems.CRAFTABLE ) - { - is = is.copy(); - is.setStackSize( 0 ); - } - - if ( vmode == ViewItems.STORED && is.getStackSize() == 0 ) - continue; - - String dspName = searchMod ? Platform.getModId( is ) : Platform.getItemDisplayName( is ); - notDone = true; - - if ( m.matcher( dspName.toLowerCase() ).find() ) - { - view.add( is ); - notDone = false; - } - - if ( terminalSearchToolTips && notDone ) - { - for (Object lp : Platform.getTooltip( is )) - if ( lp instanceof String && m.matcher( (String) lp ).find() ) - { - view.add( is ); - notDone = false; - break; - } - } - - /* - * if ( terminalSearchMods && notDone ) { if ( m.matcher( Platform.getMod( is.getItemStack() ) ).find() ) { - * view.add( is ); notDone = false; } } - */ - } - - Enum SortBy = sortSrc.getSortBy(); - Enum SortDir = sortSrc.getSortDir(); - - ItemSorters.Direction = (appeng.api.config.SortDir) SortDir; - ItemSorters.init(); - - if ( SortBy == SortOrder.MOD ) - Collections.sort( view, ItemSorters.ConfigBased_SortByMod ); - else if ( SortBy == SortOrder.AMOUNT ) - Collections.sort( view, ItemSorters.ConfigBased_SortBySize ); - else if ( SortBy == SortOrder.INVTWEAKS ) - Collections.sort( view, ItemSorters.ConfigBased_SortByInvTweaks ); - else - Collections.sort( view, ItemSorters.ConfigBased_SortByName ); - - for (IAEItemStack is : view) - dsp.add( is.getItemStack() ); - } - - public int size() - { - return view.size(); - } - - public void clear() - { - list.resetStatus(); - } - - private boolean hasPower; - - public boolean hasPower() - { - return hasPower; - } - - public void setPower(boolean hasPower) - { - this.hasPower = hasPower; - } - -} +package appeng.client.me; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.regex.Pattern; + +import net.minecraft.item.ItemStack; +import appeng.api.AEApi; +import appeng.api.config.SearchBoxMode; +import appeng.api.config.Settings; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; +import appeng.api.config.YesNo; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.client.gui.widgets.IScrollSource; +import appeng.client.gui.widgets.ISortSource; +import appeng.core.AEConfig; +import appeng.items.storage.ItemViewCell; +import appeng.util.ItemSorters; +import appeng.util.Platform; +import appeng.util.prioitylist.IPartitionList; +import cpw.mods.fml.relauncher.ReflectionHelper; + +public class ItemRepo +{ + + final private IItemList list = AEApi.instance().storage().createItemList(); + final private ArrayList view = new ArrayList(); + final private ArrayList dsp = new ArrayList(); + final private IScrollSource src; + final private ISortSource sortSrc; + + public int rowSize = 9; + + public String searchString = ""; + private String innerSearch = ""; + + public ItemRepo(IScrollSource src, ISortSource sortSrc) + { + this.src = src; + this.sortSrc = sortSrc; + } + + public IAEItemStack getReferenceItem(int idx) + { + idx += src.getCurrentScroll() * rowSize; + + if ( idx >= view.size() ) + return null; + return view.get( idx ); + } + + public ItemStack getItem(int idx) + { + idx += src.getCurrentScroll() * rowSize; + + if ( idx >= dsp.size() ) + return null; + return dsp.get( idx ); + } + + void setSearch(String search) + { + searchString = search == null ? "" : search; + } + + public void postUpdate(IAEItemStack is) + { + IAEItemStack st = list.findPrecise( is ); + + if ( st != null ) + { + st.reset(); + st.add( is ); + } + else + list.add( is ); + } + + IPartitionList myPartitionList; + + public void setViewCell(ItemStack[] list) + { + myPartitionList = ItemViewCell.createFilter( list ); + updateView(); + } + + private String NEIWord = null; + + private void updateNEI(String filter) + { + try + { + if ( NEIWord == null || !NEIWord.equals( filter ) ) + { + Class c = ReflectionHelper.getClass( getClass().getClassLoader(), "codechicken.nei.LayoutManager" ); + Field fldSearchField = c.getField( "searchField" ); + Object searchField = fldSearchField.get( c ); + + Method a = searchField.getClass().getMethod( "setText", String.class ); + Method b = searchField.getClass().getMethod( "onTextChange", String.class ); + + NEIWord = filter; + a.invoke( searchField, new String( filter ) ); + b.invoke( searchField, "" ); + } + } + catch (Throwable ignore) + { + + } + } + + public void updateView() + { + view.clear(); + dsp.clear(); + + view.ensureCapacity( list.size() ); + dsp.ensureCapacity( list.size() ); + + Enum vmode = sortSrc.getSortDisplay(); + Enum mode = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ); + if ( mode == SearchBoxMode.NEI_AUTOSEARCH || mode == SearchBoxMode.NEI_MANUAL_SEARCH ) + updateNEI( searchString ); + + innerSearch = searchString; + boolean terminalSearchToolTips = AEConfig.instance.settings.getSetting( Settings.SEARCH_TOOLTIPS ) != YesNo.NO; + // boolean terminalSearchMods = Configuration.instance.settings.getSetting( Settings.SEARCH_MODS ) != YesNo.NO; + + boolean searchMod = false; + if ( innerSearch.startsWith( "@" ) ) + { + searchMod = true; + innerSearch = innerSearch.substring( 1 ); + } + + Pattern m = null; + try + { + m = Pattern.compile( innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE ); + } + catch (Throwable ignore) + { + try + { + m = Pattern.compile( Pattern.quote( innerSearch.toLowerCase() ), Pattern.CASE_INSENSITIVE ); + } + catch (Throwable __) + { + return; + } + } + + boolean notDone = false; + for (IAEItemStack is : list) + { + if ( myPartitionList != null ) + { + if ( !myPartitionList.isListed( is ) ) + continue; + } + + if ( vmode == ViewItems.CRAFTABLE && !is.isCraftable() ) + continue; + + if ( vmode == ViewItems.CRAFTABLE ) + { + is = is.copy(); + is.setStackSize( 0 ); + } + + if ( vmode == ViewItems.STORED && is.getStackSize() == 0 ) + continue; + + String dspName = searchMod ? Platform.getModId( is ) : Platform.getItemDisplayName( is ); + notDone = true; + + if ( m.matcher( dspName.toLowerCase() ).find() ) + { + view.add( is ); + notDone = false; + } + + if ( terminalSearchToolTips && notDone ) + { + for (Object lp : Platform.getTooltip( is )) + if ( lp instanceof String && m.matcher( (String) lp ).find() ) + { + view.add( is ); + notDone = false; + break; + } + } + + /* + * if ( terminalSearchMods && notDone ) { if ( m.matcher( Platform.getMod( is.getItemStack() ) ).find() ) { + * view.add( is ); notDone = false; } } + */ + } + + Enum SortBy = sortSrc.getSortBy(); + Enum SortDir = sortSrc.getSortDir(); + + ItemSorters.Direction = (appeng.api.config.SortDir) SortDir; + ItemSorters.init(); + + if ( SortBy == SortOrder.MOD ) + Collections.sort( view, ItemSorters.ConfigBased_SortByMod ); + else if ( SortBy == SortOrder.AMOUNT ) + Collections.sort( view, ItemSorters.ConfigBased_SortBySize ); + else if ( SortBy == SortOrder.INVTWEAKS ) + Collections.sort( view, ItemSorters.ConfigBased_SortByInvTweaks ); + else + Collections.sort( view, ItemSorters.ConfigBased_SortByName ); + + for (IAEItemStack is : view) + dsp.add( is.getItemStack() ); + } + + public int size() + { + return view.size(); + } + + public void clear() + { + list.resetStatus(); + } + + private boolean hasPower; + + public boolean hasPower() + { + return hasPower; + } + + public void setPower(boolean hasPower) + { + this.hasPower = hasPower; + } + +} diff --git a/client/me/SlotDisconnected.java b/src/main/java/appeng/client/me/SlotDisconnected.java similarity index 100% rename from client/me/SlotDisconnected.java rename to src/main/java/appeng/client/me/SlotDisconnected.java diff --git a/client/me/SlotME.java b/src/main/java/appeng/client/me/SlotME.java similarity index 94% rename from client/me/SlotME.java rename to src/main/java/appeng/client/me/SlotME.java index f227dfc12..cfe8cdeb9 100644 --- a/client/me/SlotME.java +++ b/src/main/java/appeng/client/me/SlotME.java @@ -1,83 +1,83 @@ -package appeng.client.me; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import appeng.api.storage.data.IAEItemStack; - -public class SlotME extends Slot -{ - - public InternalSlotME mySlot; - - public SlotME(InternalSlotME me) { - super( null, 0, me.xPos, me.yPos ); - mySlot = me; - } - - @Override - public ItemStack getStack() - { - if ( mySlot.hasPower() ) - return mySlot.getStack(); - return null; - } - - public IAEItemStack getAEStack() - { - if ( mySlot.hasPower() ) - return mySlot.getAEStack(); - return null; - } - - @Override - public boolean canTakeStack(EntityPlayer par1EntityPlayer) - { - return false; - } - - @Override - public ItemStack decrStackSize(int par1) - { - return null; - } - - @Override - public void putStack(ItemStack par1ItemStack) - { - - } - - @Override - public boolean getHasStack() - { - if ( mySlot.hasPower() ) - return getStack() != null; - return false; - } - - @Override - public boolean isItemValid(ItemStack par1ItemStack) - { - return false; - } - - @Override - public int getSlotStackLimit() - { - return 0; - } - - @Override - public boolean isSlotInInventory(IInventory par1iInventory, int par2) - { - return false; - } - - @Override - public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) - { - } - -} +package appeng.client.me; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import appeng.api.storage.data.IAEItemStack; + +public class SlotME extends Slot +{ + + public InternalSlotME mySlot; + + public SlotME(InternalSlotME me) { + super( null, 0, me.xPos, me.yPos ); + mySlot = me; + } + + @Override + public ItemStack getStack() + { + if ( mySlot.hasPower() ) + return mySlot.getStack(); + return null; + } + + public IAEItemStack getAEStack() + { + if ( mySlot.hasPower() ) + return mySlot.getAEStack(); + return null; + } + + @Override + public boolean canTakeStack(EntityPlayer par1EntityPlayer) + { + return false; + } + + @Override + public ItemStack decrStackSize(int par1) + { + return null; + } + + @Override + public void putStack(ItemStack par1ItemStack) + { + + } + + @Override + public boolean getHasStack() + { + if ( mySlot.hasPower() ) + return getStack() != null; + return false; + } + + @Override + public boolean isItemValid(ItemStack par1ItemStack) + { + return false; + } + + @Override + public int getSlotStackLimit() + { + return 0; + } + + @Override + public boolean isSlotInInventory(IInventory par1iInventory, int par2) + { + return false; + } + + @Override + public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) + { + } + +} diff --git a/client/render/AppEngRenderItem.java b/src/main/java/appeng/client/render/AppEngRenderItem.java similarity index 100% rename from client/render/AppEngRenderItem.java rename to src/main/java/appeng/client/render/AppEngRenderItem.java diff --git a/client/render/BaseBlockRender.java b/src/main/java/appeng/client/render/BaseBlockRender.java similarity index 96% rename from client/render/BaseBlockRender.java rename to src/main/java/appeng/client/render/BaseBlockRender.java index 24f001cda..88ac16bdb 100644 --- a/client/render/BaseBlockRender.java +++ b/src/main/java/appeng/client/render/BaseBlockRender.java @@ -1,789 +1,789 @@ -package appeng.client.render; - -import java.nio.FloatBuffer; -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL11; - -import appeng.api.util.IOrientable; -import appeng.api.util.IOrientableBlock; -import appeng.block.AEBaseBlock; -import appeng.client.texture.ExtraBlockTextures; -import appeng.tile.AEBaseTile; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class BaseBlockRender -{ - - final int ORIENTATION_BITS = 7; - final static int FLIP_H_BIT = 8; - final static int FLIP_V_BIT = 16; - - final double MAX_DISTANCE; - final public boolean hasTESR; - final static private byte OrientationMap[][][] = new byte[6][6][6]; - - protected int adjustBrightness(int v, double d) - { - int r = 0xff & (v >> 16); - int g = 0xff & (v >> 8); - int b = 0xff & (v >> 0); - - r *= d; - g *= d; - b *= d; - - r = Math.min( 255, Math.max( 0, r ) ); - g = Math.min( 255, Math.max( 0, g ) ); - b = Math.min( 255, Math.max( 0, b ) ); - - return (r << 16) | (g << 8) | b; - } - - static public int getOrientation(ForgeDirection in, ForgeDirection forward, ForgeDirection up) - { - if ( in == null || in.equals( ForgeDirection.UNKNOWN ) // 1 - || forward == null || forward.equals( ForgeDirection.UNKNOWN ) // 2 - || up == null || up.equals( ForgeDirection.UNKNOWN ) ) - return 0; - - int a = in.ordinal(); - int b = forward.ordinal(); - int c = up.ordinal(); - - return OrientationMap[a][b][c]; - } - - static public void setOriMap() - { - // pointed up... - OrientationMap[0][3][1] = 0; - OrientationMap[1][3][1] = 0; - OrientationMap[2][3][1] = 0; - OrientationMap[3][3][1] = 0; - OrientationMap[4][3][1] = 0; - OrientationMap[5][3][1] = 0; - - OrientationMap[0][5][1] = 1; - OrientationMap[1][5][1] = 2; - OrientationMap[2][5][1] = 0; - OrientationMap[3][5][1] = 0; - OrientationMap[4][5][1] = 0; - OrientationMap[5][5][1] = 0; - - OrientationMap[0][2][1] = 3; - OrientationMap[1][2][1] = 3; - OrientationMap[2][2][1] = 0; - OrientationMap[3][2][1] = 0; - OrientationMap[4][2][1] = 0; - OrientationMap[5][2][1] = 0; - - OrientationMap[0][4][1] = 2; - OrientationMap[1][4][1] = 1; - OrientationMap[2][4][1] = 0; - OrientationMap[3][4][1] = 0; - OrientationMap[4][4][1] = 0; - OrientationMap[5][4][1] = 0; - - // upside down - OrientationMap[0][3][0] = 0 | FLIP_H_BIT; - OrientationMap[1][3][0] = 0 | FLIP_H_BIT; - OrientationMap[2][3][0] = 3; - OrientationMap[3][3][0] = 3; - OrientationMap[4][3][0] = 3; - OrientationMap[5][3][0] = 3; - - OrientationMap[0][4][0] = 2 | FLIP_H_BIT; - OrientationMap[1][4][0] = 1 | FLIP_H_BIT; - OrientationMap[2][4][0] = 3; - OrientationMap[3][4][0] = 3; - OrientationMap[4][4][0] = 3; - OrientationMap[5][4][0] = 3; - - OrientationMap[0][5][0] = 1 | FLIP_H_BIT; - OrientationMap[1][5][0] = 2 | FLIP_H_BIT; - OrientationMap[2][5][0] = 3; - OrientationMap[3][5][0] = 3; - OrientationMap[4][5][0] = 3; - OrientationMap[5][5][0] = 3; - - OrientationMap[0][2][0] = 3 | FLIP_H_BIT; - OrientationMap[1][2][0] = 3 | FLIP_H_BIT; - OrientationMap[2][2][0] = 3; - OrientationMap[3][2][0] = 3; - OrientationMap[4][2][0] = 3; - OrientationMap[5][2][0] = 3; - - // side 1 - OrientationMap[0][3][5] = 1 | FLIP_V_BIT; - OrientationMap[1][3][5] = 1 | FLIP_H_BIT; - OrientationMap[2][3][5] = 1; - OrientationMap[3][3][5] = 1; - OrientationMap[4][3][5] = 1; - OrientationMap[5][3][5] = 1 | FLIP_V_BIT; - - OrientationMap[0][1][5] = 1 | FLIP_H_BIT; - OrientationMap[1][1][5] = 1; - OrientationMap[2][1][5] = 3 | FLIP_V_BIT; - OrientationMap[3][1][5] = 3; - OrientationMap[4][1][5] = 1 | FLIP_V_BIT; - OrientationMap[5][1][5] = 1; - - OrientationMap[0][2][5] = 1 | FLIP_H_BIT; - OrientationMap[1][2][5] = 1 | FLIP_H_BIT; - OrientationMap[2][2][5] = 1; - OrientationMap[3][2][5] = 2 | FLIP_V_BIT; - OrientationMap[4][2][5] = 1 | FLIP_V_BIT; - OrientationMap[5][2][5] = 1; - - OrientationMap[0][0][5] = 1 | FLIP_H_BIT; - OrientationMap[1][0][5] = 1; - OrientationMap[2][0][5] = 0; - OrientationMap[3][0][5] = 0 | FLIP_V_BIT; - OrientationMap[4][0][5] = 1; - OrientationMap[5][0][5] = 1 | FLIP_V_BIT; - - // side 2 - OrientationMap[0][1][2] = 0 | FLIP_H_BIT; - OrientationMap[1][1][2] = 0; - OrientationMap[2][1][2] = 2 | FLIP_H_BIT; - OrientationMap[3][1][2] = 1; - OrientationMap[4][1][2] = 3; - OrientationMap[5][1][2] = 3 | FLIP_H_BIT; - - OrientationMap[0][4][2] = 0 | FLIP_H_BIT; - OrientationMap[1][4][2] = 0 | FLIP_H_BIT; - OrientationMap[2][4][2] = 2 | FLIP_H_BIT; - OrientationMap[3][4][2] = 1; - OrientationMap[4][4][2] = 1 | FLIP_H_BIT; - OrientationMap[5][4][2] = 2; - - OrientationMap[0][0][2] = 0 | FLIP_V_BIT; - OrientationMap[1][0][2] = 0; - OrientationMap[2][0][2] = 2; - OrientationMap[3][0][2] = 1 | FLIP_H_BIT; - OrientationMap[4][0][2] = 3 | FLIP_H_BIT; - OrientationMap[5][0][2] = 0; - - OrientationMap[0][5][2] = 0 | FLIP_H_BIT; - OrientationMap[1][5][2] = 0 | FLIP_H_BIT; - OrientationMap[2][5][2] = 2; - OrientationMap[3][5][2] = 1 | FLIP_H_BIT; - OrientationMap[4][5][2] = 2; - OrientationMap[5][5][2] = 1 | FLIP_H_BIT; - - // side 3 - OrientationMap[0][0][3] = 3 | FLIP_H_BIT; - OrientationMap[1][0][3] = 3; - OrientationMap[2][0][3] = 1; - OrientationMap[3][0][3] = 2 | FLIP_H_BIT; - OrientationMap[4][0][3] = 0; - OrientationMap[5][0][3] = 0 | FLIP_H_BIT; - - OrientationMap[0][4][3] = 3; - OrientationMap[1][4][3] = 3; - OrientationMap[2][4][3] = 1 | FLIP_H_BIT; - OrientationMap[3][4][3] = 2; - OrientationMap[4][4][3] = 1; - OrientationMap[5][4][3] = 2 | FLIP_H_BIT; - - OrientationMap[0][1][3] = 3 | FLIP_V_BIT; - OrientationMap[1][1][3] = 3; - OrientationMap[2][1][3] = 1 | FLIP_H_BIT; - OrientationMap[3][1][3] = 2; - OrientationMap[4][1][3] = 3 | FLIP_H_BIT; - OrientationMap[5][1][3] = 0; - - OrientationMap[0][5][3] = 3; - OrientationMap[1][5][3] = 3; - OrientationMap[2][5][3] = 1; - OrientationMap[3][5][3] = 2 | FLIP_H_BIT; - OrientationMap[4][5][3] = 2 | FLIP_H_BIT; - OrientationMap[5][5][3] = 1; - - // side 4 - OrientationMap[0][3][4] = 1; - OrientationMap[1][3][4] = 2; - OrientationMap[2][3][4] = 2 | FLIP_H_BIT; - OrientationMap[3][3][4] = 1; - OrientationMap[4][3][4] = 2 | FLIP_H_BIT; - OrientationMap[5][3][4] = 1; - - OrientationMap[0][0][4] = 1 | FLIP_H_BIT; - OrientationMap[1][0][4] = 2; - OrientationMap[2][0][4] = 0; - OrientationMap[3][0][4] = 0 | FLIP_H_BIT; - OrientationMap[4][0][4] = 2 | FLIP_H_BIT; - OrientationMap[5][0][4] = 1; - - OrientationMap[0][1][4] = 1 | FLIP_H_BIT; - OrientationMap[1][1][4] = 2; - OrientationMap[2][1][4] = 3 | FLIP_H_BIT; - OrientationMap[3][1][4] = 3; - OrientationMap[4][1][4] = 2; - OrientationMap[5][1][4] = 1 | FLIP_H_BIT; - - OrientationMap[0][2][4] = 1; - OrientationMap[1][2][4] = 2; - OrientationMap[2][2][4] = 1; - OrientationMap[3][2][4] = 2 | FLIP_H_BIT; - OrientationMap[4][2][4] = 2; - OrientationMap[5][2][4] = 1 | FLIP_H_BIT; - } - - public BaseBlockRender() { - this( false, 20 ); - } - - public BaseBlockRender(boolean enableTESR, double TESRrange) { - hasTESR = enableTESR; - MAX_DISTANCE = TESRrange; - setOriMap(); - } - - public double getTesrRenderDistance() - { - return MAX_DISTANCE; - } - - public IIcon firstNotNull(IIcon... s) - { - for (IIcon o : s) - if ( o != null ) - return o; - return ExtraBlockTextures.getMissing(); - } - - public void renderInvBlock(EnumSet sides, AEBaseBlock block, ItemStack item, Tessellator tess, int color, RenderBlocks renderer) - { - if ( Platform.isDrawing( tess ) ) - tess.draw(); - - int meta = 0; - if ( block != null && block.hasSubtypes() && item != null ) - meta = item.getItemDamage(); - - if ( sides.contains( ForgeDirection.DOWN ) ) - { - tess.startDrawingQuads(); - tess.setNormal( 0.0F, -1.0F, 0.0F ); - tess.setColorOpaque_I( color ); - renderer.renderFaceYNeg( - block, - 0.0D, - 0.0D, - 0.0D, - firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.DOWN ), - block.getIcon( ForgeDirection.DOWN.ordinal(), meta ) ) ); - tess.draw(); - } - - if ( sides.contains( ForgeDirection.UP ) ) - { - tess.startDrawingQuads(); - tess.setNormal( 0.0F, 1.0F, 0.0F ); - tess.setColorOpaque_I( color ); - renderer.renderFaceYPos( - block, - 0.0D, - 0.0D, - 0.0D, - firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.UP ), - block.getIcon( ForgeDirection.UP.ordinal(), meta ) ) ); - tess.draw(); - } - - if ( sides.contains( ForgeDirection.NORTH ) ) - { - tess.startDrawingQuads(); - tess.setNormal( 0.0F, 0.0F, -1.0F ); - tess.setColorOpaque_I( color ); - renderer.renderFaceZNeg( - block, - 0.0D, - 0.0D, - 0.0D, - firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.NORTH ), - block.getIcon( ForgeDirection.NORTH.ordinal(), meta ) ) ); - tess.draw(); - } - - if ( sides.contains( ForgeDirection.SOUTH ) ) - { - tess.startDrawingQuads(); - tess.setNormal( 0.0F, 0.0F, 1.0F ); - tess.setColorOpaque_I( color ); - renderer.renderFaceZPos( - block, - 0.0D, - 0.0D, - 0.0D, - firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.SOUTH ), - block.getIcon( ForgeDirection.SOUTH.ordinal(), meta ) ) ); - tess.draw(); - } - - if ( sides.contains( ForgeDirection.WEST ) ) - { - tess.startDrawingQuads(); - tess.setNormal( -1.0F, 0.0F, 0.0F ); - tess.setColorOpaque_I( color ); - renderer.renderFaceXNeg( - block, - 0.0D, - 0.0D, - 0.0D, - firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.WEST ), - block.getIcon( ForgeDirection.WEST.ordinal(), meta ) ) ); - tess.draw(); - } - - if ( sides.contains( ForgeDirection.EAST ) ) - { - tess.startDrawingQuads(); - tess.setNormal( 1.0F, 0.0F, 0.0F ); - tess.setColorOpaque_I( color ); - renderer.renderFaceXPos( - block, - 0.0D, - 0.0D, - 0.0D, - firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.EAST ), - block.getIcon( ForgeDirection.EAST.ordinal(), meta ) ) ); - tess.draw(); - } - } - - public void renderInventory(AEBaseBlock block, ItemStack item, RenderBlocks renderer, ItemRenderType type, Object[] data) - { - Tessellator tess = Tessellator.instance; - - BlockRenderInfo info = block.getRendererInstance(); - if ( info.isValid() ) - { - if ( block.hasSubtypes() ) - block.setRenderStateByMeta( item.getItemDamage() ); - - renderer.uvRotateBottom = info.getTexture( ForgeDirection.DOWN ).setFlip( - getOrientation( ForgeDirection.DOWN, ForgeDirection.SOUTH, ForgeDirection.UP ) ); - renderer.uvRotateTop = info.getTexture( ForgeDirection.UP ).setFlip( getOrientation( ForgeDirection.UP, ForgeDirection.SOUTH, ForgeDirection.UP ) ); - - renderer.uvRotateEast = info.getTexture( ForgeDirection.EAST ).setFlip( - getOrientation( ForgeDirection.EAST, ForgeDirection.SOUTH, ForgeDirection.UP ) ); - renderer.uvRotateWest = info.getTexture( ForgeDirection.WEST ).setFlip( - getOrientation( ForgeDirection.WEST, ForgeDirection.SOUTH, ForgeDirection.UP ) ); - - renderer.uvRotateNorth = info.getTexture( ForgeDirection.NORTH ).setFlip( - getOrientation( ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.UP ) ); - renderer.uvRotateSouth = info.getTexture( ForgeDirection.SOUTH ).setFlip( - getOrientation( ForgeDirection.SOUTH, ForgeDirection.SOUTH, ForgeDirection.UP ) ); - } - - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), block, item, tess, 0xffffff, renderer ); - - if ( block.hasSubtypes() ) - info.setTemporaryRenderIcon( null ); - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - } - - public IOrientable getOrientable(AEBaseBlock block, IBlockAccess w, int x, int y, int z) - { - if ( block.hasBlockTileEntity() ) - return (AEBaseTile) block.getTileEntity( w, x, y, z ); - else if ( block instanceof IOrientableBlock ) - return ((IOrientableBlock) block).getOrientable( w, x, y, z ); - return null; - } - - public void preRenderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - ForgeDirection forward = ForgeDirection.SOUTH; - ForgeDirection up = ForgeDirection.UP; - - BlockRenderInfo info = block.getRendererInstance(); - IOrientable te = getOrientable( block, world, x, y, z ); - if ( te != null ) - { - forward = te.getForward(); - up = te.getUp(); - - renderer.uvRotateBottom = info.getTexture( ForgeDirection.DOWN ).setFlip( getOrientation( ForgeDirection.DOWN, forward, up ) ); - renderer.uvRotateTop = info.getTexture( ForgeDirection.UP ).setFlip( getOrientation( ForgeDirection.UP, forward, up ) ); - - renderer.uvRotateEast = info.getTexture( ForgeDirection.EAST ).setFlip( getOrientation( ForgeDirection.EAST, forward, up ) ); - renderer.uvRotateWest = info.getTexture( ForgeDirection.WEST ).setFlip( getOrientation( ForgeDirection.WEST, forward, up ) ); - - renderer.uvRotateNorth = info.getTexture( ForgeDirection.NORTH ).setFlip( getOrientation( ForgeDirection.NORTH, forward, up ) ); - renderer.uvRotateSouth = info.getTexture( ForgeDirection.SOUTH ).setFlip( getOrientation( ForgeDirection.SOUTH, forward, up ) ); - } - - } - - public void postRenderInWorld(RenderBlocks renderer) - { - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - } - - public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - preRenderInWorld( block, world, x, y, z, renderer ); - - boolean o = renderer.renderStandardBlock( block, x, y, z ); - - postRenderInWorld( renderer ); - return o; - } - - final FloatBuffer rotMat = BufferUtils.createFloatBuffer( 16 ); - - protected void applyTESRRotation(double x, double y, double z, ForgeDirection forward, ForgeDirection up) - { - if ( forward != null && up != null ) - { - if ( forward == ForgeDirection.UNKNOWN ) - forward = ForgeDirection.SOUTH; - - if ( up == ForgeDirection.UNKNOWN ) - up = ForgeDirection.UP; - - ForgeDirection west = Platform.crossProduct( forward, up ); - - rotMat.put( 0, west.offsetX ); - rotMat.put( 1, west.offsetY ); - rotMat.put( 2, west.offsetZ ); - rotMat.put( 3, 0 ); - - rotMat.put( 4, up.offsetX ); - rotMat.put( 5, up.offsetY ); - rotMat.put( 6, up.offsetZ ); - rotMat.put( 7, 0 ); - - rotMat.put( 8, forward.offsetX ); - rotMat.put( 9, forward.offsetY ); - rotMat.put( 10, forward.offsetZ ); - rotMat.put( 11, 0 ); - - rotMat.put( 12, 0 ); - rotMat.put( 13, 0 ); - rotMat.put( 14, 0 ); - rotMat.put( 15, 1 ); - GL11.glTranslated( x + 0.5, y + 0.5, z + 0.5 ); - GL11.glMultMatrix( rotMat ); - GL11.glTranslated( -0.5, -0.5, -0.5 ); - GL11.glCullFace( GL11.GL_FRONT ); - } - else - { - GL11.glTranslated( x, y, z ); - } - } - - protected void setInvRenderBounds(RenderBlocks renderer, int i, int j, int k, int l, int m, int n) - { - renderer.setRenderBounds( i / 16.0, j / 16.0, k / 16.0, l / 16.0, m / 16.0, n / 16.0 ); - } - - protected void renderBlockBounds(RenderBlocks renderer, - - double minX, double minY, double minZ, - - double maxX, double maxY, double maxZ, - - ForgeDirection x, ForgeDirection y, ForgeDirection z) - { - minX /= 16.0; - minY /= 16.0; - minZ /= 16.0; - maxX /= 16.0; - maxY /= 16.0; - maxZ /= 16.0; - - double aX = minX * x.offsetX + minY * y.offsetX + minZ * z.offsetX; - double aY = minX * x.offsetY + minY * y.offsetY + minZ * z.offsetY; - double aZ = minX * x.offsetZ + minY * y.offsetZ + minZ * z.offsetZ; - - double bX = maxX * x.offsetX + maxY * y.offsetX + maxZ * z.offsetX; - double bY = maxX * x.offsetY + maxY * y.offsetY + maxZ * z.offsetY; - double bZ = maxX * x.offsetZ + maxY * y.offsetZ + maxZ * z.offsetZ; - - if ( x.offsetX + y.offsetX + z.offsetX < 0 ) - { - aX += 1; - bX += 1; - } - - if ( x.offsetY + y.offsetY + z.offsetY < 0 ) - { - aY += 1; - bY += 1; - } - - if ( x.offsetZ + y.offsetZ + z.offsetZ < 0 ) - { - aZ += 1; - bZ += 1; - } - - renderer.renderMinX = Math.min( aX, bX ); - renderer.renderMinY = Math.min( aY, bY ); - renderer.renderMinZ = Math.min( aZ, bZ ); - renderer.renderMaxX = Math.max( aX, bX ); - renderer.renderMaxY = Math.max( aY, bY ); - renderer.renderMaxZ = Math.max( aZ, bZ ); - } - - @SideOnly(Side.CLIENT) - private void renderFace(Tessellator tess, double offsetX, double offsetY, double offsetZ, double ax, double ay, double az, double bx, double by, double bz, - double ua, double ub, double va, double vb, IIcon ico, boolean flip) - { - if ( flip ) - { - tess.addVertexWithUV( offsetX + ax * ua + bx * va, offsetY + ay * ua + by * va, offsetZ + az * ua + bz * va, ico.getInterpolatedU( ua * 16.0 ), - ico.getInterpolatedV( va * 16.0 ) ); - tess.addVertexWithUV( offsetX + ax * ua + bx * vb, offsetY + ay * ua + by * vb, offsetZ + az * ua + bz * vb, ico.getInterpolatedU( ua * 16.0 ), - ico.getInterpolatedV( vb * 16.0 ) ); - tess.addVertexWithUV( offsetX + ax * ub + bx * vb, offsetY + ay * ub + by * vb, offsetZ + az * ub + bz * vb, ico.getInterpolatedU( ub * 16.0 ), - ico.getInterpolatedV( vb * 16.0 ) ); - tess.addVertexWithUV( offsetX + ax * ub + bx * va, offsetY + ay * ub + by * va, offsetZ + az * ub + bz * va, ico.getInterpolatedU( ub * 16.0 ), - ico.getInterpolatedV( va * 16.0 ) ); - } - else - { - tess.addVertexWithUV( offsetX + ax * ua + bx * va, offsetY + ay * ua + by * va, offsetZ + az * ua + bz * va, ico.getInterpolatedU( ua * 16.0 ), - ico.getInterpolatedV( va * 16.0 ) ); - tess.addVertexWithUV( offsetX + ax * ub + bx * va, offsetY + ay * ub + by * va, offsetZ + az * ub + bz * va, ico.getInterpolatedU( ub * 16.0 ), - ico.getInterpolatedV( va * 16.0 ) ); - tess.addVertexWithUV( offsetX + ax * ub + bx * vb, offsetY + ay * ub + by * vb, offsetZ + az * ub + bz * vb, ico.getInterpolatedU( ub * 16.0 ), - ico.getInterpolatedV( vb * 16.0 ) ); - tess.addVertexWithUV( offsetX + ax * ua + bx * vb, offsetY + ay * ua + by * vb, offsetZ + az * ua + bz * vb, ico.getInterpolatedU( ua * 16.0 ), - ico.getInterpolatedV( vb * 16.0 ) ); - } - } - - @SideOnly(Side.CLIENT) - protected void renderCutoutFace(Block block, IIcon ico, int x, int y, int z, RenderBlocks renderer, ForgeDirection orientation, float edgeThickness) - { - Tessellator tess = Tessellator.instance; - - double offsetX = 0.0, offsetY = 0.0, offsetZ = 0.0; - double layaX = 0.0, layaY = 0.0, layaZ = 0.0; - double laybX = 0.0, laybY = 0.0, laybZ = 0.0; - - boolean flip = false; - switch (orientation) - { - case NORTH: - - layaX = 1.0; - laybY = 1.0; - flip = true; - - break; - case SOUTH: - - layaX = 1.0; - laybY = 1.0; - offsetZ = 1.0; - - break; - case EAST: - - flip = true; - layaZ = 1.0; - laybY = 1.0; - offsetX = 1.0; - - break; - case WEST: - - layaZ = 1.0; - laybY = 1.0; - - break; - case UP: - - flip = true; - layaX = 1.0; - laybZ = 1.0; - offsetY = 1.0; - - break; - case DOWN: - - layaX = 1.0; - laybZ = 1.0; - - break; - default: - break; - } - - offsetX += x; - offsetY += y; - offsetZ += z; - - renderFace( tess, offsetX, offsetY, offsetZ, layaX, layaY, layaZ, laybX, laybY, laybZ, - // u -> u - 0, 1.0, - // v -> v - 0, edgeThickness, ico, flip ); - - renderFace( tess, offsetX, offsetY, offsetZ, layaX, layaY, layaZ, laybX, laybY, laybZ, - // u -> u - 0.0, edgeThickness, - // v -> v - edgeThickness, 1.0 - edgeThickness, ico, flip ); - - renderFace( tess, offsetX, offsetY, offsetZ, layaX, layaY, layaZ, laybX, laybY, laybZ, - // u -> u - 1.0 - edgeThickness, 1.0, - // v -> v - edgeThickness, 1.0 - edgeThickness, ico, flip ); - - renderFace( tess, offsetX, offsetY, offsetZ, layaX, layaY, layaZ, laybX, laybY, laybZ, - // u -> u - 0, 1.0, - // v -> v - 1.0 - edgeThickness, 1.0, ico, flip ); - } - - @SideOnly(Side.CLIENT) - protected void renderFace(int x, int y, int z, Block block, IIcon ico, RenderBlocks renderer, ForgeDirection orientation) - { - switch (orientation) - { - case NORTH: - renderer.renderFaceZNeg( block, x, y, z, ico ); - break; - case SOUTH: - renderer.renderFaceZPos( block, x, y, z, ico ); - break; - case EAST: - renderer.renderFaceXPos( block, x, y, z, ico ); - break; - case WEST: - renderer.renderFaceXNeg( block, x, y, z, ico ); - break; - case UP: - renderer.renderFaceYPos( block, x, y, z, ico ); - break; - case DOWN: - renderer.renderFaceYNeg( block, x, y, z, ico ); - break; - default: - break; - } - } - - public void selectFace(RenderBlocks renderer, ForgeDirection west, ForgeDirection up, ForgeDirection forward, int u1, int u2, int v1, int v2) - { - v1 = 16 - v1; - v2 = 16 - v2; - - double minX = (forward.offsetX > 0 ? 1 : 0) + mapFaceUV( west.offsetX, u1 ) + mapFaceUV( up.offsetX, v1 ); - double minY = (forward.offsetY > 0 ? 1 : 0) + mapFaceUV( west.offsetY, u1 ) + mapFaceUV( up.offsetY, v1 ); - double minZ = (forward.offsetZ > 0 ? 1 : 0) + mapFaceUV( west.offsetZ, u1 ) + mapFaceUV( up.offsetZ, v1 ); - - double maxX = (forward.offsetX > 0 ? 1 : 0) + mapFaceUV( west.offsetX, u2 ) + mapFaceUV( up.offsetX, v2 ); - double maxY = (forward.offsetY > 0 ? 1 : 0) + mapFaceUV( west.offsetY, u2 ) + mapFaceUV( up.offsetY, v2 ); - double maxZ = (forward.offsetZ > 0 ? 1 : 0) + mapFaceUV( west.offsetZ, u2 ) + mapFaceUV( up.offsetZ, v2 ); - - renderer.renderMinX = Math.max( 0.0, Math.min( minX, maxX ) - (forward.offsetX != 0 ? 0 : 0.001) ); - renderer.renderMaxX = Math.min( 1.0, Math.max( minX, maxX ) + (forward.offsetX != 0 ? 0 : 0.001) ); - - renderer.renderMinY = Math.max( 0.0, Math.min( minY, maxY ) - (forward.offsetY != 0 ? 0 : 0.001) ); - renderer.renderMaxY = Math.min( 1.0, Math.max( minY, maxY ) + (forward.offsetY != 0 ? 0 : 0.001) ); - - renderer.renderMinZ = Math.max( 0.0, Math.min( minZ, maxZ ) - (forward.offsetZ != 0 ? 0 : 0.001) ); - renderer.renderMaxZ = Math.min( 1.0, Math.max( minZ, maxZ ) + (forward.offsetZ != 0 ? 0 : 0.001) ); - } - - private double mapFaceUV(int offset, int uv) - { - if ( offset == 0 ) - return 0; - - if ( offset > 0 ) - return (double) uv / 16.0; - - return (16.0 - (double) uv) / 16.0; - } - - public void renderTile(AEBaseBlock block, AEBaseTile tile, Tessellator tess, double x, double y, double z, float f, RenderBlocks renderer) - { - ForgeDirection forward = ForgeDirection.SOUTH; - ForgeDirection up = ForgeDirection.UP; - - renderer.uvRotateBottom = renderer.uvRotateTop = renderer.uvRotateEast = renderer.uvRotateWest = renderer.uvRotateNorth = renderer.uvRotateSouth = 0; - - applyTESRRotation( x, y, z, forward, up ); - - Minecraft.getMinecraft().getTextureManager().bindTexture( TextureMap.locationBlocksTexture ); - RenderHelper.disableStandardItemLighting(); - - if ( Minecraft.isAmbientOcclusionEnabled() ) - GL11.glShadeModel( GL11.GL_SMOOTH ); - else - GL11.glShadeModel( GL11.GL_FLAT ); - - GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); - - tess.setTranslation( -tile.xCoord, -tile.yCoord, -tile.zCoord ); - tess.startDrawingQuads(); - - // note that this is a terrible approach... - renderer.setRenderBoundsFromBlock( block ); - renderer.renderStandardBlock( block, tile.xCoord, tile.yCoord, tile.zCoord ); - - tess.draw(); - tess.setTranslation( 0, 0, 0 ); - RenderHelper.enableStandardItemLighting(); - - renderer.uvRotateBottom = renderer.uvRotateTop = renderer.uvRotateEast = renderer.uvRotateWest = renderer.uvRotateNorth = renderer.uvRotateSouth = 0; - } - - public void doRenderItem(ItemStack itemstack, TileEntity par1EntityItemFrame) - { - if ( itemstack != null ) - { - EntityItem entityitem = new EntityItem( par1EntityItemFrame.getWorldObj(), 0.0D, 0.0D, 0.0D, itemstack ); - entityitem.getEntityItem().stackSize = 1; - - // set all this stuff and then do shit? meh? - entityitem.hoverStart = 0; - entityitem.age = 0; - entityitem.rotationYaw = 0; - - GL11.glPushMatrix(); - GL11.glTranslatef( 0, -0.14F, 0 ); - - RenderItem.renderInFrame = true; - RenderManager.instance.renderEntityWithPosYaw( entityitem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F ); - RenderItem.renderInFrame = false; - - GL11.glPopMatrix(); - } - } - -} +package appeng.client.render; + +import java.nio.FloatBuffer; +import java.util.EnumSet; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; + +import appeng.api.util.IOrientable; +import appeng.api.util.IOrientableBlock; +import appeng.block.AEBaseBlock; +import appeng.client.texture.ExtraBlockTextures; +import appeng.tile.AEBaseTile; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class BaseBlockRender +{ + + final int ORIENTATION_BITS = 7; + final static int FLIP_H_BIT = 8; + final static int FLIP_V_BIT = 16; + + final double MAX_DISTANCE; + final public boolean hasTESR; + final static private byte OrientationMap[][][] = new byte[6][6][6]; + + protected int adjustBrightness(int v, double d) + { + int r = 0xff & (v >> 16); + int g = 0xff & (v >> 8); + int b = 0xff & (v >> 0); + + r *= d; + g *= d; + b *= d; + + r = Math.min( 255, Math.max( 0, r ) ); + g = Math.min( 255, Math.max( 0, g ) ); + b = Math.min( 255, Math.max( 0, b ) ); + + return (r << 16) | (g << 8) | b; + } + + static public int getOrientation(ForgeDirection in, ForgeDirection forward, ForgeDirection up) + { + if ( in == null || in.equals( ForgeDirection.UNKNOWN ) // 1 + || forward == null || forward.equals( ForgeDirection.UNKNOWN ) // 2 + || up == null || up.equals( ForgeDirection.UNKNOWN ) ) + return 0; + + int a = in.ordinal(); + int b = forward.ordinal(); + int c = up.ordinal(); + + return OrientationMap[a][b][c]; + } + + static public void setOriMap() + { + // pointed up... + OrientationMap[0][3][1] = 0; + OrientationMap[1][3][1] = 0; + OrientationMap[2][3][1] = 0; + OrientationMap[3][3][1] = 0; + OrientationMap[4][3][1] = 0; + OrientationMap[5][3][1] = 0; + + OrientationMap[0][5][1] = 1; + OrientationMap[1][5][1] = 2; + OrientationMap[2][5][1] = 0; + OrientationMap[3][5][1] = 0; + OrientationMap[4][5][1] = 0; + OrientationMap[5][5][1] = 0; + + OrientationMap[0][2][1] = 3; + OrientationMap[1][2][1] = 3; + OrientationMap[2][2][1] = 0; + OrientationMap[3][2][1] = 0; + OrientationMap[4][2][1] = 0; + OrientationMap[5][2][1] = 0; + + OrientationMap[0][4][1] = 2; + OrientationMap[1][4][1] = 1; + OrientationMap[2][4][1] = 0; + OrientationMap[3][4][1] = 0; + OrientationMap[4][4][1] = 0; + OrientationMap[5][4][1] = 0; + + // upside down + OrientationMap[0][3][0] = 0 | FLIP_H_BIT; + OrientationMap[1][3][0] = 0 | FLIP_H_BIT; + OrientationMap[2][3][0] = 3; + OrientationMap[3][3][0] = 3; + OrientationMap[4][3][0] = 3; + OrientationMap[5][3][0] = 3; + + OrientationMap[0][4][0] = 2 | FLIP_H_BIT; + OrientationMap[1][4][0] = 1 | FLIP_H_BIT; + OrientationMap[2][4][0] = 3; + OrientationMap[3][4][0] = 3; + OrientationMap[4][4][0] = 3; + OrientationMap[5][4][0] = 3; + + OrientationMap[0][5][0] = 1 | FLIP_H_BIT; + OrientationMap[1][5][0] = 2 | FLIP_H_BIT; + OrientationMap[2][5][0] = 3; + OrientationMap[3][5][0] = 3; + OrientationMap[4][5][0] = 3; + OrientationMap[5][5][0] = 3; + + OrientationMap[0][2][0] = 3 | FLIP_H_BIT; + OrientationMap[1][2][0] = 3 | FLIP_H_BIT; + OrientationMap[2][2][0] = 3; + OrientationMap[3][2][0] = 3; + OrientationMap[4][2][0] = 3; + OrientationMap[5][2][0] = 3; + + // side 1 + OrientationMap[0][3][5] = 1 | FLIP_V_BIT; + OrientationMap[1][3][5] = 1 | FLIP_H_BIT; + OrientationMap[2][3][5] = 1; + OrientationMap[3][3][5] = 1; + OrientationMap[4][3][5] = 1; + OrientationMap[5][3][5] = 1 | FLIP_V_BIT; + + OrientationMap[0][1][5] = 1 | FLIP_H_BIT; + OrientationMap[1][1][5] = 1; + OrientationMap[2][1][5] = 3 | FLIP_V_BIT; + OrientationMap[3][1][5] = 3; + OrientationMap[4][1][5] = 1 | FLIP_V_BIT; + OrientationMap[5][1][5] = 1; + + OrientationMap[0][2][5] = 1 | FLIP_H_BIT; + OrientationMap[1][2][5] = 1 | FLIP_H_BIT; + OrientationMap[2][2][5] = 1; + OrientationMap[3][2][5] = 2 | FLIP_V_BIT; + OrientationMap[4][2][5] = 1 | FLIP_V_BIT; + OrientationMap[5][2][5] = 1; + + OrientationMap[0][0][5] = 1 | FLIP_H_BIT; + OrientationMap[1][0][5] = 1; + OrientationMap[2][0][5] = 0; + OrientationMap[3][0][5] = 0 | FLIP_V_BIT; + OrientationMap[4][0][5] = 1; + OrientationMap[5][0][5] = 1 | FLIP_V_BIT; + + // side 2 + OrientationMap[0][1][2] = 0 | FLIP_H_BIT; + OrientationMap[1][1][2] = 0; + OrientationMap[2][1][2] = 2 | FLIP_H_BIT; + OrientationMap[3][1][2] = 1; + OrientationMap[4][1][2] = 3; + OrientationMap[5][1][2] = 3 | FLIP_H_BIT; + + OrientationMap[0][4][2] = 0 | FLIP_H_BIT; + OrientationMap[1][4][2] = 0 | FLIP_H_BIT; + OrientationMap[2][4][2] = 2 | FLIP_H_BIT; + OrientationMap[3][4][2] = 1; + OrientationMap[4][4][2] = 1 | FLIP_H_BIT; + OrientationMap[5][4][2] = 2; + + OrientationMap[0][0][2] = 0 | FLIP_V_BIT; + OrientationMap[1][0][2] = 0; + OrientationMap[2][0][2] = 2; + OrientationMap[3][0][2] = 1 | FLIP_H_BIT; + OrientationMap[4][0][2] = 3 | FLIP_H_BIT; + OrientationMap[5][0][2] = 0; + + OrientationMap[0][5][2] = 0 | FLIP_H_BIT; + OrientationMap[1][5][2] = 0 | FLIP_H_BIT; + OrientationMap[2][5][2] = 2; + OrientationMap[3][5][2] = 1 | FLIP_H_BIT; + OrientationMap[4][5][2] = 2; + OrientationMap[5][5][2] = 1 | FLIP_H_BIT; + + // side 3 + OrientationMap[0][0][3] = 3 | FLIP_H_BIT; + OrientationMap[1][0][3] = 3; + OrientationMap[2][0][3] = 1; + OrientationMap[3][0][3] = 2 | FLIP_H_BIT; + OrientationMap[4][0][3] = 0; + OrientationMap[5][0][3] = 0 | FLIP_H_BIT; + + OrientationMap[0][4][3] = 3; + OrientationMap[1][4][3] = 3; + OrientationMap[2][4][3] = 1 | FLIP_H_BIT; + OrientationMap[3][4][3] = 2; + OrientationMap[4][4][3] = 1; + OrientationMap[5][4][3] = 2 | FLIP_H_BIT; + + OrientationMap[0][1][3] = 3 | FLIP_V_BIT; + OrientationMap[1][1][3] = 3; + OrientationMap[2][1][3] = 1 | FLIP_H_BIT; + OrientationMap[3][1][3] = 2; + OrientationMap[4][1][3] = 3 | FLIP_H_BIT; + OrientationMap[5][1][3] = 0; + + OrientationMap[0][5][3] = 3; + OrientationMap[1][5][3] = 3; + OrientationMap[2][5][3] = 1; + OrientationMap[3][5][3] = 2 | FLIP_H_BIT; + OrientationMap[4][5][3] = 2 | FLIP_H_BIT; + OrientationMap[5][5][3] = 1; + + // side 4 + OrientationMap[0][3][4] = 1; + OrientationMap[1][3][4] = 2; + OrientationMap[2][3][4] = 2 | FLIP_H_BIT; + OrientationMap[3][3][4] = 1; + OrientationMap[4][3][4] = 2 | FLIP_H_BIT; + OrientationMap[5][3][4] = 1; + + OrientationMap[0][0][4] = 1 | FLIP_H_BIT; + OrientationMap[1][0][4] = 2; + OrientationMap[2][0][4] = 0; + OrientationMap[3][0][4] = 0 | FLIP_H_BIT; + OrientationMap[4][0][4] = 2 | FLIP_H_BIT; + OrientationMap[5][0][4] = 1; + + OrientationMap[0][1][4] = 1 | FLIP_H_BIT; + OrientationMap[1][1][4] = 2; + OrientationMap[2][1][4] = 3 | FLIP_H_BIT; + OrientationMap[3][1][4] = 3; + OrientationMap[4][1][4] = 2; + OrientationMap[5][1][4] = 1 | FLIP_H_BIT; + + OrientationMap[0][2][4] = 1; + OrientationMap[1][2][4] = 2; + OrientationMap[2][2][4] = 1; + OrientationMap[3][2][4] = 2 | FLIP_H_BIT; + OrientationMap[4][2][4] = 2; + OrientationMap[5][2][4] = 1 | FLIP_H_BIT; + } + + public BaseBlockRender() { + this( false, 20 ); + } + + public BaseBlockRender(boolean enableTESR, double TESRrange) { + hasTESR = enableTESR; + MAX_DISTANCE = TESRrange; + setOriMap(); + } + + public double getTesrRenderDistance() + { + return MAX_DISTANCE; + } + + public IIcon firstNotNull(IIcon... s) + { + for (IIcon o : s) + if ( o != null ) + return o; + return ExtraBlockTextures.getMissing(); + } + + public void renderInvBlock(EnumSet sides, AEBaseBlock block, ItemStack item, Tessellator tess, int color, RenderBlocks renderer) + { + if ( Platform.isDrawing( tess ) ) + tess.draw(); + + int meta = 0; + if ( block != null && block.hasSubtypes() && item != null ) + meta = item.getItemDamage(); + + if ( sides.contains( ForgeDirection.DOWN ) ) + { + tess.startDrawingQuads(); + tess.setNormal( 0.0F, -1.0F, 0.0F ); + tess.setColorOpaque_I( color ); + renderer.renderFaceYNeg( + block, + 0.0D, + 0.0D, + 0.0D, + firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.DOWN ), + block.getIcon( ForgeDirection.DOWN.ordinal(), meta ) ) ); + tess.draw(); + } + + if ( sides.contains( ForgeDirection.UP ) ) + { + tess.startDrawingQuads(); + tess.setNormal( 0.0F, 1.0F, 0.0F ); + tess.setColorOpaque_I( color ); + renderer.renderFaceYPos( + block, + 0.0D, + 0.0D, + 0.0D, + firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.UP ), + block.getIcon( ForgeDirection.UP.ordinal(), meta ) ) ); + tess.draw(); + } + + if ( sides.contains( ForgeDirection.NORTH ) ) + { + tess.startDrawingQuads(); + tess.setNormal( 0.0F, 0.0F, -1.0F ); + tess.setColorOpaque_I( color ); + renderer.renderFaceZNeg( + block, + 0.0D, + 0.0D, + 0.0D, + firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.NORTH ), + block.getIcon( ForgeDirection.NORTH.ordinal(), meta ) ) ); + tess.draw(); + } + + if ( sides.contains( ForgeDirection.SOUTH ) ) + { + tess.startDrawingQuads(); + tess.setNormal( 0.0F, 0.0F, 1.0F ); + tess.setColorOpaque_I( color ); + renderer.renderFaceZPos( + block, + 0.0D, + 0.0D, + 0.0D, + firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.SOUTH ), + block.getIcon( ForgeDirection.SOUTH.ordinal(), meta ) ) ); + tess.draw(); + } + + if ( sides.contains( ForgeDirection.WEST ) ) + { + tess.startDrawingQuads(); + tess.setNormal( -1.0F, 0.0F, 0.0F ); + tess.setColorOpaque_I( color ); + renderer.renderFaceXNeg( + block, + 0.0D, + 0.0D, + 0.0D, + firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.WEST ), + block.getIcon( ForgeDirection.WEST.ordinal(), meta ) ) ); + tess.draw(); + } + + if ( sides.contains( ForgeDirection.EAST ) ) + { + tess.startDrawingQuads(); + tess.setNormal( 1.0F, 0.0F, 0.0F ); + tess.setColorOpaque_I( color ); + renderer.renderFaceXPos( + block, + 0.0D, + 0.0D, + 0.0D, + firstNotNull( renderer.overrideBlockTexture, block.getRendererInstance().getTexture( ForgeDirection.EAST ), + block.getIcon( ForgeDirection.EAST.ordinal(), meta ) ) ); + tess.draw(); + } + } + + public void renderInventory(AEBaseBlock block, ItemStack item, RenderBlocks renderer, ItemRenderType type, Object[] data) + { + Tessellator tess = Tessellator.instance; + + BlockRenderInfo info = block.getRendererInstance(); + if ( info.isValid() ) + { + if ( block.hasSubtypes() ) + block.setRenderStateByMeta( item.getItemDamage() ); + + renderer.uvRotateBottom = info.getTexture( ForgeDirection.DOWN ).setFlip( + getOrientation( ForgeDirection.DOWN, ForgeDirection.SOUTH, ForgeDirection.UP ) ); + renderer.uvRotateTop = info.getTexture( ForgeDirection.UP ).setFlip( getOrientation( ForgeDirection.UP, ForgeDirection.SOUTH, ForgeDirection.UP ) ); + + renderer.uvRotateEast = info.getTexture( ForgeDirection.EAST ).setFlip( + getOrientation( ForgeDirection.EAST, ForgeDirection.SOUTH, ForgeDirection.UP ) ); + renderer.uvRotateWest = info.getTexture( ForgeDirection.WEST ).setFlip( + getOrientation( ForgeDirection.WEST, ForgeDirection.SOUTH, ForgeDirection.UP ) ); + + renderer.uvRotateNorth = info.getTexture( ForgeDirection.NORTH ).setFlip( + getOrientation( ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.UP ) ); + renderer.uvRotateSouth = info.getTexture( ForgeDirection.SOUTH ).setFlip( + getOrientation( ForgeDirection.SOUTH, ForgeDirection.SOUTH, ForgeDirection.UP ) ); + } + + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), block, item, tess, 0xffffff, renderer ); + + if ( block.hasSubtypes() ) + info.setTemporaryRenderIcon( null ); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + } + + public IOrientable getOrientable(AEBaseBlock block, IBlockAccess w, int x, int y, int z) + { + if ( block.hasBlockTileEntity() ) + return (AEBaseTile) block.getTileEntity( w, x, y, z ); + else if ( block instanceof IOrientableBlock ) + return ((IOrientableBlock) block).getOrientable( w, x, y, z ); + return null; + } + + public void preRenderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + ForgeDirection forward = ForgeDirection.SOUTH; + ForgeDirection up = ForgeDirection.UP; + + BlockRenderInfo info = block.getRendererInstance(); + IOrientable te = getOrientable( block, world, x, y, z ); + if ( te != null ) + { + forward = te.getForward(); + up = te.getUp(); + + renderer.uvRotateBottom = info.getTexture( ForgeDirection.DOWN ).setFlip( getOrientation( ForgeDirection.DOWN, forward, up ) ); + renderer.uvRotateTop = info.getTexture( ForgeDirection.UP ).setFlip( getOrientation( ForgeDirection.UP, forward, up ) ); + + renderer.uvRotateEast = info.getTexture( ForgeDirection.EAST ).setFlip( getOrientation( ForgeDirection.EAST, forward, up ) ); + renderer.uvRotateWest = info.getTexture( ForgeDirection.WEST ).setFlip( getOrientation( ForgeDirection.WEST, forward, up ) ); + + renderer.uvRotateNorth = info.getTexture( ForgeDirection.NORTH ).setFlip( getOrientation( ForgeDirection.NORTH, forward, up ) ); + renderer.uvRotateSouth = info.getTexture( ForgeDirection.SOUTH ).setFlip( getOrientation( ForgeDirection.SOUTH, forward, up ) ); + } + + } + + public void postRenderInWorld(RenderBlocks renderer) + { + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + } + + public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + preRenderInWorld( block, world, x, y, z, renderer ); + + boolean o = renderer.renderStandardBlock( block, x, y, z ); + + postRenderInWorld( renderer ); + return o; + } + + final FloatBuffer rotMat = BufferUtils.createFloatBuffer( 16 ); + + protected void applyTESRRotation(double x, double y, double z, ForgeDirection forward, ForgeDirection up) + { + if ( forward != null && up != null ) + { + if ( forward == ForgeDirection.UNKNOWN ) + forward = ForgeDirection.SOUTH; + + if ( up == ForgeDirection.UNKNOWN ) + up = ForgeDirection.UP; + + ForgeDirection west = Platform.crossProduct( forward, up ); + + rotMat.put( 0, west.offsetX ); + rotMat.put( 1, west.offsetY ); + rotMat.put( 2, west.offsetZ ); + rotMat.put( 3, 0 ); + + rotMat.put( 4, up.offsetX ); + rotMat.put( 5, up.offsetY ); + rotMat.put( 6, up.offsetZ ); + rotMat.put( 7, 0 ); + + rotMat.put( 8, forward.offsetX ); + rotMat.put( 9, forward.offsetY ); + rotMat.put( 10, forward.offsetZ ); + rotMat.put( 11, 0 ); + + rotMat.put( 12, 0 ); + rotMat.put( 13, 0 ); + rotMat.put( 14, 0 ); + rotMat.put( 15, 1 ); + GL11.glTranslated( x + 0.5, y + 0.5, z + 0.5 ); + GL11.glMultMatrix( rotMat ); + GL11.glTranslated( -0.5, -0.5, -0.5 ); + GL11.glCullFace( GL11.GL_FRONT ); + } + else + { + GL11.glTranslated( x, y, z ); + } + } + + protected void setInvRenderBounds(RenderBlocks renderer, int i, int j, int k, int l, int m, int n) + { + renderer.setRenderBounds( i / 16.0, j / 16.0, k / 16.0, l / 16.0, m / 16.0, n / 16.0 ); + } + + protected void renderBlockBounds(RenderBlocks renderer, + + double minX, double minY, double minZ, + + double maxX, double maxY, double maxZ, + + ForgeDirection x, ForgeDirection y, ForgeDirection z) + { + minX /= 16.0; + minY /= 16.0; + minZ /= 16.0; + maxX /= 16.0; + maxY /= 16.0; + maxZ /= 16.0; + + double aX = minX * x.offsetX + minY * y.offsetX + minZ * z.offsetX; + double aY = minX * x.offsetY + minY * y.offsetY + minZ * z.offsetY; + double aZ = minX * x.offsetZ + minY * y.offsetZ + minZ * z.offsetZ; + + double bX = maxX * x.offsetX + maxY * y.offsetX + maxZ * z.offsetX; + double bY = maxX * x.offsetY + maxY * y.offsetY + maxZ * z.offsetY; + double bZ = maxX * x.offsetZ + maxY * y.offsetZ + maxZ * z.offsetZ; + + if ( x.offsetX + y.offsetX + z.offsetX < 0 ) + { + aX += 1; + bX += 1; + } + + if ( x.offsetY + y.offsetY + z.offsetY < 0 ) + { + aY += 1; + bY += 1; + } + + if ( x.offsetZ + y.offsetZ + z.offsetZ < 0 ) + { + aZ += 1; + bZ += 1; + } + + renderer.renderMinX = Math.min( aX, bX ); + renderer.renderMinY = Math.min( aY, bY ); + renderer.renderMinZ = Math.min( aZ, bZ ); + renderer.renderMaxX = Math.max( aX, bX ); + renderer.renderMaxY = Math.max( aY, bY ); + renderer.renderMaxZ = Math.max( aZ, bZ ); + } + + @SideOnly(Side.CLIENT) + private void renderFace(Tessellator tess, double offsetX, double offsetY, double offsetZ, double ax, double ay, double az, double bx, double by, double bz, + double ua, double ub, double va, double vb, IIcon ico, boolean flip) + { + if ( flip ) + { + tess.addVertexWithUV( offsetX + ax * ua + bx * va, offsetY + ay * ua + by * va, offsetZ + az * ua + bz * va, ico.getInterpolatedU( ua * 16.0 ), + ico.getInterpolatedV( va * 16.0 ) ); + tess.addVertexWithUV( offsetX + ax * ua + bx * vb, offsetY + ay * ua + by * vb, offsetZ + az * ua + bz * vb, ico.getInterpolatedU( ua * 16.0 ), + ico.getInterpolatedV( vb * 16.0 ) ); + tess.addVertexWithUV( offsetX + ax * ub + bx * vb, offsetY + ay * ub + by * vb, offsetZ + az * ub + bz * vb, ico.getInterpolatedU( ub * 16.0 ), + ico.getInterpolatedV( vb * 16.0 ) ); + tess.addVertexWithUV( offsetX + ax * ub + bx * va, offsetY + ay * ub + by * va, offsetZ + az * ub + bz * va, ico.getInterpolatedU( ub * 16.0 ), + ico.getInterpolatedV( va * 16.0 ) ); + } + else + { + tess.addVertexWithUV( offsetX + ax * ua + bx * va, offsetY + ay * ua + by * va, offsetZ + az * ua + bz * va, ico.getInterpolatedU( ua * 16.0 ), + ico.getInterpolatedV( va * 16.0 ) ); + tess.addVertexWithUV( offsetX + ax * ub + bx * va, offsetY + ay * ub + by * va, offsetZ + az * ub + bz * va, ico.getInterpolatedU( ub * 16.0 ), + ico.getInterpolatedV( va * 16.0 ) ); + tess.addVertexWithUV( offsetX + ax * ub + bx * vb, offsetY + ay * ub + by * vb, offsetZ + az * ub + bz * vb, ico.getInterpolatedU( ub * 16.0 ), + ico.getInterpolatedV( vb * 16.0 ) ); + tess.addVertexWithUV( offsetX + ax * ua + bx * vb, offsetY + ay * ua + by * vb, offsetZ + az * ua + bz * vb, ico.getInterpolatedU( ua * 16.0 ), + ico.getInterpolatedV( vb * 16.0 ) ); + } + } + + @SideOnly(Side.CLIENT) + protected void renderCutoutFace(Block block, IIcon ico, int x, int y, int z, RenderBlocks renderer, ForgeDirection orientation, float edgeThickness) + { + Tessellator tess = Tessellator.instance; + + double offsetX = 0.0, offsetY = 0.0, offsetZ = 0.0; + double layaX = 0.0, layaY = 0.0, layaZ = 0.0; + double laybX = 0.0, laybY = 0.0, laybZ = 0.0; + + boolean flip = false; + switch (orientation) + { + case NORTH: + + layaX = 1.0; + laybY = 1.0; + flip = true; + + break; + case SOUTH: + + layaX = 1.0; + laybY = 1.0; + offsetZ = 1.0; + + break; + case EAST: + + flip = true; + layaZ = 1.0; + laybY = 1.0; + offsetX = 1.0; + + break; + case WEST: + + layaZ = 1.0; + laybY = 1.0; + + break; + case UP: + + flip = true; + layaX = 1.0; + laybZ = 1.0; + offsetY = 1.0; + + break; + case DOWN: + + layaX = 1.0; + laybZ = 1.0; + + break; + default: + break; + } + + offsetX += x; + offsetY += y; + offsetZ += z; + + renderFace( tess, offsetX, offsetY, offsetZ, layaX, layaY, layaZ, laybX, laybY, laybZ, + // u -> u + 0, 1.0, + // v -> v + 0, edgeThickness, ico, flip ); + + renderFace( tess, offsetX, offsetY, offsetZ, layaX, layaY, layaZ, laybX, laybY, laybZ, + // u -> u + 0.0, edgeThickness, + // v -> v + edgeThickness, 1.0 - edgeThickness, ico, flip ); + + renderFace( tess, offsetX, offsetY, offsetZ, layaX, layaY, layaZ, laybX, laybY, laybZ, + // u -> u + 1.0 - edgeThickness, 1.0, + // v -> v + edgeThickness, 1.0 - edgeThickness, ico, flip ); + + renderFace( tess, offsetX, offsetY, offsetZ, layaX, layaY, layaZ, laybX, laybY, laybZ, + // u -> u + 0, 1.0, + // v -> v + 1.0 - edgeThickness, 1.0, ico, flip ); + } + + @SideOnly(Side.CLIENT) + protected void renderFace(int x, int y, int z, Block block, IIcon ico, RenderBlocks renderer, ForgeDirection orientation) + { + switch (orientation) + { + case NORTH: + renderer.renderFaceZNeg( block, x, y, z, ico ); + break; + case SOUTH: + renderer.renderFaceZPos( block, x, y, z, ico ); + break; + case EAST: + renderer.renderFaceXPos( block, x, y, z, ico ); + break; + case WEST: + renderer.renderFaceXNeg( block, x, y, z, ico ); + break; + case UP: + renderer.renderFaceYPos( block, x, y, z, ico ); + break; + case DOWN: + renderer.renderFaceYNeg( block, x, y, z, ico ); + break; + default: + break; + } + } + + public void selectFace(RenderBlocks renderer, ForgeDirection west, ForgeDirection up, ForgeDirection forward, int u1, int u2, int v1, int v2) + { + v1 = 16 - v1; + v2 = 16 - v2; + + double minX = (forward.offsetX > 0 ? 1 : 0) + mapFaceUV( west.offsetX, u1 ) + mapFaceUV( up.offsetX, v1 ); + double minY = (forward.offsetY > 0 ? 1 : 0) + mapFaceUV( west.offsetY, u1 ) + mapFaceUV( up.offsetY, v1 ); + double minZ = (forward.offsetZ > 0 ? 1 : 0) + mapFaceUV( west.offsetZ, u1 ) + mapFaceUV( up.offsetZ, v1 ); + + double maxX = (forward.offsetX > 0 ? 1 : 0) + mapFaceUV( west.offsetX, u2 ) + mapFaceUV( up.offsetX, v2 ); + double maxY = (forward.offsetY > 0 ? 1 : 0) + mapFaceUV( west.offsetY, u2 ) + mapFaceUV( up.offsetY, v2 ); + double maxZ = (forward.offsetZ > 0 ? 1 : 0) + mapFaceUV( west.offsetZ, u2 ) + mapFaceUV( up.offsetZ, v2 ); + + renderer.renderMinX = Math.max( 0.0, Math.min( minX, maxX ) - (forward.offsetX != 0 ? 0 : 0.001) ); + renderer.renderMaxX = Math.min( 1.0, Math.max( minX, maxX ) + (forward.offsetX != 0 ? 0 : 0.001) ); + + renderer.renderMinY = Math.max( 0.0, Math.min( minY, maxY ) - (forward.offsetY != 0 ? 0 : 0.001) ); + renderer.renderMaxY = Math.min( 1.0, Math.max( minY, maxY ) + (forward.offsetY != 0 ? 0 : 0.001) ); + + renderer.renderMinZ = Math.max( 0.0, Math.min( minZ, maxZ ) - (forward.offsetZ != 0 ? 0 : 0.001) ); + renderer.renderMaxZ = Math.min( 1.0, Math.max( minZ, maxZ ) + (forward.offsetZ != 0 ? 0 : 0.001) ); + } + + private double mapFaceUV(int offset, int uv) + { + if ( offset == 0 ) + return 0; + + if ( offset > 0 ) + return (double) uv / 16.0; + + return (16.0 - (double) uv) / 16.0; + } + + public void renderTile(AEBaseBlock block, AEBaseTile tile, Tessellator tess, double x, double y, double z, float f, RenderBlocks renderer) + { + ForgeDirection forward = ForgeDirection.SOUTH; + ForgeDirection up = ForgeDirection.UP; + + renderer.uvRotateBottom = renderer.uvRotateTop = renderer.uvRotateEast = renderer.uvRotateWest = renderer.uvRotateNorth = renderer.uvRotateSouth = 0; + + applyTESRRotation( x, y, z, forward, up ); + + Minecraft.getMinecraft().getTextureManager().bindTexture( TextureMap.locationBlocksTexture ); + RenderHelper.disableStandardItemLighting(); + + if ( Minecraft.isAmbientOcclusionEnabled() ) + GL11.glShadeModel( GL11.GL_SMOOTH ); + else + GL11.glShadeModel( GL11.GL_FLAT ); + + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + + tess.setTranslation( -tile.xCoord, -tile.yCoord, -tile.zCoord ); + tess.startDrawingQuads(); + + // note that this is a terrible approach... + renderer.setRenderBoundsFromBlock( block ); + renderer.renderStandardBlock( block, tile.xCoord, tile.yCoord, tile.zCoord ); + + tess.draw(); + tess.setTranslation( 0, 0, 0 ); + RenderHelper.enableStandardItemLighting(); + + renderer.uvRotateBottom = renderer.uvRotateTop = renderer.uvRotateEast = renderer.uvRotateWest = renderer.uvRotateNorth = renderer.uvRotateSouth = 0; + } + + public void doRenderItem(ItemStack itemstack, TileEntity par1EntityItemFrame) + { + if ( itemstack != null ) + { + EntityItem entityitem = new EntityItem( par1EntityItemFrame.getWorldObj(), 0.0D, 0.0D, 0.0D, itemstack ); + entityitem.getEntityItem().stackSize = 1; + + // set all this stuff and then do shit? meh? + entityitem.hoverStart = 0; + entityitem.age = 0; + entityitem.rotationYaw = 0; + + GL11.glPushMatrix(); + GL11.glTranslatef( 0, -0.14F, 0 ); + + RenderItem.renderInFrame = true; + RenderManager.instance.renderEntityWithPosYaw( entityitem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F ); + RenderItem.renderInFrame = false; + + GL11.glPopMatrix(); + } + } + +} diff --git a/client/render/BlockRenderInfo.java b/src/main/java/appeng/client/render/BlockRenderInfo.java similarity index 96% rename from client/render/BlockRenderInfo.java rename to src/main/java/appeng/client/render/BlockRenderInfo.java index c61929efb..84922c77a 100644 --- a/client/render/BlockRenderInfo.java +++ b/src/main/java/appeng/client/render/BlockRenderInfo.java @@ -1,119 +1,119 @@ -package appeng.client.render; - -import appeng.client.texture.FlippableIcon; -import appeng.client.texture.TmpFlippableIcon; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; - -public class BlockRenderInfo -{ - - public BlockRenderInfo(BaseBlockRender inst) { - rendererInstance = inst; - } - - final public BaseBlockRender rendererInstance; - - private boolean useTmp = false; - private TmpFlippableIcon tmpTopIcon = new TmpFlippableIcon(); - private TmpFlippableIcon tmpBottomIcon = new TmpFlippableIcon(); - private TmpFlippableIcon tmpSouthIcon = new TmpFlippableIcon(); - private TmpFlippableIcon tmpNorthIcon = new TmpFlippableIcon(); - private TmpFlippableIcon tmpEastIcon = new TmpFlippableIcon(); - private TmpFlippableIcon tmpWestIcon = new TmpFlippableIcon(); - - private FlippableIcon topIcon = null; - private FlippableIcon bottomIcon = null; - private FlippableIcon southIcon = null; - private FlippableIcon northIcon = null; - private FlippableIcon eastIcon = null; - private FlippableIcon westIcon = null; - - public void updateIcons(FlippableIcon Bottom, FlippableIcon Top, FlippableIcon North, FlippableIcon South, FlippableIcon East, FlippableIcon West) - { - topIcon = Top; - bottomIcon = Bottom; - southIcon = South; - northIcon = North; - eastIcon = East; - westIcon = West; - - } - - public void setTemporaryRenderIcon(IIcon IIcon) - { - if ( IIcon == null ) - useTmp = false; - else - { - useTmp = true; - tmpTopIcon.setOriginal( IIcon ); - tmpBottomIcon.setOriginal( IIcon ); - tmpSouthIcon.setOriginal( IIcon ); - tmpNorthIcon.setOriginal( IIcon ); - tmpEastIcon.setOriginal( IIcon ); - tmpWestIcon.setOriginal( IIcon ); - } - } - - public void setTemporaryRenderIcons(IIcon nTopIcon, IIcon nBottomIcon, IIcon nSouthIcon, IIcon nNorthIcon, IIcon nEastIcon, IIcon nWestIcon) - { - tmpTopIcon.setOriginal( nTopIcon == null ? getTexture( ForgeDirection.UP ) : nTopIcon ); - tmpBottomIcon.setOriginal( nBottomIcon == null ? getTexture( ForgeDirection.DOWN ) : nBottomIcon ); - tmpSouthIcon.setOriginal( nSouthIcon == null ? getTexture( ForgeDirection.SOUTH ) : nSouthIcon ); - tmpNorthIcon.setOriginal( nNorthIcon == null ? getTexture( ForgeDirection.NORTH ) : nNorthIcon ); - tmpEastIcon.setOriginal( nEastIcon == null ? getTexture( ForgeDirection.EAST ) : nEastIcon ); - tmpWestIcon.setOriginal( nWestIcon == null ? getTexture( ForgeDirection.WEST ) : nWestIcon ); - useTmp = true; - } - - public FlippableIcon getTexture(ForgeDirection dir) - { - if ( useTmp ) - { - switch (dir) - { - case DOWN: - return tmpBottomIcon; - case UP: - return tmpTopIcon; - case NORTH: - return tmpNorthIcon; - case SOUTH: - return tmpSouthIcon; - case EAST: - return tmpEastIcon; - case WEST: - return tmpWestIcon; - default: - break; - } - } - - switch (dir) - { - case DOWN: - return bottomIcon; - case UP: - return topIcon; - case NORTH: - return northIcon; - case SOUTH: - return southIcon; - case EAST: - return eastIcon; - case WEST: - return westIcon; - default: - break; - } - - return topIcon; - } - - public boolean isValid() - { - return topIcon != null && bottomIcon != null && southIcon != null && northIcon != null && eastIcon != null && westIcon != null; - } - -} +package appeng.client.render; + +import appeng.client.texture.FlippableIcon; +import appeng.client.texture.TmpFlippableIcon; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; + +public class BlockRenderInfo +{ + + public BlockRenderInfo(BaseBlockRender inst) { + rendererInstance = inst; + } + + final public BaseBlockRender rendererInstance; + + private boolean useTmp = false; + private TmpFlippableIcon tmpTopIcon = new TmpFlippableIcon(); + private TmpFlippableIcon tmpBottomIcon = new TmpFlippableIcon(); + private TmpFlippableIcon tmpSouthIcon = new TmpFlippableIcon(); + private TmpFlippableIcon tmpNorthIcon = new TmpFlippableIcon(); + private TmpFlippableIcon tmpEastIcon = new TmpFlippableIcon(); + private TmpFlippableIcon tmpWestIcon = new TmpFlippableIcon(); + + private FlippableIcon topIcon = null; + private FlippableIcon bottomIcon = null; + private FlippableIcon southIcon = null; + private FlippableIcon northIcon = null; + private FlippableIcon eastIcon = null; + private FlippableIcon westIcon = null; + + public void updateIcons(FlippableIcon Bottom, FlippableIcon Top, FlippableIcon North, FlippableIcon South, FlippableIcon East, FlippableIcon West) + { + topIcon = Top; + bottomIcon = Bottom; + southIcon = South; + northIcon = North; + eastIcon = East; + westIcon = West; + + } + + public void setTemporaryRenderIcon(IIcon IIcon) + { + if ( IIcon == null ) + useTmp = false; + else + { + useTmp = true; + tmpTopIcon.setOriginal( IIcon ); + tmpBottomIcon.setOriginal( IIcon ); + tmpSouthIcon.setOriginal( IIcon ); + tmpNorthIcon.setOriginal( IIcon ); + tmpEastIcon.setOriginal( IIcon ); + tmpWestIcon.setOriginal( IIcon ); + } + } + + public void setTemporaryRenderIcons(IIcon nTopIcon, IIcon nBottomIcon, IIcon nSouthIcon, IIcon nNorthIcon, IIcon nEastIcon, IIcon nWestIcon) + { + tmpTopIcon.setOriginal( nTopIcon == null ? getTexture( ForgeDirection.UP ) : nTopIcon ); + tmpBottomIcon.setOriginal( nBottomIcon == null ? getTexture( ForgeDirection.DOWN ) : nBottomIcon ); + tmpSouthIcon.setOriginal( nSouthIcon == null ? getTexture( ForgeDirection.SOUTH ) : nSouthIcon ); + tmpNorthIcon.setOriginal( nNorthIcon == null ? getTexture( ForgeDirection.NORTH ) : nNorthIcon ); + tmpEastIcon.setOriginal( nEastIcon == null ? getTexture( ForgeDirection.EAST ) : nEastIcon ); + tmpWestIcon.setOriginal( nWestIcon == null ? getTexture( ForgeDirection.WEST ) : nWestIcon ); + useTmp = true; + } + + public FlippableIcon getTexture(ForgeDirection dir) + { + if ( useTmp ) + { + switch (dir) + { + case DOWN: + return tmpBottomIcon; + case UP: + return tmpTopIcon; + case NORTH: + return tmpNorthIcon; + case SOUTH: + return tmpSouthIcon; + case EAST: + return tmpEastIcon; + case WEST: + return tmpWestIcon; + default: + break; + } + } + + switch (dir) + { + case DOWN: + return bottomIcon; + case UP: + return topIcon; + case NORTH: + return northIcon; + case SOUTH: + return southIcon; + case EAST: + return eastIcon; + case WEST: + return westIcon; + default: + break; + } + + return topIcon; + } + + public boolean isValid() + { + return topIcon != null && bottomIcon != null && southIcon != null && northIcon != null && eastIcon != null && westIcon != null; + } + +} diff --git a/client/render/BusRenderHelper.java b/src/main/java/appeng/client/render/BusRenderHelper.java similarity index 95% rename from client/render/BusRenderHelper.java rename to src/main/java/appeng/client/render/BusRenderHelper.java index f9c8b6815..522b0c5e1 100644 --- a/client/render/BusRenderHelper.java +++ b/src/main/java/appeng/client/render/BusRenderHelper.java @@ -1,495 +1,495 @@ -package appeng.client.render; - -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.parts.IBoxProvider; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.parts.ISimplifiedBundle; -import appeng.block.AEBaseBlock; -import appeng.block.networking.BlockCableBus; -import appeng.core.AEConfig; -import appeng.core.features.AEFeature; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class BusRenderHelper implements IPartRenderHelper -{ - - final public static BusRenderHelper instance = new BusRenderHelper(); - - double minX = 0; - double minY = 0; - double minZ = 0; - double maxX = 16; - double maxY = 16; - double maxZ = 16; - - AEBaseBlock blk = (AEBaseBlock) AEApi.instance().blocks().blockMultiPart.block(); - BaseBlockRender bbr = new BaseBlockRender(); - - private ForgeDirection ax = ForgeDirection.EAST; - private ForgeDirection ay = ForgeDirection.UP; - private ForgeDirection az = ForgeDirection.SOUTH; - - int color = 0xffffff; - - class BoundBoxCalculator implements IPartCollisionHelper - { - - public boolean started = false; - - float minX; - float minY; - float minZ; - - float maxX; - float maxY; - float maxZ; - - @Override - public void addBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) - { - if ( started ) - { - this.minX = Math.min( this.minX, (float) minX ); - this.minY = Math.min( this.minY, (float) minY ); - this.minZ = Math.min( this.minZ, (float) minZ ); - this.maxX = Math.max( this.maxX, (float) maxX ); - this.maxY = Math.max( this.maxY, (float) maxY ); - this.maxZ = Math.max( this.maxZ, (float) maxZ ); - } - else - { - started = true; - this.minX = (float) minX; - this.minY = (float) minY; - this.minZ = (float) minZ; - this.maxX = (float) maxX; - this.maxY = (float) maxY; - this.maxZ = (float) maxZ; - } - } - - @Override - public ForgeDirection getWorldX() - { - return ax; - } - - @Override - public ForgeDirection getWorldY() - { - return ay; - } - - @Override - public ForgeDirection getWorldZ() - { - return az; - } - - @Override - public boolean isBBCollision() - { - return false; - } - - }; - - BoundBoxCalculator bbc = new BoundBoxCalculator(); - - int renderingForPass = 0; - int currentPass = 0; - int itemsRendered = 0; - boolean noAlphaPass = AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) == false; - - public int getItemsRendered() - { - return itemsRendered; - } - - public void setPass(int pass) - { - renderingForPass = 0; - currentPass = pass; - itemsRendered = 0; - } - - @Override - public void renderForPass(int pass) - { - renderingForPass = pass; - } - - public boolean renderThis() - { - if ( renderingForPass == currentPass || noAlphaPass ) - { - itemsRendered++; - return true; - } - return false; - } - - @Override - public void normalRendering() - { - RenderBlocksWorkaround rbw = BusRenderer.instance.renderer; - rbw.calculations = true; - rbw.useTextures = true; - rbw.enableAO = false; - } - - @Override - public ISimplifiedBundle useSimplifiedRendering(int x, int y, int z, IBoxProvider p, ISimplifiedBundle sim) - { - RenderBlocksWorkaround rbw = BusRenderer.instance.renderer; - - if ( sim != null && rbw.similarLighting( blk, rbw.blockAccess, x, y, z, sim ) ) - { - rbw.populate( sim ); - rbw.faces = EnumSet.allOf( ForgeDirection.class ); - rbw.calculations = false; - rbw.useTextures = false; - - return sim; - } - else - { - boolean allFaces = rbw.renderAllFaces; - rbw.renderAllFaces = true; - rbw.calculations = true; - rbw.faces.clear(); - - bbc.started = false; - if ( p == null ) - { - bbc.minX = bbc.minY = bbc.minZ = 0; - bbc.maxX = bbc.maxY = bbc.maxZ = 16; - } - else - { - p.getBoxes( bbc ); - - if ( bbc.minX < 1 ) - bbc.minX = 1; - if ( bbc.minY < 1 ) - bbc.minY = 1; - if ( bbc.minZ < 1 ) - bbc.minZ = 1; - - if ( bbc.maxX > 15 ) - bbc.maxX = 15; - if ( bbc.maxY > 15 ) - bbc.maxY = 15; - if ( bbc.maxZ > 15 ) - bbc.maxZ = 15; - } - - setBounds( bbc.minX, bbc.minY, bbc.minZ, bbc.maxX, bbc.maxY, bbc.maxZ ); - - bbr.renderBlockBounds( rbw, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az ); - rbw.renderStandardBlock( blk, x, y, z ); - - rbw.faces = EnumSet.allOf( ForgeDirection.class ); - rbw.renderAllFaces = allFaces; - rbw.calculations = false; - rbw.useTextures = false; - - return rbw.getLightingCache(); - } - } - - @Override - public void setBounds(float minx, float miny, float minz, float maxx, float maxy, float maxz) - { - minX = minx; - minY = miny; - minZ = minz; - maxX = maxx; - maxY = maxy; - maxZ = maxz; - } - - public double getBound(ForgeDirection side) - { - switch (side) - { - default: - case UNKNOWN: - return 0.5; - case DOWN: - return minY; - case EAST: - return maxX; - case NORTH: - return minZ; - case SOUTH: - return maxZ; - case UP: - return maxY; - case WEST: - return minX; - - } - } - - @Override - public void setInvColor(int newColor) - { - color = newColor; - } - - @Override - public void setTexture(IIcon ico) - { - blk.getRendererInstance().setTemporaryRenderIcon( ico ); - } - - @Override - public void setTexture(IIcon Down, IIcon Up, IIcon North, IIcon South, IIcon West, IIcon East) - { - IIcon list[] = new IIcon[6]; - - list[0] = Down; - list[1] = Up; - list[2] = North; - list[3] = South; - list[4] = West; - list[5] = East; - - blk.getRendererInstance().setTemporaryRenderIcons( list[mapRotation( ForgeDirection.UP ).ordinal()], - list[mapRotation( ForgeDirection.DOWN ).ordinal()], list[mapRotation( ForgeDirection.SOUTH ).ordinal()], - list[mapRotation( ForgeDirection.NORTH ).ordinal()], list[mapRotation( ForgeDirection.EAST ).ordinal()], - list[mapRotation( ForgeDirection.WEST ).ordinal()] ); - } - - public ForgeDirection mapRotation(ForgeDirection dir) - { - ForgeDirection forward = az; - ForgeDirection up = ay; - 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; - } - - @Override - public void renderInventoryBox(RenderBlocks renderer) - { - renderer.setRenderBounds( minX / 16.0, minY / 16.0, minZ / 16.0, maxX / 16.0, maxY / 16.0, maxZ / 16.0 ); - bbr.renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, null, Tessellator.instance, color, renderer ); - } - - @Override - public void renderInventoryFace(IIcon IIcon, ForgeDirection face, RenderBlocks renderer) - { - renderer.setRenderBounds( minX / 16.0, minY / 16.0, minZ / 16.0, maxX / 16.0, maxY / 16.0, maxZ / 16.0 ); - setTexture( IIcon ); - bbr.renderInvBlock( EnumSet.of( face ), blk, null, Tessellator.instance, color, renderer ); - } - - @Override - public void renderBlock(int x, int y, int z, RenderBlocks renderer) - { - if ( !renderThis() ) - return; - - AEBaseBlock blk = (AEBaseBlock) AEApi.instance().blocks().blockMultiPart.block(); - BlockRenderInfo info = blk.getRendererInstance(); - ForgeDirection forward = BusRenderHelper.instance.az; - ForgeDirection up = BusRenderHelper.instance.ay; - - renderer.uvRotateBottom = info.getTexture( ForgeDirection.DOWN ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.DOWN, forward, up ) ); - renderer.uvRotateTop = info.getTexture( ForgeDirection.UP ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.UP, forward, up ) ); - - renderer.uvRotateEast = info.getTexture( ForgeDirection.EAST ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.EAST, forward, up ) ); - renderer.uvRotateWest = info.getTexture( ForgeDirection.WEST ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.WEST, forward, up ) ); - - renderer.uvRotateNorth = info.getTexture( ForgeDirection.NORTH ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.NORTH, forward, up ) ); - renderer.uvRotateSouth = info.getTexture( ForgeDirection.SOUTH ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.SOUTH, forward, up ) ); - - bbr.renderBlockBounds( renderer, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az ); - - renderer.renderStandardBlock( blk, x, y, z ); - } - - @Override - public Block getBlock() - { - return AEApi.instance().blocks().blockMultiPart.block(); - } - - public void setRenderColor(int color) - { - BlockCableBus blk = (BlockCableBus) AEApi.instance().blocks().blockMultiPart.block(); - blk.setRenderColor( color ); - } - - public void prepareBounds(RenderBlocks renderer) - { - bbr.renderBlockBounds( renderer, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az ); - } - - @Override - public void setFacesToRender(EnumSet faces) - { - BusRenderer.instance.renderer.renderFaces = faces; - } - - public void renderBlockCurrentBounds(int x, int y, int z, RenderBlocks renderer) - { - if ( !renderThis() ) - return; - - renderer.renderStandardBlock( blk, x, y, z ); - } - - @Override - public void renderFaceCutout(int x, int y, int z, IIcon ico, ForgeDirection face, float edgeThickness, RenderBlocks renderer) - { - if ( !renderThis() ) - return; - - switch (face) - { - case DOWN: - face = ay.getOpposite(); - break; - case EAST: - face = ax; - break; - case NORTH: - face = az.getOpposite(); - break; - case SOUTH: - face = az; - break; - case UP: - face = ay; - break; - case WEST: - face = ax.getOpposite(); - break; - case UNKNOWN: - break; - default: - break; - } - - bbr.renderCutoutFace( blk, ico, x, y, z, renderer, face, edgeThickness ); - } - - @Override - public void renderFace(int x, int y, int z, IIcon ico, ForgeDirection face, RenderBlocks renderer) - { - if ( !renderThis() ) - return; - - prepareBounds( renderer ); - switch (face) - { - case DOWN: - face = ay.getOpposite(); - break; - case EAST: - face = ax; - break; - case NORTH: - face = az.getOpposite(); - break; - case SOUTH: - face = az; - break; - case UP: - face = ay; - break; - case WEST: - face = ax.getOpposite(); - break; - case UNKNOWN: - break; - default: - break; - } - - bbr.renderFace( x, y, z, blk, ico, renderer, face ); - } - - @Override - public ForgeDirection getWorldX() - { - return ax; - } - - @Override - public ForgeDirection getWorldY() - { - return ay; - } - - @Override - public ForgeDirection getWorldZ() - { - return az; - } - - public void setOrientation(ForgeDirection dx, ForgeDirection dy, ForgeDirection dz) - { - ax = dx == null ? ForgeDirection.EAST : dx; - ay = dy == null ? ForgeDirection.UP : dy; - az = dz == null ? ForgeDirection.SOUTH : dz; - } - - public double[] getBounds() - { - return new double[] { minX, minY, minZ, maxX, maxY, maxZ }; - } - - public void setBounds(double[] bounds) - { - if ( bounds == null || bounds.length != 6 ) - return; - - minX = bounds[0]; - minY = bounds[1]; - minZ = bounds[2]; - maxX = bounds[3]; - maxY = bounds[4]; - maxZ = bounds[5]; - } - -} +package appeng.client.render; + +import java.util.EnumSet; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.parts.IBoxProvider; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.parts.ISimplifiedBundle; +import appeng.block.AEBaseBlock; +import appeng.block.networking.BlockCableBus; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class BusRenderHelper implements IPartRenderHelper +{ + + final public static BusRenderHelper instance = new BusRenderHelper(); + + double minX = 0; + double minY = 0; + double minZ = 0; + double maxX = 16; + double maxY = 16; + double maxZ = 16; + + AEBaseBlock blk = (AEBaseBlock) AEApi.instance().blocks().blockMultiPart.block(); + BaseBlockRender bbr = new BaseBlockRender(); + + private ForgeDirection ax = ForgeDirection.EAST; + private ForgeDirection ay = ForgeDirection.UP; + private ForgeDirection az = ForgeDirection.SOUTH; + + int color = 0xffffff; + + class BoundBoxCalculator implements IPartCollisionHelper + { + + public boolean started = false; + + float minX; + float minY; + float minZ; + + float maxX; + float maxY; + float maxZ; + + @Override + public void addBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) + { + if ( started ) + { + this.minX = Math.min( this.minX, (float) minX ); + this.minY = Math.min( this.minY, (float) minY ); + this.minZ = Math.min( this.minZ, (float) minZ ); + this.maxX = Math.max( this.maxX, (float) maxX ); + this.maxY = Math.max( this.maxY, (float) maxY ); + this.maxZ = Math.max( this.maxZ, (float) maxZ ); + } + else + { + started = true; + this.minX = (float) minX; + this.minY = (float) minY; + this.minZ = (float) minZ; + this.maxX = (float) maxX; + this.maxY = (float) maxY; + this.maxZ = (float) maxZ; + } + } + + @Override + public ForgeDirection getWorldX() + { + return ax; + } + + @Override + public ForgeDirection getWorldY() + { + return ay; + } + + @Override + public ForgeDirection getWorldZ() + { + return az; + } + + @Override + public boolean isBBCollision() + { + return false; + } + + }; + + BoundBoxCalculator bbc = new BoundBoxCalculator(); + + int renderingForPass = 0; + int currentPass = 0; + int itemsRendered = 0; + boolean noAlphaPass = AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) == false; + + public int getItemsRendered() + { + return itemsRendered; + } + + public void setPass(int pass) + { + renderingForPass = 0; + currentPass = pass; + itemsRendered = 0; + } + + @Override + public void renderForPass(int pass) + { + renderingForPass = pass; + } + + public boolean renderThis() + { + if ( renderingForPass == currentPass || noAlphaPass ) + { + itemsRendered++; + return true; + } + return false; + } + + @Override + public void normalRendering() + { + RenderBlocksWorkaround rbw = BusRenderer.instance.renderer; + rbw.calculations = true; + rbw.useTextures = true; + rbw.enableAO = false; + } + + @Override + public ISimplifiedBundle useSimplifiedRendering(int x, int y, int z, IBoxProvider p, ISimplifiedBundle sim) + { + RenderBlocksWorkaround rbw = BusRenderer.instance.renderer; + + if ( sim != null && rbw.similarLighting( blk, rbw.blockAccess, x, y, z, sim ) ) + { + rbw.populate( sim ); + rbw.faces = EnumSet.allOf( ForgeDirection.class ); + rbw.calculations = false; + rbw.useTextures = false; + + return sim; + } + else + { + boolean allFaces = rbw.renderAllFaces; + rbw.renderAllFaces = true; + rbw.calculations = true; + rbw.faces.clear(); + + bbc.started = false; + if ( p == null ) + { + bbc.minX = bbc.minY = bbc.minZ = 0; + bbc.maxX = bbc.maxY = bbc.maxZ = 16; + } + else + { + p.getBoxes( bbc ); + + if ( bbc.minX < 1 ) + bbc.minX = 1; + if ( bbc.minY < 1 ) + bbc.minY = 1; + if ( bbc.minZ < 1 ) + bbc.minZ = 1; + + if ( bbc.maxX > 15 ) + bbc.maxX = 15; + if ( bbc.maxY > 15 ) + bbc.maxY = 15; + if ( bbc.maxZ > 15 ) + bbc.maxZ = 15; + } + + setBounds( bbc.minX, bbc.minY, bbc.minZ, bbc.maxX, bbc.maxY, bbc.maxZ ); + + bbr.renderBlockBounds( rbw, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az ); + rbw.renderStandardBlock( blk, x, y, z ); + + rbw.faces = EnumSet.allOf( ForgeDirection.class ); + rbw.renderAllFaces = allFaces; + rbw.calculations = false; + rbw.useTextures = false; + + return rbw.getLightingCache(); + } + } + + @Override + public void setBounds(float minx, float miny, float minz, float maxx, float maxy, float maxz) + { + minX = minx; + minY = miny; + minZ = minz; + maxX = maxx; + maxY = maxy; + maxZ = maxz; + } + + public double getBound(ForgeDirection side) + { + switch (side) + { + default: + case UNKNOWN: + return 0.5; + case DOWN: + return minY; + case EAST: + return maxX; + case NORTH: + return minZ; + case SOUTH: + return maxZ; + case UP: + return maxY; + case WEST: + return minX; + + } + } + + @Override + public void setInvColor(int newColor) + { + color = newColor; + } + + @Override + public void setTexture(IIcon ico) + { + blk.getRendererInstance().setTemporaryRenderIcon( ico ); + } + + @Override + public void setTexture(IIcon Down, IIcon Up, IIcon North, IIcon South, IIcon West, IIcon East) + { + IIcon list[] = new IIcon[6]; + + list[0] = Down; + list[1] = Up; + list[2] = North; + list[3] = South; + list[4] = West; + list[5] = East; + + blk.getRendererInstance().setTemporaryRenderIcons( list[mapRotation( ForgeDirection.UP ).ordinal()], + list[mapRotation( ForgeDirection.DOWN ).ordinal()], list[mapRotation( ForgeDirection.SOUTH ).ordinal()], + list[mapRotation( ForgeDirection.NORTH ).ordinal()], list[mapRotation( ForgeDirection.EAST ).ordinal()], + list[mapRotation( ForgeDirection.WEST ).ordinal()] ); + } + + public ForgeDirection mapRotation(ForgeDirection dir) + { + ForgeDirection forward = az; + ForgeDirection up = ay; + 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; + } + + @Override + public void renderInventoryBox(RenderBlocks renderer) + { + renderer.setRenderBounds( minX / 16.0, minY / 16.0, minZ / 16.0, maxX / 16.0, maxY / 16.0, maxZ / 16.0 ); + bbr.renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, null, Tessellator.instance, color, renderer ); + } + + @Override + public void renderInventoryFace(IIcon IIcon, ForgeDirection face, RenderBlocks renderer) + { + renderer.setRenderBounds( minX / 16.0, minY / 16.0, minZ / 16.0, maxX / 16.0, maxY / 16.0, maxZ / 16.0 ); + setTexture( IIcon ); + bbr.renderInvBlock( EnumSet.of( face ), blk, null, Tessellator.instance, color, renderer ); + } + + @Override + public void renderBlock(int x, int y, int z, RenderBlocks renderer) + { + if ( !renderThis() ) + return; + + AEBaseBlock blk = (AEBaseBlock) AEApi.instance().blocks().blockMultiPart.block(); + BlockRenderInfo info = blk.getRendererInstance(); + ForgeDirection forward = BusRenderHelper.instance.az; + ForgeDirection up = BusRenderHelper.instance.ay; + + renderer.uvRotateBottom = info.getTexture( ForgeDirection.DOWN ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.DOWN, forward, up ) ); + renderer.uvRotateTop = info.getTexture( ForgeDirection.UP ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.UP, forward, up ) ); + + renderer.uvRotateEast = info.getTexture( ForgeDirection.EAST ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.EAST, forward, up ) ); + renderer.uvRotateWest = info.getTexture( ForgeDirection.WEST ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.WEST, forward, up ) ); + + renderer.uvRotateNorth = info.getTexture( ForgeDirection.NORTH ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.NORTH, forward, up ) ); + renderer.uvRotateSouth = info.getTexture( ForgeDirection.SOUTH ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.SOUTH, forward, up ) ); + + bbr.renderBlockBounds( renderer, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az ); + + renderer.renderStandardBlock( blk, x, y, z ); + } + + @Override + public Block getBlock() + { + return AEApi.instance().blocks().blockMultiPart.block(); + } + + public void setRenderColor(int color) + { + BlockCableBus blk = (BlockCableBus) AEApi.instance().blocks().blockMultiPart.block(); + blk.setRenderColor( color ); + } + + public void prepareBounds(RenderBlocks renderer) + { + bbr.renderBlockBounds( renderer, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az ); + } + + @Override + public void setFacesToRender(EnumSet faces) + { + BusRenderer.instance.renderer.renderFaces = faces; + } + + public void renderBlockCurrentBounds(int x, int y, int z, RenderBlocks renderer) + { + if ( !renderThis() ) + return; + + renderer.renderStandardBlock( blk, x, y, z ); + } + + @Override + public void renderFaceCutout(int x, int y, int z, IIcon ico, ForgeDirection face, float edgeThickness, RenderBlocks renderer) + { + if ( !renderThis() ) + return; + + switch (face) + { + case DOWN: + face = ay.getOpposite(); + break; + case EAST: + face = ax; + break; + case NORTH: + face = az.getOpposite(); + break; + case SOUTH: + face = az; + break; + case UP: + face = ay; + break; + case WEST: + face = ax.getOpposite(); + break; + case UNKNOWN: + break; + default: + break; + } + + bbr.renderCutoutFace( blk, ico, x, y, z, renderer, face, edgeThickness ); + } + + @Override + public void renderFace(int x, int y, int z, IIcon ico, ForgeDirection face, RenderBlocks renderer) + { + if ( !renderThis() ) + return; + + prepareBounds( renderer ); + switch (face) + { + case DOWN: + face = ay.getOpposite(); + break; + case EAST: + face = ax; + break; + case NORTH: + face = az.getOpposite(); + break; + case SOUTH: + face = az; + break; + case UP: + face = ay; + break; + case WEST: + face = ax.getOpposite(); + break; + case UNKNOWN: + break; + default: + break; + } + + bbr.renderFace( x, y, z, blk, ico, renderer, face ); + } + + @Override + public ForgeDirection getWorldX() + { + return ax; + } + + @Override + public ForgeDirection getWorldY() + { + return ay; + } + + @Override + public ForgeDirection getWorldZ() + { + return az; + } + + public void setOrientation(ForgeDirection dx, ForgeDirection dy, ForgeDirection dz) + { + ax = dx == null ? ForgeDirection.EAST : dx; + ay = dy == null ? ForgeDirection.UP : dy; + az = dz == null ? ForgeDirection.SOUTH : dz; + } + + public double[] getBounds() + { + return new double[] { minX, minY, minZ, maxX, maxY, maxZ }; + } + + public void setBounds(double[] bounds) + { + if ( bounds == null || bounds.length != 6 ) + return; + + minX = bounds[0]; + minY = bounds[1]; + minZ = bounds[2]; + maxX = bounds[3]; + maxY = bounds[4]; + maxZ = bounds[5]; + } + +} diff --git a/client/render/BusRenderer.java b/src/main/java/appeng/client/render/BusRenderer.java similarity index 96% rename from client/render/BusRenderer.java rename to src/main/java/appeng/client/render/BusRenderer.java index 33d7e5fd5..879f3dcce 100644 --- a/client/render/BusRenderer.java +++ b/src/main/java/appeng/client/render/BusRenderer.java @@ -1,155 +1,155 @@ -package appeng.client.render; - -import java.util.HashMap; - -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.client.IItemRenderer; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import appeng.api.parts.IAlphaPassItem; -import appeng.api.parts.IFacadePart; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartItem; -import appeng.client.ClientHelper; -import appeng.core.AEConfig; -import appeng.core.features.AEFeature; -import appeng.facade.IFacadeItem; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class BusRenderer implements IItemRenderer -{ - - public static final BusRenderer instance = new BusRenderer(); - - public RenderBlocksWorkaround renderer = new RenderBlocksWorkaround(); - public static final HashMap renderPart = new HashMap(); - - public IPart getRenderer(ItemStack is, IPartItem c) - { - int id = (Item.getIdFromItem( is.getItem() ) << Platform.DEF_OFFSET) | is.getItemDamage(); - - IPart part = renderPart.get( id ); - if ( part == null ) - { - part = c.createPartFromItemStack( is ); - if ( part != null ) - renderPart.put( id, part ); - } - - return part; - } - - @Override - public boolean handleRenderType(ItemStack item, ItemRenderType type) - { - return true; - } - - @Override - public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) - { - return true; - } - - @Override - public void renderItem(ItemRenderType type, ItemStack item, Object... data) - { - if ( item == null ) - return; - - GL11.glPushMatrix(); - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - GL11.glEnable( GL11.GL_DEPTH_TEST ); - GL11.glEnable( GL11.GL_TEXTURE_2D ); - GL11.glEnable( GL11.GL_LIGHTING ); - - if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) && item.getItem() instanceof IAlphaPassItem - && ((IAlphaPassItem) item.getItem()).useAlphaPass( item ) ) - { - GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA ); - GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); - GL11.glDisable( GL11.GL_ALPHA_TEST ); - GL11.glEnable( GL11.GL_BLEND ); - } - else - { - GL11.glAlphaFunc( GL11.GL_GREATER, 0.4f ); - GL11.glEnable( GL11.GL_ALPHA_TEST ); - GL11.glDisable( GL11.GL_BLEND ); - } - - if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON ) - { - GL11.glTranslatef( -0.2f, -0.1f, -0.3f ); - } - - if ( type == ItemRenderType.ENTITY ) - { - GL11.glRotatef( 90.0f, 0.0f, 1.0f, 0.0f ); - GL11.glScalef( 0.8f, 0.8f, 0.8f ); - GL11.glTranslatef( -0.8f, -0.87f, -0.7f ); - } - - if ( type == ItemRenderType.INVENTORY ) - GL11.glTranslatef( 0.0f, -0.1f, 0.0f ); - - GL11.glTranslated( 0.2, 0.3, 0.1 ); - GL11.glScaled( 1.2, 1.2, 1. ); - - GL11.glColor4f( 1, 1, 1, 1 ); - Tessellator.instance.setColorOpaque_F( 1, 1, 1 ); - Tessellator.instance.setBrightness( 14 << 20 | 14 << 4 ); - - BusRenderHelper.instance.setBounds( 0, 0, 0, 1, 1, 1 ); - BusRenderHelper.instance.setTexture( null ); - BusRenderHelper.instance.setInvColor( 0xffffff ); - renderer.blockAccess = ClientHelper.proxy.getWorld(); - - BusRenderHelper.instance.setOrientation( ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH ); - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - renderer.useInventoryTint = false; - renderer.overrideBlockTexture = null; - - if ( item.getItem() instanceof IFacadeItem ) - { - IFacadeItem fi = (IFacadeItem) item.getItem(); - IFacadePart fp = fi.createPartFromItemStack( item, ForgeDirection.SOUTH ); - - if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON ) - { - GL11.glRotatef( 160.0f, 0.0f, 1.0f, 0.0f ); - GL11.glTranslated( -0.4, 0.1, -1.6 ); - } - - if ( fp != null ) - fp.renderInventory( BusRenderHelper.instance, renderer ); - } - else - { - IPart ip = getRenderer( item, (IPartItem) item.getItem() ); - if ( ip != null ) - { - if ( type == ItemRenderType.ENTITY ) - { - int depth = ip.cableConnectionRenderTo(); - GL11.glTranslatef( 0.0f, 0.0f, -0.04f * (8 - depth) - 0.06f ); - } - - ip.renderInventory( BusRenderHelper.instance, renderer ); - } - } - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - - GL11.glPopAttrib(); - GL11.glPopMatrix(); - } -} +package appeng.client.render; + +import java.util.HashMap; + +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import appeng.api.parts.IAlphaPassItem; +import appeng.api.parts.IFacadePart; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartItem; +import appeng.client.ClientHelper; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; +import appeng.facade.IFacadeItem; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class BusRenderer implements IItemRenderer +{ + + public static final BusRenderer instance = new BusRenderer(); + + public RenderBlocksWorkaround renderer = new RenderBlocksWorkaround(); + public static final HashMap renderPart = new HashMap(); + + public IPart getRenderer(ItemStack is, IPartItem c) + { + int id = (Item.getIdFromItem( is.getItem() ) << Platform.DEF_OFFSET) | is.getItemDamage(); + + IPart part = renderPart.get( id ); + if ( part == null ) + { + part = c.createPartFromItemStack( is ); + if ( part != null ) + renderPart.put( id, part ); + } + + return part; + } + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) + { + return true; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) + { + return true; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) + { + if ( item == null ) + return; + + GL11.glPushMatrix(); + GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + GL11.glEnable( GL11.GL_DEPTH_TEST ); + GL11.glEnable( GL11.GL_TEXTURE_2D ); + GL11.glEnable( GL11.GL_LIGHTING ); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) && item.getItem() instanceof IAlphaPassItem + && ((IAlphaPassItem) item.getItem()).useAlphaPass( item ) ) + { + GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA ); + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + GL11.glDisable( GL11.GL_ALPHA_TEST ); + GL11.glEnable( GL11.GL_BLEND ); + } + else + { + GL11.glAlphaFunc( GL11.GL_GREATER, 0.4f ); + GL11.glEnable( GL11.GL_ALPHA_TEST ); + GL11.glDisable( GL11.GL_BLEND ); + } + + if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON ) + { + GL11.glTranslatef( -0.2f, -0.1f, -0.3f ); + } + + if ( type == ItemRenderType.ENTITY ) + { + GL11.glRotatef( 90.0f, 0.0f, 1.0f, 0.0f ); + GL11.glScalef( 0.8f, 0.8f, 0.8f ); + GL11.glTranslatef( -0.8f, -0.87f, -0.7f ); + } + + if ( type == ItemRenderType.INVENTORY ) + GL11.glTranslatef( 0.0f, -0.1f, 0.0f ); + + GL11.glTranslated( 0.2, 0.3, 0.1 ); + GL11.glScaled( 1.2, 1.2, 1. ); + + GL11.glColor4f( 1, 1, 1, 1 ); + Tessellator.instance.setColorOpaque_F( 1, 1, 1 ); + Tessellator.instance.setBrightness( 14 << 20 | 14 << 4 ); + + BusRenderHelper.instance.setBounds( 0, 0, 0, 1, 1, 1 ); + BusRenderHelper.instance.setTexture( null ); + BusRenderHelper.instance.setInvColor( 0xffffff ); + renderer.blockAccess = ClientHelper.proxy.getWorld(); + + BusRenderHelper.instance.setOrientation( ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH ); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + renderer.useInventoryTint = false; + renderer.overrideBlockTexture = null; + + if ( item.getItem() instanceof IFacadeItem ) + { + IFacadeItem fi = (IFacadeItem) item.getItem(); + IFacadePart fp = fi.createPartFromItemStack( item, ForgeDirection.SOUTH ); + + if ( type == ItemRenderType.EQUIPPED_FIRST_PERSON ) + { + GL11.glRotatef( 160.0f, 0.0f, 1.0f, 0.0f ); + GL11.glTranslated( -0.4, 0.1, -1.6 ); + } + + if ( fp != null ) + fp.renderInventory( BusRenderHelper.instance, renderer ); + } + else + { + IPart ip = getRenderer( item, (IPartItem) item.getItem() ); + if ( ip != null ) + { + if ( type == ItemRenderType.ENTITY ) + { + int depth = ip.cableConnectionRenderTo(); + GL11.glTranslatef( 0.0f, 0.0f, -0.04f * (8 - depth) - 0.06f ); + } + + ip.renderInventory( BusRenderHelper.instance, renderer ); + } + } + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } +} diff --git a/client/render/CableRenderHelper.java b/src/main/java/appeng/client/render/CableRenderHelper.java similarity index 100% rename from client/render/CableRenderHelper.java rename to src/main/java/appeng/client/render/CableRenderHelper.java diff --git a/client/render/ItemRenderer.java b/src/main/java/appeng/client/render/ItemRenderer.java similarity index 96% rename from client/render/ItemRenderer.java rename to src/main/java/appeng/client/render/ItemRenderer.java index 3a6129411..b1fe1e3d3 100644 --- a/client/render/ItemRenderer.java +++ b/src/main/java/appeng/client/render/ItemRenderer.java @@ -1,47 +1,47 @@ -package appeng.client.render; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.client.IItemRenderer; - -import org.lwjgl.opengl.GL11; - -public class ItemRenderer implements IItemRenderer -{ - - public static final ItemRenderer instance = new ItemRenderer(); - - @Override - public boolean handleRenderType(ItemStack item, ItemRenderType type) - { - return true; - } - - @Override - public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) - { - return true; - } - - @Override - public void renderItem(ItemRenderType type, ItemStack item, Object... data) - { - GL11.glPushMatrix(); - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - GL11.glEnable( GL11.GL_ALPHA_TEST ); - GL11.glEnable( GL11.GL_DEPTH_TEST ); - GL11.glEnable( GL11.GL_BLEND ); - GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA ); - GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); - - if ( type == ItemRenderType.ENTITY ) - GL11.glTranslatef( -0.5f, -0.5f, -0.5f ); - if ( type == ItemRenderType.INVENTORY ) - GL11.glTranslatef( 0.0f, -0.1f, 0.0f ); - - WorldRender.instance.renderItemBlock( item, type, data ); - - GL11.glPopAttrib(); - GL11.glPopMatrix(); - } - -} +package appeng.client.render; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.IItemRenderer; + +import org.lwjgl.opengl.GL11; + +public class ItemRenderer implements IItemRenderer +{ + + public static final ItemRenderer instance = new ItemRenderer(); + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) + { + return true; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) + { + return true; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) + { + GL11.glPushMatrix(); + GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + GL11.glEnable( GL11.GL_ALPHA_TEST ); + GL11.glEnable( GL11.GL_DEPTH_TEST ); + GL11.glEnable( GL11.GL_BLEND ); + GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA ); + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + + if ( type == ItemRenderType.ENTITY ) + GL11.glTranslatef( -0.5f, -0.5f, -0.5f ); + if ( type == ItemRenderType.INVENTORY ) + GL11.glTranslatef( 0.0f, -0.1f, 0.0f ); + + WorldRender.instance.renderItemBlock( item, type, data ); + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } + +} diff --git a/client/render/RenderBlocksWorkaround.java b/src/main/java/appeng/client/render/RenderBlocksWorkaround.java similarity index 96% rename from client/render/RenderBlocksWorkaround.java rename to src/main/java/appeng/client/render/RenderBlocksWorkaround.java index 2220683ec..f8794d30b 100644 --- a/client/render/RenderBlocksWorkaround.java +++ b/src/main/java/appeng/client/render/RenderBlocksWorkaround.java @@ -1,686 +1,686 @@ -package appeng.client.render; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.parts.ISimplifiedBundle; -import appeng.core.AELog; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class RenderBlocksWorkaround extends RenderBlocks -{ - - public boolean calculations = true; - public EnumSet renderFaces = EnumSet.allOf( ForgeDirection.class ); - public EnumSet faces = EnumSet.allOf( ForgeDirection.class ); - - private class LightingCache implements ISimplifiedBundle - { - - public IIcon rXPos; - public IIcon rXNeg; - public IIcon rYPos; - public IIcon rYNeg; - public IIcon rZPos; - public IIcon rZNeg; - - public boolean isAO; - - public int bXPos; - public int bXNeg; - public int bYPos; - public int bYNeg; - public int bZPos; - public int bZNeg; - - public int aoXPos[]; - public int aoXNeg[]; - public int aoYPos[]; - public int aoYNeg[]; - public int aoZPos[]; - public int aoZNeg[]; - - public float foXPos[]; - public float foXNeg[]; - public float foYPos[]; - public float foYNeg[]; - public float foZPos[]; - public float foZNeg[]; - - public int lightHash; - - public LightingCache(LightingCache secondCSrc) { - rXPos = secondCSrc.rXPos; - rXNeg = secondCSrc.rXNeg; - rYPos = secondCSrc.rYPos; - rYNeg = secondCSrc.rYNeg; - rZPos = secondCSrc.rZPos; - rZNeg = secondCSrc.rZNeg; - - isAO = secondCSrc.isAO; - - bXPos = secondCSrc.bXPos; - bXNeg = secondCSrc.bXNeg; - bYPos = secondCSrc.bYPos; - bYNeg = secondCSrc.bYNeg; - bZPos = secondCSrc.bZPos; - bZNeg = secondCSrc.bZNeg; - - aoXPos = secondCSrc.aoXPos.clone(); - aoXNeg = secondCSrc.aoXNeg.clone(); - aoYPos = secondCSrc.aoYPos.clone(); - aoYNeg = secondCSrc.aoYNeg.clone(); - aoZPos = secondCSrc.aoZPos.clone(); - aoZNeg = secondCSrc.aoZNeg.clone(); - - foXPos = secondCSrc.foXPos.clone(); - foXNeg = secondCSrc.foXNeg.clone(); - foYPos = secondCSrc.foYPos.clone(); - foYNeg = secondCSrc.foYNeg.clone(); - foZPos = secondCSrc.foZPos.clone(); - foZNeg = secondCSrc.foZNeg.clone(); - - lightHash = secondCSrc.lightHash; - } - - public LightingCache() { - rXPos = null; - rXNeg = null; - rYPos = null; - rYNeg = null; - rZPos = null; - rZNeg = null; - - isAO = false; - - bXPos = 0; - bXNeg = 0; - bYPos = 0; - bYNeg = 0; - bZPos = 0; - bZNeg = 0; - - aoXPos = new int[5]; - aoXNeg = new int[5]; - aoYPos = new int[5]; - aoYNeg = new int[5]; - aoZPos = new int[5]; - aoZNeg = new int[5]; - - foXPos = new float[12]; - foXNeg = new float[12]; - foYPos = new float[12]; - foYNeg = new float[12]; - foZPos = new float[12]; - foZNeg = new float[12]; - - lightHash = 0; - } - - }; - - private LightingCache lightState = new LightingCache(); - - public boolean isFacade = false; - public boolean useTextures = true; - - Field fBrightness; - Field fColor; - - public int getCurrentColor() - { - try - { - if ( fColor == null ) - { - try - { - fColor = Tessellator.class.getDeclaredField( "color" ); - } - catch (Throwable t) - { - fColor = Tessellator.class.getDeclaredField( "field_78402_m" ); - } - fColor.setAccessible( true ); - } - return (Integer) fColor.get( Tessellator.instance ); - } - catch (Throwable t) - { - return 0; - } - } - - public int getCurrentBrightness() - { - try - { - if ( fBrightness == null ) - { - try - { - fBrightness = Tessellator.class.getDeclaredField( "brightness" ); - } - catch (Throwable t) - { - fBrightness = Tessellator.class.getDeclaredField( "field_78401_l" ); - } - fBrightness.setAccessible( true ); - } - return (Integer) fBrightness.get( Tessellator.instance ); - } - catch (Throwable t) - { - return 0; - } - } - - public void setTexture(IIcon ico) - { - lightState.rXPos = lightState.rXNeg = lightState.rYPos = lightState.rYNeg = lightState.rZPos = lightState.rZNeg = ico; - } - - public void setTexture(IIcon rYNeg, IIcon rYPos, IIcon rZNeg, IIcon rZPos, IIcon rXNeg, IIcon rXPos) - { - lightState.rXPos = rXPos; - lightState.rXNeg = rXNeg; - lightState.rYPos = rYPos; - lightState.rYNeg = rYNeg; - lightState.rZPos = rZPos; - lightState.rZNeg = rZNeg; - } - - public boolean renderStandardBlockNoCalculations(Block b, int x, int y, int z) - { - Tessellator.instance.setBrightness( lightState.bXPos ); - restoreAO( lightState.aoXPos, lightState.foXPos ); - renderFaceXPos( b, x, y, z, useTextures ? lightState.rXPos : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.EAST.ordinal() ) ); - - Tessellator.instance.setBrightness( lightState.bXNeg ); - restoreAO( lightState.aoXNeg, lightState.foXNeg ); - renderFaceXNeg( b, x, y, z, useTextures ? lightState.rXNeg : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.WEST.ordinal() ) ); - - Tessellator.instance.setBrightness( lightState.bYPos ); - restoreAO( lightState.aoYPos, lightState.foYPos ); - renderFaceYPos( b, x, y, z, useTextures ? lightState.rYPos : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.UP.ordinal() ) ); - - Tessellator.instance.setBrightness( lightState.bYNeg ); - restoreAO( lightState.aoYNeg, lightState.foYNeg ); - renderFaceYNeg( b, x, y, z, useTextures ? lightState.rYNeg : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.DOWN.ordinal() ) ); - - Tessellator.instance.setBrightness( lightState.bZPos ); - restoreAO( lightState.aoZPos, lightState.foZPos ); - renderFaceZPos( b, x, y, z, useTextures ? lightState.rZPos : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.SOUTH.ordinal() ) ); - - Tessellator.instance.setBrightness( lightState.bZNeg ); - restoreAO( lightState.aoZNeg, lightState.foZNeg ); - renderFaceZNeg( b, x, y, z, useTextures ? lightState.rZNeg : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.NORTH.ordinal() ) ); - - return true; - } - - private void restoreAO(int[] z, float[] c) - { - brightnessBottomLeft = z[0]; - brightnessBottomRight = z[1]; - brightnessTopLeft = z[2]; - brightnessTopRight = z[3]; - Tessellator.instance.setColorRGBA_I( z[4], (int) (opacity * 255) ); - - colorRedTopLeft = c[0]; - colorGreenTopLeft = c[1]; - colorBlueTopLeft = c[2]; - colorRedBottomLeft = c[3]; - colorGreenBottomLeft = c[4]; - colorBlueBottomLeft = c[5]; - colorRedBottomRight = c[6]; - colorGreenBottomRight = c[7]; - colorBlueBottomRight = c[8]; - colorRedTopRight = c[9]; - colorGreenTopRight = c[10]; - colorBlueTopRight = c[11]; - } - - private void saveAO(int[] z, float[] c) - { - z[0] = brightnessBottomLeft; - z[1] = brightnessBottomRight; - z[2] = brightnessTopLeft; - z[3] = brightnessTopRight; - z[4] = getCurrentColor(); - - c[0] = colorRedTopLeft; - c[1] = colorGreenTopLeft; - c[2] = colorBlueTopLeft; - c[3] = colorRedBottomLeft; - c[4] = colorGreenBottomLeft; - c[5] = colorBlueBottomLeft; - c[6] = colorRedBottomRight; - c[7] = colorGreenBottomRight; - c[8] = colorBlueBottomRight; - c[9] = colorRedTopRight; - c[10] = colorGreenTopRight; - c[11] = colorBlueTopRight; - } - - @Override - public boolean renderStandardBlock(Block blk, int x, int y, int z) - { - try - { - if ( calculations ) - { - lightState.lightHash = getLightingHash( blk, this.blockAccess, x, y, z ); - return super.renderStandardBlock( blk, x, y, z ); - } - else - { - enableAO = lightState.isAO; - boolean out = renderStandardBlockNoCalculations( blk, x, y, z ); - enableAO = false; - return out; - } - } - catch (Throwable t) - { - AELog.error( t ); - // meh - } - return false; - } - - @Override - public void renderFaceXNeg(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) - { - if ( faces.contains( ForgeDirection.WEST ) ) - { - if ( !renderFaces.contains( ForgeDirection.WEST ) ) - return; - - if ( isFacade ) - { - Tessellator tessellator = Tessellator.instance; - - double d3 = (double) par8Icon.getInterpolatedU( this.renderMinZ * 16.0D ); - double d4 = (double) par8Icon.getInterpolatedU( this.renderMaxZ * 16.0D ); - double d5 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMaxY * 16.0D ); - double d6 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMinY * 16.0D ); - - double d11 = par2 + this.renderMinX; - double d12 = par4 + this.renderMinY; - double d13 = par4 + this.renderMaxY; - double d14 = par6 + this.renderMinZ; - double d15 = par6 + this.renderMaxZ; - - if ( this.enableAO ) - { - partialLightingColoring( renderMaxY, renderMaxZ ); - tessellator.addVertexWithUV( d11, d13, d15, d4, d5 ); - partialLightingColoring( renderMaxY, renderMinZ ); - tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); - partialLightingColoring( renderMinY, renderMinZ ); - tessellator.addVertexWithUV( d11, d12, d14, d3, d6 ); - partialLightingColoring( renderMinY, renderMaxZ ); - tessellator.addVertexWithUV( d11, d12, d15, d4, d6 ); - } - else - { - tessellator.addVertexWithUV( d11, d13, d15, d4, d5 ); - tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); - tessellator.addVertexWithUV( d11, d12, d14, d3, d6 ); - tessellator.addVertexWithUV( d11, d12, d15, d4, d6 ); - } - } - else - super.renderFaceXNeg( par1Block, par2, par4, par6, par8Icon ); - } - else - { - lightState.isAO = enableAO; - lightState.rXNeg = par8Icon; - saveAO( lightState.aoXNeg, lightState.foXNeg ); - lightState.bXNeg = getCurrentBrightness(); - } - } - - @Override - public void renderFaceXPos(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) - { - if ( faces.contains( ForgeDirection.EAST ) ) - { - if ( !renderFaces.contains( ForgeDirection.EAST ) ) - return; - - if ( isFacade ) - { - Tessellator tessellator = Tessellator.instance; - - double d3 = (double) par8Icon.getInterpolatedU( 16.0D - this.renderMinZ * 16.0D ); - double d4 = (double) par8Icon.getInterpolatedU( 16.0D - this.renderMaxZ * 16.0D ); - double d5 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMaxY * 16.0D ); - double d6 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMinY * 16.0D ); - - double d11 = par2 + this.renderMaxX; - double d12 = par4 + this.renderMinY; - double d13 = par4 + this.renderMaxY; - double d14 = par6 + this.renderMinZ; - double d15 = par6 + this.renderMaxZ; - - if ( this.enableAO ) - { - partialLightingColoring( 1.0 - renderMinY, renderMaxZ ); - tessellator.addVertexWithUV( d11, d12, d15, d4, d6 ); - partialLightingColoring( 1.0 - renderMinY, renderMinZ ); - tessellator.addVertexWithUV( d11, d12, d14, d3, d6 ); - partialLightingColoring( 1.0 - renderMaxY, renderMinZ ); - tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); - partialLightingColoring( 1.0 - renderMaxY, renderMaxZ ); - tessellator.addVertexWithUV( d11, d13, d15, d4, d5 ); - } - else - { - tessellator.addVertexWithUV( d11, d12, d15, d4, d6 ); - tessellator.addVertexWithUV( d11, d12, d14, d3, d6 ); - tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); - tessellator.addVertexWithUV( d11, d13, d15, d4, d5 ); - } - } - else - super.renderFaceXPos( par1Block, par2, par4, par6, par8Icon ); - } - else - { - lightState.isAO = enableAO; - lightState.rXPos = par8Icon; - saveAO( lightState.aoXPos, lightState.foXPos ); - lightState.bXPos = getCurrentBrightness(); - } - } - - private void partialLightingColoring(double u, double v) - { - double rA = colorRedTopLeft * u + (1.0 - u) * colorRedTopRight; - double rB = colorRedBottomLeft * u + (1.0 - u) * colorRedBottomRight; - float r = (float) (rA * v + rB * (1.0 - v)); - - double gA = colorGreenTopLeft * u + (1.0 - u) * colorGreenTopRight; - double gB = colorGreenBottomLeft * u + (1.0 - u) * colorGreenBottomRight; - float g = (float) (gA * v + gB * (1.0 - v)); - - double bA = colorBlueTopLeft * u + (1.0 - u) * colorBlueTopRight; - double bB = colorBlueBottomLeft * u + (1.0 - u) * colorBlueBottomRight; - float b = (float) (bA * v + bB * (1.0 - v)); - - double highA = (brightnessTopLeft >> 16 & 255) * u + (1.0 - u) * (brightnessTopRight >> 16 & 255); - double highB = (brightnessBottomLeft >> 16 & 255) * u + (1.0 - u) * (brightnessBottomRight >> 16 & 255); - int high = ((int) (highA * v + highB * (1.0 - v))) & 255; - - double lowA = ((brightnessTopLeft & 255)) * u + (1.0 - u) * ((brightnessTopRight & 255)); - double lowB = ((brightnessBottomLeft & 255)) * u + (1.0 - u) * ((brightnessBottomRight & 255)); - int low = ((int) (lowA * v + lowB * (1.0 - v))) & 255; - - int out = (high << 16) | low; - - Tessellator.instance.setColorRGBA_F( r, g, b, opacity ); - Tessellator.instance.setBrightness( out ); - } - - @Override - public void renderFaceYNeg(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) - { - if ( faces.contains( ForgeDirection.DOWN ) ) - { - if ( !renderFaces.contains( ForgeDirection.DOWN ) ) - return; - - if ( isFacade ) - { - Tessellator tessellator = Tessellator.instance; - - double d3 = (double) par8Icon.getInterpolatedU( this.renderMinX * 16.0D ); - double d4 = (double) par8Icon.getInterpolatedU( this.renderMaxX * 16.0D ); - double d5 = (double) par8Icon.getInterpolatedV( this.renderMinZ * 16.0D ); - double d6 = (double) par8Icon.getInterpolatedV( this.renderMaxZ * 16.0D ); - - double d11 = par2 + this.renderMinX; - double d12 = par2 + this.renderMaxX; - double d13 = par4 + this.renderMinY; - double d14 = par6 + this.renderMinZ; - double d15 = par6 + this.renderMaxZ; - - if ( this.enableAO ) - { - partialLightingColoring( 1.0 - renderMinX, renderMaxZ ); - tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); - partialLightingColoring( 1.0 - renderMinX, renderMinZ ); - tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); - partialLightingColoring( 1.0 - renderMaxX, renderMinZ ); - tessellator.addVertexWithUV( d12, d13, d14, d4, d5 ); - partialLightingColoring( 1.0 - renderMaxX, renderMaxZ ); - tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); - } - else - { - tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); - tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); - tessellator.addVertexWithUV( d12, d13, d14, d4, d5 ); - tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); - } - } - else - super.renderFaceYNeg( par1Block, par2, par4, par6, par8Icon ); - } - else - { - lightState.isAO = enableAO; - lightState.rYNeg = par8Icon; - saveAO( lightState.aoYNeg, lightState.foYNeg ); - lightState.bYNeg = getCurrentBrightness(); - } - } - - @Override - public void renderFaceYPos(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) - { - if ( faces.contains( ForgeDirection.UP ) ) - { - if ( !renderFaces.contains( ForgeDirection.UP ) ) - return; - - if ( isFacade ) - { - Tessellator tessellator = Tessellator.instance; - - double d3 = (double) par8Icon.getInterpolatedU( this.renderMinX * 16.0D ); - double d4 = (double) par8Icon.getInterpolatedU( this.renderMaxX * 16.0D ); - double d5 = (double) par8Icon.getInterpolatedV( this.renderMinZ * 16.0D ); - double d6 = (double) par8Icon.getInterpolatedV( this.renderMaxZ * 16.0D ); - - double d11 = par2 + this.renderMinX; - double d12 = par2 + this.renderMaxX; - double d13 = par4 + this.renderMaxY; - double d14 = par6 + this.renderMinZ; - double d15 = par6 + this.renderMaxZ; - - if ( this.enableAO ) - { - partialLightingColoring( this.renderMaxX, renderMaxZ ); - tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); - partialLightingColoring( this.renderMaxX, renderMinZ ); - tessellator.addVertexWithUV( d12, d13, d14, d4, d5 ); - partialLightingColoring( this.renderMinX, renderMinZ ); - tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); - partialLightingColoring( this.renderMinX, renderMaxZ ); - tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); - } - else - { - tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); - tessellator.addVertexWithUV( d12, d13, d14, d4, d5 ); - tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); - tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); - } - } - else - super.renderFaceYPos( par1Block, par2, par4, par6, par8Icon ); - } - else - { - lightState.isAO = enableAO; - lightState.rYPos = par8Icon; - saveAO( lightState.aoYPos, lightState.foYPos ); - lightState.bYPos = getCurrentBrightness(); - } - } - - @Override - public void renderFaceZNeg(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) - { - if ( faces.contains( ForgeDirection.NORTH ) ) - { - if ( !renderFaces.contains( ForgeDirection.NORTH ) ) - return; - - if ( isFacade ) - { - Tessellator tessellator = Tessellator.instance; - - double d3 = (double) par8Icon.getInterpolatedU( 16.0D - this.renderMinX * 16.0D ); - double d4 = (double) par8Icon.getInterpolatedU( 16.0D - this.renderMaxX * 16.0D ); - double d5 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMaxY * 16.0D ); - double d6 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMinY * 16.0D ); - - double d11 = par2 + this.renderMinX; - double d12 = par2 + this.renderMaxX; - double d13 = par4 + this.renderMinY; - double d14 = par4 + this.renderMaxY; - double d15 = par6 + this.renderMinZ; - - if ( this.enableAO ) - { - partialLightingColoring( renderMaxY, 1.0 - renderMinX ); - tessellator.addVertexWithUV( d11, d14, d15, d3, d5 ); - partialLightingColoring( renderMaxY, 1.0 - renderMaxX ); - tessellator.addVertexWithUV( d12, d14, d15, d4, d5 ); - partialLightingColoring( renderMinY, 1.0 - renderMaxX ); - tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); - partialLightingColoring( renderMinY, 1.0 - renderMinX ); - tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); - } - else - { - tessellator.addVertexWithUV( d11, d14, d15, d3, d5 ); - tessellator.addVertexWithUV( d12, d14, d15, d4, d5 ); - tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); - tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); - } - } - else - super.renderFaceZNeg( par1Block, par2, par4, par6, par8Icon ); - } - else - { - lightState.isAO = enableAO; - lightState.rZNeg = par8Icon; - saveAO( lightState.aoZNeg, lightState.foZNeg ); - lightState.bZNeg = getCurrentBrightness(); - } - } - - @Override - public void renderFaceZPos(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) - { - if ( faces.contains( ForgeDirection.SOUTH ) ) - { - if ( !renderFaces.contains( ForgeDirection.SOUTH ) ) - return; - - if ( isFacade ) - { - Tessellator tessellator = Tessellator.instance; - - double d3 = (double) par8Icon.getInterpolatedU( this.renderMinX * 16.0D ); - double d4 = (double) par8Icon.getInterpolatedU( this.renderMaxX * 16.0D ); - double d5 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMaxY * 16.0D ); - double d6 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMinY * 16.0D ); - - double d11 = par2 + this.renderMinX; - double d12 = par2 + this.renderMaxX; - double d13 = par4 + this.renderMinY; - double d14 = par4 + this.renderMaxY; - double d15 = par6 + this.renderMaxZ; - - if ( this.enableAO ) - { - partialLightingColoring( 1.0 - renderMinX, renderMaxY ); - tessellator.addVertexWithUV( d11, d14, d15, d3, d5 ); - partialLightingColoring( 1.0 - renderMinX, renderMinY ); - tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); - partialLightingColoring( 1.0 - renderMaxX, renderMinY ); - tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); - partialLightingColoring( 1.0 - renderMaxX, renderMaxY ); - tessellator.addVertexWithUV( d12, d14, d15, d4, d5 ); - } - else - { - tessellator.addVertexWithUV( d11, d14, d15, d3, d5 ); - tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); - tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); - tessellator.addVertexWithUV( d12, d14, d15, d4, d5 ); - } - } - else - super.renderFaceZPos( par1Block, par2, par4, par6, par8Icon ); - } - else - { - lightState.isAO = enableAO; - lightState.rZPos = par8Icon; - saveAO( lightState.aoZPos, lightState.foZPos ); - lightState.bZPos = getCurrentBrightness(); - } - } - - public boolean similarLighting(Block blk, IBlockAccess w, int x, int y, int z, ISimplifiedBundle sim) - { - int lh = getLightingHash( blk, w, x, y, z ); - return ((LightingCache) sim).lightHash == lh; - } - - int lightHashTmp[] = new int[27]; - public float opacity = 1.0f; - - private int getLightingHash(Block blk, IBlockAccess w, int x, int y, int z) - { - int o = 0; - - for (int i = -1; i <= 1; i++) - for (int j = -1; j <= 1; j++) - for (int k = -1; k <= 1; k++) - { - - lightHashTmp[o++] = blk.getMixedBrightnessForBlock( this.blockAccess, x + i, y + j, z + k ); - } - - return Arrays.hashCode( lightHashTmp ); - } - - public void populate(ISimplifiedBundle sim) - { - lightState = new LightingCache( (LightingCache) sim ); - } - - public ISimplifiedBundle getLightingCache() - { - return new LightingCache( lightState ); - } -} +package appeng.client.render; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.EnumSet; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.parts.ISimplifiedBundle; +import appeng.core.AELog; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderBlocksWorkaround extends RenderBlocks +{ + + public boolean calculations = true; + public EnumSet renderFaces = EnumSet.allOf( ForgeDirection.class ); + public EnumSet faces = EnumSet.allOf( ForgeDirection.class ); + + private class LightingCache implements ISimplifiedBundle + { + + public IIcon rXPos; + public IIcon rXNeg; + public IIcon rYPos; + public IIcon rYNeg; + public IIcon rZPos; + public IIcon rZNeg; + + public boolean isAO; + + public int bXPos; + public int bXNeg; + public int bYPos; + public int bYNeg; + public int bZPos; + public int bZNeg; + + public int aoXPos[]; + public int aoXNeg[]; + public int aoYPos[]; + public int aoYNeg[]; + public int aoZPos[]; + public int aoZNeg[]; + + public float foXPos[]; + public float foXNeg[]; + public float foYPos[]; + public float foYNeg[]; + public float foZPos[]; + public float foZNeg[]; + + public int lightHash; + + public LightingCache(LightingCache secondCSrc) { + rXPos = secondCSrc.rXPos; + rXNeg = secondCSrc.rXNeg; + rYPos = secondCSrc.rYPos; + rYNeg = secondCSrc.rYNeg; + rZPos = secondCSrc.rZPos; + rZNeg = secondCSrc.rZNeg; + + isAO = secondCSrc.isAO; + + bXPos = secondCSrc.bXPos; + bXNeg = secondCSrc.bXNeg; + bYPos = secondCSrc.bYPos; + bYNeg = secondCSrc.bYNeg; + bZPos = secondCSrc.bZPos; + bZNeg = secondCSrc.bZNeg; + + aoXPos = secondCSrc.aoXPos.clone(); + aoXNeg = secondCSrc.aoXNeg.clone(); + aoYPos = secondCSrc.aoYPos.clone(); + aoYNeg = secondCSrc.aoYNeg.clone(); + aoZPos = secondCSrc.aoZPos.clone(); + aoZNeg = secondCSrc.aoZNeg.clone(); + + foXPos = secondCSrc.foXPos.clone(); + foXNeg = secondCSrc.foXNeg.clone(); + foYPos = secondCSrc.foYPos.clone(); + foYNeg = secondCSrc.foYNeg.clone(); + foZPos = secondCSrc.foZPos.clone(); + foZNeg = secondCSrc.foZNeg.clone(); + + lightHash = secondCSrc.lightHash; + } + + public LightingCache() { + rXPos = null; + rXNeg = null; + rYPos = null; + rYNeg = null; + rZPos = null; + rZNeg = null; + + isAO = false; + + bXPos = 0; + bXNeg = 0; + bYPos = 0; + bYNeg = 0; + bZPos = 0; + bZNeg = 0; + + aoXPos = new int[5]; + aoXNeg = new int[5]; + aoYPos = new int[5]; + aoYNeg = new int[5]; + aoZPos = new int[5]; + aoZNeg = new int[5]; + + foXPos = new float[12]; + foXNeg = new float[12]; + foYPos = new float[12]; + foYNeg = new float[12]; + foZPos = new float[12]; + foZNeg = new float[12]; + + lightHash = 0; + } + + }; + + private LightingCache lightState = new LightingCache(); + + public boolean isFacade = false; + public boolean useTextures = true; + + Field fBrightness; + Field fColor; + + public int getCurrentColor() + { + try + { + if ( fColor == null ) + { + try + { + fColor = Tessellator.class.getDeclaredField( "color" ); + } + catch (Throwable t) + { + fColor = Tessellator.class.getDeclaredField( "field_78402_m" ); + } + fColor.setAccessible( true ); + } + return (Integer) fColor.get( Tessellator.instance ); + } + catch (Throwable t) + { + return 0; + } + } + + public int getCurrentBrightness() + { + try + { + if ( fBrightness == null ) + { + try + { + fBrightness = Tessellator.class.getDeclaredField( "brightness" ); + } + catch (Throwable t) + { + fBrightness = Tessellator.class.getDeclaredField( "field_78401_l" ); + } + fBrightness.setAccessible( true ); + } + return (Integer) fBrightness.get( Tessellator.instance ); + } + catch (Throwable t) + { + return 0; + } + } + + public void setTexture(IIcon ico) + { + lightState.rXPos = lightState.rXNeg = lightState.rYPos = lightState.rYNeg = lightState.rZPos = lightState.rZNeg = ico; + } + + public void setTexture(IIcon rYNeg, IIcon rYPos, IIcon rZNeg, IIcon rZPos, IIcon rXNeg, IIcon rXPos) + { + lightState.rXPos = rXPos; + lightState.rXNeg = rXNeg; + lightState.rYPos = rYPos; + lightState.rYNeg = rYNeg; + lightState.rZPos = rZPos; + lightState.rZNeg = rZNeg; + } + + public boolean renderStandardBlockNoCalculations(Block b, int x, int y, int z) + { + Tessellator.instance.setBrightness( lightState.bXPos ); + restoreAO( lightState.aoXPos, lightState.foXPos ); + renderFaceXPos( b, x, y, z, useTextures ? lightState.rXPos : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.EAST.ordinal() ) ); + + Tessellator.instance.setBrightness( lightState.bXNeg ); + restoreAO( lightState.aoXNeg, lightState.foXNeg ); + renderFaceXNeg( b, x, y, z, useTextures ? lightState.rXNeg : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.WEST.ordinal() ) ); + + Tessellator.instance.setBrightness( lightState.bYPos ); + restoreAO( lightState.aoYPos, lightState.foYPos ); + renderFaceYPos( b, x, y, z, useTextures ? lightState.rYPos : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.UP.ordinal() ) ); + + Tessellator.instance.setBrightness( lightState.bYNeg ); + restoreAO( lightState.aoYNeg, lightState.foYNeg ); + renderFaceYNeg( b, x, y, z, useTextures ? lightState.rYNeg : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.DOWN.ordinal() ) ); + + Tessellator.instance.setBrightness( lightState.bZPos ); + restoreAO( lightState.aoZPos, lightState.foZPos ); + renderFaceZPos( b, x, y, z, useTextures ? lightState.rZPos : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.SOUTH.ordinal() ) ); + + Tessellator.instance.setBrightness( lightState.bZNeg ); + restoreAO( lightState.aoZNeg, lightState.foZNeg ); + renderFaceZNeg( b, x, y, z, useTextures ? lightState.rZNeg : getBlockIcon( b, this.blockAccess, x, y, z, ForgeDirection.NORTH.ordinal() ) ); + + return true; + } + + private void restoreAO(int[] z, float[] c) + { + brightnessBottomLeft = z[0]; + brightnessBottomRight = z[1]; + brightnessTopLeft = z[2]; + brightnessTopRight = z[3]; + Tessellator.instance.setColorRGBA_I( z[4], (int) (opacity * 255) ); + + colorRedTopLeft = c[0]; + colorGreenTopLeft = c[1]; + colorBlueTopLeft = c[2]; + colorRedBottomLeft = c[3]; + colorGreenBottomLeft = c[4]; + colorBlueBottomLeft = c[5]; + colorRedBottomRight = c[6]; + colorGreenBottomRight = c[7]; + colorBlueBottomRight = c[8]; + colorRedTopRight = c[9]; + colorGreenTopRight = c[10]; + colorBlueTopRight = c[11]; + } + + private void saveAO(int[] z, float[] c) + { + z[0] = brightnessBottomLeft; + z[1] = brightnessBottomRight; + z[2] = brightnessTopLeft; + z[3] = brightnessTopRight; + z[4] = getCurrentColor(); + + c[0] = colorRedTopLeft; + c[1] = colorGreenTopLeft; + c[2] = colorBlueTopLeft; + c[3] = colorRedBottomLeft; + c[4] = colorGreenBottomLeft; + c[5] = colorBlueBottomLeft; + c[6] = colorRedBottomRight; + c[7] = colorGreenBottomRight; + c[8] = colorBlueBottomRight; + c[9] = colorRedTopRight; + c[10] = colorGreenTopRight; + c[11] = colorBlueTopRight; + } + + @Override + public boolean renderStandardBlock(Block blk, int x, int y, int z) + { + try + { + if ( calculations ) + { + lightState.lightHash = getLightingHash( blk, this.blockAccess, x, y, z ); + return super.renderStandardBlock( blk, x, y, z ); + } + else + { + enableAO = lightState.isAO; + boolean out = renderStandardBlockNoCalculations( blk, x, y, z ); + enableAO = false; + return out; + } + } + catch (Throwable t) + { + AELog.error( t ); + // meh + } + return false; + } + + @Override + public void renderFaceXNeg(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) + { + if ( faces.contains( ForgeDirection.WEST ) ) + { + if ( !renderFaces.contains( ForgeDirection.WEST ) ) + return; + + if ( isFacade ) + { + Tessellator tessellator = Tessellator.instance; + + double d3 = (double) par8Icon.getInterpolatedU( this.renderMinZ * 16.0D ); + double d4 = (double) par8Icon.getInterpolatedU( this.renderMaxZ * 16.0D ); + double d5 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMaxY * 16.0D ); + double d6 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMinY * 16.0D ); + + double d11 = par2 + this.renderMinX; + double d12 = par4 + this.renderMinY; + double d13 = par4 + this.renderMaxY; + double d14 = par6 + this.renderMinZ; + double d15 = par6 + this.renderMaxZ; + + if ( this.enableAO ) + { + partialLightingColoring( renderMaxY, renderMaxZ ); + tessellator.addVertexWithUV( d11, d13, d15, d4, d5 ); + partialLightingColoring( renderMaxY, renderMinZ ); + tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); + partialLightingColoring( renderMinY, renderMinZ ); + tessellator.addVertexWithUV( d11, d12, d14, d3, d6 ); + partialLightingColoring( renderMinY, renderMaxZ ); + tessellator.addVertexWithUV( d11, d12, d15, d4, d6 ); + } + else + { + tessellator.addVertexWithUV( d11, d13, d15, d4, d5 ); + tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); + tessellator.addVertexWithUV( d11, d12, d14, d3, d6 ); + tessellator.addVertexWithUV( d11, d12, d15, d4, d6 ); + } + } + else + super.renderFaceXNeg( par1Block, par2, par4, par6, par8Icon ); + } + else + { + lightState.isAO = enableAO; + lightState.rXNeg = par8Icon; + saveAO( lightState.aoXNeg, lightState.foXNeg ); + lightState.bXNeg = getCurrentBrightness(); + } + } + + @Override + public void renderFaceXPos(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) + { + if ( faces.contains( ForgeDirection.EAST ) ) + { + if ( !renderFaces.contains( ForgeDirection.EAST ) ) + return; + + if ( isFacade ) + { + Tessellator tessellator = Tessellator.instance; + + double d3 = (double) par8Icon.getInterpolatedU( 16.0D - this.renderMinZ * 16.0D ); + double d4 = (double) par8Icon.getInterpolatedU( 16.0D - this.renderMaxZ * 16.0D ); + double d5 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMaxY * 16.0D ); + double d6 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMinY * 16.0D ); + + double d11 = par2 + this.renderMaxX; + double d12 = par4 + this.renderMinY; + double d13 = par4 + this.renderMaxY; + double d14 = par6 + this.renderMinZ; + double d15 = par6 + this.renderMaxZ; + + if ( this.enableAO ) + { + partialLightingColoring( 1.0 - renderMinY, renderMaxZ ); + tessellator.addVertexWithUV( d11, d12, d15, d4, d6 ); + partialLightingColoring( 1.0 - renderMinY, renderMinZ ); + tessellator.addVertexWithUV( d11, d12, d14, d3, d6 ); + partialLightingColoring( 1.0 - renderMaxY, renderMinZ ); + tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); + partialLightingColoring( 1.0 - renderMaxY, renderMaxZ ); + tessellator.addVertexWithUV( d11, d13, d15, d4, d5 ); + } + else + { + tessellator.addVertexWithUV( d11, d12, d15, d4, d6 ); + tessellator.addVertexWithUV( d11, d12, d14, d3, d6 ); + tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); + tessellator.addVertexWithUV( d11, d13, d15, d4, d5 ); + } + } + else + super.renderFaceXPos( par1Block, par2, par4, par6, par8Icon ); + } + else + { + lightState.isAO = enableAO; + lightState.rXPos = par8Icon; + saveAO( lightState.aoXPos, lightState.foXPos ); + lightState.bXPos = getCurrentBrightness(); + } + } + + private void partialLightingColoring(double u, double v) + { + double rA = colorRedTopLeft * u + (1.0 - u) * colorRedTopRight; + double rB = colorRedBottomLeft * u + (1.0 - u) * colorRedBottomRight; + float r = (float) (rA * v + rB * (1.0 - v)); + + double gA = colorGreenTopLeft * u + (1.0 - u) * colorGreenTopRight; + double gB = colorGreenBottomLeft * u + (1.0 - u) * colorGreenBottomRight; + float g = (float) (gA * v + gB * (1.0 - v)); + + double bA = colorBlueTopLeft * u + (1.0 - u) * colorBlueTopRight; + double bB = colorBlueBottomLeft * u + (1.0 - u) * colorBlueBottomRight; + float b = (float) (bA * v + bB * (1.0 - v)); + + double highA = (brightnessTopLeft >> 16 & 255) * u + (1.0 - u) * (brightnessTopRight >> 16 & 255); + double highB = (brightnessBottomLeft >> 16 & 255) * u + (1.0 - u) * (brightnessBottomRight >> 16 & 255); + int high = ((int) (highA * v + highB * (1.0 - v))) & 255; + + double lowA = ((brightnessTopLeft & 255)) * u + (1.0 - u) * ((brightnessTopRight & 255)); + double lowB = ((brightnessBottomLeft & 255)) * u + (1.0 - u) * ((brightnessBottomRight & 255)); + int low = ((int) (lowA * v + lowB * (1.0 - v))) & 255; + + int out = (high << 16) | low; + + Tessellator.instance.setColorRGBA_F( r, g, b, opacity ); + Tessellator.instance.setBrightness( out ); + } + + @Override + public void renderFaceYNeg(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) + { + if ( faces.contains( ForgeDirection.DOWN ) ) + { + if ( !renderFaces.contains( ForgeDirection.DOWN ) ) + return; + + if ( isFacade ) + { + Tessellator tessellator = Tessellator.instance; + + double d3 = (double) par8Icon.getInterpolatedU( this.renderMinX * 16.0D ); + double d4 = (double) par8Icon.getInterpolatedU( this.renderMaxX * 16.0D ); + double d5 = (double) par8Icon.getInterpolatedV( this.renderMinZ * 16.0D ); + double d6 = (double) par8Icon.getInterpolatedV( this.renderMaxZ * 16.0D ); + + double d11 = par2 + this.renderMinX; + double d12 = par2 + this.renderMaxX; + double d13 = par4 + this.renderMinY; + double d14 = par6 + this.renderMinZ; + double d15 = par6 + this.renderMaxZ; + + if ( this.enableAO ) + { + partialLightingColoring( 1.0 - renderMinX, renderMaxZ ); + tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); + partialLightingColoring( 1.0 - renderMinX, renderMinZ ); + tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); + partialLightingColoring( 1.0 - renderMaxX, renderMinZ ); + tessellator.addVertexWithUV( d12, d13, d14, d4, d5 ); + partialLightingColoring( 1.0 - renderMaxX, renderMaxZ ); + tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); + } + else + { + tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); + tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); + tessellator.addVertexWithUV( d12, d13, d14, d4, d5 ); + tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); + } + } + else + super.renderFaceYNeg( par1Block, par2, par4, par6, par8Icon ); + } + else + { + lightState.isAO = enableAO; + lightState.rYNeg = par8Icon; + saveAO( lightState.aoYNeg, lightState.foYNeg ); + lightState.bYNeg = getCurrentBrightness(); + } + } + + @Override + public void renderFaceYPos(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) + { + if ( faces.contains( ForgeDirection.UP ) ) + { + if ( !renderFaces.contains( ForgeDirection.UP ) ) + return; + + if ( isFacade ) + { + Tessellator tessellator = Tessellator.instance; + + double d3 = (double) par8Icon.getInterpolatedU( this.renderMinX * 16.0D ); + double d4 = (double) par8Icon.getInterpolatedU( this.renderMaxX * 16.0D ); + double d5 = (double) par8Icon.getInterpolatedV( this.renderMinZ * 16.0D ); + double d6 = (double) par8Icon.getInterpolatedV( this.renderMaxZ * 16.0D ); + + double d11 = par2 + this.renderMinX; + double d12 = par2 + this.renderMaxX; + double d13 = par4 + this.renderMaxY; + double d14 = par6 + this.renderMinZ; + double d15 = par6 + this.renderMaxZ; + + if ( this.enableAO ) + { + partialLightingColoring( this.renderMaxX, renderMaxZ ); + tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); + partialLightingColoring( this.renderMaxX, renderMinZ ); + tessellator.addVertexWithUV( d12, d13, d14, d4, d5 ); + partialLightingColoring( this.renderMinX, renderMinZ ); + tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); + partialLightingColoring( this.renderMinX, renderMaxZ ); + tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); + } + else + { + tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); + tessellator.addVertexWithUV( d12, d13, d14, d4, d5 ); + tessellator.addVertexWithUV( d11, d13, d14, d3, d5 ); + tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); + } + } + else + super.renderFaceYPos( par1Block, par2, par4, par6, par8Icon ); + } + else + { + lightState.isAO = enableAO; + lightState.rYPos = par8Icon; + saveAO( lightState.aoYPos, lightState.foYPos ); + lightState.bYPos = getCurrentBrightness(); + } + } + + @Override + public void renderFaceZNeg(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) + { + if ( faces.contains( ForgeDirection.NORTH ) ) + { + if ( !renderFaces.contains( ForgeDirection.NORTH ) ) + return; + + if ( isFacade ) + { + Tessellator tessellator = Tessellator.instance; + + double d3 = (double) par8Icon.getInterpolatedU( 16.0D - this.renderMinX * 16.0D ); + double d4 = (double) par8Icon.getInterpolatedU( 16.0D - this.renderMaxX * 16.0D ); + double d5 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMaxY * 16.0D ); + double d6 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMinY * 16.0D ); + + double d11 = par2 + this.renderMinX; + double d12 = par2 + this.renderMaxX; + double d13 = par4 + this.renderMinY; + double d14 = par4 + this.renderMaxY; + double d15 = par6 + this.renderMinZ; + + if ( this.enableAO ) + { + partialLightingColoring( renderMaxY, 1.0 - renderMinX ); + tessellator.addVertexWithUV( d11, d14, d15, d3, d5 ); + partialLightingColoring( renderMaxY, 1.0 - renderMaxX ); + tessellator.addVertexWithUV( d12, d14, d15, d4, d5 ); + partialLightingColoring( renderMinY, 1.0 - renderMaxX ); + tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); + partialLightingColoring( renderMinY, 1.0 - renderMinX ); + tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); + } + else + { + tessellator.addVertexWithUV( d11, d14, d15, d3, d5 ); + tessellator.addVertexWithUV( d12, d14, d15, d4, d5 ); + tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); + tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); + } + } + else + super.renderFaceZNeg( par1Block, par2, par4, par6, par8Icon ); + } + else + { + lightState.isAO = enableAO; + lightState.rZNeg = par8Icon; + saveAO( lightState.aoZNeg, lightState.foZNeg ); + lightState.bZNeg = getCurrentBrightness(); + } + } + + @Override + public void renderFaceZPos(Block par1Block, double par2, double par4, double par6, IIcon par8Icon) + { + if ( faces.contains( ForgeDirection.SOUTH ) ) + { + if ( !renderFaces.contains( ForgeDirection.SOUTH ) ) + return; + + if ( isFacade ) + { + Tessellator tessellator = Tessellator.instance; + + double d3 = (double) par8Icon.getInterpolatedU( this.renderMinX * 16.0D ); + double d4 = (double) par8Icon.getInterpolatedU( this.renderMaxX * 16.0D ); + double d5 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMaxY * 16.0D ); + double d6 = (double) par8Icon.getInterpolatedV( 16.0D - this.renderMinY * 16.0D ); + + double d11 = par2 + this.renderMinX; + double d12 = par2 + this.renderMaxX; + double d13 = par4 + this.renderMinY; + double d14 = par4 + this.renderMaxY; + double d15 = par6 + this.renderMaxZ; + + if ( this.enableAO ) + { + partialLightingColoring( 1.0 - renderMinX, renderMaxY ); + tessellator.addVertexWithUV( d11, d14, d15, d3, d5 ); + partialLightingColoring( 1.0 - renderMinX, renderMinY ); + tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); + partialLightingColoring( 1.0 - renderMaxX, renderMinY ); + tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); + partialLightingColoring( 1.0 - renderMaxX, renderMaxY ); + tessellator.addVertexWithUV( d12, d14, d15, d4, d5 ); + } + else + { + tessellator.addVertexWithUV( d11, d14, d15, d3, d5 ); + tessellator.addVertexWithUV( d11, d13, d15, d3, d6 ); + tessellator.addVertexWithUV( d12, d13, d15, d4, d6 ); + tessellator.addVertexWithUV( d12, d14, d15, d4, d5 ); + } + } + else + super.renderFaceZPos( par1Block, par2, par4, par6, par8Icon ); + } + else + { + lightState.isAO = enableAO; + lightState.rZPos = par8Icon; + saveAO( lightState.aoZPos, lightState.foZPos ); + lightState.bZPos = getCurrentBrightness(); + } + } + + public boolean similarLighting(Block blk, IBlockAccess w, int x, int y, int z, ISimplifiedBundle sim) + { + int lh = getLightingHash( blk, w, x, y, z ); + return ((LightingCache) sim).lightHash == lh; + } + + int lightHashTmp[] = new int[27]; + public float opacity = 1.0f; + + private int getLightingHash(Block blk, IBlockAccess w, int x, int y, int z) + { + int o = 0; + + for (int i = -1; i <= 1; i++) + for (int j = -1; j <= 1; j++) + for (int k = -1; k <= 1; k++) + { + + lightHashTmp[o++] = blk.getMixedBrightnessForBlock( this.blockAccess, x + i, y + j, z + k ); + } + + return Arrays.hashCode( lightHashTmp ); + } + + public void populate(ISimplifiedBundle sim) + { + lightState = new LightingCache( (LightingCache) sim ); + } + + public ISimplifiedBundle getLightingCache() + { + return new LightingCache( lightState ); + } +} diff --git a/client/render/SpatialSkyRender.java b/src/main/java/appeng/client/render/SpatialSkyRender.java similarity index 100% rename from client/render/SpatialSkyRender.java rename to src/main/java/appeng/client/render/SpatialSkyRender.java diff --git a/client/render/TESRWrapper.java b/src/main/java/appeng/client/render/TESRWrapper.java similarity index 100% rename from client/render/TESRWrapper.java rename to src/main/java/appeng/client/render/TESRWrapper.java diff --git a/client/render/WorldRender.java b/src/main/java/appeng/client/render/WorldRender.java similarity index 96% rename from client/render/WorldRender.java rename to src/main/java/appeng/client/render/WorldRender.java index 0a07567a0..453fea84f 100644 --- a/client/render/WorldRender.java +++ b/src/main/java/appeng/client/render/WorldRender.java @@ -1,90 +1,90 @@ -package appeng.client.render; - -import java.util.HashMap; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import appeng.block.AEBaseBlock; -import appeng.core.AELog; -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; -import cpw.mods.fml.client.registry.RenderingRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class WorldRender implements ISimpleBlockRenderingHandler -{ - - private RenderBlocks renderer = new RenderBlocks(); - final int renderID = RenderingRegistry.getNextAvailableRenderId(); - public static final WorldRender instance = new WorldRender(); - boolean hasError = false; - - public HashMap blockRenders = new HashMap(); - - void setRender(AEBaseBlock in, BaseBlockRender r) - { - blockRenders.put( in, r ); - } - - private WorldRender() { - } - - @Override - public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) - { - // wtf is this for? - } - - @Override - public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) - { - AEBaseBlock blk = (AEBaseBlock) block; - renderer.setRenderBoundsFromBlock( block ); - return getRender( blk ).renderInWorld( blk, world, x, y, z, renderer ); - } - - @Override - public boolean shouldRender3DInInventory(int modelId) - { - return true; - } - - @Override - public int getRenderId() - { - return renderID; - } - - public void renderItemBlock(ItemStack item, ItemRenderType type, Object[] data) - { - Block blk = Block.getBlockFromItem( item.getItem() ); - if ( blk instanceof AEBaseBlock ) - { - AEBaseBlock block = (AEBaseBlock) blk; - renderer.setRenderBoundsFromBlock( block ); - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - getRender( block ).renderInventory( block, item, renderer, type, data ); - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - } - else - { - if ( !hasError ) - { - hasError = true; - AELog.severe( "Invalid render - item/block mismatch" ); - AELog.severe( " item: " + item.getUnlocalizedName() ); - AELog.severe( " block: " + blk.getUnlocalizedName() ); - } - } - } - - private BaseBlockRender getRender(AEBaseBlock block) - { - return block.getRendererInstance().rendererInstance; - } -} +package appeng.client.render; + +import java.util.HashMap; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import appeng.block.AEBaseBlock; +import appeng.core.AELog; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import cpw.mods.fml.client.registry.RenderingRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class WorldRender implements ISimpleBlockRenderingHandler +{ + + private RenderBlocks renderer = new RenderBlocks(); + final int renderID = RenderingRegistry.getNextAvailableRenderId(); + public static final WorldRender instance = new WorldRender(); + boolean hasError = false; + + public HashMap blockRenders = new HashMap(); + + void setRender(AEBaseBlock in, BaseBlockRender r) + { + blockRenders.put( in, r ); + } + + private WorldRender() { + } + + @Override + public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) + { + // wtf is this for? + } + + @Override + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) + { + AEBaseBlock blk = (AEBaseBlock) block; + renderer.setRenderBoundsFromBlock( block ); + return getRender( blk ).renderInWorld( blk, world, x, y, z, renderer ); + } + + @Override + public boolean shouldRender3DInInventory(int modelId) + { + return true; + } + + @Override + public int getRenderId() + { + return renderID; + } + + public void renderItemBlock(ItemStack item, ItemRenderType type, Object[] data) + { + Block blk = Block.getBlockFromItem( item.getItem() ); + if ( blk instanceof AEBaseBlock ) + { + AEBaseBlock block = (AEBaseBlock) blk; + renderer.setRenderBoundsFromBlock( block ); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + getRender( block ).renderInventory( block, item, renderer, type, data ); + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + } + else + { + if ( !hasError ) + { + hasError = true; + AELog.severe( "Invalid render - item/block mismatch" ); + AELog.severe( " item: " + item.getUnlocalizedName() ); + AELog.severe( " block: " + blk.getUnlocalizedName() ); + } + } + } + + private BaseBlockRender getRender(AEBaseBlock block) + { + return block.getRendererInstance().rendererInstance; + } +} diff --git a/client/render/blocks/RenderBlockAssembler.java b/src/main/java/appeng/client/render/blocks/RenderBlockAssembler.java similarity index 100% rename from client/render/blocks/RenderBlockAssembler.java rename to src/main/java/appeng/client/render/blocks/RenderBlockAssembler.java diff --git a/client/render/blocks/RenderBlockCharger.java b/src/main/java/appeng/client/render/blocks/RenderBlockCharger.java similarity index 97% rename from client/render/blocks/RenderBlockCharger.java rename to src/main/java/appeng/client/render/blocks/RenderBlockCharger.java index 7014d81ac..c8873b874 100644 --- a/client/render/blocks/RenderBlockCharger.java +++ b/src/main/java/appeng/client/render/blocks/RenderBlockCharger.java @@ -1,157 +1,157 @@ -package appeng.client.render.blocks; - -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; - -import appeng.api.util.IOrientable; -import appeng.block.AEBaseBlock; -import appeng.block.misc.BlockCharger; -import appeng.client.render.BaseBlockRender; -import appeng.client.texture.ExtraBlockTextures; -import appeng.core.AELog; -import appeng.tile.AEBaseTile; -import appeng.util.Platform; - -public class RenderBlockCharger extends BaseBlockRender -{ - - public RenderBlockCharger() { - super( true, 30 ); - } - - @Override - public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - Tessellator tess = Tessellator.instance; - - renderer.renderAllFaces = true; - setInvRenderBounds( renderer, 6, 1, 0, 10, 15, 2 ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - blk.getRendererInstance().setTemporaryRenderIcons( ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null, null ); - - setInvRenderBounds( renderer, 2, 0, 2, 14, 3, 14 ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - setInvRenderBounds( renderer, 3, 3, 3, 13, 4, 13 ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - blk.getRendererInstance().setTemporaryRenderIcon( null ); - - blk.getRendererInstance().setTemporaryRenderIcons( null, ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null ); - - setInvRenderBounds( renderer, 2, 13, 2, 14, 16, 14 ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - setInvRenderBounds( renderer, 3, 12, 3, 13, 13, 13 ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - renderer.renderAllFaces = false; - blk.getRendererInstance().setTemporaryRenderIcon( null ); - - } - - @Override - public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - preRenderInWorld( block, world, x, y, z, renderer ); - - BlockCharger blk = (BlockCharger) block; - - IOrientable te = getOrientable( block, world, x, y, z ); - - ForgeDirection fdy = te.getUp(); - ForgeDirection fdz = te.getForward(); - ForgeDirection fdx = Platform.crossProduct( fdz, fdy ).getOpposite(); - - renderer.renderAllFaces = true; - renderBlockBounds( renderer, 6, 1, 0, 10, 15, 2, fdx, fdy, fdz ); - boolean out = renderer.renderStandardBlock( blk, x, y, z ); - - blk.getRendererInstance().setTemporaryRenderIcons( ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null, null ); - - renderBlockBounds( renderer, 2, 0, 2, 14, 3, 14, fdx, fdy, fdz ); - out = renderer.renderStandardBlock( blk, x, y, z ); - - renderBlockBounds( renderer, 3, 3, 3, 13, 4, 13, fdx, fdy, fdz ); - out = renderer.renderStandardBlock( blk, x, y, z ); - - blk.getRendererInstance().setTemporaryRenderIcon( null ); - - blk.getRendererInstance().setTemporaryRenderIcons( null, ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null ); - - renderBlockBounds( renderer, 2, 13, 2, 14, 16, 14, fdx, fdy, fdz ); - out = renderer.renderStandardBlock( blk, x, y, z ); - - renderBlockBounds( renderer, 3, 12, 3, 13, 13, 13, fdx, fdy, fdz ); - out = renderer.renderStandardBlock( blk, x, y, z ); - - renderer.renderAllFaces = false; - blk.getRendererInstance().setTemporaryRenderIcon( null ); - - postRenderInWorld( renderer ); - return out; - } - - @Override - public void renderTile(AEBaseBlock block, AEBaseTile tile, Tessellator tess, double x, double y, double z, float f, RenderBlocks renderer) - { - ItemStack sis = null; - if ( tile instanceof IInventory ) - sis = ((IInventory) tile).getStackInSlot( 0 ); - - if ( sis != null ) - { - GL11.glPushMatrix(); - applyTESRRotation( x, y, z, tile.getForward(), tile.getUp() ); - - try - { - GL11.glTranslatef( 0.5f, 0.45f, 0.5f ); - GL11.glScalef( 1.0f / 1.1f, 1.0f / 1.1f, 1.0f / 1.1f ); - GL11.glScalef( 1.0f, 1.0f, 1.0f ); - - Block blk = Block.getBlockFromItem( sis.getItem() ); - if ( sis.getItemSpriteNumber() == 0 && block != null && RenderBlocks.renderItemIn3d( blk.getRenderType() ) ) - { - GL11.glRotatef( 25.0f, 1.0f, 0.0f, 0.0f ); - GL11.glRotatef( 15.0f, 0.0f, 1.0f, 0.0f ); - GL11.glRotatef( 30.0f, 0.0f, 1.0f, 0.0f ); - } - - int light = tile.getWorldObj().getLightBrightnessForSkyBlocks( tile.xCoord, tile.yCoord, tile.zCoord, 0 ); - int br = light;// << 20 | light << 4; - int var11 = br % 65536; - int var12 = br / 65536; - OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11, var12 ); - - GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); - - GL11.glDisable( GL11.GL_LIGHTING ); - GL11.glDisable( GL12.GL_RESCALE_NORMAL ); - tess.setColorOpaque_F( 1.0f, 1.0f, 1.0f ); - - doRenderItem( sis, tile ); - } - catch (Exception err) - { - AELog.error( err ); - } - - GL11.glPopMatrix(); - } - } - -} +package appeng.client.render.blocks; + +import java.util.EnumSet; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import appeng.api.util.IOrientable; +import appeng.block.AEBaseBlock; +import appeng.block.misc.BlockCharger; +import appeng.client.render.BaseBlockRender; +import appeng.client.texture.ExtraBlockTextures; +import appeng.core.AELog; +import appeng.tile.AEBaseTile; +import appeng.util.Platform; + +public class RenderBlockCharger extends BaseBlockRender +{ + + public RenderBlockCharger() { + super( true, 30 ); + } + + @Override + public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + Tessellator tess = Tessellator.instance; + + renderer.renderAllFaces = true; + setInvRenderBounds( renderer, 6, 1, 0, 10, 15, 2 ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + blk.getRendererInstance().setTemporaryRenderIcons( ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null, null ); + + setInvRenderBounds( renderer, 2, 0, 2, 14, 3, 14 ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + setInvRenderBounds( renderer, 3, 3, 3, 13, 4, 13 ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + blk.getRendererInstance().setTemporaryRenderIcon( null ); + + blk.getRendererInstance().setTemporaryRenderIcons( null, ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null ); + + setInvRenderBounds( renderer, 2, 13, 2, 14, 16, 14 ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + setInvRenderBounds( renderer, 3, 12, 3, 13, 13, 13 ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + renderer.renderAllFaces = false; + blk.getRendererInstance().setTemporaryRenderIcon( null ); + + } + + @Override + public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + preRenderInWorld( block, world, x, y, z, renderer ); + + BlockCharger blk = (BlockCharger) block; + + IOrientable te = getOrientable( block, world, x, y, z ); + + ForgeDirection fdy = te.getUp(); + ForgeDirection fdz = te.getForward(); + ForgeDirection fdx = Platform.crossProduct( fdz, fdy ).getOpposite(); + + renderer.renderAllFaces = true; + renderBlockBounds( renderer, 6, 1, 0, 10, 15, 2, fdx, fdy, fdz ); + boolean out = renderer.renderStandardBlock( blk, x, y, z ); + + blk.getRendererInstance().setTemporaryRenderIcons( ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null, null ); + + renderBlockBounds( renderer, 2, 0, 2, 14, 3, 14, fdx, fdy, fdz ); + out = renderer.renderStandardBlock( blk, x, y, z ); + + renderBlockBounds( renderer, 3, 3, 3, 13, 4, 13, fdx, fdy, fdz ); + out = renderer.renderStandardBlock( blk, x, y, z ); + + blk.getRendererInstance().setTemporaryRenderIcon( null ); + + blk.getRendererInstance().setTemporaryRenderIcons( null, ExtraBlockTextures.BlockChargerInside.getIcon(), null, null, null, null ); + + renderBlockBounds( renderer, 2, 13, 2, 14, 16, 14, fdx, fdy, fdz ); + out = renderer.renderStandardBlock( blk, x, y, z ); + + renderBlockBounds( renderer, 3, 12, 3, 13, 13, 13, fdx, fdy, fdz ); + out = renderer.renderStandardBlock( blk, x, y, z ); + + renderer.renderAllFaces = false; + blk.getRendererInstance().setTemporaryRenderIcon( null ); + + postRenderInWorld( renderer ); + return out; + } + + @Override + public void renderTile(AEBaseBlock block, AEBaseTile tile, Tessellator tess, double x, double y, double z, float f, RenderBlocks renderer) + { + ItemStack sis = null; + if ( tile instanceof IInventory ) + sis = ((IInventory) tile).getStackInSlot( 0 ); + + if ( sis != null ) + { + GL11.glPushMatrix(); + applyTESRRotation( x, y, z, tile.getForward(), tile.getUp() ); + + try + { + GL11.glTranslatef( 0.5f, 0.45f, 0.5f ); + GL11.glScalef( 1.0f / 1.1f, 1.0f / 1.1f, 1.0f / 1.1f ); + GL11.glScalef( 1.0f, 1.0f, 1.0f ); + + Block blk = Block.getBlockFromItem( sis.getItem() ); + if ( sis.getItemSpriteNumber() == 0 && block != null && RenderBlocks.renderItemIn3d( blk.getRenderType() ) ) + { + GL11.glRotatef( 25.0f, 1.0f, 0.0f, 0.0f ); + GL11.glRotatef( 15.0f, 0.0f, 1.0f, 0.0f ); + GL11.glRotatef( 30.0f, 0.0f, 1.0f, 0.0f ); + } + + int light = tile.getWorldObj().getLightBrightnessForSkyBlocks( tile.xCoord, tile.yCoord, tile.zCoord, 0 ); + int br = light;// << 20 | light << 4; + int var11 = br % 65536; + int var12 = br / 65536; + OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11, var12 ); + + GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); + + GL11.glDisable( GL11.GL_LIGHTING ); + GL11.glDisable( GL12.GL_RESCALE_NORMAL ); + tess.setColorOpaque_F( 1.0f, 1.0f, 1.0f ); + + doRenderItem( sis, tile ); + } + catch (Exception err) + { + AELog.error( err ); + } + + GL11.glPopMatrix(); + } + } + +} diff --git a/client/render/blocks/RenderBlockController.java b/src/main/java/appeng/client/render/blocks/RenderBlockController.java similarity index 97% rename from client/render/blocks/RenderBlockController.java rename to src/main/java/appeng/client/render/blocks/RenderBlockController.java index ffdf397e4..df3a845d8 100644 --- a/client/render/blocks/RenderBlockController.java +++ b/src/main/java/appeng/client/render/blocks/RenderBlockController.java @@ -1,133 +1,133 @@ -package appeng.client.render.blocks; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockAccess; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.texture.ExtraBlockTextures; -import appeng.tile.networking.TileController; - -public class RenderBlockController extends BaseBlockRender -{ - - public RenderBlockController() { - super( false, 20 ); - } - - @Override - public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - - boolean xx = getTileEntity( world, x - 1, y, z ) instanceof TileController && getTileEntity( world, x + 1, y, z ) instanceof TileController; - boolean yy = getTileEntity( world, x, y - 1, z ) instanceof TileController && getTileEntity( world, x, y + 1, z ) instanceof TileController; - boolean zz = getTileEntity( world, x, y, z - 1 ) instanceof TileController && getTileEntity( world, x, y, z + 1 ) instanceof TileController; - - int meta = world.getBlockMetadata( x, y, z ); - boolean hasPower = meta > 0; - boolean isConflict = meta == 2; - - ExtraBlockTextures lights = null; - - if ( xx && !yy && !zz ) - { - if ( hasPower ) - { - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() ); - if ( isConflict ) - lights = ExtraBlockTextures.BlockControllerColumnConflict; - else - lights = ExtraBlockTextures.BlockControllerColumnLights; - } - else - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() ); - - renderer.uvRotateEast = 1; - renderer.uvRotateWest = 1; - renderer.uvRotateTop = 1; - renderer.uvRotateBottom = 1; - } - else if ( !xx && yy && !zz ) - { - if ( hasPower ) - { - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() ); - if ( isConflict ) - lights = ExtraBlockTextures.BlockControllerColumnConflict; - else - lights = ExtraBlockTextures.BlockControllerColumnLights; - } - else - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() ); - - renderer.uvRotateEast = 0; - renderer.uvRotateNorth = 0; - } - else if ( !xx && !yy && zz ) - { - if ( hasPower ) - { - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() ); - if ( isConflict ) - lights = ExtraBlockTextures.BlockControllerColumnConflict; - else - lights = ExtraBlockTextures.BlockControllerColumnLights; - } - else - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() ); - - renderer.uvRotateNorth = 1; - renderer.uvRotateSouth = 1; - renderer.uvRotateTop = 0; - } - else if ( (xx ? 1 : 0) + (yy ? 1 : 0) + (zz ? 1 : 0) >= 2 ) - { - int v = (Math.abs( x ) + Math.abs( y ) + Math.abs( z )) % 2; - renderer.uvRotateEast = renderer.uvRotateBottom = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - - if ( v == 0 ) - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerInsideA.getIcon() ); - else - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerInsideB.getIcon() ); - } - else - { - if ( hasPower ) - { - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerPowered.getIcon() ); - if ( isConflict ) - lights = ExtraBlockTextures.BlockControllerConflict; - else - lights = ExtraBlockTextures.BlockControllerLights; - } - else - blk.getRendererInstance().setTemporaryRenderIcon( null ); - - } - - boolean out = renderer.renderStandardBlock( blk, x, y, z ); - if ( lights != null ) - { - Tessellator.instance.setColorOpaque_F( 1.0f, 1.0f, 1.0f ); - Tessellator.instance.setBrightness( 14 << 20 | 14 << 4 ); - renderer.renderFaceXNeg( blk, x, y, z, lights.getIcon() ); - renderer.renderFaceXPos( blk, x, y, z, lights.getIcon() ); - renderer.renderFaceYNeg( blk, x, y, z, lights.getIcon() ); - renderer.renderFaceYPos( blk, x, y, z, lights.getIcon() ); - renderer.renderFaceZNeg( blk, x, y, z, lights.getIcon() ); - renderer.renderFaceZPos( blk, x, y, z, lights.getIcon() ); - } - - blk.getRendererInstance().setTemporaryRenderIcon( null ); - renderer.uvRotateEast = renderer.uvRotateBottom = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - return out; - } - - private TileEntity getTileEntity(IBlockAccess world, int x, int y, int z) - { - if ( y >= 0 ) - return world.getTileEntity( x, y, z ); - return null; - } -} +package appeng.client.render.blocks; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.texture.ExtraBlockTextures; +import appeng.tile.networking.TileController; + +public class RenderBlockController extends BaseBlockRender +{ + + public RenderBlockController() { + super( false, 20 ); + } + + @Override + public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + + boolean xx = getTileEntity( world, x - 1, y, z ) instanceof TileController && getTileEntity( world, x + 1, y, z ) instanceof TileController; + boolean yy = getTileEntity( world, x, y - 1, z ) instanceof TileController && getTileEntity( world, x, y + 1, z ) instanceof TileController; + boolean zz = getTileEntity( world, x, y, z - 1 ) instanceof TileController && getTileEntity( world, x, y, z + 1 ) instanceof TileController; + + int meta = world.getBlockMetadata( x, y, z ); + boolean hasPower = meta > 0; + boolean isConflict = meta == 2; + + ExtraBlockTextures lights = null; + + if ( xx && !yy && !zz ) + { + if ( hasPower ) + { + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() ); + if ( isConflict ) + lights = ExtraBlockTextures.BlockControllerColumnConflict; + else + lights = ExtraBlockTextures.BlockControllerColumnLights; + } + else + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() ); + + renderer.uvRotateEast = 1; + renderer.uvRotateWest = 1; + renderer.uvRotateTop = 1; + renderer.uvRotateBottom = 1; + } + else if ( !xx && yy && !zz ) + { + if ( hasPower ) + { + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() ); + if ( isConflict ) + lights = ExtraBlockTextures.BlockControllerColumnConflict; + else + lights = ExtraBlockTextures.BlockControllerColumnLights; + } + else + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() ); + + renderer.uvRotateEast = 0; + renderer.uvRotateNorth = 0; + } + else if ( !xx && !yy && zz ) + { + if ( hasPower ) + { + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumnPowered.getIcon() ); + if ( isConflict ) + lights = ExtraBlockTextures.BlockControllerColumnConflict; + else + lights = ExtraBlockTextures.BlockControllerColumnLights; + } + else + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerColumn.getIcon() ); + + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 1; + renderer.uvRotateTop = 0; + } + else if ( (xx ? 1 : 0) + (yy ? 1 : 0) + (zz ? 1 : 0) >= 2 ) + { + int v = (Math.abs( x ) + Math.abs( y ) + Math.abs( z )) % 2; + renderer.uvRotateEast = renderer.uvRotateBottom = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + + if ( v == 0 ) + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerInsideA.getIcon() ); + else + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerInsideB.getIcon() ); + } + else + { + if ( hasPower ) + { + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.BlockControllerPowered.getIcon() ); + if ( isConflict ) + lights = ExtraBlockTextures.BlockControllerConflict; + else + lights = ExtraBlockTextures.BlockControllerLights; + } + else + blk.getRendererInstance().setTemporaryRenderIcon( null ); + + } + + boolean out = renderer.renderStandardBlock( blk, x, y, z ); + if ( lights != null ) + { + Tessellator.instance.setColorOpaque_F( 1.0f, 1.0f, 1.0f ); + Tessellator.instance.setBrightness( 14 << 20 | 14 << 4 ); + renderer.renderFaceXNeg( blk, x, y, z, lights.getIcon() ); + renderer.renderFaceXPos( blk, x, y, z, lights.getIcon() ); + renderer.renderFaceYNeg( blk, x, y, z, lights.getIcon() ); + renderer.renderFaceYPos( blk, x, y, z, lights.getIcon() ); + renderer.renderFaceZNeg( blk, x, y, z, lights.getIcon() ); + renderer.renderFaceZPos( blk, x, y, z, lights.getIcon() ); + } + + blk.getRendererInstance().setTemporaryRenderIcon( null ); + renderer.uvRotateEast = renderer.uvRotateBottom = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + return out; + } + + private TileEntity getTileEntity(IBlockAccess world, int x, int y, int z) + { + if ( y >= 0 ) + return world.getTileEntity( x, y, z ); + return null; + } +} diff --git a/client/render/blocks/RenderBlockCraftingCPU.java b/src/main/java/appeng/client/render/blocks/RenderBlockCraftingCPU.java similarity index 100% rename from client/render/blocks/RenderBlockCraftingCPU.java rename to src/main/java/appeng/client/render/blocks/RenderBlockCraftingCPU.java diff --git a/client/render/blocks/RenderBlockCraftingCPUMonitor.java b/src/main/java/appeng/client/render/blocks/RenderBlockCraftingCPUMonitor.java similarity index 100% rename from client/render/blocks/RenderBlockCraftingCPUMonitor.java rename to src/main/java/appeng/client/render/blocks/RenderBlockCraftingCPUMonitor.java diff --git a/client/render/blocks/RenderBlockCrank.java b/src/main/java/appeng/client/render/blocks/RenderBlockCrank.java similarity index 97% rename from client/render/blocks/RenderBlockCrank.java rename to src/main/java/appeng/client/render/blocks/RenderBlockCrank.java index 2519513ff..ac39af7b9 100644 --- a/client/render/blocks/RenderBlockCrank.java +++ b/src/main/java/appeng/client/render/blocks/RenderBlockCrank.java @@ -1,88 +1,88 @@ -package appeng.client.render.blocks; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.tile.AEBaseTile; -import appeng.tile.grindstone.TileCrank; - -public class RenderBlockCrank extends BaseBlockRender -{ - - public RenderBlockCrank() { - super( true, 60 ); - } - - @Override - public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - renderer.renderAllFaces = true; - - renderer.setRenderBounds( 0.5D - 0.05, 0.5D - 0.5, 0.5D - 0.05, 0.5D + 0.05, 0.5D + 0.3, 0.5D + 0.05 ); - super.renderInventory( blk, is, renderer, type, obj ); - - renderer.setRenderBounds( 0.70D - 0.15, 0.75D - 0.05, 0.5D - 0.05, 0.70D + 0.28, 0.75D + 0.05, 0.5D + 0.05 ); - super.renderInventory( blk, is, renderer, type, obj ); - - renderer.renderAllFaces = false; - } - - @Override - public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - return true; - } - - @Override - public void renderTile(AEBaseBlock blk, AEBaseTile tile, Tessellator tess, double x, double y, double z, float f, RenderBlocks rbinstance) - { - TileCrank tc = (TileCrank) tile; - if ( tc.getUp() == null || tc.getUp() == ForgeDirection.UNKNOWN ) - return; - - Minecraft.getMinecraft().getTextureManager().bindTexture( TextureMap.locationBlocksTexture ); - RenderHelper.disableStandardItemLighting(); - - if ( Minecraft.isAmbientOcclusionEnabled() ) - GL11.glShadeModel( GL11.GL_SMOOTH ); - else - GL11.glShadeModel( GL11.GL_FLAT ); - - GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); - - applyTESRRotation( x, y, z, tile.getForward(), tile.getUp() ); - - GL11.glTranslated( 0.5, 0, 0.5 ); - GL11.glRotatef( tc.visibleRotation, 0, 1, 0 ); - GL11.glTranslated( -0.5, 0, -0.5 ); - - tess.setTranslation( -tc.xCoord, -tc.yCoord, -tc.zCoord ); - tess.startDrawingQuads(); - rbinstance.renderAllFaces = true; - rbinstance.blockAccess = tc.getWorldObj(); - - rbinstance.setRenderBounds( 0.5D - 0.05, 0.5D - 0.5, 0.5D - 0.05, 0.5D + 0.05, 0.5D + 0.1, 0.5D + 0.05 ); - - rbinstance.renderStandardBlock( blk, tc.xCoord, tc.yCoord, tc.zCoord ); - - rbinstance.setRenderBounds( 0.70D - 0.15, 0.55D - 0.05, 0.5D - 0.05, 0.70D + 0.15, 0.55D + 0.05, 0.5D + 0.05 ); - - rbinstance.renderStandardBlock( blk, tc.xCoord, tc.yCoord, tc.zCoord ); - - tess.draw(); - tess.setTranslation( 0, 0, 0 ); - RenderHelper.enableStandardItemLighting(); - } - -} +package appeng.client.render.blocks; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.tile.AEBaseTile; +import appeng.tile.grindstone.TileCrank; + +public class RenderBlockCrank extends BaseBlockRender +{ + + public RenderBlockCrank() { + super( true, 60 ); + } + + @Override + public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + renderer.renderAllFaces = true; + + renderer.setRenderBounds( 0.5D - 0.05, 0.5D - 0.5, 0.5D - 0.05, 0.5D + 0.05, 0.5D + 0.3, 0.5D + 0.05 ); + super.renderInventory( blk, is, renderer, type, obj ); + + renderer.setRenderBounds( 0.70D - 0.15, 0.75D - 0.05, 0.5D - 0.05, 0.70D + 0.28, 0.75D + 0.05, 0.5D + 0.05 ); + super.renderInventory( blk, is, renderer, type, obj ); + + renderer.renderAllFaces = false; + } + + @Override + public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + return true; + } + + @Override + public void renderTile(AEBaseBlock blk, AEBaseTile tile, Tessellator tess, double x, double y, double z, float f, RenderBlocks rbinstance) + { + TileCrank tc = (TileCrank) tile; + if ( tc.getUp() == null || tc.getUp() == ForgeDirection.UNKNOWN ) + return; + + Minecraft.getMinecraft().getTextureManager().bindTexture( TextureMap.locationBlocksTexture ); + RenderHelper.disableStandardItemLighting(); + + if ( Minecraft.isAmbientOcclusionEnabled() ) + GL11.glShadeModel( GL11.GL_SMOOTH ); + else + GL11.glShadeModel( GL11.GL_FLAT ); + + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + + applyTESRRotation( x, y, z, tile.getForward(), tile.getUp() ); + + GL11.glTranslated( 0.5, 0, 0.5 ); + GL11.glRotatef( tc.visibleRotation, 0, 1, 0 ); + GL11.glTranslated( -0.5, 0, -0.5 ); + + tess.setTranslation( -tc.xCoord, -tc.yCoord, -tc.zCoord ); + tess.startDrawingQuads(); + rbinstance.renderAllFaces = true; + rbinstance.blockAccess = tc.getWorldObj(); + + rbinstance.setRenderBounds( 0.5D - 0.05, 0.5D - 0.5, 0.5D - 0.05, 0.5D + 0.05, 0.5D + 0.1, 0.5D + 0.05 ); + + rbinstance.renderStandardBlock( blk, tc.xCoord, tc.yCoord, tc.zCoord ); + + rbinstance.setRenderBounds( 0.70D - 0.15, 0.55D - 0.05, 0.5D - 0.05, 0.70D + 0.15, 0.55D + 0.05, 0.5D + 0.05 ); + + rbinstance.renderStandardBlock( blk, tc.xCoord, tc.yCoord, tc.zCoord ); + + tess.draw(); + tess.setTranslation( 0, 0, 0 ); + RenderHelper.enableStandardItemLighting(); + } + +} diff --git a/client/render/blocks/RenderBlockEnergyCube.java b/src/main/java/appeng/client/render/blocks/RenderBlockEnergyCube.java similarity index 96% rename from client/render/blocks/RenderBlockEnergyCube.java rename to src/main/java/appeng/client/render/blocks/RenderBlockEnergyCube.java index 16203fa0f..e3bf90dff 100644 --- a/client/render/blocks/RenderBlockEnergyCube.java +++ b/src/main/java/appeng/client/render/blocks/RenderBlockEnergyCube.java @@ -1,48 +1,48 @@ -package appeng.client.render.blocks; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; - -public class RenderBlockEnergyCube extends BaseBlockRender -{ - - public RenderBlockEnergyCube() { - super( false, 20 ); - } - - @Override - public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - IAEItemPowerStorage myItem = (IAEItemPowerStorage) is.getItem(); - double internalCurrentPower = myItem.getAECurrentPower( is ); - double internalMaxPower = myItem.getAEMaxPower( is ); - - int meta = (int) (8.0 * (internalCurrentPower / internalMaxPower)); - - if ( meta > 7 ) - meta = 7; - if ( meta < 0 ) - meta = 0; - - renderer.setOverrideBlockTexture( blk.getIcon( 0, meta ) ); - super.renderInventory( blk, is, renderer, type, obj ); - renderer.setOverrideBlockTexture( null ); - } - - @Override - public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - int meta = world.getBlockMetadata( x, y, z ); - - renderer.overrideBlockTexture = blk.getIcon( 0, meta ); - boolean out = renderer.renderStandardBlock( blk, x, y, z ); - renderer.overrideBlockTexture = null; - - return out; - } -} +package appeng.client.render.blocks; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import appeng.api.implementations.items.IAEItemPowerStorage; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; + +public class RenderBlockEnergyCube extends BaseBlockRender +{ + + public RenderBlockEnergyCube() { + super( false, 20 ); + } + + @Override + public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + IAEItemPowerStorage myItem = (IAEItemPowerStorage) is.getItem(); + double internalCurrentPower = myItem.getAECurrentPower( is ); + double internalMaxPower = myItem.getAEMaxPower( is ); + + int meta = (int) (8.0 * (internalCurrentPower / internalMaxPower)); + + if ( meta > 7 ) + meta = 7; + if ( meta < 0 ) + meta = 0; + + renderer.setOverrideBlockTexture( blk.getIcon( 0, meta ) ); + super.renderInventory( blk, is, renderer, type, obj ); + renderer.setOverrideBlockTexture( null ); + } + + @Override + public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + int meta = world.getBlockMetadata( x, y, z ); + + renderer.overrideBlockTexture = blk.getIcon( 0, meta ); + boolean out = renderer.renderStandardBlock( blk, x, y, z ); + renderer.overrideBlockTexture = null; + + return out; + } +} diff --git a/client/render/blocks/RenderBlockInscriber.java b/src/main/java/appeng/client/render/blocks/RenderBlockInscriber.java similarity index 100% rename from client/render/blocks/RenderBlockInscriber.java rename to src/main/java/appeng/client/render/blocks/RenderBlockInscriber.java diff --git a/client/render/blocks/RenderBlockInterface.java b/src/main/java/appeng/client/render/blocks/RenderBlockInterface.java similarity index 100% rename from client/render/blocks/RenderBlockInterface.java rename to src/main/java/appeng/client/render/blocks/RenderBlockInterface.java diff --git a/client/render/blocks/RenderBlockPaint.java b/src/main/java/appeng/client/render/blocks/RenderBlockPaint.java similarity index 100% rename from client/render/blocks/RenderBlockPaint.java rename to src/main/java/appeng/client/render/blocks/RenderBlockPaint.java diff --git a/client/render/blocks/RenderBlockQuartzAccelerator.java b/src/main/java/appeng/client/render/blocks/RenderBlockQuartzAccelerator.java similarity index 100% rename from client/render/blocks/RenderBlockQuartzAccelerator.java rename to src/main/java/appeng/client/render/blocks/RenderBlockQuartzAccelerator.java diff --git a/client/render/blocks/RenderBlockSkyChest.java b/src/main/java/appeng/client/render/blocks/RenderBlockSkyChest.java similarity index 100% rename from client/render/blocks/RenderBlockSkyChest.java rename to src/main/java/appeng/client/render/blocks/RenderBlockSkyChest.java diff --git a/client/render/blocks/RenderBlockSkyCompass.java b/src/main/java/appeng/client/render/blocks/RenderBlockSkyCompass.java similarity index 100% rename from client/render/blocks/RenderBlockSkyCompass.java rename to src/main/java/appeng/client/render/blocks/RenderBlockSkyCompass.java diff --git a/client/render/blocks/RenderBlockWireless.java b/src/main/java/appeng/client/render/blocks/RenderBlockWireless.java similarity index 97% rename from client/render/blocks/RenderBlockWireless.java rename to src/main/java/appeng/client/render/blocks/RenderBlockWireless.java index 410c76576..862aed51b 100644 --- a/client/render/blocks/RenderBlockWireless.java +++ b/src/main/java/appeng/client/render/blocks/RenderBlockWireless.java @@ -1,248 +1,248 @@ -package appeng.client.render.blocks; - -import java.util.EnumSet; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.util.AEColor; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.BlockRenderInfo; -import appeng.client.texture.CableBusTextures; -import appeng.client.texture.ExtraBlockTextures; -import appeng.client.texture.OffsetIcon; -import appeng.tile.networking.TileWireless; -import appeng.util.Platform; - -public class RenderBlockWireless extends BaseBlockRender -{ - - public RenderBlockWireless() { - super( false, 20 ); - } - - @Override - public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - this.blk = blk; - cenx = 0; - ceny = 0; - cenz = 0; - hasChan = false; - hasPower = false; - BlockRenderInfo ri = blk.getRendererInstance(); - Tessellator tess = Tessellator.instance; - - renderer.renderAllFaces = true; - - IIcon r = CableBusTextures.PartMonitorSidesStatus.getIcon(); - ri.setTemporaryRenderIcons( r, r, CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), r, r ); - renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - r = CableBusTextures.PartWirelessSides.getIcon(); - ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r ); - renderBlockBounds( renderer, 5, 5, 1, 11, 11, 2, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - tess.startDrawingQuads(); - ri.setTemporaryRenderIcon( null ); - renderTorchAtAngle( renderer, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH ); - super.postRenderInWorld( renderer ); - tess.draw(); - - ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r ); - - ForgeDirection sides[] = new ForgeDirection[] { ForgeDirection.EAST, ForgeDirection.WEST, ForgeDirection.UP, ForgeDirection.DOWN }; - - int s = 1; - - for (ForgeDirection side : sides) - { - renderBlockBounds( renderer, 8 + (side.offsetX != 0 ? side.offsetX * 2 : -2), 8 + (side.offsetY != 0 ? side.offsetY * 2 : -2), 2 - + (side.offsetZ != 0 ? side.offsetZ * 2 : -1) + s, 8 + (side.offsetX != 0 ? side.offsetX * 4 : 2), - 8 + (side.offsetY != 0 ? side.offsetY * 4 : 2), 2 + (side.offsetZ != 0 ? side.offsetZ * 5 : 1) + s, ForgeDirection.EAST, ForgeDirection.UP, - ForgeDirection.SOUTH ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - } - - s = 3; - for (ForgeDirection side : sides) - { - renderBlockBounds( renderer, 8 + (side.offsetX != 0 ? side.offsetX * 4 : -1), 8 + (side.offsetY != 0 ? side.offsetY * 4 : -1), 1 - + (side.offsetZ != 0 ? side.offsetZ * 4 : -1) + s, 8 + (side.offsetX != 0 ? side.offsetX * 5 : 1), - 8 + (side.offsetY != 0 ? side.offsetY * 5 : 1), 2 + (side.offsetZ != 0 ? side.offsetZ * 5 : 1) + s, ForgeDirection.EAST, ForgeDirection.UP, - ForgeDirection.SOUTH ); - - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - } - } - - int cenx = 0; - int ceny = 0; - int cenz = 0; - AEBaseBlock blk; - boolean hasChan = false; - boolean hasPower = false; - - @Override - public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - TileWireless tw = blk.getTileEntity( world, x, y, z ); - this.blk = blk; - if ( tw != null ) - { - hasChan = (tw.clientFlags & (TileWireless.POWERED_FLAG | TileWireless.CHANNEL_FLAG)) == (TileWireless.POWERED_FLAG | TileWireless.CHANNEL_FLAG); - hasPower = (tw.clientFlags & TileWireless.POWERED_FLAG) == TileWireless.POWERED_FLAG; - - BlockRenderInfo ri = blk.getRendererInstance(); - - ForgeDirection fdy = tw.getUp(); - ForgeDirection fdz = tw.getForward(); - ForgeDirection fdx = Platform.crossProduct( fdz, fdy ).getOpposite(); - - renderer.renderAllFaces = true; - - IIcon r = CableBusTextures.PartMonitorSidesStatus.getIcon(); - ri.setTemporaryRenderIcons( r, r, CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), r, r ); - renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, fdx, fdy, fdz ); - super.renderInWorld( blk, world, x, y, z, renderer ); - - r = CableBusTextures.PartWirelessSides.getIcon(); - ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r ); - renderBlockBounds( renderer, 5, 5, 1, 11, 11, 2, fdx, fdy, fdz ); - super.renderInWorld( blk, world, x, y, z, renderer ); - - cenx = x; - ceny = y; - cenz = z; - ri.setTemporaryRenderIcon( null ); - - renderTorchAtAngle( renderer, fdx, fdy, fdz ); - super.postRenderInWorld( renderer ); - - ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r ); - - ForgeDirection sides[] = new ForgeDirection[] { ForgeDirection.EAST, ForgeDirection.WEST, ForgeDirection.UP, ForgeDirection.DOWN }; - - int s = 1; - - for (ForgeDirection side : sides) - { - renderBlockBounds( renderer, 8 + (side.offsetX != 0 ? side.offsetX * 2 : -2), 8 + (side.offsetY != 0 ? side.offsetY * 2 : -2), 2 - + (side.offsetZ != 0 ? side.offsetZ * 2 : -1) + s, 8 + (side.offsetX != 0 ? side.offsetX * 4 : 2), - 8 + (side.offsetY != 0 ? side.offsetY * 4 : 2), 2 + (side.offsetZ != 0 ? side.offsetZ * 5 : 1) + s, fdx, fdy, fdz ); - super.renderInWorld( blk, world, x, y, z, renderer ); - } - - s = 3; - for (ForgeDirection side : sides) - { - renderBlockBounds( renderer, 8 + (side.offsetX != 0 ? side.offsetX * 4 : -1), 8 + (side.offsetY != 0 ? side.offsetY * 4 : -1), 1 - + (side.offsetZ != 0 ? side.offsetZ * 4 : -1) + s, 8 + (side.offsetX != 0 ? side.offsetX * 5 : 1), - 8 + (side.offsetY != 0 ? side.offsetY * 5 : 1), 2 + (side.offsetZ != 0 ? side.offsetZ * 5 : 1) + s, fdx, fdy, fdz ); - super.renderInWorld( blk, world, x, y, z, renderer ); - } - - r = CableBusTextures.PartMonitorSidesStatusLights.getIcon(); - // ri.setTemporaryRenderIcons( r, r, ExtraTextures.BlockChargerInside.getIcon(), - // ExtraTextures.BlockChargerInside.getIcon(), r, r ); - renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, fdx, fdy, fdz ); - - if ( hasChan ) - { - int l = 14; - Tessellator.instance.setBrightness( l << 20 | l << 4 ); - Tessellator.instance.setColorOpaque_I( AEColor.Transparent.blackVariant ); - } - else if ( hasPower ) - { - int l = 9; - Tessellator.instance.setBrightness( l << 20 | l << 4 ); - Tessellator.instance.setColorOpaque_I( AEColor.Transparent.whiteVariant ); - } - else - { - Tessellator.instance.setBrightness( 0 ); - Tessellator.instance.setColorOpaque_I( 0x000000 ); - } - - if ( ForgeDirection.UP != fdz.getOpposite() ) - super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.UP ); - if ( ForgeDirection.DOWN != fdz.getOpposite() ) - super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.DOWN ); - if ( ForgeDirection.EAST != fdz.getOpposite() ) - super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.EAST ); - if ( ForgeDirection.WEST != fdz.getOpposite() ) - super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.WEST ); - if ( ForgeDirection.SOUTH != fdz.getOpposite() ) - super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.SOUTH ); - if ( ForgeDirection.NORTH != fdz.getOpposite() ) - super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.NORTH ); - - ri.setTemporaryRenderIcon( null ); - renderer.renderAllFaces = false; - } - - return true; - } - - private void renderTorchAtAngle(RenderBlocks renderer, ForgeDirection x, ForgeDirection y, ForgeDirection z) - { - IIcon r = (hasChan ? CableBusTextures.BlockWirelessOn.getIcon() : blk.getIcon( 0, 0 )); - IIcon sides = new OffsetIcon( r, 0.0f, -2.0f ); - - switch (z) - { - case DOWN: - renderer.uvRotateNorth = 3; - renderer.uvRotateSouth = 3; - renderer.uvRotateEast = 3; - renderer.uvRotateWest = 3; - break; - case EAST: - renderer.uvRotateTop = 1; - renderer.uvRotateBottom = 2; - renderer.uvRotateEast = 2; - renderer.uvRotateWest = 1; - break; - case NORTH: - renderer.uvRotateTop = 0; - renderer.uvRotateBottom = 0; - renderer.uvRotateNorth = 2; - renderer.uvRotateSouth = 1; - break; - case SOUTH: - renderer.uvRotateTop = 3; - renderer.uvRotateBottom = 3; - renderer.uvRotateNorth = 1; - renderer.uvRotateSouth = 2; - break; - case WEST: - renderer.uvRotateTop = 2; - renderer.uvRotateBottom = 1; - renderer.uvRotateEast = 1; - renderer.uvRotateWest = 2; - break; - default: - break; - } - - Tessellator.instance.setColorOpaque_I( 0xffffff ); - renderBlockBounds( renderer, 0, 7, 1, 16, 9, 16, x, y, z ); - renderFace( cenx, ceny, cenz, blk, sides, renderer, y ); - renderFace( cenx, ceny, cenz, blk, sides, renderer, y.getOpposite() ); - - renderBlockBounds( renderer, 7, 0, 1, 9, 16, 16, x, y, z ); - renderFace( cenx, ceny, cenz, blk, sides, renderer, x ); - renderFace( cenx, ceny, cenz, blk, sides, renderer, x.getOpposite() ); - - renderBlockBounds( renderer, 7, 7, 1, 9, 9, 10.6, x, y, z ); - renderFace( cenx, ceny, cenz, blk, r, renderer, z ); - } -} +package appeng.client.render.blocks; + +import java.util.EnumSet; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.util.AEColor; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.BlockRenderInfo; +import appeng.client.texture.CableBusTextures; +import appeng.client.texture.ExtraBlockTextures; +import appeng.client.texture.OffsetIcon; +import appeng.tile.networking.TileWireless; +import appeng.util.Platform; + +public class RenderBlockWireless extends BaseBlockRender +{ + + public RenderBlockWireless() { + super( false, 20 ); + } + + @Override + public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + this.blk = blk; + cenx = 0; + ceny = 0; + cenz = 0; + hasChan = false; + hasPower = false; + BlockRenderInfo ri = blk.getRendererInstance(); + Tessellator tess = Tessellator.instance; + + renderer.renderAllFaces = true; + + IIcon r = CableBusTextures.PartMonitorSidesStatus.getIcon(); + ri.setTemporaryRenderIcons( r, r, CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), r, r ); + renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + r = CableBusTextures.PartWirelessSides.getIcon(); + ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r ); + renderBlockBounds( renderer, 5, 5, 1, 11, 11, 2, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + tess.startDrawingQuads(); + ri.setTemporaryRenderIcon( null ); + renderTorchAtAngle( renderer, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH ); + super.postRenderInWorld( renderer ); + tess.draw(); + + ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r ); + + ForgeDirection sides[] = new ForgeDirection[] { ForgeDirection.EAST, ForgeDirection.WEST, ForgeDirection.UP, ForgeDirection.DOWN }; + + int s = 1; + + for (ForgeDirection side : sides) + { + renderBlockBounds( renderer, 8 + (side.offsetX != 0 ? side.offsetX * 2 : -2), 8 + (side.offsetY != 0 ? side.offsetY * 2 : -2), 2 + + (side.offsetZ != 0 ? side.offsetZ * 2 : -1) + s, 8 + (side.offsetX != 0 ? side.offsetX * 4 : 2), + 8 + (side.offsetY != 0 ? side.offsetY * 4 : 2), 2 + (side.offsetZ != 0 ? side.offsetZ * 5 : 1) + s, ForgeDirection.EAST, ForgeDirection.UP, + ForgeDirection.SOUTH ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + } + + s = 3; + for (ForgeDirection side : sides) + { + renderBlockBounds( renderer, 8 + (side.offsetX != 0 ? side.offsetX * 4 : -1), 8 + (side.offsetY != 0 ? side.offsetY * 4 : -1), 1 + + (side.offsetZ != 0 ? side.offsetZ * 4 : -1) + s, 8 + (side.offsetX != 0 ? side.offsetX * 5 : 1), + 8 + (side.offsetY != 0 ? side.offsetY * 5 : 1), 2 + (side.offsetZ != 0 ? side.offsetZ * 5 : 1) + s, ForgeDirection.EAST, ForgeDirection.UP, + ForgeDirection.SOUTH ); + + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + } + } + + int cenx = 0; + int ceny = 0; + int cenz = 0; + AEBaseBlock blk; + boolean hasChan = false; + boolean hasPower = false; + + @Override + public boolean renderInWorld(AEBaseBlock blk, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + TileWireless tw = blk.getTileEntity( world, x, y, z ); + this.blk = blk; + if ( tw != null ) + { + hasChan = (tw.clientFlags & (TileWireless.POWERED_FLAG | TileWireless.CHANNEL_FLAG)) == (TileWireless.POWERED_FLAG | TileWireless.CHANNEL_FLAG); + hasPower = (tw.clientFlags & TileWireless.POWERED_FLAG) == TileWireless.POWERED_FLAG; + + BlockRenderInfo ri = blk.getRendererInstance(); + + ForgeDirection fdy = tw.getUp(); + ForgeDirection fdz = tw.getForward(); + ForgeDirection fdx = Platform.crossProduct( fdz, fdy ).getOpposite(); + + renderer.renderAllFaces = true; + + IIcon r = CableBusTextures.PartMonitorSidesStatus.getIcon(); + ri.setTemporaryRenderIcons( r, r, CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), r, r ); + renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, fdx, fdy, fdz ); + super.renderInWorld( blk, world, x, y, z, renderer ); + + r = CableBusTextures.PartWirelessSides.getIcon(); + ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r ); + renderBlockBounds( renderer, 5, 5, 1, 11, 11, 2, fdx, fdy, fdz ); + super.renderInWorld( blk, world, x, y, z, renderer ); + + cenx = x; + ceny = y; + cenz = z; + ri.setTemporaryRenderIcon( null ); + + renderTorchAtAngle( renderer, fdx, fdy, fdz ); + super.postRenderInWorld( renderer ); + + ri.setTemporaryRenderIcons( r, r, ExtraBlockTextures.BlockWirelessInside.getIcon(), ExtraBlockTextures.BlockWirelessInside.getIcon(), r, r ); + + ForgeDirection sides[] = new ForgeDirection[] { ForgeDirection.EAST, ForgeDirection.WEST, ForgeDirection.UP, ForgeDirection.DOWN }; + + int s = 1; + + for (ForgeDirection side : sides) + { + renderBlockBounds( renderer, 8 + (side.offsetX != 0 ? side.offsetX * 2 : -2), 8 + (side.offsetY != 0 ? side.offsetY * 2 : -2), 2 + + (side.offsetZ != 0 ? side.offsetZ * 2 : -1) + s, 8 + (side.offsetX != 0 ? side.offsetX * 4 : 2), + 8 + (side.offsetY != 0 ? side.offsetY * 4 : 2), 2 + (side.offsetZ != 0 ? side.offsetZ * 5 : 1) + s, fdx, fdy, fdz ); + super.renderInWorld( blk, world, x, y, z, renderer ); + } + + s = 3; + for (ForgeDirection side : sides) + { + renderBlockBounds( renderer, 8 + (side.offsetX != 0 ? side.offsetX * 4 : -1), 8 + (side.offsetY != 0 ? side.offsetY * 4 : -1), 1 + + (side.offsetZ != 0 ? side.offsetZ * 4 : -1) + s, 8 + (side.offsetX != 0 ? side.offsetX * 5 : 1), + 8 + (side.offsetY != 0 ? side.offsetY * 5 : 1), 2 + (side.offsetZ != 0 ? side.offsetZ * 5 : 1) + s, fdx, fdy, fdz ); + super.renderInWorld( blk, world, x, y, z, renderer ); + } + + r = CableBusTextures.PartMonitorSidesStatusLights.getIcon(); + // ri.setTemporaryRenderIcons( r, r, ExtraTextures.BlockChargerInside.getIcon(), + // ExtraTextures.BlockChargerInside.getIcon(), r, r ); + renderBlockBounds( renderer, 5, 5, 0, 11, 11, 1, fdx, fdy, fdz ); + + if ( hasChan ) + { + int l = 14; + Tessellator.instance.setBrightness( l << 20 | l << 4 ); + Tessellator.instance.setColorOpaque_I( AEColor.Transparent.blackVariant ); + } + else if ( hasPower ) + { + int l = 9; + Tessellator.instance.setBrightness( l << 20 | l << 4 ); + Tessellator.instance.setColorOpaque_I( AEColor.Transparent.whiteVariant ); + } + else + { + Tessellator.instance.setBrightness( 0 ); + Tessellator.instance.setColorOpaque_I( 0x000000 ); + } + + if ( ForgeDirection.UP != fdz.getOpposite() ) + super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.UP ); + if ( ForgeDirection.DOWN != fdz.getOpposite() ) + super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.DOWN ); + if ( ForgeDirection.EAST != fdz.getOpposite() ) + super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.EAST ); + if ( ForgeDirection.WEST != fdz.getOpposite() ) + super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.WEST ); + if ( ForgeDirection.SOUTH != fdz.getOpposite() ) + super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.SOUTH ); + if ( ForgeDirection.NORTH != fdz.getOpposite() ) + super.renderFace( x, y, z, blk, r, renderer, ForgeDirection.NORTH ); + + ri.setTemporaryRenderIcon( null ); + renderer.renderAllFaces = false; + } + + return true; + } + + private void renderTorchAtAngle(RenderBlocks renderer, ForgeDirection x, ForgeDirection y, ForgeDirection z) + { + IIcon r = (hasChan ? CableBusTextures.BlockWirelessOn.getIcon() : blk.getIcon( 0, 0 )); + IIcon sides = new OffsetIcon( r, 0.0f, -2.0f ); + + switch (z) + { + case DOWN: + renderer.uvRotateNorth = 3; + renderer.uvRotateSouth = 3; + renderer.uvRotateEast = 3; + renderer.uvRotateWest = 3; + break; + case EAST: + renderer.uvRotateTop = 1; + renderer.uvRotateBottom = 2; + renderer.uvRotateEast = 2; + renderer.uvRotateWest = 1; + break; + case NORTH: + renderer.uvRotateTop = 0; + renderer.uvRotateBottom = 0; + renderer.uvRotateNorth = 2; + renderer.uvRotateSouth = 1; + break; + case SOUTH: + renderer.uvRotateTop = 3; + renderer.uvRotateBottom = 3; + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 2; + break; + case WEST: + renderer.uvRotateTop = 2; + renderer.uvRotateBottom = 1; + renderer.uvRotateEast = 1; + renderer.uvRotateWest = 2; + break; + default: + break; + } + + Tessellator.instance.setColorOpaque_I( 0xffffff ); + renderBlockBounds( renderer, 0, 7, 1, 16, 9, 16, x, y, z ); + renderFace( cenx, ceny, cenz, blk, sides, renderer, y ); + renderFace( cenx, ceny, cenz, blk, sides, renderer, y.getOpposite() ); + + renderBlockBounds( renderer, 7, 0, 1, 9, 16, 16, x, y, z ); + renderFace( cenx, ceny, cenz, blk, sides, renderer, x ); + renderFace( cenx, ceny, cenz, blk, sides, renderer, x.getOpposite() ); + + renderBlockBounds( renderer, 7, 7, 1, 9, 9, 10.6, x, y, z ); + renderFace( cenx, ceny, cenz, blk, r, renderer, z ); + } +} diff --git a/client/render/blocks/RenderDrive.java b/src/main/java/appeng/client/render/blocks/RenderDrive.java similarity index 97% rename from client/render/blocks/RenderDrive.java rename to src/main/java/appeng/client/render/blocks/RenderDrive.java index 9f9b46ee2..54a29d26c 100644 --- a/client/render/blocks/RenderDrive.java +++ b/src/main/java/appeng/client/render/blocks/RenderDrive.java @@ -1,309 +1,309 @@ -package appeng.client.render.blocks; - -import java.util.EnumSet; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.texture.ExtraBlockTextures; -import appeng.tile.storage.TileDrive; -import appeng.util.Platform; - -public class RenderDrive extends BaseBlockRender -{ - - public RenderDrive() { - super( false, 0 ); - } - - @Override - public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - renderer.overrideBlockTexture = ExtraBlockTextures.getMissing(); - this.renderInvBlock( EnumSet.of( ForgeDirection.SOUTH ), block, is, Tessellator.instance, 0x000000, renderer ); - - renderer.overrideBlockTexture = null; - super.renderInventory( block, is, renderer, type, obj ); - } - - @Override - public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - TileDrive sp = imb.getTileEntity( world, x, y, z ); - renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); - - ForgeDirection up = sp.getUp(); - ForgeDirection forward = sp.getForward(); - ForgeDirection west = Platform.crossProduct( forward, up ); - - boolean result = super.renderInWorld( imb, world, x, y, z, renderer ); - Tessellator tess = Tessellator.instance; - - IIcon ico = ExtraBlockTextures.MEStorageCellTextures.getIcon(); - - int b = world.getLightBrightnessForSkyBlocks( x + forward.offsetX, y + forward.offsetY, z + forward.offsetZ, 0 ); - - for (int yy = 0; yy < 5; yy++) - { - for (int xx = 0; xx < 2; xx++) - { - int stat = sp.getCellStatus( yy * 2 + (1 - xx) ); - selectFace( renderer, west, up, forward, 2 + xx * 7, 7 + xx * 7, 1 + yy * 3, 3 + yy * 3 ); - - int spin = 0; - - switch (forward.offsetX + forward.offsetY * 2 + forward.offsetZ * 3) - { - case 1: - switch (up) - { - case UP: - spin = 3; - break; - case DOWN: - spin = 1; - break; - case NORTH: - spin = 0; - break; - case SOUTH: - spin = 2; - break; - default: - } - break; - case -1: - switch (up) - { - case UP: - spin = 1; - break; - case DOWN: - spin = 3; - break; - case NORTH: - spin = 0; - break; - case SOUTH: - spin = 2; - break; - default: - } - break; - case -2: - switch (up) - { - case EAST: - spin = 1; - break; - case WEST: - spin = 3; - break; - case NORTH: - spin = 2; - break; - case SOUTH: - spin = 0; - break; - default: - } - break; - case 2: - switch (up) - { - case EAST: - spin = 1; - break; - case WEST: - spin = 3; - break; - case NORTH: - spin = 0; - break; - case SOUTH: - spin = 0; - break; - default: - } - break; - case 3: - switch (up) - { - case UP: - spin = 2; - break; - case DOWN: - spin = 0; - break; - case EAST: - spin = 3; - break; - case WEST: - spin = 1; - break; - default: - } - break; - case -3: - switch (up) - { - case UP: - spin = 2; - break; - case DOWN: - spin = 0; - break; - case EAST: - spin = 1; - break; - case WEST: - spin = 3; - break; - default: - } - break; - } - - double u1 = ico.getInterpolatedU( (spin % 4 < 2) ? 1 : 6 ); - double u2 = ico.getInterpolatedU( ((spin + 1) % 4 < 2) ? 1 : 6 ); - double u3 = ico.getInterpolatedU( ((spin + 2) % 4 < 2) ? 1 : 6 ); - double u4 = ico.getInterpolatedU( ((spin + 3) % 4 < 2) ? 1 : 6 ); - - int m = 1; - int mx = 3; - if ( stat == 0 ) - { - m = 4; - mx = 5; - } - - double v1 = ico.getInterpolatedV( ((spin + 1) % 4 < 2) ? m : mx ); - double v2 = ico.getInterpolatedV( ((spin + 2) % 4 < 2) ? m : mx ); - double v3 = ico.getInterpolatedV( ((spin + 3) % 4 < 2) ? m : mx ); - double v4 = ico.getInterpolatedV( ((spin + 0) % 4 < 2) ? m : mx ); - - tess.setBrightness( b ); - tess.setColorOpaque_I( 0xffffff ); - switch (forward.offsetX + forward.offsetY * 2 + forward.offsetZ * 3) - { - case 1: - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMinZ, u4, v4 ); - break; - case -1: - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMinZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); - break; - case -2: - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); - break; - case 2: - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); - break; - case 3: - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMinY, z + renderer.renderMaxZ, u4, v4 ); - break; - case -3: - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMinY, z + renderer.renderMaxZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u4, v4 ); - break; - } - - if ( (forward == ForgeDirection.UP && up == ForgeDirection.SOUTH) || forward == ForgeDirection.DOWN ) - selectFace( renderer, west, up, forward, 3 + xx * 7, 4 + xx * 7, 1 + yy * 3, 2 + yy * 3 ); - else - selectFace( renderer, west, up, forward, 5 + xx * 7, 6 + xx * 7, 2 + yy * 3, 3 + yy * 3 ); - - if ( stat != 0 ) - { - IIcon wico = ExtraBlockTextures.White.getIcon(); - u1 = wico.getInterpolatedU( (spin % 4 < 2) ? 1 : 6 ); - u2 = wico.getInterpolatedU( ((spin + 1) % 4 < 2) ? 1 : 6 ); - u3 = wico.getInterpolatedU( ((spin + 2) % 4 < 2) ? 1 : 6 ); - u4 = wico.getInterpolatedU( ((spin + 3) % 4 < 2) ? 1 : 6 ); - - v1 = wico.getInterpolatedV( ((spin + 1) % 4 < 2) ? 1 : 3 ); - v2 = wico.getInterpolatedV( ((spin + 2) % 4 < 2) ? 1 : 3 ); - v3 = wico.getInterpolatedV( ((spin + 3) % 4 < 2) ? 1 : 3 ); - v4 = wico.getInterpolatedV( ((spin + 0) % 4 < 2) ? 1 : 3 ); - - if ( sp.isPowered() ) - tess.setBrightness( 15 << 20 | 15 << 4 ); - else - tess.setBrightness( 0 ); - - if ( stat == 1 ) - Tessellator.instance.setColorOpaque_I( 0x00ff00 ); - if ( stat == 2 ) - Tessellator.instance.setColorOpaque_I( 0xffaa00 ); - if ( stat == 3 ) - Tessellator.instance.setColorOpaque_I( 0xff0000 ); - - switch (forward.offsetX + forward.offsetY * 2 + forward.offsetZ * 3) - { - case 1: - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMinZ, u4, v4 ); - break; - case -1: - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMinZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); - break; - case -2: - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); - break; - case 2: - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); - break; - case 3: - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMinY, z + renderer.renderMaxZ, u4, v4 ); - break; - case -3: - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMinY, z + renderer.renderMaxZ, u1, v1 ); - tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); - tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u4, v4 ); - break; - } - } - } - } - - renderer.overrideBlockTexture = null; - return result; - } -} +package appeng.client.render.blocks; + +import java.util.EnumSet; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.texture.ExtraBlockTextures; +import appeng.tile.storage.TileDrive; +import appeng.util.Platform; + +public class RenderDrive extends BaseBlockRender +{ + + public RenderDrive() { + super( false, 0 ); + } + + @Override + public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + renderer.overrideBlockTexture = ExtraBlockTextures.getMissing(); + this.renderInvBlock( EnumSet.of( ForgeDirection.SOUTH ), block, is, Tessellator.instance, 0x000000, renderer ); + + renderer.overrideBlockTexture = null; + super.renderInventory( block, is, renderer, type, obj ); + } + + @Override + public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + TileDrive sp = imb.getTileEntity( world, x, y, z ); + renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); + + ForgeDirection up = sp.getUp(); + ForgeDirection forward = sp.getForward(); + ForgeDirection west = Platform.crossProduct( forward, up ); + + boolean result = super.renderInWorld( imb, world, x, y, z, renderer ); + Tessellator tess = Tessellator.instance; + + IIcon ico = ExtraBlockTextures.MEStorageCellTextures.getIcon(); + + int b = world.getLightBrightnessForSkyBlocks( x + forward.offsetX, y + forward.offsetY, z + forward.offsetZ, 0 ); + + for (int yy = 0; yy < 5; yy++) + { + for (int xx = 0; xx < 2; xx++) + { + int stat = sp.getCellStatus( yy * 2 + (1 - xx) ); + selectFace( renderer, west, up, forward, 2 + xx * 7, 7 + xx * 7, 1 + yy * 3, 3 + yy * 3 ); + + int spin = 0; + + switch (forward.offsetX + forward.offsetY * 2 + forward.offsetZ * 3) + { + case 1: + switch (up) + { + case UP: + spin = 3; + break; + case DOWN: + spin = 1; + break; + case NORTH: + spin = 0; + break; + case SOUTH: + spin = 2; + break; + default: + } + break; + case -1: + switch (up) + { + case UP: + spin = 1; + break; + case DOWN: + spin = 3; + break; + case NORTH: + spin = 0; + break; + case SOUTH: + spin = 2; + break; + default: + } + break; + case -2: + switch (up) + { + case EAST: + spin = 1; + break; + case WEST: + spin = 3; + break; + case NORTH: + spin = 2; + break; + case SOUTH: + spin = 0; + break; + default: + } + break; + case 2: + switch (up) + { + case EAST: + spin = 1; + break; + case WEST: + spin = 3; + break; + case NORTH: + spin = 0; + break; + case SOUTH: + spin = 0; + break; + default: + } + break; + case 3: + switch (up) + { + case UP: + spin = 2; + break; + case DOWN: + spin = 0; + break; + case EAST: + spin = 3; + break; + case WEST: + spin = 1; + break; + default: + } + break; + case -3: + switch (up) + { + case UP: + spin = 2; + break; + case DOWN: + spin = 0; + break; + case EAST: + spin = 1; + break; + case WEST: + spin = 3; + break; + default: + } + break; + } + + double u1 = ico.getInterpolatedU( (spin % 4 < 2) ? 1 : 6 ); + double u2 = ico.getInterpolatedU( ((spin + 1) % 4 < 2) ? 1 : 6 ); + double u3 = ico.getInterpolatedU( ((spin + 2) % 4 < 2) ? 1 : 6 ); + double u4 = ico.getInterpolatedU( ((spin + 3) % 4 < 2) ? 1 : 6 ); + + int m = 1; + int mx = 3; + if ( stat == 0 ) + { + m = 4; + mx = 5; + } + + double v1 = ico.getInterpolatedV( ((spin + 1) % 4 < 2) ? m : mx ); + double v2 = ico.getInterpolatedV( ((spin + 2) % 4 < 2) ? m : mx ); + double v3 = ico.getInterpolatedV( ((spin + 3) % 4 < 2) ? m : mx ); + double v4 = ico.getInterpolatedV( ((spin + 0) % 4 < 2) ? m : mx ); + + tess.setBrightness( b ); + tess.setColorOpaque_I( 0xffffff ); + switch (forward.offsetX + forward.offsetY * 2 + forward.offsetZ * 3) + { + case 1: + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMinZ, u4, v4 ); + break; + case -1: + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMinZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); + break; + case -2: + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); + break; + case 2: + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); + break; + case 3: + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMinY, z + renderer.renderMaxZ, u4, v4 ); + break; + case -3: + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMinY, z + renderer.renderMaxZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u4, v4 ); + break; + } + + if ( (forward == ForgeDirection.UP && up == ForgeDirection.SOUTH) || forward == ForgeDirection.DOWN ) + selectFace( renderer, west, up, forward, 3 + xx * 7, 4 + xx * 7, 1 + yy * 3, 2 + yy * 3 ); + else + selectFace( renderer, west, up, forward, 5 + xx * 7, 6 + xx * 7, 2 + yy * 3, 3 + yy * 3 ); + + if ( stat != 0 ) + { + IIcon wico = ExtraBlockTextures.White.getIcon(); + u1 = wico.getInterpolatedU( (spin % 4 < 2) ? 1 : 6 ); + u2 = wico.getInterpolatedU( ((spin + 1) % 4 < 2) ? 1 : 6 ); + u3 = wico.getInterpolatedU( ((spin + 2) % 4 < 2) ? 1 : 6 ); + u4 = wico.getInterpolatedU( ((spin + 3) % 4 < 2) ? 1 : 6 ); + + v1 = wico.getInterpolatedV( ((spin + 1) % 4 < 2) ? 1 : 3 ); + v2 = wico.getInterpolatedV( ((spin + 2) % 4 < 2) ? 1 : 3 ); + v3 = wico.getInterpolatedV( ((spin + 3) % 4 < 2) ? 1 : 3 ); + v4 = wico.getInterpolatedV( ((spin + 0) % 4 < 2) ? 1 : 3 ); + + if ( sp.isPowered() ) + tess.setBrightness( 15 << 20 | 15 << 4 ); + else + tess.setBrightness( 0 ); + + if ( stat == 1 ) + Tessellator.instance.setColorOpaque_I( 0x00ff00 ); + if ( stat == 2 ) + Tessellator.instance.setColorOpaque_I( 0xffaa00 ); + if ( stat == 3 ) + Tessellator.instance.setColorOpaque_I( 0xff0000 ); + + switch (forward.offsetX + forward.offsetY * 2 + forward.offsetZ * 3) + { + case 1: + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMinZ, u4, v4 ); + break; + case -1: + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMinZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); + break; + case -2: + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); + break; + case 2: + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMinZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMinZ, u4, v4 ); + break; + case 3: + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMinY, z + renderer.renderMaxZ, u4, v4 ); + break; + case -3: + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMinY, z + renderer.renderMaxZ, u1, v1 ); + tess.addVertexWithUV( x + renderer.renderMinX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u2, v2 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMaxY, z + renderer.renderMaxZ, u3, v3 ); + tess.addVertexWithUV( x + renderer.renderMaxX, y + renderer.renderMinY, z + renderer.renderMaxZ, u4, v4 ); + break; + } + } + } + } + + renderer.overrideBlockTexture = null; + return result; + } +} diff --git a/client/render/blocks/RenderMEChest.java b/src/main/java/appeng/client/render/blocks/RenderMEChest.java similarity index 97% rename from client/render/blocks/RenderMEChest.java rename to src/main/java/appeng/client/render/blocks/RenderMEChest.java index 6182c0da7..d11ac59f7 100644 --- a/client/render/blocks/RenderMEChest.java +++ b/src/main/java/appeng/client/render/blocks/RenderMEChest.java @@ -1,143 +1,143 @@ -package appeng.client.render.blocks; - -import java.util.EnumSet; - -import appeng.client.texture.FlippableIcon; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.storage.ICellHandler; -import appeng.api.util.AEColor; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.texture.ExtraBlockTextures; -import appeng.client.texture.OffsetIcon; -import appeng.tile.storage.TileChest; -import appeng.util.Platform; - -public class RenderMEChest extends BaseBlockRender -{ - - public RenderMEChest() { - super( false, 0 ); - } - - @Override - public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - Tessellator.instance.setBrightness( 0 ); - renderer.overrideBlockTexture = ExtraBlockTextures.getMissing(); - this.renderInvBlock( EnumSet.of( ForgeDirection.SOUTH ), block, is, Tessellator.instance, 0x000000, renderer ); - - renderer.overrideBlockTexture = ExtraBlockTextures.MEChest.getIcon(); - this.renderInvBlock( EnumSet.of( ForgeDirection.UP ), block, is, Tessellator.instance, adjustBrightness( AEColor.Transparent.whiteVariant, 0.7 ), - renderer ); - - renderer.overrideBlockTexture = null; - super.renderInventory( block, is, renderer, type, obj ); - } - - @Override - public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - TileChest sp = imb.getTileEntity( world, x, y, z ); - renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); - - ForgeDirection up = sp.getUp(); - ForgeDirection forward = sp.getForward(); - ForgeDirection west = Platform.crossProduct( forward, up ); - - preRenderInWorld( imb, world, x, y, z, renderer ); - - int stat = sp.getCellStatus( 0 ); - boolean result = renderer.renderStandardBlock( imb, x, y, z ); - - selectFace( renderer, west, up, forward, 5, 16 - 5, 9, 12 ); - - int offsetU = -4; - int offsetV = 8; - if ( stat == 0 ) - offsetV = 3; - - int b = world.getLightBrightnessForSkyBlocks( x + forward.offsetX, y + forward.offsetY, z + forward.offsetZ, 0 ); - Tessellator.instance.setBrightness( b ); - Tessellator.instance.setColorOpaque_I( 0xffffff ); - - FlippableIcon fico = new FlippableIcon( new OffsetIcon( ExtraBlockTextures.MEStorageCellTextures.getIcon(), offsetU, offsetV ) ); - if ( forward == ForgeDirection.EAST && (up == ForgeDirection.NORTH || up == ForgeDirection.SOUTH) ) - fico.setFlip( true, false ); - else if ( forward == ForgeDirection.NORTH && up == ForgeDirection.EAST ) - fico.setFlip( false, true ); - else if ( forward == ForgeDirection.NORTH && up == ForgeDirection.WEST ) - fico.setFlip( true, false ); - else if ( forward == ForgeDirection.DOWN && up == ForgeDirection.EAST ) - fico.setFlip( false, true ); - else if ( forward == ForgeDirection.DOWN ) - fico.setFlip( true, false ); - - /* - * 1.7.2 - * - * else if ( forward == ForgeDirection.EAST && up == ForgeDirection.UP ) fico.setFlip( true, false ); else if ( - * forward == ForgeDirection.NORTH && up == ForgeDirection.UP ) fico.setFlip( true, false ); - */ - - renderFace( x, y, z, imb, fico, renderer, forward ); - - if ( stat != 0 ) - { - b = 0; - if ( sp.isPowered() ) - { - b = 15 << 20 | 15 << 4; - } - - Tessellator.instance.setBrightness( b ); - if ( stat == 1 ) - Tessellator.instance.setColorOpaque_I( 0x00ff00 ); - if ( stat == 2 ) - Tessellator.instance.setColorOpaque_I( 0xffaa00 ); - if ( stat == 3 ) - Tessellator.instance.setColorOpaque_I( 0xff0000 ); - selectFace( renderer, west, up, forward, 9, 10, 11, 12 ); - renderFace( x, y, z, imb, ExtraBlockTextures.White.getIcon(), renderer, forward ); - } - - b = world.getLightBrightnessForSkyBlocks( x + up.offsetX, y + up.offsetY, z + up.offsetZ, 0 ); - if ( sp.isPowered() ) - { - b = 15 << 20 | 15 << 4; - } - - Tessellator.instance.setBrightness( b ); - Tessellator.instance.setColorOpaque_I( 0xffffff ); - renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); - - ICellHandler ch = AEApi.instance().registries().cell().getHandler( sp.getStorageType() ); - - Tessellator.instance.setColorOpaque_I( sp.getColor().whiteVariant ); - IIcon ico = ch == null ? null : ch.getTopTexture_Light(); - renderFace( x, y, z, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up ); - - if ( ico != null ) - { - Tessellator.instance.setColorOpaque_I( sp.getColor().mediumVariant ); - ico = ch == null ? null : ch.getTopTexture_Medium(); - renderFace( x, y, z, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up ); - - Tessellator.instance.setColorOpaque_I( sp.getColor().blackVariant ); - ico = ch == null ? null : ch.getTopTexture_Dark(); - renderFace( x, y, z, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up ); - } - - renderer.overrideBlockTexture = null; - postRenderInWorld( renderer ); - - return result; - } -} +package appeng.client.render.blocks; + +import java.util.EnumSet; + +import appeng.client.texture.FlippableIcon; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.storage.ICellHandler; +import appeng.api.util.AEColor; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.texture.ExtraBlockTextures; +import appeng.client.texture.OffsetIcon; +import appeng.tile.storage.TileChest; +import appeng.util.Platform; + +public class RenderMEChest extends BaseBlockRender +{ + + public RenderMEChest() { + super( false, 0 ); + } + + @Override + public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + Tessellator.instance.setBrightness( 0 ); + renderer.overrideBlockTexture = ExtraBlockTextures.getMissing(); + this.renderInvBlock( EnumSet.of( ForgeDirection.SOUTH ), block, is, Tessellator.instance, 0x000000, renderer ); + + renderer.overrideBlockTexture = ExtraBlockTextures.MEChest.getIcon(); + this.renderInvBlock( EnumSet.of( ForgeDirection.UP ), block, is, Tessellator.instance, adjustBrightness( AEColor.Transparent.whiteVariant, 0.7 ), + renderer ); + + renderer.overrideBlockTexture = null; + super.renderInventory( block, is, renderer, type, obj ); + } + + @Override + public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + TileChest sp = imb.getTileEntity( world, x, y, z ); + renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); + + ForgeDirection up = sp.getUp(); + ForgeDirection forward = sp.getForward(); + ForgeDirection west = Platform.crossProduct( forward, up ); + + preRenderInWorld( imb, world, x, y, z, renderer ); + + int stat = sp.getCellStatus( 0 ); + boolean result = renderer.renderStandardBlock( imb, x, y, z ); + + selectFace( renderer, west, up, forward, 5, 16 - 5, 9, 12 ); + + int offsetU = -4; + int offsetV = 8; + if ( stat == 0 ) + offsetV = 3; + + int b = world.getLightBrightnessForSkyBlocks( x + forward.offsetX, y + forward.offsetY, z + forward.offsetZ, 0 ); + Tessellator.instance.setBrightness( b ); + Tessellator.instance.setColorOpaque_I( 0xffffff ); + + FlippableIcon fico = new FlippableIcon( new OffsetIcon( ExtraBlockTextures.MEStorageCellTextures.getIcon(), offsetU, offsetV ) ); + if ( forward == ForgeDirection.EAST && (up == ForgeDirection.NORTH || up == ForgeDirection.SOUTH) ) + fico.setFlip( true, false ); + else if ( forward == ForgeDirection.NORTH && up == ForgeDirection.EAST ) + fico.setFlip( false, true ); + else if ( forward == ForgeDirection.NORTH && up == ForgeDirection.WEST ) + fico.setFlip( true, false ); + else if ( forward == ForgeDirection.DOWN && up == ForgeDirection.EAST ) + fico.setFlip( false, true ); + else if ( forward == ForgeDirection.DOWN ) + fico.setFlip( true, false ); + + /* + * 1.7.2 + * + * else if ( forward == ForgeDirection.EAST && up == ForgeDirection.UP ) fico.setFlip( true, false ); else if ( + * forward == ForgeDirection.NORTH && up == ForgeDirection.UP ) fico.setFlip( true, false ); + */ + + renderFace( x, y, z, imb, fico, renderer, forward ); + + if ( stat != 0 ) + { + b = 0; + if ( sp.isPowered() ) + { + b = 15 << 20 | 15 << 4; + } + + Tessellator.instance.setBrightness( b ); + if ( stat == 1 ) + Tessellator.instance.setColorOpaque_I( 0x00ff00 ); + if ( stat == 2 ) + Tessellator.instance.setColorOpaque_I( 0xffaa00 ); + if ( stat == 3 ) + Tessellator.instance.setColorOpaque_I( 0xff0000 ); + selectFace( renderer, west, up, forward, 9, 10, 11, 12 ); + renderFace( x, y, z, imb, ExtraBlockTextures.White.getIcon(), renderer, forward ); + } + + b = world.getLightBrightnessForSkyBlocks( x + up.offsetX, y + up.offsetY, z + up.offsetZ, 0 ); + if ( sp.isPowered() ) + { + b = 15 << 20 | 15 << 4; + } + + Tessellator.instance.setBrightness( b ); + Tessellator.instance.setColorOpaque_I( 0xffffff ); + renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); + + ICellHandler ch = AEApi.instance().registries().cell().getHandler( sp.getStorageType() ); + + Tessellator.instance.setColorOpaque_I( sp.getColor().whiteVariant ); + IIcon ico = ch == null ? null : ch.getTopTexture_Light(); + renderFace( x, y, z, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up ); + + if ( ico != null ) + { + Tessellator.instance.setColorOpaque_I( sp.getColor().mediumVariant ); + ico = ch == null ? null : ch.getTopTexture_Medium(); + renderFace( x, y, z, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up ); + + Tessellator.instance.setColorOpaque_I( sp.getColor().blackVariant ); + ico = ch == null ? null : ch.getTopTexture_Dark(); + renderFace( x, y, z, imb, ico == null ? ExtraBlockTextures.MEChest.getIcon() : ico, renderer, up ); + } + + renderer.overrideBlockTexture = null; + postRenderInWorld( renderer ); + + return result; + } +} diff --git a/client/render/blocks/RenderNull.java b/src/main/java/appeng/client/render/blocks/RenderNull.java similarity index 96% rename from client/render/blocks/RenderNull.java rename to src/main/java/appeng/client/render/blocks/RenderNull.java index 7cf8cdadb..763932930 100644 --- a/client/render/blocks/RenderNull.java +++ b/src/main/java/appeng/client/render/blocks/RenderNull.java @@ -1,29 +1,29 @@ -package appeng.client.render.blocks; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; - -public class RenderNull extends BaseBlockRender -{ - - public RenderNull() { - super( false, 20 ); - } - - @Override - public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - - } - - @Override - public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - return true; - } - -} +package appeng.client.render.blocks; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; + +public class RenderNull extends BaseBlockRender +{ + + public RenderNull() { + super( false, 20 ); + } + + @Override + public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + + } + + @Override + public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + return true; + } + +} diff --git a/client/render/blocks/RenderQNB.java b/src/main/java/appeng/client/render/blocks/RenderQNB.java similarity index 97% rename from client/render/blocks/RenderQNB.java rename to src/main/java/appeng/client/render/blocks/RenderQNB.java index a860c499a..3f71c82e3 100644 --- a/client/render/blocks/RenderQNB.java +++ b/src/main/java/appeng/client/render/blocks/RenderQNB.java @@ -1,186 +1,186 @@ -package appeng.client.render.blocks; - -import java.util.EnumSet; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.util.AEColor; -import appeng.api.util.AEColoredItemDefinition; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.texture.ExtraBlockTextures; -import appeng.tile.qnb.TileQuantumBridge; - -public class RenderQNB extends BaseBlockRender -{ - - public void renderCableAt(double Thickness, IBlockAccess world, int x, int y, int z, AEBaseBlock block, RenderBlocks renderer, IIcon texture, double pull, - EnumSet connections) - { - block.getRendererInstance().setTemporaryRenderIcon( texture ); - - if ( connections.contains( ForgeDirection.UNKNOWN ) ) - { - renderer.setRenderBounds( 0.5D - Thickness, 0.5D - Thickness, 0.5D - Thickness, 0.5D + Thickness, 0.5D + Thickness, 0.5D + Thickness ); - renderer.renderStandardBlock( block, x, y, z ); - } - - if ( connections.contains( ForgeDirection.WEST ) ) - { - renderer.setRenderBounds( 0.0D, 0.5D - Thickness, 0.5D - Thickness, 0.5D - Thickness - pull, 0.5D + Thickness, 0.5D + Thickness ); - renderer.renderStandardBlock( block, x, y, z ); - } - - if ( connections.contains( ForgeDirection.EAST ) ) - { - renderer.setRenderBounds( 0.5D + Thickness + pull, 0.5D - Thickness, 0.5D - Thickness, 1.0D, 0.5D + Thickness, 0.5D + Thickness ); - renderer.renderStandardBlock( block, x, y, z ); - } - - if ( connections.contains( ForgeDirection.NORTH ) ) - { - renderer.setRenderBounds( 0.5D - Thickness, 0.5D - Thickness, 0.0D, 0.5D + Thickness, 0.5D + Thickness, 0.5D - Thickness - pull ); - renderer.renderStandardBlock( block, x, y, z ); - } - - if ( connections.contains( ForgeDirection.SOUTH ) ) - { - renderer.setRenderBounds( 0.5D - Thickness, 0.5D - Thickness, 0.5D + Thickness + pull, 0.5D + Thickness, 0.5D + Thickness, 1.0D ); - renderer.renderStandardBlock( block, x, y, z ); - } - - if ( connections.contains( ForgeDirection.DOWN ) ) - { - renderer.setRenderBounds( 0.5D - Thickness, 0.0D, 0.5D - Thickness, 0.5D + Thickness, 0.5D - Thickness - pull, 0.5D + Thickness ); - renderer.renderStandardBlock( block, x, y, z ); - } - - if ( connections.contains( ForgeDirection.UP ) ) - { - renderer.setRenderBounds( 0.5D - Thickness, 0.5D + Thickness + pull, 0.5D - Thickness, 0.5D + Thickness, 1.0D, 0.5D + Thickness ); - renderer.renderStandardBlock( block, x, y, z ); - } - - block.getRendererInstance().setTemporaryRenderIcon( null ); - } - - @Override - public void renderInventory(AEBaseBlock block, ItemStack item, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - float px = 2.0f / 16.0f; - float maxpx = 14.0f / 16.0f; - renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); - - super.renderInventory( block, item, renderer, type, obj ); - } - - @Override - public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - TileQuantumBridge tqb = block.getTileEntity( world, x, y, z ); - if ( tqb == null ) - return false; - - renderer.renderAllFaces = true; - - if ( tqb.getBlockType() == AEApi.instance().blocks().blockQuantumLink.block() ) - { - if ( tqb.isFormed() ) - { - AEColoredItemDefinition cabldef = AEApi.instance().parts().partCableGlass; - Item cable = cabldef.item( AEColor.Transparent ); - - AEColoredItemDefinition ccabldef = AEApi.instance().parts().partCableCovered; - Item ccable = ccabldef.item( AEColor.Transparent ); - - EnumSet sides = tqb.getConnections(); - renderCableAt( 0.11D, world, x, y, z, block, renderer, cable.getIconIndex( cabldef.stack( AEColor.Transparent, 1 ) ), 0.141D, sides ); - renderCableAt( 0.188D, world, x, y, z, block, renderer, ccable.getIconIndex( ccabldef.stack( AEColor.Transparent, 1 ) ), 0.1875D, sides ); - } - - float px = 2.0f / 16.0f; - float maxpx = 14.0f / 16.0f; - renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); - renderer.renderStandardBlock( block, x, y, z ); - // super.renderWorldBlock(world, x, y, z, block, modelId, renderer); - } - else - { - if ( !tqb.isFormed() ) - { - float px = 2.0f / 16.0f; - float maxpx = 14.0f / 16.0f; - renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); - renderer.renderStandardBlock( block, x, y, z ); - } - else if ( tqb.isCorner() ) - { - // renderCableAt(0.11D, world, x, y, z, block, modelId, - // renderer, - // AppEngTextureRegistry.Blocks.MECable.get(), true, 0.0D); - AEColoredItemDefinition ccabldef = AEApi.instance().parts().partCableCovered; - Item ccable = ccabldef.item( AEColor.Transparent ); - - renderCableAt( 0.188D, world, x, y, z, block, renderer, ccable.getIconIndex( ccabldef.stack( AEColor.Transparent, 1 ) ), 0.05D, - tqb.getConnections() ); - - float px = 4.0f / 16.0f; - float maxpx = 12.0f / 16.0f; - - renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); - renderer.renderStandardBlock( block, x, y, z ); - - if ( tqb.isPowered() ) - { - - px = 3.9f / 16.0f; - maxpx = 12.1f / 16.0f; - renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); - - int bn = 15; - Tessellator.instance.setColorOpaque_F( 1.0F, 1.0F, 1.0F ); - Tessellator.instance.setBrightness( bn << 20 | bn << 4 ); - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) - renderFace( x, y, z, block, ExtraBlockTextures.BlockQRingCornerLight.getIcon(), renderer, side ); - - } - } - else - { - float px = 2.0f / 16.0f; - float maxpx = 14.0f / 16.0f; - renderer.setRenderBounds( 0, px, px, 1, maxpx, maxpx ); - renderer.renderStandardBlock( block, x, y, z ); - - renderer.setRenderBounds( px, 0, px, maxpx, 1, maxpx ); - renderer.renderStandardBlock( block, x, y, z ); - - renderer.setRenderBounds( px, px, 0, maxpx, maxpx, 1 ); - renderer.renderStandardBlock( block, x, y, z ); - - if ( tqb.isPowered() ) - { - px = -0.01f / 16.0f; - maxpx = 16.01f / 16.0f; - renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); - - int bn = 15; - Tessellator.instance.setColorOpaque_F( 1.0F, 1.0F, 1.0F ); - Tessellator.instance.setBrightness( bn << 20 | bn << 4 ); - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) - renderFace( x, y, z, block, ExtraBlockTextures.BlockQRingEdgeLight.getIcon(), renderer, side ); - } - } - } - - renderer.renderAllFaces = false; - return true; - } -} +package appeng.client.render.blocks; + +import java.util.EnumSet; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.util.AEColor; +import appeng.api.util.AEColoredItemDefinition; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.texture.ExtraBlockTextures; +import appeng.tile.qnb.TileQuantumBridge; + +public class RenderQNB extends BaseBlockRender +{ + + public void renderCableAt(double Thickness, IBlockAccess world, int x, int y, int z, AEBaseBlock block, RenderBlocks renderer, IIcon texture, double pull, + EnumSet connections) + { + block.getRendererInstance().setTemporaryRenderIcon( texture ); + + if ( connections.contains( ForgeDirection.UNKNOWN ) ) + { + renderer.setRenderBounds( 0.5D - Thickness, 0.5D - Thickness, 0.5D - Thickness, 0.5D + Thickness, 0.5D + Thickness, 0.5D + Thickness ); + renderer.renderStandardBlock( block, x, y, z ); + } + + if ( connections.contains( ForgeDirection.WEST ) ) + { + renderer.setRenderBounds( 0.0D, 0.5D - Thickness, 0.5D - Thickness, 0.5D - Thickness - pull, 0.5D + Thickness, 0.5D + Thickness ); + renderer.renderStandardBlock( block, x, y, z ); + } + + if ( connections.contains( ForgeDirection.EAST ) ) + { + renderer.setRenderBounds( 0.5D + Thickness + pull, 0.5D - Thickness, 0.5D - Thickness, 1.0D, 0.5D + Thickness, 0.5D + Thickness ); + renderer.renderStandardBlock( block, x, y, z ); + } + + if ( connections.contains( ForgeDirection.NORTH ) ) + { + renderer.setRenderBounds( 0.5D - Thickness, 0.5D - Thickness, 0.0D, 0.5D + Thickness, 0.5D + Thickness, 0.5D - Thickness - pull ); + renderer.renderStandardBlock( block, x, y, z ); + } + + if ( connections.contains( ForgeDirection.SOUTH ) ) + { + renderer.setRenderBounds( 0.5D - Thickness, 0.5D - Thickness, 0.5D + Thickness + pull, 0.5D + Thickness, 0.5D + Thickness, 1.0D ); + renderer.renderStandardBlock( block, x, y, z ); + } + + if ( connections.contains( ForgeDirection.DOWN ) ) + { + renderer.setRenderBounds( 0.5D - Thickness, 0.0D, 0.5D - Thickness, 0.5D + Thickness, 0.5D - Thickness - pull, 0.5D + Thickness ); + renderer.renderStandardBlock( block, x, y, z ); + } + + if ( connections.contains( ForgeDirection.UP ) ) + { + renderer.setRenderBounds( 0.5D - Thickness, 0.5D + Thickness + pull, 0.5D - Thickness, 0.5D + Thickness, 1.0D, 0.5D + Thickness ); + renderer.renderStandardBlock( block, x, y, z ); + } + + block.getRendererInstance().setTemporaryRenderIcon( null ); + } + + @Override + public void renderInventory(AEBaseBlock block, ItemStack item, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + float px = 2.0f / 16.0f; + float maxpx = 14.0f / 16.0f; + renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); + + super.renderInventory( block, item, renderer, type, obj ); + } + + @Override + public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + TileQuantumBridge tqb = block.getTileEntity( world, x, y, z ); + if ( tqb == null ) + return false; + + renderer.renderAllFaces = true; + + if ( tqb.getBlockType() == AEApi.instance().blocks().blockQuantumLink.block() ) + { + if ( tqb.isFormed() ) + { + AEColoredItemDefinition cabldef = AEApi.instance().parts().partCableGlass; + Item cable = cabldef.item( AEColor.Transparent ); + + AEColoredItemDefinition ccabldef = AEApi.instance().parts().partCableCovered; + Item ccable = ccabldef.item( AEColor.Transparent ); + + EnumSet sides = tqb.getConnections(); + renderCableAt( 0.11D, world, x, y, z, block, renderer, cable.getIconIndex( cabldef.stack( AEColor.Transparent, 1 ) ), 0.141D, sides ); + renderCableAt( 0.188D, world, x, y, z, block, renderer, ccable.getIconIndex( ccabldef.stack( AEColor.Transparent, 1 ) ), 0.1875D, sides ); + } + + float px = 2.0f / 16.0f; + float maxpx = 14.0f / 16.0f; + renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); + renderer.renderStandardBlock( block, x, y, z ); + // super.renderWorldBlock(world, x, y, z, block, modelId, renderer); + } + else + { + if ( !tqb.isFormed() ) + { + float px = 2.0f / 16.0f; + float maxpx = 14.0f / 16.0f; + renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); + renderer.renderStandardBlock( block, x, y, z ); + } + else if ( tqb.isCorner() ) + { + // renderCableAt(0.11D, world, x, y, z, block, modelId, + // renderer, + // AppEngTextureRegistry.Blocks.MECable.get(), true, 0.0D); + AEColoredItemDefinition ccabldef = AEApi.instance().parts().partCableCovered; + Item ccable = ccabldef.item( AEColor.Transparent ); + + renderCableAt( 0.188D, world, x, y, z, block, renderer, ccable.getIconIndex( ccabldef.stack( AEColor.Transparent, 1 ) ), 0.05D, + tqb.getConnections() ); + + float px = 4.0f / 16.0f; + float maxpx = 12.0f / 16.0f; + + renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); + renderer.renderStandardBlock( block, x, y, z ); + + if ( tqb.isPowered() ) + { + + px = 3.9f / 16.0f; + maxpx = 12.1f / 16.0f; + renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); + + int bn = 15; + Tessellator.instance.setColorOpaque_F( 1.0F, 1.0F, 1.0F ); + Tessellator.instance.setBrightness( bn << 20 | bn << 4 ); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + renderFace( x, y, z, block, ExtraBlockTextures.BlockQRingCornerLight.getIcon(), renderer, side ); + + } + } + else + { + float px = 2.0f / 16.0f; + float maxpx = 14.0f / 16.0f; + renderer.setRenderBounds( 0, px, px, 1, maxpx, maxpx ); + renderer.renderStandardBlock( block, x, y, z ); + + renderer.setRenderBounds( px, 0, px, maxpx, 1, maxpx ); + renderer.renderStandardBlock( block, x, y, z ); + + renderer.setRenderBounds( px, px, 0, maxpx, maxpx, 1 ); + renderer.renderStandardBlock( block, x, y, z ); + + if ( tqb.isPowered() ) + { + px = -0.01f / 16.0f; + maxpx = 16.01f / 16.0f; + renderer.setRenderBounds( px, px, px, maxpx, maxpx, maxpx ); + + int bn = 15; + Tessellator.instance.setColorOpaque_F( 1.0F, 1.0F, 1.0F ); + Tessellator.instance.setBrightness( bn << 20 | bn << 4 ); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + renderFace( x, y, z, block, ExtraBlockTextures.BlockQRingEdgeLight.getIcon(), renderer, side ); + } + } + } + + renderer.renderAllFaces = false; + return true; + } +} diff --git a/client/render/blocks/RenderQuartzGlass.java b/src/main/java/appeng/client/render/blocks/RenderQuartzGlass.java similarity index 97% rename from client/render/blocks/RenderQuartzGlass.java rename to src/main/java/appeng/client/render/blocks/RenderQuartzGlass.java index 4944d357e..eb2fd890f 100644 --- a/client/render/blocks/RenderQuartzGlass.java +++ b/src/main/java/appeng/client/render/blocks/RenderQuartzGlass.java @@ -1,189 +1,189 @@ -package appeng.client.render.blocks; - -import java.util.Random; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.texture.ExtraBlockTextures; -import appeng.client.texture.OffsetIcon; - -public class RenderQuartzGlass extends BaseBlockRender -{ - - static byte offsets[][][]; - - public RenderQuartzGlass() { - super( false, 0 ); - if ( offsets == null ) - { - Random r = new Random( 924 ); - offsets = new byte[10][10][10]; - for (int x = 0; x < 10; x++) - for (int y = 0; y < 10; y++) - r.nextBytes( offsets[x][y] ); - } - } - - boolean isFlush(AEBaseBlock imb, IBlockAccess world, int x, int y, int z) - { - return isGlass( imb, world, x, y, z ); - } - - boolean isGlass(AEBaseBlock imb, IBlockAccess world, int x, int y, int z) - { - return world.getBlock( x, y, z ) == AEApi.instance().blocks().blockQuartzGlass.block() - || world.getBlock( x, y, z ) == AEApi.instance().blocks().blockQuartzVibrantGlass.block(); - } - - void renderEdge(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer, ForgeDirection side, ForgeDirection direction) - { - if ( !isFlush( imb, world, x + side.offsetX, y + side.offsetY, z + side.offsetZ ) ) - { - if ( !isFlush( imb, world, x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ ) ) - { - float minX = 0.5f + (side.offsetX + direction.offsetX) / 2.0f; - float minY = 0.5f + (side.offsetY + direction.offsetY) / 2.0f; - float minZ = 0.5f + (side.offsetZ + direction.offsetZ) / 2.0f; - float maxX = 0.5f + (side.offsetX + direction.offsetX) / 2.0f; - float maxY = 0.5f + (side.offsetY + direction.offsetY) / 2.0f; - float maxZ = 0.5f + (side.offsetZ + direction.offsetZ) / 2.0f; - - if ( 0 == side.offsetX && 0 == direction.offsetX ) - { - minX = 0.0f; - maxX = 1.0f; - } - if ( 0 == side.offsetY && 0 == direction.offsetY ) - { - minY = 0.0f; - maxY = 1.0f; - } - if ( 0 == side.offsetZ && 0 == direction.offsetZ ) - { - minZ = 0.0f; - maxZ = 1.0f; - } - - if ( maxX <= 0.001f ) - maxX += 0.9f / 16.0f; - if ( maxY <= 0.001f ) - maxY += 0.9f / 16.0f; - if ( maxZ <= 0.001f ) - maxZ += 0.9f / 16.0f; - - if ( minX >= 0.999f ) - minX -= 0.9f / 16.0f; - if ( minY >= 0.999f ) - minY -= 0.9f / 16.0f; - if ( minZ >= 0.999f ) - minZ -= 0.9f / 16.0f; - - renderer.setRenderBounds( minX, minY, minZ, maxX, maxY, maxZ ); - - switch (side) - { - case WEST: - renderer.renderFaceXNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); - break; - case EAST: - renderer.renderFaceXPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); - break; - case NORTH: - renderer.renderFaceZNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); - break; - case SOUTH: - renderer.renderFaceZPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); - break; - case DOWN: - renderer.renderFaceYNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); - break; - case UP: - renderer.renderFaceYPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); - break; - default: - break; - } - } - } - } - - @Override - public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - renderer.overrideBlockTexture = ExtraBlockTextures.GlassFrame.getIcon(); - super.renderInventory( block, is, renderer, type, obj ); - renderer.overrideBlockTexture = null; - super.renderInventory( block, is, renderer, type, obj ); - } - - @Override - public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); - - int cx = Math.abs( x % 10 ); - int cy = Math.abs( y % 10 ); - int cz = Math.abs( z % 10 ); - - int u = offsets[cx][cy][cz] % 4; - int v = offsets[9 - cx][9 - cy][9 - cz] % 4; - - switch (Math.abs( (offsets[cx][cy][cz] + (x + y + z)) % 4 )) - { - case 0: - renderer.overrideBlockTexture = new OffsetIcon( imb.getIcon( 0, 0 ), u / 2, v / 2 ); - break; - case 1: - renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassB.getIcon(), u / 2, v / 2 ); - break; - case 2: - renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassC.getIcon(), u, v ); - break; - case 3: - renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassD.getIcon(), u, v ); - break; - } - - boolean result = renderer.renderStandardBlock( imb, x, y, z ); - - renderer.overrideBlockTexture = null; - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.EAST ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.WEST ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.NORTH ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.SOUTH ); - - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.EAST ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.WEST ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.NORTH ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.SOUTH ); - - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.UP ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.DOWN ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.NORTH ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.SOUTH ); - - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.UP ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.DOWN ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.NORTH ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.SOUTH ); - - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.EAST ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.WEST ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.UP ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.DOWN ); - - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.EAST ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.WEST ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.UP ); - renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.DOWN ); - - return result; - } - -} +package appeng.client.render.blocks; + +import java.util.Random; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.texture.ExtraBlockTextures; +import appeng.client.texture.OffsetIcon; + +public class RenderQuartzGlass extends BaseBlockRender +{ + + static byte offsets[][][]; + + public RenderQuartzGlass() { + super( false, 0 ); + if ( offsets == null ) + { + Random r = new Random( 924 ); + offsets = new byte[10][10][10]; + for (int x = 0; x < 10; x++) + for (int y = 0; y < 10; y++) + r.nextBytes( offsets[x][y] ); + } + } + + boolean isFlush(AEBaseBlock imb, IBlockAccess world, int x, int y, int z) + { + return isGlass( imb, world, x, y, z ); + } + + boolean isGlass(AEBaseBlock imb, IBlockAccess world, int x, int y, int z) + { + return world.getBlock( x, y, z ) == AEApi.instance().blocks().blockQuartzGlass.block() + || world.getBlock( x, y, z ) == AEApi.instance().blocks().blockQuartzVibrantGlass.block(); + } + + void renderEdge(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer, ForgeDirection side, ForgeDirection direction) + { + if ( !isFlush( imb, world, x + side.offsetX, y + side.offsetY, z + side.offsetZ ) ) + { + if ( !isFlush( imb, world, x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ ) ) + { + float minX = 0.5f + (side.offsetX + direction.offsetX) / 2.0f; + float minY = 0.5f + (side.offsetY + direction.offsetY) / 2.0f; + float minZ = 0.5f + (side.offsetZ + direction.offsetZ) / 2.0f; + float maxX = 0.5f + (side.offsetX + direction.offsetX) / 2.0f; + float maxY = 0.5f + (side.offsetY + direction.offsetY) / 2.0f; + float maxZ = 0.5f + (side.offsetZ + direction.offsetZ) / 2.0f; + + if ( 0 == side.offsetX && 0 == direction.offsetX ) + { + minX = 0.0f; + maxX = 1.0f; + } + if ( 0 == side.offsetY && 0 == direction.offsetY ) + { + minY = 0.0f; + maxY = 1.0f; + } + if ( 0 == side.offsetZ && 0 == direction.offsetZ ) + { + minZ = 0.0f; + maxZ = 1.0f; + } + + if ( maxX <= 0.001f ) + maxX += 0.9f / 16.0f; + if ( maxY <= 0.001f ) + maxY += 0.9f / 16.0f; + if ( maxZ <= 0.001f ) + maxZ += 0.9f / 16.0f; + + if ( minX >= 0.999f ) + minX -= 0.9f / 16.0f; + if ( minY >= 0.999f ) + minY -= 0.9f / 16.0f; + if ( minZ >= 0.999f ) + minZ -= 0.9f / 16.0f; + + renderer.setRenderBounds( minX, minY, minZ, maxX, maxY, maxZ ); + + switch (side) + { + case WEST: + renderer.renderFaceXNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); + break; + case EAST: + renderer.renderFaceXPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); + break; + case NORTH: + renderer.renderFaceZNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); + break; + case SOUTH: + renderer.renderFaceZPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); + break; + case DOWN: + renderer.renderFaceYNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); + break; + case UP: + renderer.renderFaceYPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() ); + break; + default: + break; + } + } + } + } + + @Override + public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + renderer.overrideBlockTexture = ExtraBlockTextures.GlassFrame.getIcon(); + super.renderInventory( block, is, renderer, type, obj ); + renderer.overrideBlockTexture = null; + super.renderInventory( block, is, renderer, type, obj ); + } + + @Override + public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); + + int cx = Math.abs( x % 10 ); + int cy = Math.abs( y % 10 ); + int cz = Math.abs( z % 10 ); + + int u = offsets[cx][cy][cz] % 4; + int v = offsets[9 - cx][9 - cy][9 - cz] % 4; + + switch (Math.abs( (offsets[cx][cy][cz] + (x + y + z)) % 4 )) + { + case 0: + renderer.overrideBlockTexture = new OffsetIcon( imb.getIcon( 0, 0 ), u / 2, v / 2 ); + break; + case 1: + renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassB.getIcon(), u / 2, v / 2 ); + break; + case 2: + renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassC.getIcon(), u, v ); + break; + case 3: + renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassD.getIcon(), u, v ); + break; + } + + boolean result = renderer.renderStandardBlock( imb, x, y, z ); + + renderer.overrideBlockTexture = null; + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.EAST ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.WEST ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.NORTH ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.SOUTH ); + + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.EAST ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.WEST ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.NORTH ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.SOUTH ); + + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.UP ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.DOWN ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.NORTH ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.SOUTH ); + + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.UP ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.DOWN ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.NORTH ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.SOUTH ); + + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.EAST ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.WEST ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.UP ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.DOWN ); + + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.EAST ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.WEST ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.UP ); + renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.DOWN ); + + return result; + } + +} diff --git a/client/render/blocks/RenderQuartzOre.java b/src/main/java/appeng/client/render/blocks/RenderQuartzOre.java similarity index 97% rename from client/render/blocks/RenderQuartzOre.java rename to src/main/java/appeng/client/render/blocks/RenderQuartzOre.java index 768d7ca72..003772ca2 100644 --- a/client/render/blocks/RenderQuartzOre.java +++ b/src/main/java/appeng/client/render/blocks/RenderQuartzOre.java @@ -1,42 +1,42 @@ -package appeng.client.render.blocks; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import appeng.block.AEBaseBlock; -import appeng.block.solids.OreQuartz; -import appeng.client.render.BaseBlockRender; -import appeng.client.texture.ExtraBlockTextures; - -public class RenderQuartzOre extends BaseBlockRender -{ - - public RenderQuartzOre() { - super( false, 20 ); - } - - @Override - public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - super.renderInventory( blk, is, renderer, type, obj ); - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.OreQuartzStone.getIcon() ); - super.renderInventory( blk, is, renderer, type, obj ); - blk.getRendererInstance().setTemporaryRenderIcon( null ); - } - - @Override - public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - OreQuartz blk = (OreQuartz) block; - blk.enhanceBrightness = true; - super.renderInWorld( block, world, x, y, z, renderer ); - blk.enhanceBrightness = false; - - blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.OreQuartzStone.getIcon() ); - boolean out = super.renderInWorld( block, world, x, y, z, renderer ); - blk.getRendererInstance().setTemporaryRenderIcon( null ); - - return out; - } -} +package appeng.client.render.blocks; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import appeng.block.AEBaseBlock; +import appeng.block.solids.OreQuartz; +import appeng.client.render.BaseBlockRender; +import appeng.client.texture.ExtraBlockTextures; + +public class RenderQuartzOre extends BaseBlockRender +{ + + public RenderQuartzOre() { + super( false, 20 ); + } + + @Override + public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + super.renderInventory( blk, is, renderer, type, obj ); + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.OreQuartzStone.getIcon() ); + super.renderInventory( blk, is, renderer, type, obj ); + blk.getRendererInstance().setTemporaryRenderIcon( null ); + } + + @Override + public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + OreQuartz blk = (OreQuartz) block; + blk.enhanceBrightness = true; + super.renderInWorld( block, world, x, y, z, renderer ); + blk.enhanceBrightness = false; + + blk.getRendererInstance().setTemporaryRenderIcon( ExtraBlockTextures.OreQuartzStone.getIcon() ); + boolean out = super.renderInWorld( block, world, x, y, z, renderer ); + blk.getRendererInstance().setTemporaryRenderIcon( null ); + + return out; + } +} diff --git a/client/render/blocks/RenderQuartzTorch.java b/src/main/java/appeng/client/render/blocks/RenderQuartzTorch.java similarity index 97% rename from client/render/blocks/RenderQuartzTorch.java rename to src/main/java/appeng/client/render/blocks/RenderQuartzTorch.java index 07edf267f..a27611ecd 100644 --- a/client/render/blocks/RenderQuartzTorch.java +++ b/src/main/java/appeng/client/render/blocks/RenderQuartzTorch.java @@ -1,194 +1,194 @@ -package appeng.client.render.blocks; - -import java.util.EnumSet; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.util.IOrientable; -import appeng.api.util.IOrientableBlock; -import appeng.block.AEBaseBlock; -import appeng.block.misc.BlockQuartzTorch; -import appeng.client.render.BaseBlockRender; - -public class RenderQuartzTorch extends BaseBlockRender -{ - - public RenderQuartzTorch() { - super( false, 20 ); - } - - @Override - public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - Tessellator tess = Tessellator.instance; - - float Point2 = 6.0f / 16.0f; - float Point3 = 7.0f / 16.0f; - float Point13 = 10.0f / 16.0f; - float Point12 = 9.0f / 16.0f; - - float Onepx = 1.0f / 16.0f; - float rbottom = 5.0f / 16.0f; - float rtop = 10.0f / 16.0f; - - float bottom = 7.0f / 16.0f; - float top = 8.0f / 16.0f; - - float xOff = 0.0f; - float yOff = 0.0f; - float zOff = 0.0f; - - renderer.setRenderBounds( Point3 + xOff, rbottom + yOff, Point3 + zOff, Point12 + xOff, rtop + yOff, Point12 + zOff ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - renderer.setRenderBounds( Point3 + xOff, rtop + yOff, Point3 + zOff, Point3 + Onepx + xOff, rtop + Onepx + yOff, Point3 + Onepx + zOff ); - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - renderer.setRenderBounds( Point12 - Onepx + xOff, rbottom - Onepx + yOff, Point12 - Onepx + zOff, Point12 + xOff, rbottom + yOff, Point12 + zOff ); - - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - blk.getRendererInstance().setTemporaryRenderIcon( Blocks.hopper.getIcon( 0, 0 ) ); - renderer.renderAllFaces = true; - - renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point2 + zOff, Point13 + xOff, top + yOff, Point3 + zOff ); - - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point12 + zOff, Point13 + xOff, top + yOff, Point13 + zOff ); - - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point3 + zOff, Point3 + xOff, top + yOff, Point12 + zOff ); - - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - renderer.setRenderBounds( Point12 + xOff, bottom + yOff, Point3 + zOff, Point13 + xOff, top + yOff, Point12 + zOff ); - - renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); - - renderer.renderAllFaces = false; - blk.getRendererInstance().setTemporaryRenderIcon( null ); - - } - - @Override - public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - BlockQuartzTorch blk = (BlockQuartzTorch) block; - - IOrientable te = ((IOrientableBlock) block).getOrientable( world, x, y, z ); - - float Point2 = 6.0f / 16.0f; - float Point3 = 7.0f / 16.0f; - float Point13 = 10.0f / 16.0f; - float Point12 = 9.0f / 16.0f; - - float Onepx = 1.0f / 16.0f; - float rbottom = 5.0f / 16.0f; - float rtop = 10.0f / 16.0f; - - float bottom = 7.0f / 16.0f; - float top = 8.0f / 16.0f; - - float xOff = 0.0f; - float yOff = 0.0f; - float zOff = 0.0f; - - renderer.renderAllFaces = true; - if ( te != null ) - { - ForgeDirection forward = te.getUp(); - xOff = forward.offsetX * -(4.0f / 16.0f); - yOff = forward.offsetY * -(4.0f / 16.0f); - zOff = forward.offsetZ * -(4.0f / 16.0f); - } - - renderer.setRenderBounds( Point3 + xOff, rbottom + yOff, Point3 + zOff, Point12 + xOff, rtop + yOff, Point12 + zOff ); - super.renderInWorld( block, world, x, y, z, renderer ); - - int r = (x + y + z) % 2; - if ( r == 0 ) - { - renderer.setRenderBounds( Point3 + xOff, rtop + yOff, Point3 + zOff, Point3 + Onepx + xOff, rtop + Onepx + yOff, Point3 + Onepx + zOff ); - super.renderInWorld( block, world, x, y, z, renderer ); - - renderer.setRenderBounds( Point12 - Onepx + xOff, rbottom - Onepx + yOff, Point12 - Onepx + zOff, Point12 + xOff, rbottom + yOff, Point12 + zOff ); - super.renderInWorld( block, world, x, y, z, renderer ); - } - else - { - renderer.setRenderBounds( Point3 + xOff, rbottom - Onepx + yOff, Point3 + zOff, Point3 + Onepx + xOff, rbottom + yOff, Point3 + Onepx + zOff ); - super.renderInWorld( block, world, x, y, z, renderer ); - - renderer.setRenderBounds( Point12 - Onepx + xOff, rtop + yOff, Point12 - Onepx + zOff, Point12 + xOff, rtop + Onepx + yOff, Point12 + zOff ); - super.renderInWorld( block, world, x, y, z, renderer ); - } - - blk.getRendererInstance().setTemporaryRenderIcon( Blocks.hopper.getIcon( 0, 0 ) ); - - renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point2 + zOff, Point13 + xOff, top + yOff, Point3 + zOff ); - boolean out = renderer.renderStandardBlock( blk, x, y, z ); - - renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point12 + zOff, Point13 + xOff, top + yOff, Point13 + zOff ); - renderer.renderStandardBlock( blk, x, y, z ); - - renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point3 + zOff, Point3 + xOff, top + yOff, Point12 + zOff ); - renderer.renderStandardBlock( blk, x, y, z ); - - renderer.setRenderBounds( Point12 + xOff, bottom + yOff, Point3 + zOff, Point13 + xOff, top + yOff, Point12 + zOff ); - renderer.renderStandardBlock( blk, x, y, z ); - - if ( te != null ) - { - ForgeDirection forward = te.getUp(); - switch (forward) - { - case EAST: - renderer.setRenderBounds( 0, bottom + yOff, bottom + zOff, Point2 + xOff, top + yOff, top + zOff ); - renderer.renderStandardBlock( blk, x, y, z ); - break; - case WEST: - renderer.setRenderBounds( Point13 + xOff, bottom + yOff, bottom + zOff, 1.0, top + yOff, top + zOff ); - renderer.renderStandardBlock( blk, x, y, z ); - break; - case NORTH: - renderer.setRenderBounds( bottom + xOff, bottom + yOff, Point13 + zOff, top + xOff, top + yOff, 1.0 ); - renderer.renderStandardBlock( blk, x, y, z ); - break; - case SOUTH: - renderer.setRenderBounds( bottom + xOff, bottom + yOff, 0, top + xOff, top + yOff, Point2 + zOff ); - renderer.renderStandardBlock( blk, x, y, z ); - break; - case UP: - renderer.setRenderBounds( Point2, 0, Point2, Point3, bottom + yOff, Point3 ); - renderer.renderStandardBlock( blk, x, y, z ); - renderer.setRenderBounds( Point2, 0, Point12, Point3, bottom + yOff, Point13 ); - renderer.renderStandardBlock( blk, x, y, z ); - renderer.setRenderBounds( Point12, 0, Point2, Point13, bottom + yOff, Point3 ); - renderer.renderStandardBlock( blk, x, y, z ); - renderer.setRenderBounds( Point12, 0, Point12, Point13, bottom + yOff, Point13 ); - renderer.renderStandardBlock( blk, x, y, z ); - break; - case DOWN: - renderer.setRenderBounds( Point2, top + yOff, Point2, Point3, 1.0, Point3 ); - renderer.renderStandardBlock( blk, x, y, z ); - renderer.setRenderBounds( Point2, top + yOff, Point12, Point3, 1.0, Point13 ); - renderer.renderStandardBlock( blk, x, y, z ); - renderer.setRenderBounds( Point12, top + yOff, Point2, Point13, 1.0, Point3 ); - renderer.renderStandardBlock( blk, x, y, z ); - renderer.setRenderBounds( Point12, top + yOff, Point12, Point13, 1.0, Point13 ); - renderer.renderStandardBlock( blk, x, y, z ); - break; - default: - } - } - - renderer.renderAllFaces = false; - blk.getRendererInstance().setTemporaryRenderIcon( null ); - - return out; - } -} +package appeng.client.render.blocks; + +import java.util.EnumSet; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.util.IOrientable; +import appeng.api.util.IOrientableBlock; +import appeng.block.AEBaseBlock; +import appeng.block.misc.BlockQuartzTorch; +import appeng.client.render.BaseBlockRender; + +public class RenderQuartzTorch extends BaseBlockRender +{ + + public RenderQuartzTorch() { + super( false, 20 ); + } + + @Override + public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + Tessellator tess = Tessellator.instance; + + float Point2 = 6.0f / 16.0f; + float Point3 = 7.0f / 16.0f; + float Point13 = 10.0f / 16.0f; + float Point12 = 9.0f / 16.0f; + + float Onepx = 1.0f / 16.0f; + float rbottom = 5.0f / 16.0f; + float rtop = 10.0f / 16.0f; + + float bottom = 7.0f / 16.0f; + float top = 8.0f / 16.0f; + + float xOff = 0.0f; + float yOff = 0.0f; + float zOff = 0.0f; + + renderer.setRenderBounds( Point3 + xOff, rbottom + yOff, Point3 + zOff, Point12 + xOff, rtop + yOff, Point12 + zOff ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + renderer.setRenderBounds( Point3 + xOff, rtop + yOff, Point3 + zOff, Point3 + Onepx + xOff, rtop + Onepx + yOff, Point3 + Onepx + zOff ); + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + renderer.setRenderBounds( Point12 - Onepx + xOff, rbottom - Onepx + yOff, Point12 - Onepx + zOff, Point12 + xOff, rbottom + yOff, Point12 + zOff ); + + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + blk.getRendererInstance().setTemporaryRenderIcon( Blocks.hopper.getIcon( 0, 0 ) ); + renderer.renderAllFaces = true; + + renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point2 + zOff, Point13 + xOff, top + yOff, Point3 + zOff ); + + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point12 + zOff, Point13 + xOff, top + yOff, Point13 + zOff ); + + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point3 + zOff, Point3 + xOff, top + yOff, Point12 + zOff ); + + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + renderer.setRenderBounds( Point12 + xOff, bottom + yOff, Point3 + zOff, Point13 + xOff, top + yOff, Point12 + zOff ); + + renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, is, tess, 0xffffff, renderer ); + + renderer.renderAllFaces = false; + blk.getRendererInstance().setTemporaryRenderIcon( null ); + + } + + @Override + public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + BlockQuartzTorch blk = (BlockQuartzTorch) block; + + IOrientable te = ((IOrientableBlock) block).getOrientable( world, x, y, z ); + + float Point2 = 6.0f / 16.0f; + float Point3 = 7.0f / 16.0f; + float Point13 = 10.0f / 16.0f; + float Point12 = 9.0f / 16.0f; + + float Onepx = 1.0f / 16.0f; + float rbottom = 5.0f / 16.0f; + float rtop = 10.0f / 16.0f; + + float bottom = 7.0f / 16.0f; + float top = 8.0f / 16.0f; + + float xOff = 0.0f; + float yOff = 0.0f; + float zOff = 0.0f; + + renderer.renderAllFaces = true; + if ( te != null ) + { + ForgeDirection forward = te.getUp(); + xOff = forward.offsetX * -(4.0f / 16.0f); + yOff = forward.offsetY * -(4.0f / 16.0f); + zOff = forward.offsetZ * -(4.0f / 16.0f); + } + + renderer.setRenderBounds( Point3 + xOff, rbottom + yOff, Point3 + zOff, Point12 + xOff, rtop + yOff, Point12 + zOff ); + super.renderInWorld( block, world, x, y, z, renderer ); + + int r = (x + y + z) % 2; + if ( r == 0 ) + { + renderer.setRenderBounds( Point3 + xOff, rtop + yOff, Point3 + zOff, Point3 + Onepx + xOff, rtop + Onepx + yOff, Point3 + Onepx + zOff ); + super.renderInWorld( block, world, x, y, z, renderer ); + + renderer.setRenderBounds( Point12 - Onepx + xOff, rbottom - Onepx + yOff, Point12 - Onepx + zOff, Point12 + xOff, rbottom + yOff, Point12 + zOff ); + super.renderInWorld( block, world, x, y, z, renderer ); + } + else + { + renderer.setRenderBounds( Point3 + xOff, rbottom - Onepx + yOff, Point3 + zOff, Point3 + Onepx + xOff, rbottom + yOff, Point3 + Onepx + zOff ); + super.renderInWorld( block, world, x, y, z, renderer ); + + renderer.setRenderBounds( Point12 - Onepx + xOff, rtop + yOff, Point12 - Onepx + zOff, Point12 + xOff, rtop + Onepx + yOff, Point12 + zOff ); + super.renderInWorld( block, world, x, y, z, renderer ); + } + + blk.getRendererInstance().setTemporaryRenderIcon( Blocks.hopper.getIcon( 0, 0 ) ); + + renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point2 + zOff, Point13 + xOff, top + yOff, Point3 + zOff ); + boolean out = renderer.renderStandardBlock( blk, x, y, z ); + + renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point12 + zOff, Point13 + xOff, top + yOff, Point13 + zOff ); + renderer.renderStandardBlock( blk, x, y, z ); + + renderer.setRenderBounds( Point2 + xOff, bottom + yOff, Point3 + zOff, Point3 + xOff, top + yOff, Point12 + zOff ); + renderer.renderStandardBlock( blk, x, y, z ); + + renderer.setRenderBounds( Point12 + xOff, bottom + yOff, Point3 + zOff, Point13 + xOff, top + yOff, Point12 + zOff ); + renderer.renderStandardBlock( blk, x, y, z ); + + if ( te != null ) + { + ForgeDirection forward = te.getUp(); + switch (forward) + { + case EAST: + renderer.setRenderBounds( 0, bottom + yOff, bottom + zOff, Point2 + xOff, top + yOff, top + zOff ); + renderer.renderStandardBlock( blk, x, y, z ); + break; + case WEST: + renderer.setRenderBounds( Point13 + xOff, bottom + yOff, bottom + zOff, 1.0, top + yOff, top + zOff ); + renderer.renderStandardBlock( blk, x, y, z ); + break; + case NORTH: + renderer.setRenderBounds( bottom + xOff, bottom + yOff, Point13 + zOff, top + xOff, top + yOff, 1.0 ); + renderer.renderStandardBlock( blk, x, y, z ); + break; + case SOUTH: + renderer.setRenderBounds( bottom + xOff, bottom + yOff, 0, top + xOff, top + yOff, Point2 + zOff ); + renderer.renderStandardBlock( blk, x, y, z ); + break; + case UP: + renderer.setRenderBounds( Point2, 0, Point2, Point3, bottom + yOff, Point3 ); + renderer.renderStandardBlock( blk, x, y, z ); + renderer.setRenderBounds( Point2, 0, Point12, Point3, bottom + yOff, Point13 ); + renderer.renderStandardBlock( blk, x, y, z ); + renderer.setRenderBounds( Point12, 0, Point2, Point13, bottom + yOff, Point3 ); + renderer.renderStandardBlock( blk, x, y, z ); + renderer.setRenderBounds( Point12, 0, Point12, Point13, bottom + yOff, Point13 ); + renderer.renderStandardBlock( blk, x, y, z ); + break; + case DOWN: + renderer.setRenderBounds( Point2, top + yOff, Point2, Point3, 1.0, Point3 ); + renderer.renderStandardBlock( blk, x, y, z ); + renderer.setRenderBounds( Point2, top + yOff, Point12, Point3, 1.0, Point13 ); + renderer.renderStandardBlock( blk, x, y, z ); + renderer.setRenderBounds( Point12, top + yOff, Point2, Point13, 1.0, Point3 ); + renderer.renderStandardBlock( blk, x, y, z ); + renderer.setRenderBounds( Point12, top + yOff, Point12, Point13, 1.0, Point13 ); + renderer.renderStandardBlock( blk, x, y, z ); + break; + default: + } + } + + renderer.renderAllFaces = false; + blk.getRendererInstance().setTemporaryRenderIcon( null ); + + return out; + } +} diff --git a/client/render/blocks/RenderSpatialPylon.java b/src/main/java/appeng/client/render/blocks/RenderSpatialPylon.java similarity index 97% rename from client/render/blocks/RenderSpatialPylon.java rename to src/main/java/appeng/client/render/blocks/RenderSpatialPylon.java index 181c29a5d..216598375 100644 --- a/client/render/blocks/RenderSpatialPylon.java +++ b/src/main/java/appeng/client/render/blocks/RenderSpatialPylon.java @@ -1,189 +1,189 @@ -package appeng.client.render.blocks; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.BlockRenderInfo; -import appeng.client.texture.ExtraBlockTextures; -import appeng.tile.spatial.TileSpatialPylon; - -public class RenderSpatialPylon extends BaseBlockRender -{ - - public RenderSpatialPylon() { - super( false, 0 ); - } - - @Override - public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - renderer.overrideBlockTexture = ExtraBlockTextures.BlockSpatialPylon_dim.getIcon(); - super.renderInventory( block, is, renderer, type, obj ); - renderer.overrideBlockTexture = null; - super.renderInventory( block, is, renderer, type, obj ); - } - - @Override - public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); - - TileSpatialPylon sp = imb.getTileEntity( world, x, y, z ); - - int displayBits = sp.getDisplayBits(); - ForgeDirection ori = ForgeDirection.UNKNOWN; - - if ( displayBits != 0 ) - { - if ( (displayBits & sp.DISPLAY_Z) == sp.DISPLAY_X ) - { - ori = ForgeDirection.EAST; - if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) - { - renderer.uvRotateEast = 1; - renderer.uvRotateWest = 2; - renderer.uvRotateTop = 2; - renderer.uvRotateBottom = 1; - } - else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMIN ) - { - renderer.uvRotateEast = 2; - renderer.uvRotateWest = 1; - renderer.uvRotateTop = 1; - renderer.uvRotateBottom = 2; - } - else - { - renderer.uvRotateEast = 1; - renderer.uvRotateWest = 1; - renderer.uvRotateTop = 1; - renderer.uvRotateBottom = 1; - } - } - - else if ( (displayBits & sp.DISPLAY_Z) == sp.DISPLAY_Y ) - { - ori = ForgeDirection.UP; - if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) - { - renderer.uvRotateNorth = 3; - renderer.uvRotateSouth = 3; - renderer.uvRotateEast = 3; - renderer.uvRotateWest = 3; - } - } - - else if ( (displayBits & sp.DISPLAY_Z) == sp.DISPLAY_Z ) - { - ori = ForgeDirection.NORTH; - if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) - { - renderer.uvRotateSouth = 1; - renderer.uvRotateNorth = 2; - } - else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMIN ) - { - renderer.uvRotateNorth = 1; - renderer.uvRotateSouth = 2; - renderer.uvRotateTop = 3; - renderer.uvRotateBottom = 3; - } - else - { - renderer.uvRotateNorth = 1; - renderer.uvRotateSouth = 2; - } - } - - BlockRenderInfo bri = imb.getRendererInstance(); - bri.setTemporaryRenderIcon( null ); - bri.setTemporaryRenderIcons( getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.UP ), - getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.DOWN ), - getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.SOUTH ), - getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.NORTH ), - getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.EAST ), - getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.WEST ) ); - - boolean r = renderer.renderStandardBlock( imb, x, y, z ); - - if ( (displayBits & sp.DISPLAY_POWEREDENABLED) == sp.DISPLAY_POWEREDENABLED ) - { - int bn = 15; - Tessellator.instance.setBrightness( bn << 20 | bn << 4 ); - Tessellator.instance.setColorOpaque_I( 0xffffff ); - - for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) - renderFace( x, y, z, imb, getBlockTextureFromSideInside( imb, sp, displayBits, ori, d ), renderer, d ); - } - else - { - bri.setTemporaryRenderIcon( null ); - bri.setTemporaryRenderIcons( getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.UP ), - getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.DOWN ), - getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.SOUTH ), - getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.NORTH ), - getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.EAST ), - getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.WEST ) ); - - renderer.renderStandardBlock( imb, x, y, z ); - } - - bri.setTemporaryRenderIcon( null ); - renderer.uvRotateEast = renderer.uvRotateWest = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateBottom = 0; - - return r; - } - - renderer.overrideBlockTexture = imb.getIcon( 0, 0 ); - boolean result = renderer.renderStandardBlock( imb, x, y, z ); - - renderer.overrideBlockTexture = ExtraBlockTextures.BlockSpatialPylon_dim.getIcon(); - result = renderer.renderStandardBlock( imb, x, y, z ); - - renderer.overrideBlockTexture = null; - return result; - } - - private IIcon getBlockTextureFromSideOutside(AEBaseBlock blk, TileSpatialPylon sp, int displayBits, ForgeDirection ori, ForgeDirection dir) - { - - if ( ori.equals( dir ) || ori.getOpposite().equals( dir ) ) - return blk.getRendererInstance().getTexture( dir ); - - if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_MIDDLE ) - return ExtraBlockTextures.BlockSpatialPylonC.getIcon(); - - else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMIN ) - return ExtraBlockTextures.BlockSpatialPylonE.getIcon(); - - else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) - return ExtraBlockTextures.BlockSpatialPylonE.getIcon(); - - return blk.getIcon( 0, 0 ); - } - - private IIcon getBlockTextureFromSideInside(AEBaseBlock blk, TileSpatialPylon sp, int displayBits, ForgeDirection ori, ForgeDirection dir) - { - boolean good = (displayBits & sp.DISPLAY_ENABLED) == sp.DISPLAY_ENABLED; - - if ( ori.equals( dir ) || ori.getOpposite().equals( dir ) ) - return good ? ExtraBlockTextures.BlockSpatialPylon_dim.getIcon() : ExtraBlockTextures.BlockSpatialPylon_red.getIcon(); - - if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_MIDDLE ) - return good ? ExtraBlockTextures.BlockSpatialPylonC_dim.getIcon() : ExtraBlockTextures.BlockSpatialPylonC_red.getIcon(); - - else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMIN ) - return good ? ExtraBlockTextures.BlockSpatialPylonE_dim.getIcon() : ExtraBlockTextures.BlockSpatialPylonE_red.getIcon(); - - else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) - return good ? ExtraBlockTextures.BlockSpatialPylonE_dim.getIcon() : ExtraBlockTextures.BlockSpatialPylonE_red.getIcon(); - - return blk.getIcon( 0, 0 ); - } -} +package appeng.client.render.blocks; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.BlockRenderInfo; +import appeng.client.texture.ExtraBlockTextures; +import appeng.tile.spatial.TileSpatialPylon; + +public class RenderSpatialPylon extends BaseBlockRender +{ + + public RenderSpatialPylon() { + super( false, 0 ); + } + + @Override + public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + renderer.overrideBlockTexture = ExtraBlockTextures.BlockSpatialPylon_dim.getIcon(); + super.renderInventory( block, is, renderer, type, obj ); + renderer.overrideBlockTexture = null; + super.renderInventory( block, is, renderer, type, obj ); + } + + @Override + public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); + + TileSpatialPylon sp = imb.getTileEntity( world, x, y, z ); + + int displayBits = sp.getDisplayBits(); + ForgeDirection ori = ForgeDirection.UNKNOWN; + + if ( displayBits != 0 ) + { + if ( (displayBits & sp.DISPLAY_Z) == sp.DISPLAY_X ) + { + ori = ForgeDirection.EAST; + if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) + { + renderer.uvRotateEast = 1; + renderer.uvRotateWest = 2; + renderer.uvRotateTop = 2; + renderer.uvRotateBottom = 1; + } + else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMIN ) + { + renderer.uvRotateEast = 2; + renderer.uvRotateWest = 1; + renderer.uvRotateTop = 1; + renderer.uvRotateBottom = 2; + } + else + { + renderer.uvRotateEast = 1; + renderer.uvRotateWest = 1; + renderer.uvRotateTop = 1; + renderer.uvRotateBottom = 1; + } + } + + else if ( (displayBits & sp.DISPLAY_Z) == sp.DISPLAY_Y ) + { + ori = ForgeDirection.UP; + if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) + { + renderer.uvRotateNorth = 3; + renderer.uvRotateSouth = 3; + renderer.uvRotateEast = 3; + renderer.uvRotateWest = 3; + } + } + + else if ( (displayBits & sp.DISPLAY_Z) == sp.DISPLAY_Z ) + { + ori = ForgeDirection.NORTH; + if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) + { + renderer.uvRotateSouth = 1; + renderer.uvRotateNorth = 2; + } + else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMIN ) + { + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 2; + renderer.uvRotateTop = 3; + renderer.uvRotateBottom = 3; + } + else + { + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 2; + } + } + + BlockRenderInfo bri = imb.getRendererInstance(); + bri.setTemporaryRenderIcon( null ); + bri.setTemporaryRenderIcons( getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.UP ), + getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.DOWN ), + getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.SOUTH ), + getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.NORTH ), + getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.EAST ), + getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.WEST ) ); + + boolean r = renderer.renderStandardBlock( imb, x, y, z ); + + if ( (displayBits & sp.DISPLAY_POWEREDENABLED) == sp.DISPLAY_POWEREDENABLED ) + { + int bn = 15; + Tessellator.instance.setBrightness( bn << 20 | bn << 4 ); + Tessellator.instance.setColorOpaque_I( 0xffffff ); + + for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) + renderFace( x, y, z, imb, getBlockTextureFromSideInside( imb, sp, displayBits, ori, d ), renderer, d ); + } + else + { + bri.setTemporaryRenderIcon( null ); + bri.setTemporaryRenderIcons( getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.UP ), + getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.DOWN ), + getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.SOUTH ), + getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.NORTH ), + getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.EAST ), + getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.WEST ) ); + + renderer.renderStandardBlock( imb, x, y, z ); + } + + bri.setTemporaryRenderIcon( null ); + renderer.uvRotateEast = renderer.uvRotateWest = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateBottom = 0; + + return r; + } + + renderer.overrideBlockTexture = imb.getIcon( 0, 0 ); + boolean result = renderer.renderStandardBlock( imb, x, y, z ); + + renderer.overrideBlockTexture = ExtraBlockTextures.BlockSpatialPylon_dim.getIcon(); + result = renderer.renderStandardBlock( imb, x, y, z ); + + renderer.overrideBlockTexture = null; + return result; + } + + private IIcon getBlockTextureFromSideOutside(AEBaseBlock blk, TileSpatialPylon sp, int displayBits, ForgeDirection ori, ForgeDirection dir) + { + + if ( ori.equals( dir ) || ori.getOpposite().equals( dir ) ) + return blk.getRendererInstance().getTexture( dir ); + + if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_MIDDLE ) + return ExtraBlockTextures.BlockSpatialPylonC.getIcon(); + + else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMIN ) + return ExtraBlockTextures.BlockSpatialPylonE.getIcon(); + + else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) + return ExtraBlockTextures.BlockSpatialPylonE.getIcon(); + + return blk.getIcon( 0, 0 ); + } + + private IIcon getBlockTextureFromSideInside(AEBaseBlock blk, TileSpatialPylon sp, int displayBits, ForgeDirection ori, ForgeDirection dir) + { + boolean good = (displayBits & sp.DISPLAY_ENABLED) == sp.DISPLAY_ENABLED; + + if ( ori.equals( dir ) || ori.getOpposite().equals( dir ) ) + return good ? ExtraBlockTextures.BlockSpatialPylon_dim.getIcon() : ExtraBlockTextures.BlockSpatialPylon_red.getIcon(); + + if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_MIDDLE ) + return good ? ExtraBlockTextures.BlockSpatialPylonC_dim.getIcon() : ExtraBlockTextures.BlockSpatialPylonC_red.getIcon(); + + else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMIN ) + return good ? ExtraBlockTextures.BlockSpatialPylonE_dim.getIcon() : ExtraBlockTextures.BlockSpatialPylonE_red.getIcon(); + + else if ( (displayBits & sp.DISPLAY_MIDDLE) == sp.DISPLAY_ENDMAX ) + return good ? ExtraBlockTextures.BlockSpatialPylonE_dim.getIcon() : ExtraBlockTextures.BlockSpatialPylonE_red.getIcon(); + + return blk.getIcon( 0, 0 ); + } +} diff --git a/client/render/blocks/RenderTinyTNT.java b/src/main/java/appeng/client/render/blocks/RenderTinyTNT.java similarity index 96% rename from client/render/blocks/RenderTinyTNT.java rename to src/main/java/appeng/client/render/blocks/RenderTinyTNT.java index ee7d3b6de..1f0838d95 100644 --- a/client/render/blocks/RenderTinyTNT.java +++ b/src/main/java/appeng/client/render/blocks/RenderTinyTNT.java @@ -1,34 +1,34 @@ -package appeng.client.render.blocks; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; - -public class RenderTinyTNT extends BaseBlockRender -{ - - public RenderTinyTNT() { - super( false, 0 ); - } - - @Override - public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - renderer.setRenderBounds( 0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f ); - super.renderInventory( block, is, renderer, type, obj ); - } - - @Override - public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - renderer.renderAllFaces = true; - renderer.setRenderBounds( 0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f ); - boolean out = super.renderInWorld( imb, world, x, y, z, renderer ); - renderer.renderAllFaces = false; - return out; - } - -} +package appeng.client.render.blocks; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; + +public class RenderTinyTNT extends BaseBlockRender +{ + + public RenderTinyTNT() { + super( false, 0 ); + } + + @Override + public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + renderer.setRenderBounds( 0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f ); + super.renderInventory( block, is, renderer, type, obj ); + } + + @Override + public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + renderer.renderAllFaces = true; + renderer.setRenderBounds( 0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f ); + boolean out = super.renderInWorld( imb, world, x, y, z, renderer ); + renderer.renderAllFaces = false; + return out; + } + +} diff --git a/client/render/blocks/RendererCableBus.java b/src/main/java/appeng/client/render/blocks/RendererCableBus.java similarity index 96% rename from client/render/blocks/RendererCableBus.java rename to src/main/java/appeng/client/render/blocks/RendererCableBus.java index f17e12ed3..13ca35e45 100644 --- a/client/render/blocks/RendererCableBus.java +++ b/src/main/java/appeng/client/render/blocks/RendererCableBus.java @@ -1,55 +1,55 @@ -package appeng.client.render.blocks; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.client.IItemRenderer.ItemRenderType; -import appeng.block.AEBaseBlock; -import appeng.client.render.BaseBlockRender; -import appeng.client.render.BusRenderHelper; -import appeng.client.render.BusRenderer; -import appeng.tile.AEBaseTile; -import appeng.tile.networking.TileCableBus; - -public class RendererCableBus extends BaseBlockRender -{ - - public RendererCableBus() { - super( true, 30 ); - } - - @Override - public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) - { - // nothing. - } - - @Override - public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) - { - AEBaseTile t = block.getTileEntity( world, x, y, z ); - - if ( t instanceof TileCableBus ) - { - BusRenderer.instance.renderer.renderAllFaces = true; - BusRenderer.instance.renderer.blockAccess = renderer.blockAccess; - BusRenderer.instance.renderer.overrideBlockTexture = renderer.overrideBlockTexture; - ((TileCableBus) t).cb.renderStatic( x, y, z ); - BusRenderer.instance.renderer.renderAllFaces = false; - } - - return BusRenderHelper.instance.getItemsRendered() > 0; - } - - @Override - public void renderTile(AEBaseBlock block, AEBaseTile t, Tessellator tess, double x, double y, double z, float f, RenderBlocks renderer) - { - if ( t instanceof TileCableBus ) - { - BusRenderer.instance.renderer.overrideBlockTexture = null; - ((TileCableBus) t).cb.renderDynamic( x, y, z ); - } - } - -} +package appeng.client.render.blocks; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import appeng.block.AEBaseBlock; +import appeng.client.render.BaseBlockRender; +import appeng.client.render.BusRenderHelper; +import appeng.client.render.BusRenderer; +import appeng.tile.AEBaseTile; +import appeng.tile.networking.TileCableBus; + +public class RendererCableBus extends BaseBlockRender +{ + + public RendererCableBus() { + super( true, 30 ); + } + + @Override + public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj) + { + // nothing. + } + + @Override + public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) + { + AEBaseTile t = block.getTileEntity( world, x, y, z ); + + if ( t instanceof TileCableBus ) + { + BusRenderer.instance.renderer.renderAllFaces = true; + BusRenderer.instance.renderer.blockAccess = renderer.blockAccess; + BusRenderer.instance.renderer.overrideBlockTexture = renderer.overrideBlockTexture; + ((TileCableBus) t).cb.renderStatic( x, y, z ); + BusRenderer.instance.renderer.renderAllFaces = false; + } + + return BusRenderHelper.instance.getItemsRendered() > 0; + } + + @Override + public void renderTile(AEBaseBlock block, AEBaseTile t, Tessellator tess, double x, double y, double z, float f, RenderBlocks renderer) + { + if ( t instanceof TileCableBus ) + { + BusRenderer.instance.renderer.overrideBlockTexture = null; + ((TileCableBus) t).cb.renderDynamic( x, y, z ); + } + } + +} diff --git a/client/render/blocks/RendererSecurity.java b/src/main/java/appeng/client/render/blocks/RendererSecurity.java similarity index 100% rename from client/render/blocks/RendererSecurity.java rename to src/main/java/appeng/client/render/blocks/RendererSecurity.java diff --git a/client/render/effects/AssemblerFX.java b/src/main/java/appeng/client/render/effects/AssemblerFX.java similarity index 100% rename from client/render/effects/AssemblerFX.java rename to src/main/java/appeng/client/render/effects/AssemblerFX.java diff --git a/client/render/effects/ChargedOreFX.java b/src/main/java/appeng/client/render/effects/ChargedOreFX.java similarity index 100% rename from client/render/effects/ChargedOreFX.java rename to src/main/java/appeng/client/render/effects/ChargedOreFX.java diff --git a/client/render/effects/CraftingFx.java b/src/main/java/appeng/client/render/effects/CraftingFx.java similarity index 100% rename from client/render/effects/CraftingFx.java rename to src/main/java/appeng/client/render/effects/CraftingFx.java diff --git a/client/render/effects/EnergyFx.java b/src/main/java/appeng/client/render/effects/EnergyFx.java similarity index 97% rename from client/render/effects/EnergyFx.java rename to src/main/java/appeng/client/render/effects/EnergyFx.java index c3f392a47..121ca3389 100644 --- a/client/render/effects/EnergyFx.java +++ b/src/main/java/appeng/client/render/effects/EnergyFx.java @@ -1,90 +1,90 @@ -package appeng.client.render.effects; - -import net.minecraft.client.particle.EntityBreakingFX; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.Item; -import net.minecraft.util.IIcon; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.client.texture.ExtraBlockTextures; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class EnergyFx extends EntityBreakingFX -{ - - private IIcon particleTextureIndex; - - private int startBlkX; - private int startBlkY; - private int startBlkZ; - - public int getFXLayer() - { - return 1; - } - - public EnergyFx(World par1World, double par2, double par4, double par6, Item par8Item) { - super( par1World, par2, par4, par6, par8Item ); - particleGravity = 0; - this.particleBlue = 255; - this.particleGreen = 255; - this.particleRed = 255; - this.particleAlpha = 1.4f; - this.particleScale = 3.5f; - this.particleTextureIndex = ExtraBlockTextures.BlockEnergyParticle.getIcon(); - - startBlkX = MathHelper.floor_double( posX ); - startBlkY = MathHelper.floor_double( posY ); - startBlkZ = MathHelper.floor_double( posZ ); - } - - public void fromItem(ForgeDirection d) - { - this.posX += 0.2 * d.offsetX; - this.posY += 0.2 * d.offsetY; - this.posZ += 0.2 * d.offsetZ; - this.particleScale *= 0.8f; - } - - public void onUpdate() - { - super.onUpdate(); - this.particleScale *= 0.89f; - this.particleAlpha *= 0.89f; - } - - public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) - { - float f6 = this.particleTextureIndex.getMinU(); - float f7 = this.particleTextureIndex.getMaxU(); - float f8 = this.particleTextureIndex.getMinV(); - float f9 = this.particleTextureIndex.getMaxV(); - float f10 = 0.1F * this.particleScale; - - float f11 = (float) (this.prevPosX + (this.posX - this.prevPosX) * (double) par2 - interpPosX); - float f12 = (float) (this.prevPosY + (this.posY - this.prevPosY) * (double) par2 - interpPosY); - float f13 = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * (double) par2 - interpPosZ); - float f14 = 1.0F; - - int blkX = MathHelper.floor_double( posX ); - int blkY = MathHelper.floor_double( posY ); - int blkZ = MathHelper.floor_double( posZ ); - - if ( blkX == startBlkX && blkY == startBlkY && blkZ == startBlkZ ) - { - par1Tessellator.setColorRGBA_F( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ); - par1Tessellator.addVertexWithUV( (double) (f11 - par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 - par5 * f10 - par7 * f10), - (double) f7, (double) f9 ); - par1Tessellator.addVertexWithUV( (double) (f11 - par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 - par5 * f10 + par7 * f10), - (double) f7, (double) f8 ); - par1Tessellator.addVertexWithUV( (double) (f11 + par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 + par5 * f10 + par7 * f10), - (double) f6, (double) f8 ); - par1Tessellator.addVertexWithUV( (double) (f11 + par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 + par5 * f10 - par7 * f10), - (double) f6, (double) f9 ); - } - } - -} +package appeng.client.render.effects; + +import net.minecraft.client.particle.EntityBreakingFX; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.Item; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.client.texture.ExtraBlockTextures; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class EnergyFx extends EntityBreakingFX +{ + + private IIcon particleTextureIndex; + + private int startBlkX; + private int startBlkY; + private int startBlkZ; + + public int getFXLayer() + { + return 1; + } + + public EnergyFx(World par1World, double par2, double par4, double par6, Item par8Item) { + super( par1World, par2, par4, par6, par8Item ); + particleGravity = 0; + this.particleBlue = 255; + this.particleGreen = 255; + this.particleRed = 255; + this.particleAlpha = 1.4f; + this.particleScale = 3.5f; + this.particleTextureIndex = ExtraBlockTextures.BlockEnergyParticle.getIcon(); + + startBlkX = MathHelper.floor_double( posX ); + startBlkY = MathHelper.floor_double( posY ); + startBlkZ = MathHelper.floor_double( posZ ); + } + + public void fromItem(ForgeDirection d) + { + this.posX += 0.2 * d.offsetX; + this.posY += 0.2 * d.offsetY; + this.posZ += 0.2 * d.offsetZ; + this.particleScale *= 0.8f; + } + + public void onUpdate() + { + super.onUpdate(); + this.particleScale *= 0.89f; + this.particleAlpha *= 0.89f; + } + + public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) + { + float f6 = this.particleTextureIndex.getMinU(); + float f7 = this.particleTextureIndex.getMaxU(); + float f8 = this.particleTextureIndex.getMinV(); + float f9 = this.particleTextureIndex.getMaxV(); + float f10 = 0.1F * this.particleScale; + + float f11 = (float) (this.prevPosX + (this.posX - this.prevPosX) * (double) par2 - interpPosX); + float f12 = (float) (this.prevPosY + (this.posY - this.prevPosY) * (double) par2 - interpPosY); + float f13 = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * (double) par2 - interpPosZ); + float f14 = 1.0F; + + int blkX = MathHelper.floor_double( posX ); + int blkY = MathHelper.floor_double( posY ); + int blkZ = MathHelper.floor_double( posZ ); + + if ( blkX == startBlkX && blkY == startBlkY && blkZ == startBlkZ ) + { + par1Tessellator.setColorRGBA_F( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha ); + par1Tessellator.addVertexWithUV( (double) (f11 - par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 - par5 * f10 - par7 * f10), + (double) f7, (double) f9 ); + par1Tessellator.addVertexWithUV( (double) (f11 - par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 - par5 * f10 + par7 * f10), + (double) f7, (double) f8 ); + par1Tessellator.addVertexWithUV( (double) (f11 + par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 + par5 * f10 + par7 * f10), + (double) f6, (double) f8 ); + par1Tessellator.addVertexWithUV( (double) (f11 + par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 + par5 * f10 - par7 * f10), + (double) f6, (double) f9 ); + } + } + +} diff --git a/client/render/effects/LightningArcFX.java b/src/main/java/appeng/client/render/effects/LightningArcFX.java similarity index 100% rename from client/render/effects/LightningArcFX.java rename to src/main/java/appeng/client/render/effects/LightningArcFX.java diff --git a/client/render/effects/LightningFX.java b/src/main/java/appeng/client/render/effects/LightningFX.java similarity index 100% rename from client/render/effects/LightningFX.java rename to src/main/java/appeng/client/render/effects/LightningFX.java diff --git a/client/render/effects/MatterCannonFX.java b/src/main/java/appeng/client/render/effects/MatterCannonFX.java similarity index 100% rename from client/render/effects/MatterCannonFX.java rename to src/main/java/appeng/client/render/effects/MatterCannonFX.java diff --git a/client/render/effects/VibrantFX.java b/src/main/java/appeng/client/render/effects/VibrantFX.java similarity index 100% rename from client/render/effects/VibrantFX.java rename to src/main/java/appeng/client/render/effects/VibrantFX.java diff --git a/client/render/items/ItemEncodedPatternRenderer.java b/src/main/java/appeng/client/render/items/ItemEncodedPatternRenderer.java similarity index 100% rename from client/render/items/ItemEncodedPatternRenderer.java rename to src/main/java/appeng/client/render/items/ItemEncodedPatternRenderer.java diff --git a/client/render/items/PaintBallRender.java b/src/main/java/appeng/client/render/items/PaintBallRender.java similarity index 100% rename from client/render/items/PaintBallRender.java rename to src/main/java/appeng/client/render/items/PaintBallRender.java diff --git a/client/render/items/ToolBiometricCardRender.java b/src/main/java/appeng/client/render/items/ToolBiometricCardRender.java similarity index 100% rename from client/render/items/ToolBiometricCardRender.java rename to src/main/java/appeng/client/render/items/ToolBiometricCardRender.java diff --git a/client/render/items/ToolColorApplicatorRender.java b/src/main/java/appeng/client/render/items/ToolColorApplicatorRender.java similarity index 100% rename from client/render/items/ToolColorApplicatorRender.java rename to src/main/java/appeng/client/render/items/ToolColorApplicatorRender.java diff --git a/client/render/model/ModelCompass.java b/src/main/java/appeng/client/render/model/ModelCompass.java similarity index 100% rename from client/render/model/ModelCompass.java rename to src/main/java/appeng/client/render/model/ModelCompass.java diff --git a/client/texture/CableBusTextures.java b/src/main/java/appeng/client/texture/CableBusTextures.java similarity index 98% rename from client/texture/CableBusTextures.java rename to src/main/java/appeng/client/texture/CableBusTextures.java index 514dc9e7d..9e137c668 100644 --- a/client/texture/CableBusTextures.java +++ b/src/main/java/appeng/client/texture/CableBusTextures.java @@ -1,104 +1,104 @@ -package appeng.client.texture; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public enum CableBusTextures -{ - - Channels00("MECableSmart00"), Channels01("MECableSmart01"), Channels02("MECableSmart02"), Channels03("MECableSmart03"), Channels10("MECableSmart10"), Channels11( - "MECableSmart11"), Channels12("MECableSmart12"), Channels13("MECableSmart13"), Channels14("MECableSmart14"), Channels04("MECableSmart04"), - - LevelEmitterTorchOn("ItemPart.LevelEmitterOn"), BlockWirelessOn("BlockWirelessOn"), - - BlockP2PTunnel2("ItemPart.P2PTunnel2"), BlockP2PTunnel3("ItemPart.P2PTunnel3"), - - // MEWaiting("MEWaiting"), - - PartMonitorSides("PartMonitorSides"), PartMonitorBack("PartMonitorBack"), - - Transparent("Transparent"), PartMonitorSidesStatus("PartMonitorSidesStatus"), PartMonitorSidesStatusLights("PartMonitorSidesStatusLights"), - - PartMonitor_Colored("PartMonitor_Colored"), PartMonitor_Bright("PartMonitor_Bright"), - - PartPatternTerm_Bright("PartPatternTerm_Bright"), PartPatternTerm_Colored("PartPatternTerm_Colored"), PartPatternTerm_Dark("PartPatternTerm_Dark"), - - PartConvMonitor_Bright("PartConvMonitor_Bright"), PartConvMonitor_Colored("PartConvMonitor_Colored"), PartConvMonitor_Dark("PartConvMonitor_Dark"), - - PartInterfaceTerm_Bright("PartInterfaceTerm_Bright"), PartInterfaceTerm_Colored("PartInterfaceTerm_Colored"), PartInterfaceTerm_Dark( - "PartInterfaceTerm_Dark"), - - PartCraftingTerm_Bright("PartCraftingTerm_Bright"), PartCraftingTerm_Colored("PartCraftingTerm_Colored"), PartCraftingTerm_Dark("PartCraftingTerm_Dark"), // - - PartStorageMonitor_Bright("PartStorageMonitor_Bright"), PartStorageMonitor_Colored("PartStorageMonitor_Colored"), PartStorageMonitor_Dark( - "PartStorageMonitor_Dark"), - - PartTerminal_Bright("PartTerminal_Bright"), PartTerminal_Colored("PartTerminal_Colored"), PartTerminal_Dark("PartTerminal_Dark"), - - MECable_Green("MECable_Green"), MECable_Grey("MECable_Grey"), MECable_LightBlue("MECable_LightBlue"), MECable_LightGrey("MECable_LightGrey"), MECable_Lime( - "MECable_Lime"), MECable_Magenta("MECable_Magenta"), MECable_Orange("MECable_Orange"), MECable_Pink("MECable_Pink"), MECable_Purple( - "MECable_Purple"), MECable_Red("MECable_Red"), MECable_White("MECable_White"), MECable_Yellow("MECable_Yellow"), MECable_Black("MECable_Black"), MECable_Blue( - "MECable_Blue"), MECable_Brown("MECable_Brown"), MECable_Cyan("MECable_Cyan"), - - MEDense_Black("MEDense_Black"), MEDense_Blue("MEDense_Blue"), MEDense_Brown("MEDense_Brown"), MEDense_Cyan("MEDense_Cyan"), MEDense_Gray("MEDense_Gray"), MEDense_Green( - "MEDense_Green"), MEDense_LightBlue("MEDense_LightBlue"), MEDense_LightGrey("MEDense_LightGrey"), MEDense_Lime("MEDense_Lime"), MEDense_Magenta( - "MEDense_Magenta"), MEDense_Orange("MEDense_Orange"), MEDense_Pink("MEDense_Pink"), MEDense_Purple("MEDense_Purple"), MEDense_Red("MEDense_Red"), MEDense_White( - "MEDense_White"), MEDense_Yellow("MEDense_Yellow"), - - MESmart_Black("MESmart_Black"), MESmart_Blue("MESmart_Blue"), MESmart_Brown("MESmart_Brown"), MESmart_Cyan("MESmart_Cyan"), MESmart_Gray("MESmart_Gray"), MESmart_Green( - "MESmart_Green"), MESmart_LightBlue("MESmart_LightBlue"), MESmart_LightGrey("MESmart_LightGrey"), MESmart_Lime("MESmart_Lime"), MESmart_Magenta( - "MESmart_Magenta"), MESmart_Orange("MESmart_Orange"), MESmart_Pink("MESmart_Pink"), MESmart_Purple("MESmart_Purple"), MESmart_Red("MESmart_Red"), MESmart_White( - "MESmart_White"), MESmart_Yellow("MESmart_Yellow"), - - MECovered_Black("MECovered_Black"), MECovered_Blue("MECovered_Blue"), MECovered_Brown("MECovered_Brown"), MECovered_Cyan("MECovered_Cyan"), MECovered_Gray( - "MECovered_Gray"), MECovered_Green("MECovered_Green"), MECovered_LightBlue("MECovered_LightBlue"), MECovered_LightGrey("MECovered_LightGrey"), MECovered_Lime( - "MECovered_Lime"), MECovered_Magenta("MECovered_Magenta"), MECovered_Orange("MECovered_Orange"), MECovered_Pink("MECovered_Pink"), MECovered_Purple( - "MECovered_Purple"), MECovered_Red("MECovered_Red"), MECovered_White("MECovered_White"), MECovered_Yellow("MECovered_Yellow"), - - BlockAnnihilationPlaneOn("BlockAnnihilationPlaneOn"), - - BlockFormPlaneOn("BlockFormPlaneOn"), - - ItemPartLevelEmitterOn("ItemPart.LevelEmitterOn"), PartTransitionPlaneBack("PartTransitionPlaneBack"), - - PartTunnelSides("PartTunnelSides"), PartPlaneSides("PartPlaneSides"), PartExportSides("PartExportSides"), PartImportSides("PartImportSides"), - - PartWirelessSides("PartWirelessSides"), PartStorageSides("PartStorageSides"), PartStorageBack("PartStorageBack"); - - final private String name; - public IIcon IIcon; - - public static ResourceLocation GuiTexture(String string) - { - return null; - } - - public String getName() - { - return name; - } - - private CableBusTextures(String name) { - this.name = name; - } - - public IIcon getIcon() - { - return IIcon; - } - - public void registerIcon(TextureMap map) - { - IIcon = map.registerIcon( "appliedenergistics2:" + name ); - } - - @SideOnly(Side.CLIENT) - public static IIcon getMissing() - { - return ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture( TextureMap.locationBlocksTexture )).getAtlasSprite( "missingno" ); - } -} +package appeng.client.texture; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public enum CableBusTextures +{ + + Channels00("MECableSmart00"), Channels01("MECableSmart01"), Channels02("MECableSmart02"), Channels03("MECableSmart03"), Channels10("MECableSmart10"), Channels11( + "MECableSmart11"), Channels12("MECableSmart12"), Channels13("MECableSmart13"), Channels14("MECableSmart14"), Channels04("MECableSmart04"), + + LevelEmitterTorchOn("ItemPart.LevelEmitterOn"), BlockWirelessOn("BlockWirelessOn"), + + BlockP2PTunnel2("ItemPart.P2PTunnel2"), BlockP2PTunnel3("ItemPart.P2PTunnel3"), + + // MEWaiting("MEWaiting"), + + PartMonitorSides("PartMonitorSides"), PartMonitorBack("PartMonitorBack"), + + Transparent("Transparent"), PartMonitorSidesStatus("PartMonitorSidesStatus"), PartMonitorSidesStatusLights("PartMonitorSidesStatusLights"), + + PartMonitor_Colored("PartMonitor_Colored"), PartMonitor_Bright("PartMonitor_Bright"), + + PartPatternTerm_Bright("PartPatternTerm_Bright"), PartPatternTerm_Colored("PartPatternTerm_Colored"), PartPatternTerm_Dark("PartPatternTerm_Dark"), + + PartConvMonitor_Bright("PartConvMonitor_Bright"), PartConvMonitor_Colored("PartConvMonitor_Colored"), PartConvMonitor_Dark("PartConvMonitor_Dark"), + + PartInterfaceTerm_Bright("PartInterfaceTerm_Bright"), PartInterfaceTerm_Colored("PartInterfaceTerm_Colored"), PartInterfaceTerm_Dark( + "PartInterfaceTerm_Dark"), + + PartCraftingTerm_Bright("PartCraftingTerm_Bright"), PartCraftingTerm_Colored("PartCraftingTerm_Colored"), PartCraftingTerm_Dark("PartCraftingTerm_Dark"), // + + PartStorageMonitor_Bright("PartStorageMonitor_Bright"), PartStorageMonitor_Colored("PartStorageMonitor_Colored"), PartStorageMonitor_Dark( + "PartStorageMonitor_Dark"), + + PartTerminal_Bright("PartTerminal_Bright"), PartTerminal_Colored("PartTerminal_Colored"), PartTerminal_Dark("PartTerminal_Dark"), + + MECable_Green("MECable_Green"), MECable_Grey("MECable_Grey"), MECable_LightBlue("MECable_LightBlue"), MECable_LightGrey("MECable_LightGrey"), MECable_Lime( + "MECable_Lime"), MECable_Magenta("MECable_Magenta"), MECable_Orange("MECable_Orange"), MECable_Pink("MECable_Pink"), MECable_Purple( + "MECable_Purple"), MECable_Red("MECable_Red"), MECable_White("MECable_White"), MECable_Yellow("MECable_Yellow"), MECable_Black("MECable_Black"), MECable_Blue( + "MECable_Blue"), MECable_Brown("MECable_Brown"), MECable_Cyan("MECable_Cyan"), + + MEDense_Black("MEDense_Black"), MEDense_Blue("MEDense_Blue"), MEDense_Brown("MEDense_Brown"), MEDense_Cyan("MEDense_Cyan"), MEDense_Gray("MEDense_Gray"), MEDense_Green( + "MEDense_Green"), MEDense_LightBlue("MEDense_LightBlue"), MEDense_LightGrey("MEDense_LightGrey"), MEDense_Lime("MEDense_Lime"), MEDense_Magenta( + "MEDense_Magenta"), MEDense_Orange("MEDense_Orange"), MEDense_Pink("MEDense_Pink"), MEDense_Purple("MEDense_Purple"), MEDense_Red("MEDense_Red"), MEDense_White( + "MEDense_White"), MEDense_Yellow("MEDense_Yellow"), + + MESmart_Black("MESmart_Black"), MESmart_Blue("MESmart_Blue"), MESmart_Brown("MESmart_Brown"), MESmart_Cyan("MESmart_Cyan"), MESmart_Gray("MESmart_Gray"), MESmart_Green( + "MESmart_Green"), MESmart_LightBlue("MESmart_LightBlue"), MESmart_LightGrey("MESmart_LightGrey"), MESmart_Lime("MESmart_Lime"), MESmart_Magenta( + "MESmart_Magenta"), MESmart_Orange("MESmart_Orange"), MESmart_Pink("MESmart_Pink"), MESmart_Purple("MESmart_Purple"), MESmart_Red("MESmart_Red"), MESmart_White( + "MESmart_White"), MESmart_Yellow("MESmart_Yellow"), + + MECovered_Black("MECovered_Black"), MECovered_Blue("MECovered_Blue"), MECovered_Brown("MECovered_Brown"), MECovered_Cyan("MECovered_Cyan"), MECovered_Gray( + "MECovered_Gray"), MECovered_Green("MECovered_Green"), MECovered_LightBlue("MECovered_LightBlue"), MECovered_LightGrey("MECovered_LightGrey"), MECovered_Lime( + "MECovered_Lime"), MECovered_Magenta("MECovered_Magenta"), MECovered_Orange("MECovered_Orange"), MECovered_Pink("MECovered_Pink"), MECovered_Purple( + "MECovered_Purple"), MECovered_Red("MECovered_Red"), MECovered_White("MECovered_White"), MECovered_Yellow("MECovered_Yellow"), + + BlockAnnihilationPlaneOn("BlockAnnihilationPlaneOn"), + + BlockFormPlaneOn("BlockFormPlaneOn"), + + ItemPartLevelEmitterOn("ItemPart.LevelEmitterOn"), PartTransitionPlaneBack("PartTransitionPlaneBack"), + + PartTunnelSides("PartTunnelSides"), PartPlaneSides("PartPlaneSides"), PartExportSides("PartExportSides"), PartImportSides("PartImportSides"), + + PartWirelessSides("PartWirelessSides"), PartStorageSides("PartStorageSides"), PartStorageBack("PartStorageBack"); + + final private String name; + public IIcon IIcon; + + public static ResourceLocation GuiTexture(String string) + { + return null; + } + + public String getName() + { + return name; + } + + private CableBusTextures(String name) { + this.name = name; + } + + public IIcon getIcon() + { + return IIcon; + } + + public void registerIcon(TextureMap map) + { + IIcon = map.registerIcon( "appliedenergistics2:" + name ); + } + + @SideOnly(Side.CLIENT) + public static IIcon getMissing() + { + return ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture( TextureMap.locationBlocksTexture )).getAtlasSprite( "missingno" ); + } +} diff --git a/client/texture/ExtraBlockTextures.java b/src/main/java/appeng/client/texture/ExtraBlockTextures.java similarity index 100% rename from client/texture/ExtraBlockTextures.java rename to src/main/java/appeng/client/texture/ExtraBlockTextures.java diff --git a/client/texture/ExtraItemTextures.java b/src/main/java/appeng/client/texture/ExtraItemTextures.java similarity index 100% rename from client/texture/ExtraItemTextures.java rename to src/main/java/appeng/client/texture/ExtraItemTextures.java diff --git a/client/texture/FlippableIcon.java b/src/main/java/appeng/client/texture/FlippableIcon.java similarity index 100% rename from client/texture/FlippableIcon.java rename to src/main/java/appeng/client/texture/FlippableIcon.java diff --git a/client/texture/FullIcon.java b/src/main/java/appeng/client/texture/FullIcon.java similarity index 100% rename from client/texture/FullIcon.java rename to src/main/java/appeng/client/texture/FullIcon.java diff --git a/client/texture/MissingIcon.java b/src/main/java/appeng/client/texture/MissingIcon.java similarity index 100% rename from client/texture/MissingIcon.java rename to src/main/java/appeng/client/texture/MissingIcon.java diff --git a/client/texture/OffsetIcon.java b/src/main/java/appeng/client/texture/OffsetIcon.java similarity index 100% rename from client/texture/OffsetIcon.java rename to src/main/java/appeng/client/texture/OffsetIcon.java diff --git a/client/texture/TaughtIcon.java b/src/main/java/appeng/client/texture/TaughtIcon.java similarity index 100% rename from client/texture/TaughtIcon.java rename to src/main/java/appeng/client/texture/TaughtIcon.java diff --git a/client/texture/TmpFlippableIcon.java b/src/main/java/appeng/client/texture/TmpFlippableIcon.java similarity index 100% rename from client/texture/TmpFlippableIcon.java rename to src/main/java/appeng/client/texture/TmpFlippableIcon.java diff --git a/container/AEBaseContainer.java b/src/main/java/appeng/container/AEBaseContainer.java similarity index 100% rename from container/AEBaseContainer.java rename to src/main/java/appeng/container/AEBaseContainer.java diff --git a/container/ContainerNull.java b/src/main/java/appeng/container/ContainerNull.java similarity index 94% rename from container/ContainerNull.java rename to src/main/java/appeng/container/ContainerNull.java index 79f110d77..0788e722d 100644 --- a/container/ContainerNull.java +++ b/src/main/java/appeng/container/ContainerNull.java @@ -1,18 +1,18 @@ -package appeng.container; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; - -/* - * Totaly useless container that does nothing. - */ -public class ContainerNull extends Container -{ - - @Override - public boolean canInteractWith(EntityPlayer entityplayer) - { - return false; - } - -} +package appeng.container; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; + +/* + * Totaly useless container that does nothing. + */ +public class ContainerNull extends Container +{ + + @Override + public boolean canInteractWith(EntityPlayer entityplayer) + { + return false; + } + +} diff --git a/container/ContainerOpenContext.java b/src/main/java/appeng/container/ContainerOpenContext.java similarity index 100% rename from container/ContainerOpenContext.java rename to src/main/java/appeng/container/ContainerOpenContext.java diff --git a/container/guisync/GuiSync.java b/src/main/java/appeng/container/guisync/GuiSync.java similarity index 100% rename from container/guisync/GuiSync.java rename to src/main/java/appeng/container/guisync/GuiSync.java diff --git a/container/guisync/SyncDat.java b/src/main/java/appeng/container/guisync/SyncDat.java similarity index 100% rename from container/guisync/SyncDat.java rename to src/main/java/appeng/container/guisync/SyncDat.java diff --git a/container/implementations/ContainerCellWorkbench.java b/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java similarity index 100% rename from container/implementations/ContainerCellWorkbench.java rename to src/main/java/appeng/container/implementations/ContainerCellWorkbench.java diff --git a/container/implementations/ContainerChest.java b/src/main/java/appeng/container/implementations/ContainerChest.java similarity index 96% rename from container/implementations/ContainerChest.java rename to src/main/java/appeng/container/implementations/ContainerChest.java index 7902df12a..7f44fac14 100644 --- a/container/implementations/ContainerChest.java +++ b/src/main/java/appeng/container/implementations/ContainerChest.java @@ -1,22 +1,22 @@ -package appeng.container.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import appeng.container.AEBaseContainer; -import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.storage.TileChest; - -public class ContainerChest extends AEBaseContainer -{ - - TileChest myte; - - public ContainerChest(InventoryPlayer ip, TileChest te) { - super( ip, te, null ); - myte = te; - - addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, myte, 1, 80, 37, invPlayer ) ); - - bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 ); - } - -} +package appeng.container.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import appeng.container.AEBaseContainer; +import appeng.container.slot.SlotRestrictedInput; +import appeng.tile.storage.TileChest; + +public class ContainerChest extends AEBaseContainer +{ + + TileChest myte; + + public ContainerChest(InventoryPlayer ip, TileChest te) { + super( ip, te, null ); + myte = te; + + addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, myte, 1, 80, 37, invPlayer ) ); + + bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 ); + } + +} diff --git a/container/implementations/ContainerCondenser.java b/src/main/java/appeng/container/implementations/ContainerCondenser.java similarity index 100% rename from container/implementations/ContainerCondenser.java rename to src/main/java/appeng/container/implementations/ContainerCondenser.java diff --git a/container/implementations/ContainerCraftAmount.java b/src/main/java/appeng/container/implementations/ContainerCraftAmount.java similarity index 100% rename from container/implementations/ContainerCraftAmount.java rename to src/main/java/appeng/container/implementations/ContainerCraftAmount.java diff --git a/container/implementations/ContainerCraftConfirm.java b/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java similarity index 100% rename from container/implementations/ContainerCraftConfirm.java rename to src/main/java/appeng/container/implementations/ContainerCraftConfirm.java diff --git a/container/implementations/ContainerCraftingCPU.java b/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java similarity index 100% rename from container/implementations/ContainerCraftingCPU.java rename to src/main/java/appeng/container/implementations/ContainerCraftingCPU.java diff --git a/container/implementations/ContainerCraftingStatus.java b/src/main/java/appeng/container/implementations/ContainerCraftingStatus.java similarity index 100% rename from container/implementations/ContainerCraftingStatus.java rename to src/main/java/appeng/container/implementations/ContainerCraftingStatus.java diff --git a/container/implementations/ContainerCraftingTerm.java b/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java similarity index 100% rename from container/implementations/ContainerCraftingTerm.java rename to src/main/java/appeng/container/implementations/ContainerCraftingTerm.java diff --git a/container/implementations/ContainerDrive.java b/src/main/java/appeng/container/implementations/ContainerDrive.java similarity index 96% rename from container/implementations/ContainerDrive.java rename to src/main/java/appeng/container/implementations/ContainerDrive.java index 2e4b21a50..046f8e3e9 100644 --- a/container/implementations/ContainerDrive.java +++ b/src/main/java/appeng/container/implementations/ContainerDrive.java @@ -1,26 +1,26 @@ -package appeng.container.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import appeng.container.AEBaseContainer; -import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.storage.TileDrive; - -public class ContainerDrive extends AEBaseContainer -{ - - TileDrive myte; - - public ContainerDrive(InventoryPlayer ip, TileDrive te) { - super( ip, te, null ); - myte = te; - - for (int y = 0; y < 5; y++) - for (int x = 0; x < 2; x++) - { - addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, te, x + y * 2, 71 + x * 18, 14 + y * 18, invPlayer ) ); - } - - bindPlayerInventory( ip, 0, 199 - /* height of playerinventory */82 ); - } - -} +package appeng.container.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import appeng.container.AEBaseContainer; +import appeng.container.slot.SlotRestrictedInput; +import appeng.tile.storage.TileDrive; + +public class ContainerDrive extends AEBaseContainer +{ + + TileDrive myte; + + public ContainerDrive(InventoryPlayer ip, TileDrive te) { + super( ip, te, null ); + myte = te; + + for (int y = 0; y < 5; y++) + for (int x = 0; x < 2; x++) + { + addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, te, x + y * 2, 71 + x * 18, 14 + y * 18, invPlayer ) ); + } + + bindPlayerInventory( ip, 0, 199 - /* height of playerinventory */82 ); + } + +} diff --git a/container/implementations/ContainerFormationPlane.java b/src/main/java/appeng/container/implementations/ContainerFormationPlane.java similarity index 100% rename from container/implementations/ContainerFormationPlane.java rename to src/main/java/appeng/container/implementations/ContainerFormationPlane.java diff --git a/container/implementations/ContainerGrinder.java b/src/main/java/appeng/container/implementations/ContainerGrinder.java similarity index 97% rename from container/implementations/ContainerGrinder.java rename to src/main/java/appeng/container/implementations/ContainerGrinder.java index 7a59dd350..b7f6bb902 100644 --- a/container/implementations/ContainerGrinder.java +++ b/src/main/java/appeng/container/implementations/ContainerGrinder.java @@ -1,32 +1,32 @@ -package appeng.container.implementations; - -import appeng.container.slot.SlotInaccessible; -import net.minecraft.entity.player.InventoryPlayer; -import appeng.container.AEBaseContainer; -import appeng.container.slot.SlotOutput; -import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.grindstone.TileGrinder; - -public class ContainerGrinder extends AEBaseContainer -{ - - TileGrinder myte; - - public ContainerGrinder(InventoryPlayer ip, TileGrinder te) { - super( ip, te, null ); - myte = te; - - addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 0, 12, 17, invPlayer ) ); - addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 1, 12 + 18, 17, invPlayer ) ); - addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 2, 12 + 36, 17, invPlayer ) ); - - addSlotToContainer( new SlotInaccessible( te, 6, 80, 40 ) ); - - addSlotToContainer( new SlotOutput( te, 3, 112, 63, 2 * 16 + 15 ) ); - addSlotToContainer( new SlotOutput( te, 4, 112 + 18, 63, 2 * 16 + 15 ) ); - addSlotToContainer( new SlotOutput( te, 5, 112 + 36, 63, 2 * 16 + 15 ) ); - - bindPlayerInventory( ip, 0, 176 - /* height of playerinventory */82 ); - } - -} +package appeng.container.implementations; + +import appeng.container.slot.SlotInaccessible; +import net.minecraft.entity.player.InventoryPlayer; +import appeng.container.AEBaseContainer; +import appeng.container.slot.SlotOutput; +import appeng.container.slot.SlotRestrictedInput; +import appeng.tile.grindstone.TileGrinder; + +public class ContainerGrinder extends AEBaseContainer +{ + + TileGrinder myte; + + public ContainerGrinder(InventoryPlayer ip, TileGrinder te) { + super( ip, te, null ); + myte = te; + + addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 0, 12, 17, invPlayer ) ); + addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 1, 12 + 18, 17, invPlayer ) ); + addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 2, 12 + 36, 17, invPlayer ) ); + + addSlotToContainer( new SlotInaccessible( te, 6, 80, 40 ) ); + + addSlotToContainer( new SlotOutput( te, 3, 112, 63, 2 * 16 + 15 ) ); + addSlotToContainer( new SlotOutput( te, 4, 112 + 18, 63, 2 * 16 + 15 ) ); + addSlotToContainer( new SlotOutput( te, 5, 112 + 36, 63, 2 * 16 + 15 ) ); + + bindPlayerInventory( ip, 0, 176 - /* height of playerinventory */82 ); + } + +} diff --git a/container/implementations/ContainerIOPort.java b/src/main/java/appeng/container/implementations/ContainerIOPort.java similarity index 100% rename from container/implementations/ContainerIOPort.java rename to src/main/java/appeng/container/implementations/ContainerIOPort.java diff --git a/container/implementations/ContainerInscriber.java b/src/main/java/appeng/container/implementations/ContainerInscriber.java similarity index 100% rename from container/implementations/ContainerInscriber.java rename to src/main/java/appeng/container/implementations/ContainerInscriber.java diff --git a/container/implementations/ContainerInterface.java b/src/main/java/appeng/container/implementations/ContainerInterface.java similarity index 100% rename from container/implementations/ContainerInterface.java rename to src/main/java/appeng/container/implementations/ContainerInterface.java diff --git a/container/implementations/ContainerInterfaceTerminal.java b/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java similarity index 96% rename from container/implementations/ContainerInterfaceTerminal.java rename to src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java index bbcbd375d..9b1c78698 100644 --- a/container/implementations/ContainerInterfaceTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java @@ -1,373 +1,373 @@ -package appeng.container.implementations; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.Settings; -import appeng.api.config.YesNo; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.IActionHost; -import appeng.container.AEBaseContainer; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketCompressedNBT; -import appeng.helpers.DualityInterface; -import appeng.helpers.IInterfaceHost; -import appeng.helpers.InventoryAction; -import appeng.items.misc.ItemEncodedPattern; -import appeng.parts.misc.PartInterface; -import appeng.parts.reporting.PartMonitor; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.misc.TileInterface; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.AdaptorIInventory; -import appeng.util.inv.AdaptorPlayerHand; -import appeng.util.inv.WrapperInvSlot; - -public class ContainerInterfaceTerminal extends AEBaseContainer -{ - - /** - * this stuff is all server side.. - */ - - static private long autoBase = Long.MIN_VALUE; - - class InvTracker - { - - long which = autoBase++; - String unlocalizedName; - - public InvTracker(DualityInterface dual, IInventory patterns, String unlocalizedName) { - server = patterns; - client = new AppEngInternalInventory( null, server.getSizeInventory() ); - this.unlocalizedName = unlocalizedName; - this.sortBy = dual.getSortValue(); - } - - IInventory client; - IInventory server; - public long sortBy; - - }; - - Map diList = new HashMap(); - Map byId = new HashMap(); - IGrid g; - - public ContainerInterfaceTerminal(InventoryPlayer ip, PartMonitor anchor) { - super( ip, anchor ); - - if ( Platform.isServer() ) - g = anchor.getActionableNode().getGrid(); - - bindPlayerInventory( ip, 0, 222 - /* height of playerinventory */82 ); - } - - NBTTagCompound data = new NBTTagCompound(); - - class PatternInvSlot extends WrapperInvSlot - { - - public PatternInvSlot(IInventory inv) { - super( inv ); - } - - @Override - public boolean isItemValid(ItemStack itemstack) - { - return itemstack != null && itemstack.getItem() instanceof ItemEncodedPattern; - } - - }; - - @Override - public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id) - { - InvTracker inv = byId.get( id ); - if ( inv != null ) - { - ItemStack is = inv.server.getStackInSlot( slot ); - boolean hasItemInHand = player.inventory.getItemStack() != null; - - InventoryAdaptor playerHand = new AdaptorPlayerHand( player ); - - WrapperInvSlot slotInv = new PatternInvSlot( inv.server ); - - IInventory theSlot = slotInv.getWrapper( slot ); - InventoryAdaptor interfaceSlot = new AdaptorIInventory( theSlot ); - - switch (action) - { - case PICKUP_OR_SETDOWN: - - if ( hasItemInHand ) - { - ItemStack inSlot = theSlot.getStackInSlot( 0 ); - if ( inSlot == null ) - player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) ); - else - { - inSlot = inSlot.copy(); - ItemStack inHand = player.inventory.getItemStack().copy(); - - theSlot.setInventorySlotContents( 0, null ); - player.inventory.setItemStack( null ); - - player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) ); - - if ( player.inventory.getItemStack() == null ) - player.inventory.setItemStack( inSlot ); - else - { - player.inventory.setItemStack( inHand ); - theSlot.setInventorySlotContents( 0, inSlot ); - } - } - } - else - { - IInventory mySlot = slotInv.getWrapper( slot ); - mySlot.setInventorySlotContents( 0, playerHand.addItems( mySlot.getStackInSlot( 0 ) ) ); - } - - break; - case SPLIT_OR_PLACESINGLE: - - if ( hasItemInHand ) - { - ItemStack extra = playerHand.removeItems( 1, null, null ); - if ( extra != null ) - extra = interfaceSlot.addItems( extra ); - if ( extra != null ) - playerHand.addItems( extra ); - } - else if ( is != null ) - { - ItemStack extra = interfaceSlot.removeItems( (is.stackSize + 1) / 2, null, null ); - if ( extra != null ) - extra = playerHand.addItems( extra ); - if ( extra != null ) - interfaceSlot.addItems( extra ); - } - - break; - case SHIFT_CLICK: - - IInventory mySlot = slotInv.getWrapper( slot ); - InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN ); - mySlot.setInventorySlotContents( 0, playerInv.addItems( mySlot.getStackInSlot( 0 ) ) ); - - break; - case MOVE_REGION: - - InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN ); - for (int x = 0; x < inv.server.getSizeInventory(); x++) - { - inv.server.setInventorySlotContents( x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) ); - } - - break; - case CREATIVE_DUPLICATE: - - if ( player.capabilities.isCreativeMode && !hasItemInHand ) - { - player.inventory.setItemStack( is == null ? null : is.copy() ); - } - - break; - default: - return; - } - - updateHeld( player ); - } - } - - @Override - public void detectAndSendChanges() - { - if ( Platform.isClient() ) - return; - - super.detectAndSendChanges(); - - if ( g == null ) - return; - - int total = 0; - boolean missing = false; - - IActionHost host = getActionHost(); - if ( host != null ) - { - IGridNode agn = host.getActionableNode(); - if ( agn != null && agn.isActive() ) - { - for (IGridNode gn : g.getMachines( TileInterface.class )) - { - if ( gn.isActive() ) - { - IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); - if ( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO ) - continue; - - InvTracker t = diList.get( ih ); - - if ( t == null ) - missing = true; - else - { - DualityInterface dual = ih.getInterfaceDuality(); - if ( !t.unlocalizedName.equals( dual.getTermName() ) ) - missing = true; - } - - total++; - } - } - - for (IGridNode gn : g.getMachines( PartInterface.class )) - { - if ( gn.isActive() ) - { - IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); - if ( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO ) - continue; - - InvTracker t = diList.get( ih ); - - if ( t == null ) - missing = true; - else - { - DualityInterface dual = ih.getInterfaceDuality(); - if ( !t.unlocalizedName.equals( dual.getTermName() ) ) - missing = true; - } - - total++; - } - } - } - } - - if ( total != diList.size() || missing ) - regenList( data ); - else - { - for (Entry en : diList.entrySet()) - { - InvTracker inv = en.getValue(); - for (int x = 0; x < inv.server.getSizeInventory(); x++) - { - if ( isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) ) - addItems( data, inv, x, 1 ); - } - } - } - - if ( !data.hasNoTags() ) - { - try - { - NetworkHandler.instance.sendTo( new PacketCompressedNBT( data ), (EntityPlayerMP) getPlayerInv().player ); - } - catch (IOException e) - { - // :P - } - - data = new NBTTagCompound(); - } - } - - private boolean isDifferent(ItemStack a, ItemStack b) - { - if ( a == null && b == null ) - return false; - - if ( a == null || b == null ) - return true; - - return !ItemStack.areItemStacksEqual( a, b ); - } - - private void regenList(NBTTagCompound data) - { - byId.clear(); - diList.clear(); - - IActionHost host = getActionHost(); - if ( host != null ) - { - IGridNode agn = host.getActionableNode(); - if ( agn != null && agn.isActive() ) - { - for (IGridNode gn : g.getMachines( TileInterface.class )) - { - IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); - DualityInterface dual = ih.getInterfaceDuality(); - if ( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES ) - diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) ); - } - - for (IGridNode gn : g.getMachines( PartInterface.class )) - { - IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); - DualityInterface dual = ih.getInterfaceDuality(); - if ( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES ) - diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) ); - } - } - } - - data.setBoolean( "clear", true ); - - for (Entry en : diList.entrySet()) - { - InvTracker inv = en.getValue(); - byId.put( inv.which, inv ); - addItems( data, inv, 0, inv.server.getSizeInventory() ); - } - } - - private void addItems(NBTTagCompound data, InvTracker inv, int offset, int length) - { - String name = "=" + Long.toString( inv.which, Character.MAX_RADIX ); - NBTTagCompound invv = data.getCompoundTag( name ); - - if ( invv.hasNoTags() ) - { - invv.setLong( "sortBy", inv.sortBy ); - invv.setString( "un", inv.unlocalizedName ); - } - - for (int x = 0; x < length; x++) - { - NBTTagCompound itemNBT = new NBTTagCompound(); - - ItemStack is = inv.server.getStackInSlot( x + offset ); - - // "update" client side. - inv.client.setInventorySlotContents( x + offset, is == null ? null : is.copy() ); - - if ( is != null ) - is.writeToNBT( itemNBT ); - - invv.setTag( Integer.toString( x + offset ), itemNBT ); - } - - data.setTag( name, invv ); - } -} +package appeng.container.implementations; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.Settings; +import appeng.api.config.YesNo; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridNode; +import appeng.api.networking.security.IActionHost; +import appeng.container.AEBaseContainer; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketCompressedNBT; +import appeng.helpers.DualityInterface; +import appeng.helpers.IInterfaceHost; +import appeng.helpers.InventoryAction; +import appeng.items.misc.ItemEncodedPattern; +import appeng.parts.misc.PartInterface; +import appeng.parts.reporting.PartMonitor; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.tile.misc.TileInterface; +import appeng.util.InventoryAdaptor; +import appeng.util.Platform; +import appeng.util.inv.AdaptorIInventory; +import appeng.util.inv.AdaptorPlayerHand; +import appeng.util.inv.WrapperInvSlot; + +public class ContainerInterfaceTerminal extends AEBaseContainer +{ + + /** + * this stuff is all server side.. + */ + + static private long autoBase = Long.MIN_VALUE; + + class InvTracker + { + + long which = autoBase++; + String unlocalizedName; + + public InvTracker(DualityInterface dual, IInventory patterns, String unlocalizedName) { + server = patterns; + client = new AppEngInternalInventory( null, server.getSizeInventory() ); + this.unlocalizedName = unlocalizedName; + this.sortBy = dual.getSortValue(); + } + + IInventory client; + IInventory server; + public long sortBy; + + }; + + Map diList = new HashMap(); + Map byId = new HashMap(); + IGrid g; + + public ContainerInterfaceTerminal(InventoryPlayer ip, PartMonitor anchor) { + super( ip, anchor ); + + if ( Platform.isServer() ) + g = anchor.getActionableNode().getGrid(); + + bindPlayerInventory( ip, 0, 222 - /* height of playerinventory */82 ); + } + + NBTTagCompound data = new NBTTagCompound(); + + class PatternInvSlot extends WrapperInvSlot + { + + public PatternInvSlot(IInventory inv) { + super( inv ); + } + + @Override + public boolean isItemValid(ItemStack itemstack) + { + return itemstack != null && itemstack.getItem() instanceof ItemEncodedPattern; + } + + }; + + @Override + public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id) + { + InvTracker inv = byId.get( id ); + if ( inv != null ) + { + ItemStack is = inv.server.getStackInSlot( slot ); + boolean hasItemInHand = player.inventory.getItemStack() != null; + + InventoryAdaptor playerHand = new AdaptorPlayerHand( player ); + + WrapperInvSlot slotInv = new PatternInvSlot( inv.server ); + + IInventory theSlot = slotInv.getWrapper( slot ); + InventoryAdaptor interfaceSlot = new AdaptorIInventory( theSlot ); + + switch (action) + { + case PICKUP_OR_SETDOWN: + + if ( hasItemInHand ) + { + ItemStack inSlot = theSlot.getStackInSlot( 0 ); + if ( inSlot == null ) + player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) ); + else + { + inSlot = inSlot.copy(); + ItemStack inHand = player.inventory.getItemStack().copy(); + + theSlot.setInventorySlotContents( 0, null ); + player.inventory.setItemStack( null ); + + player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) ); + + if ( player.inventory.getItemStack() == null ) + player.inventory.setItemStack( inSlot ); + else + { + player.inventory.setItemStack( inHand ); + theSlot.setInventorySlotContents( 0, inSlot ); + } + } + } + else + { + IInventory mySlot = slotInv.getWrapper( slot ); + mySlot.setInventorySlotContents( 0, playerHand.addItems( mySlot.getStackInSlot( 0 ) ) ); + } + + break; + case SPLIT_OR_PLACESINGLE: + + if ( hasItemInHand ) + { + ItemStack extra = playerHand.removeItems( 1, null, null ); + if ( extra != null ) + extra = interfaceSlot.addItems( extra ); + if ( extra != null ) + playerHand.addItems( extra ); + } + else if ( is != null ) + { + ItemStack extra = interfaceSlot.removeItems( (is.stackSize + 1) / 2, null, null ); + if ( extra != null ) + extra = playerHand.addItems( extra ); + if ( extra != null ) + interfaceSlot.addItems( extra ); + } + + break; + case SHIFT_CLICK: + + IInventory mySlot = slotInv.getWrapper( slot ); + InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN ); + mySlot.setInventorySlotContents( 0, playerInv.addItems( mySlot.getStackInSlot( 0 ) ) ); + + break; + case MOVE_REGION: + + InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN ); + for (int x = 0; x < inv.server.getSizeInventory(); x++) + { + inv.server.setInventorySlotContents( x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) ); + } + + break; + case CREATIVE_DUPLICATE: + + if ( player.capabilities.isCreativeMode && !hasItemInHand ) + { + player.inventory.setItemStack( is == null ? null : is.copy() ); + } + + break; + default: + return; + } + + updateHeld( player ); + } + } + + @Override + public void detectAndSendChanges() + { + if ( Platform.isClient() ) + return; + + super.detectAndSendChanges(); + + if ( g == null ) + return; + + int total = 0; + boolean missing = false; + + IActionHost host = getActionHost(); + if ( host != null ) + { + IGridNode agn = host.getActionableNode(); + if ( agn != null && agn.isActive() ) + { + for (IGridNode gn : g.getMachines( TileInterface.class )) + { + if ( gn.isActive() ) + { + IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); + if ( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO ) + continue; + + InvTracker t = diList.get( ih ); + + if ( t == null ) + missing = true; + else + { + DualityInterface dual = ih.getInterfaceDuality(); + if ( !t.unlocalizedName.equals( dual.getTermName() ) ) + missing = true; + } + + total++; + } + } + + for (IGridNode gn : g.getMachines( PartInterface.class )) + { + if ( gn.isActive() ) + { + IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); + if ( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO ) + continue; + + InvTracker t = diList.get( ih ); + + if ( t == null ) + missing = true; + else + { + DualityInterface dual = ih.getInterfaceDuality(); + if ( !t.unlocalizedName.equals( dual.getTermName() ) ) + missing = true; + } + + total++; + } + } + } + } + + if ( total != diList.size() || missing ) + regenList( data ); + else + { + for (Entry en : diList.entrySet()) + { + InvTracker inv = en.getValue(); + for (int x = 0; x < inv.server.getSizeInventory(); x++) + { + if ( isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) ) + addItems( data, inv, x, 1 ); + } + } + } + + if ( !data.hasNoTags() ) + { + try + { + NetworkHandler.instance.sendTo( new PacketCompressedNBT( data ), (EntityPlayerMP) getPlayerInv().player ); + } + catch (IOException e) + { + // :P + } + + data = new NBTTagCompound(); + } + } + + private boolean isDifferent(ItemStack a, ItemStack b) + { + if ( a == null && b == null ) + return false; + + if ( a == null || b == null ) + return true; + + return !ItemStack.areItemStacksEqual( a, b ); + } + + private void regenList(NBTTagCompound data) + { + byId.clear(); + diList.clear(); + + IActionHost host = getActionHost(); + if ( host != null ) + { + IGridNode agn = host.getActionableNode(); + if ( agn != null && agn.isActive() ) + { + for (IGridNode gn : g.getMachines( TileInterface.class )) + { + IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); + DualityInterface dual = ih.getInterfaceDuality(); + if ( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES ) + diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) ); + } + + for (IGridNode gn : g.getMachines( PartInterface.class )) + { + IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); + DualityInterface dual = ih.getInterfaceDuality(); + if ( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES ) + diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) ); + } + } + } + + data.setBoolean( "clear", true ); + + for (Entry en : diList.entrySet()) + { + InvTracker inv = en.getValue(); + byId.put( inv.which, inv ); + addItems( data, inv, 0, inv.server.getSizeInventory() ); + } + } + + private void addItems(NBTTagCompound data, InvTracker inv, int offset, int length) + { + String name = "=" + Long.toString( inv.which, Character.MAX_RADIX ); + NBTTagCompound invv = data.getCompoundTag( name ); + + if ( invv.hasNoTags() ) + { + invv.setLong( "sortBy", inv.sortBy ); + invv.setString( "un", inv.unlocalizedName ); + } + + for (int x = 0; x < length; x++) + { + NBTTagCompound itemNBT = new NBTTagCompound(); + + ItemStack is = inv.server.getStackInSlot( x + offset ); + + // "update" client side. + inv.client.setInventorySlotContents( x + offset, is == null ? null : is.copy() ); + + if ( is != null ) + is.writeToNBT( itemNBT ); + + invv.setTag( Integer.toString( x + offset ), itemNBT ); + } + + data.setTag( name, invv ); + } +} diff --git a/container/implementations/ContainerLevelEmitter.java b/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java similarity index 96% rename from container/implementations/ContainerLevelEmitter.java rename to src/main/java/appeng/container/implementations/ContainerLevelEmitter.java index 6f4fd895c..2269c58d1 100644 --- a/container/implementations/ContainerLevelEmitter.java +++ b/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java @@ -1,115 +1,115 @@ -package appeng.container.implementations; - -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import appeng.api.config.FuzzyMode; -import appeng.api.config.LevelType; -import appeng.api.config.RedstoneMode; -import appeng.api.config.SecurityPermissions; -import appeng.api.config.Settings; -import appeng.api.config.YesNo; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotFakeTypeOnly; -import appeng.container.slot.SlotRestrictedInput; -import appeng.parts.automation.PartLevelEmitter; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class ContainerLevelEmitter extends ContainerUpgradeable -{ - - PartLevelEmitter lvlEmitter; - - @SideOnly(Side.CLIENT) - public GuiTextField textField; - - @SideOnly(Side.CLIENT) - public void setTextField(GuiTextField level) - { - textField = level; - textField.setText( "" + EmitterValue ); - } - - public ContainerLevelEmitter(InventoryPlayer ip, PartLevelEmitter te) { - super( ip, te ); - lvlEmitter = te; - } - - @Override - public int availableUpgrades() - { - - return 1; - } - - @Override - protected boolean supportCapacity() - { - return false; - } - - public void setLevel(long l, EntityPlayer player) - { - lvlEmitter.setReportingValue( l ); - EmitterValue = l; - } - - @Override - protected void setupConfig() - { - int x = 80 + 44; - int y = 40; - - IInventory upgrades = myte.getInventoryByName( "upgrades" ); - if ( availableUpgrades() > 0 ) - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() ); - if ( availableUpgrades() > 1 ) - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() ); - if ( availableUpgrades() > 2 ) - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() ); - if ( availableUpgrades() > 3 ) - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() ); - - IInventory inv = myte.getInventoryByName( "config" ); - addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) ); - } - - @GuiSync(2) - public LevelType lvType; - - @GuiSync(3) - public long EmitterValue = -1; - - @GuiSync(4) - public YesNo cmType; - - @Override - public void detectAndSendChanges() - { - verifyPermissions( SecurityPermissions.BUILD, false ); - - if ( Platform.isServer() ) - { - this.EmitterValue = lvlEmitter.getReportingValue(); - this.cmType = (YesNo) this.myte.getConfigManager().getSetting( Settings.CRAFT_VIA_REDSTONE ); - this.lvType = (LevelType) this.myte.getConfigManager().getSetting( Settings.LEVEL_TYPE ); - this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ); - this.rsMode = (RedstoneMode) this.myte.getConfigManager().getSetting( Settings.REDSTONE_EMITTER ); - } - - standardDetectAndSendChanges(); - } - - public void onUpdate(String field, Object oldValue, Object newValue) - { - if ( field.equals( "EmitterValue" ) ) - { - if ( textField != null ) - textField.setText( "" + EmitterValue ); - } - } - -} +package appeng.container.implementations; + +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import appeng.api.config.FuzzyMode; +import appeng.api.config.LevelType; +import appeng.api.config.RedstoneMode; +import appeng.api.config.SecurityPermissions; +import appeng.api.config.Settings; +import appeng.api.config.YesNo; +import appeng.container.guisync.GuiSync; +import appeng.container.slot.SlotFakeTypeOnly; +import appeng.container.slot.SlotRestrictedInput; +import appeng.parts.automation.PartLevelEmitter; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ContainerLevelEmitter extends ContainerUpgradeable +{ + + PartLevelEmitter lvlEmitter; + + @SideOnly(Side.CLIENT) + public GuiTextField textField; + + @SideOnly(Side.CLIENT) + public void setTextField(GuiTextField level) + { + textField = level; + textField.setText( "" + EmitterValue ); + } + + public ContainerLevelEmitter(InventoryPlayer ip, PartLevelEmitter te) { + super( ip, te ); + lvlEmitter = te; + } + + @Override + public int availableUpgrades() + { + + return 1; + } + + @Override + protected boolean supportCapacity() + { + return false; + } + + public void setLevel(long l, EntityPlayer player) + { + lvlEmitter.setReportingValue( l ); + EmitterValue = l; + } + + @Override + protected void setupConfig() + { + int x = 80 + 44; + int y = 40; + + IInventory upgrades = myte.getInventoryByName( "upgrades" ); + if ( availableUpgrades() > 0 ) + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() ); + if ( availableUpgrades() > 1 ) + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() ); + if ( availableUpgrades() > 2 ) + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() ); + if ( availableUpgrades() > 3 ) + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() ); + + IInventory inv = myte.getInventoryByName( "config" ); + addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) ); + } + + @GuiSync(2) + public LevelType lvType; + + @GuiSync(3) + public long EmitterValue = -1; + + @GuiSync(4) + public YesNo cmType; + + @Override + public void detectAndSendChanges() + { + verifyPermissions( SecurityPermissions.BUILD, false ); + + if ( Platform.isServer() ) + { + this.EmitterValue = lvlEmitter.getReportingValue(); + this.cmType = (YesNo) this.myte.getConfigManager().getSetting( Settings.CRAFT_VIA_REDSTONE ); + this.lvType = (LevelType) this.myte.getConfigManager().getSetting( Settings.LEVEL_TYPE ); + this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ); + this.rsMode = (RedstoneMode) this.myte.getConfigManager().getSetting( Settings.REDSTONE_EMITTER ); + } + + standardDetectAndSendChanges(); + } + + public void onUpdate(String field, Object oldValue, Object newValue) + { + if ( field.equals( "EmitterValue" ) ) + { + if ( textField != null ) + textField.setText( "" + EmitterValue ); + } + } + +} diff --git a/container/implementations/ContainerMAC.java b/src/main/java/appeng/container/implementations/ContainerMAC.java similarity index 100% rename from container/implementations/ContainerMAC.java rename to src/main/java/appeng/container/implementations/ContainerMAC.java diff --git a/container/implementations/ContainerMEMonitorable.java b/src/main/java/appeng/container/implementations/ContainerMEMonitorable.java similarity index 100% rename from container/implementations/ContainerMEMonitorable.java rename to src/main/java/appeng/container/implementations/ContainerMEMonitorable.java diff --git a/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java similarity index 96% rename from container/implementations/ContainerMEPortableCell.java rename to src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 62072e1eb..2b8535006 100644 --- a/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -1,58 +1,58 @@ -package appeng.container.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.implementations.guiobjects.IPortableCell; -import appeng.api.storage.ITerminalHost; -import appeng.util.Platform; - -public class ContainerMEPortableCell extends ContainerMEMonitorable -{ - - double powerMultiplier = 0.5; - IPortableCell civ; - - public ContainerMEPortableCell(InventoryPlayer ip, IPortableCell monitorable) { - super( ip, (ITerminalHost) monitorable, false ); - lockPlayerInventorySlot( ip.currentItem ); - civ = monitorable; - bindPlayerInventory( ip, 0, 0 ); - } - - int ticks = 0; - - @Override - public void detectAndSendChanges() - { - ItemStack currentItem = getPlayerInv().getCurrentItem(); - - if ( civ != null ) - { - if ( currentItem != civ.getItemStack() ) - { - if ( currentItem != null ) - { - if ( Platform.isSameItem( civ.getItemStack(), currentItem ) ) - getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, civ.getItemStack() ); - else - isContainerValid = false; - } - else - isContainerValid = false; - } - } - else - isContainerValid = false; - - // drain 1 ae t - ticks++; - if ( ticks > 10 ) - { - civ.extractAEPower( powerMultiplier * (double) ticks, Actionable.MODULATE, PowerMultiplier.CONFIG ); - ticks = 0; - } - super.detectAndSendChanges(); - } -} +package appeng.container.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.storage.ITerminalHost; +import appeng.util.Platform; + +public class ContainerMEPortableCell extends ContainerMEMonitorable +{ + + double powerMultiplier = 0.5; + IPortableCell civ; + + public ContainerMEPortableCell(InventoryPlayer ip, IPortableCell monitorable) { + super( ip, (ITerminalHost) monitorable, false ); + lockPlayerInventorySlot( ip.currentItem ); + civ = monitorable; + bindPlayerInventory( ip, 0, 0 ); + } + + int ticks = 0; + + @Override + public void detectAndSendChanges() + { + ItemStack currentItem = getPlayerInv().getCurrentItem(); + + if ( civ != null ) + { + if ( currentItem != civ.getItemStack() ) + { + if ( currentItem != null ) + { + if ( Platform.isSameItem( civ.getItemStack(), currentItem ) ) + getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, civ.getItemStack() ); + else + isContainerValid = false; + } + else + isContainerValid = false; + } + } + else + isContainerValid = false; + + // drain 1 ae t + ticks++; + if ( ticks > 10 ) + { + civ.extractAEPower( powerMultiplier * (double) ticks, Actionable.MODULATE, PowerMultiplier.CONFIG ); + ticks = 0; + } + super.detectAndSendChanges(); + } +} diff --git a/container/implementations/ContainerNetworkStatus.java b/src/main/java/appeng/container/implementations/ContainerNetworkStatus.java similarity index 96% rename from container/implementations/ContainerNetworkStatus.java rename to src/main/java/appeng/container/implementations/ContainerNetworkStatus.java index 6846b235f..667e6ad68 100644 --- a/container/implementations/ContainerNetworkStatus.java +++ b/src/main/java/appeng/container/implementations/ContainerNetworkStatus.java @@ -1,123 +1,123 @@ -package appeng.container.implementations; - -import java.io.IOException; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.implementations.guiobjects.INetworkTool; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridBlock; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.container.AEBaseContainer; -import appeng.container.guisync.GuiSync; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketMEInventoryUpdate; -import appeng.util.Platform; -import appeng.util.item.AEItemStack; - -public class ContainerNetworkStatus extends AEBaseContainer -{ - - IGrid network; - - public ContainerNetworkStatus(InventoryPlayer ip, INetworkTool te) { - super( ip, null, null ); - IGridHost host = te.getGridHost(); - - if ( host != null ) - { - findNode( host, ForgeDirection.UNKNOWN ); - for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) - findNode( host, d ); - } - - if ( network == null && Platform.isServer() ) - isContainerValid = false; - } - - private void findNode(IGridHost host, ForgeDirection d) - { - if ( network == null ) - { - IGridNode node = host.getGridNode( d ); - if ( node != null ) - network = node.getGrid(); - } - } - - int delay = 40; - - @GuiSync(0) - public long avgAddition; - @GuiSync(1) - public long powerUsage; - @GuiSync(2) - public long currentPower; - @GuiSync(3) - public long maxPower; - - @Override - public void detectAndSendChanges() - { - delay++; - if ( Platform.isServer() && delay > 15 && network != null ) - { - delay = 0; - - IEnergyGrid eg = network.getCache( IEnergyGrid.class ); - if ( eg != null ) - { - avgAddition = (long) (100.0 * eg.getAvgPowerInjection()); - powerUsage = (long) (100.0 * eg.getAvgPowerUsage()); - currentPower = (long) (100.0 * eg.getStoredPower()); - maxPower = (long) (100.0 * eg.getMaxStoredPower()); - } - - PacketMEInventoryUpdate piu; - try - { - piu = new PacketMEInventoryUpdate(); - - for (Class machineClass : network.getMachinesClasses()) - { - IItemList list = AEApi.instance().storage().createItemList(); - for (IGridNode machine : network.getMachines( machineClass )) - { - IGridBlock blk = machine.getGridBlock(); - ItemStack is = blk.getMachineRepresentation(); - if ( is != null && is.getItem() != null ) - { - IAEItemStack ais = AEItemStack.create( is ); - ais.setStackSize( 1 ); - ais.setCountRequestable( (long) (blk.getIdlePowerUsage() * 100.0) ); - list.add( ais ); - } - } - - for (IAEItemStack ais : list) - piu.appendItem( ais ); - } - - for (Object c : this.crafters) - { - if ( c instanceof EntityPlayer ) - NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c ); - } - } - catch (IOException e) - { - // :P - } - - } - super.detectAndSendChanges(); - } -} +package appeng.container.implementations; + +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.implementations.guiobjects.INetworkTool; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridBlock; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.container.AEBaseContainer; +import appeng.container.guisync.GuiSync; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketMEInventoryUpdate; +import appeng.util.Platform; +import appeng.util.item.AEItemStack; + +public class ContainerNetworkStatus extends AEBaseContainer +{ + + IGrid network; + + public ContainerNetworkStatus(InventoryPlayer ip, INetworkTool te) { + super( ip, null, null ); + IGridHost host = te.getGridHost(); + + if ( host != null ) + { + findNode( host, ForgeDirection.UNKNOWN ); + for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) + findNode( host, d ); + } + + if ( network == null && Platform.isServer() ) + isContainerValid = false; + } + + private void findNode(IGridHost host, ForgeDirection d) + { + if ( network == null ) + { + IGridNode node = host.getGridNode( d ); + if ( node != null ) + network = node.getGrid(); + } + } + + int delay = 40; + + @GuiSync(0) + public long avgAddition; + @GuiSync(1) + public long powerUsage; + @GuiSync(2) + public long currentPower; + @GuiSync(3) + public long maxPower; + + @Override + public void detectAndSendChanges() + { + delay++; + if ( Platform.isServer() && delay > 15 && network != null ) + { + delay = 0; + + IEnergyGrid eg = network.getCache( IEnergyGrid.class ); + if ( eg != null ) + { + avgAddition = (long) (100.0 * eg.getAvgPowerInjection()); + powerUsage = (long) (100.0 * eg.getAvgPowerUsage()); + currentPower = (long) (100.0 * eg.getStoredPower()); + maxPower = (long) (100.0 * eg.getMaxStoredPower()); + } + + PacketMEInventoryUpdate piu; + try + { + piu = new PacketMEInventoryUpdate(); + + for (Class machineClass : network.getMachinesClasses()) + { + IItemList list = AEApi.instance().storage().createItemList(); + for (IGridNode machine : network.getMachines( machineClass )) + { + IGridBlock blk = machine.getGridBlock(); + ItemStack is = blk.getMachineRepresentation(); + if ( is != null && is.getItem() != null ) + { + IAEItemStack ais = AEItemStack.create( is ); + ais.setStackSize( 1 ); + ais.setCountRequestable( (long) (blk.getIdlePowerUsage() * 100.0) ); + list.add( ais ); + } + } + + for (IAEItemStack ais : list) + piu.appendItem( ais ); + } + + for (Object c : this.crafters) + { + if ( c instanceof EntityPlayer ) + NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c ); + } + } + catch (IOException e) + { + // :P + } + + } + super.detectAndSendChanges(); + } +} diff --git a/container/implementations/ContainerNetworkTool.java b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java similarity index 96% rename from container/implementations/ContainerNetworkTool.java rename to src/main/java/appeng/container/implementations/ContainerNetworkTool.java index bace2a0a4..537b7e9a9 100644 --- a/container/implementations/ContainerNetworkTool.java +++ b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java @@ -1,68 +1,68 @@ -package appeng.container.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import appeng.api.implementations.guiobjects.INetworkTool; -import appeng.container.AEBaseContainer; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotRestrictedInput; -import appeng.util.Platform; - -public class ContainerNetworkTool extends AEBaseContainer -{ - - INetworkTool toolInv; - - @GuiSync(1) - public boolean facadeMode; - - public ContainerNetworkTool(InventoryPlayer ip, INetworkTool te) { - super( ip, null, null ); - toolInv = te; - - lockPlayerInventorySlot( ip.currentItem ); - - for (int y = 0; y < 3; y++) - for (int x = 0; x < 3; x++) - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te, y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, invPlayer )) ); - - bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 ); - } - - public void toggleFacadeMode() - { - NBTTagCompound data = Platform.openNbtData( toolInv.getItemStack() ); - data.setBoolean( "hideFacades", !data.getBoolean( "hideFacades" ) ); - this.detectAndSendChanges(); - } - - @Override - public void detectAndSendChanges() - { - ItemStack currentItem = getPlayerInv().getCurrentItem(); - - if ( currentItem != toolInv.getItemStack() ) - { - if ( currentItem != null ) - { - if ( Platform.isSameItem( toolInv.getItemStack(), currentItem ) ) - { - getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, toolInv.getItemStack() ); - } - else - isContainerValid = false; - } - else - isContainerValid = false; - } - - if ( isContainerValid ) - { - NBTTagCompound data = Platform.openNbtData( currentItem ); - facadeMode = data.getBoolean( "hideFacades" ); - } - - super.detectAndSendChanges(); - } -} +package appeng.container.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import appeng.api.implementations.guiobjects.INetworkTool; +import appeng.container.AEBaseContainer; +import appeng.container.guisync.GuiSync; +import appeng.container.slot.SlotRestrictedInput; +import appeng.util.Platform; + +public class ContainerNetworkTool extends AEBaseContainer +{ + + INetworkTool toolInv; + + @GuiSync(1) + public boolean facadeMode; + + public ContainerNetworkTool(InventoryPlayer ip, INetworkTool te) { + super( ip, null, null ); + toolInv = te; + + lockPlayerInventorySlot( ip.currentItem ); + + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te, y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, invPlayer )) ); + + bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 ); + } + + public void toggleFacadeMode() + { + NBTTagCompound data = Platform.openNbtData( toolInv.getItemStack() ); + data.setBoolean( "hideFacades", !data.getBoolean( "hideFacades" ) ); + this.detectAndSendChanges(); + } + + @Override + public void detectAndSendChanges() + { + ItemStack currentItem = getPlayerInv().getCurrentItem(); + + if ( currentItem != toolInv.getItemStack() ) + { + if ( currentItem != null ) + { + if ( Platform.isSameItem( toolInv.getItemStack(), currentItem ) ) + { + getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, toolInv.getItemStack() ); + } + else + isContainerValid = false; + } + else + isContainerValid = false; + } + + if ( isContainerValid ) + { + NBTTagCompound data = Platform.openNbtData( currentItem ); + facadeMode = data.getBoolean( "hideFacades" ); + } + + super.detectAndSendChanges(); + } +} diff --git a/container/implementations/ContainerPatternTerm.java b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java similarity index 100% rename from container/implementations/ContainerPatternTerm.java rename to src/main/java/appeng/container/implementations/ContainerPatternTerm.java diff --git a/container/implementations/ContainerPriority.java b/src/main/java/appeng/container/implementations/ContainerPriority.java similarity index 100% rename from container/implementations/ContainerPriority.java rename to src/main/java/appeng/container/implementations/ContainerPriority.java diff --git a/container/implementations/ContainerQNB.java b/src/main/java/appeng/container/implementations/ContainerQNB.java similarity index 96% rename from container/implementations/ContainerQNB.java rename to src/main/java/appeng/container/implementations/ContainerQNB.java index 11e0587b4..7174c646e 100644 --- a/container/implementations/ContainerQNB.java +++ b/src/main/java/appeng/container/implementations/ContainerQNB.java @@ -1,22 +1,22 @@ -package appeng.container.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import appeng.container.AEBaseContainer; -import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.qnb.TileQuantumBridge; - -public class ContainerQNB extends AEBaseContainer -{ - - TileQuantumBridge myte; - - public ContainerQNB(InventoryPlayer ip, TileQuantumBridge te) { - super( ip, te, null ); - myte = te; - - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, te, 0, 80, 37, invPlayer )).setStackLimit( 1 ) ); - - bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); - } - -} +package appeng.container.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import appeng.container.AEBaseContainer; +import appeng.container.slot.SlotRestrictedInput; +import appeng.tile.qnb.TileQuantumBridge; + +public class ContainerQNB extends AEBaseContainer +{ + + TileQuantumBridge myte; + + public ContainerQNB(InventoryPlayer ip, TileQuantumBridge te) { + super( ip, te, null ); + myte = te; + + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, te, 0, 80, 37, invPlayer )).setStackLimit( 1 ) ); + + bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); + } + +} diff --git a/container/implementations/ContainerQuartzKnife.java b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java similarity index 100% rename from container/implementations/ContainerQuartzKnife.java rename to src/main/java/appeng/container/implementations/ContainerQuartzKnife.java diff --git a/container/implementations/ContainerSecurity.java b/src/main/java/appeng/container/implementations/ContainerSecurity.java similarity index 100% rename from container/implementations/ContainerSecurity.java rename to src/main/java/appeng/container/implementations/ContainerSecurity.java diff --git a/container/implementations/ContainerSkyChest.java b/src/main/java/appeng/container/implementations/ContainerSkyChest.java similarity index 100% rename from container/implementations/ContainerSkyChest.java rename to src/main/java/appeng/container/implementations/ContainerSkyChest.java diff --git a/container/implementations/ContainerSpatialIOPort.java b/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java similarity index 96% rename from container/implementations/ContainerSpatialIOPort.java rename to src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java index 875e8af59..3ea8e6c8e 100644 --- a/container/implementations/ContainerSpatialIOPort.java +++ b/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java @@ -1,73 +1,73 @@ -package appeng.container.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.SecurityPermissions; -import appeng.api.networking.IGrid; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.spatial.ISpatialCache; -import appeng.container.AEBaseContainer; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotOutput; -import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.spatial.TileSpatialIOPort; -import appeng.util.Platform; - -public class ContainerSpatialIOPort extends AEBaseContainer -{ - - TileSpatialIOPort myte; - - IGrid network; - - @GuiSync(0) - public long currentPower; - @GuiSync(1) - public long maxPower; - @GuiSync(2) - public long reqPower; - @GuiSync(3) - public long eff; - - int delay = 40; - - public ContainerSpatialIOPort(InventoryPlayer ip, TileSpatialIOPort te) { - super( ip, te, null ); - myte = te; - - if ( Platform.isServer() ) - network = te.getGridNode( ForgeDirection.UNKNOWN ).getGrid(); - - addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, te, 0, 52, 48, invPlayer ) ); - addSlotToContainer( new SlotOutput( te, 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) ); - - bindPlayerInventory( ip, 0, 197 - /* height of playerinventory */82 ); - } - - @Override - public void detectAndSendChanges() - { - verifyPermissions( SecurityPermissions.BUILD, false ); - - if ( Platform.isServer() ) - { - delay++; - if ( delay > 15 && network != null ) - { - delay = 0; - - IEnergyGrid eg = network.getCache( IEnergyGrid.class ); - ISpatialCache sc = network.getCache( ISpatialCache.class ); - if ( eg != null ) - { - currentPower = (long) (100.0 * eg.getStoredPower()); - maxPower = (long) (100.0 * eg.getMaxStoredPower()); - reqPower = (long) (100.0 * sc.requiredPower()); - eff = (long) (100.0f * sc.currentEfficiency()); - } - } - } - - super.detectAndSendChanges(); - } -} +package appeng.container.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.SecurityPermissions; +import appeng.api.networking.IGrid; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.spatial.ISpatialCache; +import appeng.container.AEBaseContainer; +import appeng.container.guisync.GuiSync; +import appeng.container.slot.SlotOutput; +import appeng.container.slot.SlotRestrictedInput; +import appeng.tile.spatial.TileSpatialIOPort; +import appeng.util.Platform; + +public class ContainerSpatialIOPort extends AEBaseContainer +{ + + TileSpatialIOPort myte; + + IGrid network; + + @GuiSync(0) + public long currentPower; + @GuiSync(1) + public long maxPower; + @GuiSync(2) + public long reqPower; + @GuiSync(3) + public long eff; + + int delay = 40; + + public ContainerSpatialIOPort(InventoryPlayer ip, TileSpatialIOPort te) { + super( ip, te, null ); + myte = te; + + if ( Platform.isServer() ) + network = te.getGridNode( ForgeDirection.UNKNOWN ).getGrid(); + + addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, te, 0, 52, 48, invPlayer ) ); + addSlotToContainer( new SlotOutput( te, 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) ); + + bindPlayerInventory( ip, 0, 197 - /* height of playerinventory */82 ); + } + + @Override + public void detectAndSendChanges() + { + verifyPermissions( SecurityPermissions.BUILD, false ); + + if ( Platform.isServer() ) + { + delay++; + if ( delay > 15 && network != null ) + { + delay = 0; + + IEnergyGrid eg = network.getCache( IEnergyGrid.class ); + ISpatialCache sc = network.getCache( ISpatialCache.class ); + if ( eg != null ) + { + currentPower = (long) (100.0 * eg.getStoredPower()); + maxPower = (long) (100.0 * eg.getMaxStoredPower()); + reqPower = (long) (100.0 * sc.requiredPower()); + eff = (long) (100.0f * sc.currentEfficiency()); + } + } + } + + super.detectAndSendChanges(); + } +} diff --git a/container/implementations/ContainerStorageBus.java b/src/main/java/appeng/container/implementations/ContainerStorageBus.java similarity index 96% rename from container/implementations/ContainerStorageBus.java rename to src/main/java/appeng/container/implementations/ContainerStorageBus.java index 9c4d936f4..3c3cca2e6 100644 --- a/container/implementations/ContainerStorageBus.java +++ b/src/main/java/appeng/container/implementations/ContainerStorageBus.java @@ -1,145 +1,145 @@ -package appeng.container.implementations; - -import java.util.Iterator; - -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import appeng.api.AEApi; -import appeng.api.config.AccessRestriction; -import appeng.api.config.FuzzyMode; -import appeng.api.config.SecurityPermissions; -import appeng.api.config.Settings; -import appeng.api.config.StorageFilter; -import appeng.api.config.Upgrades; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.OptionalSlotFakeTypeOnly; -import appeng.container.slot.SlotFakeTypeOnly; -import appeng.container.slot.SlotRestrictedInput; -import appeng.parts.misc.PartStorageBus; -import appeng.util.Platform; -import appeng.util.iterators.NullIterator; - -public class ContainerStorageBus extends ContainerUpgradeable -{ - - PartStorageBus storageBus; - - @GuiSync(3) - public AccessRestriction rwMode = AccessRestriction.READ_WRITE; - - @GuiSync(4) - public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY; - - public ContainerStorageBus(InventoryPlayer ip, PartStorageBus te) { - super( ip, te ); - storageBus = te; - } - - @Override - protected int getHeight() - { - return 251; - } - - @Override - public int availableUpgrades() - { - return 5; - } - - @Override - protected boolean supportCapacity() - { - return true; - } - - @Override - public boolean isSlotEnabled(int idx) - { - int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY ); - - return upgrades > idx; - } - - @Override - protected void setupConfig() - { - int xo = 8; - int yo = 23 + 6; - - IInventory config = myte.getInventoryByName( "config" ); - for (int y = 0; y < 7; y++) - { - for (int x = 0; x < 9; x++) - { - if ( y < 2 ) - addSlotToContainer( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) ); - else - addSlotToContainer( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) ); - } - } - - IInventory upgrades = myte.getInventoryByName( "upgrades" ); - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() ); - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() ); - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() ); - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() ); - addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, invPlayer )).setNotDraggable() ); - } - - @Override - public void detectAndSendChanges() - { - verifyPermissions( SecurityPermissions.BUILD, false ); - - if ( Platform.isServer() ) - { - this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ); - this.rwMode = (AccessRestriction) this.myte.getConfigManager().getSetting( Settings.ACCESS ); - this.storageFilter = (StorageFilter) this.myte.getConfigManager().getSetting( Settings.STORAGE_FILTER ); - } - - standardDetectAndSendChanges(); - } - - public void clear() - { - IInventory inv = myte.getInventoryByName( "config" ); - for (int x = 0; x < inv.getSizeInventory(); x++) - inv.setInventorySlotContents( x, null ); - detectAndSendChanges(); - } - - public void partition() - { - IInventory inv = myte.getInventoryByName( "config" ); - - IMEInventory cellInv = storageBus.getInternalHandler(); - - Iterator i = new NullIterator(); - if ( cellInv != null ) - { - IItemList list = cellInv.getAvailableItems( AEApi.instance().storage().createItemList() ); - i = list.iterator(); - } - - for (int x = 0; x < inv.getSizeInventory(); x++) - { - if ( i.hasNext() && isSlotEnabled( (x / 9) - 2 ) ) - { - ItemStack g = i.next().getItemStack(); - g.stackSize = 1; - inv.setInventorySlotContents( x, g ); - } - else - inv.setInventorySlotContents( x, null ); - } - - detectAndSendChanges(); - } - -} +package appeng.container.implementations; + +import java.util.Iterator; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import appeng.api.AEApi; +import appeng.api.config.AccessRestriction; +import appeng.api.config.FuzzyMode; +import appeng.api.config.SecurityPermissions; +import appeng.api.config.Settings; +import appeng.api.config.StorageFilter; +import appeng.api.config.Upgrades; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.container.guisync.GuiSync; +import appeng.container.slot.OptionalSlotFakeTypeOnly; +import appeng.container.slot.SlotFakeTypeOnly; +import appeng.container.slot.SlotRestrictedInput; +import appeng.parts.misc.PartStorageBus; +import appeng.util.Platform; +import appeng.util.iterators.NullIterator; + +public class ContainerStorageBus extends ContainerUpgradeable +{ + + PartStorageBus storageBus; + + @GuiSync(3) + public AccessRestriction rwMode = AccessRestriction.READ_WRITE; + + @GuiSync(4) + public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY; + + public ContainerStorageBus(InventoryPlayer ip, PartStorageBus te) { + super( ip, te ); + storageBus = te; + } + + @Override + protected int getHeight() + { + return 251; + } + + @Override + public int availableUpgrades() + { + return 5; + } + + @Override + protected boolean supportCapacity() + { + return true; + } + + @Override + public boolean isSlotEnabled(int idx) + { + int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY ); + + return upgrades > idx; + } + + @Override + protected void setupConfig() + { + int xo = 8; + int yo = 23 + 6; + + IInventory config = myte.getInventoryByName( "config" ); + for (int y = 0; y < 7; y++) + { + for (int x = 0; x < 9; x++) + { + if ( y < 2 ) + addSlotToContainer( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) ); + else + addSlotToContainer( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) ); + } + } + + IInventory upgrades = myte.getInventoryByName( "upgrades" ); + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() ); + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() ); + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() ); + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() ); + addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, invPlayer )).setNotDraggable() ); + } + + @Override + public void detectAndSendChanges() + { + verifyPermissions( SecurityPermissions.BUILD, false ); + + if ( Platform.isServer() ) + { + this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ); + this.rwMode = (AccessRestriction) this.myte.getConfigManager().getSetting( Settings.ACCESS ); + this.storageFilter = (StorageFilter) this.myte.getConfigManager().getSetting( Settings.STORAGE_FILTER ); + } + + standardDetectAndSendChanges(); + } + + public void clear() + { + IInventory inv = myte.getInventoryByName( "config" ); + for (int x = 0; x < inv.getSizeInventory(); x++) + inv.setInventorySlotContents( x, null ); + detectAndSendChanges(); + } + + public void partition() + { + IInventory inv = myte.getInventoryByName( "config" ); + + IMEInventory cellInv = storageBus.getInternalHandler(); + + Iterator i = new NullIterator(); + if ( cellInv != null ) + { + IItemList list = cellInv.getAvailableItems( AEApi.instance().storage().createItemList() ); + i = list.iterator(); + } + + for (int x = 0; x < inv.getSizeInventory(); x++) + { + if ( i.hasNext() && isSlotEnabled( (x / 9) - 2 ) ) + { + ItemStack g = i.next().getItemStack(); + g.stackSize = 1; + inv.setInventorySlotContents( x, g ); + } + else + inv.setInventorySlotContents( x, null ); + } + + detectAndSendChanges(); + } + +} diff --git a/container/implementations/ContainerUpgradeable.java b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java similarity index 100% rename from container/implementations/ContainerUpgradeable.java rename to src/main/java/appeng/container/implementations/ContainerUpgradeable.java diff --git a/container/implementations/ContainerVibrationChamber.java b/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java similarity index 96% rename from container/implementations/ContainerVibrationChamber.java rename to src/main/java/appeng/container/implementations/ContainerVibrationChamber.java index 7eaf3258b..e01139266 100644 --- a/container/implementations/ContainerVibrationChamber.java +++ b/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java @@ -1,44 +1,44 @@ -package appeng.container.implementations; - -import net.minecraft.entity.player.InventoryPlayer; -import appeng.container.AEBaseContainer; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.misc.TileVibrationChamber; -import appeng.util.Platform; - -public class ContainerVibrationChamber extends AEBaseContainer -{ - - TileVibrationChamber myte; - - public ContainerVibrationChamber(InventoryPlayer ip, TileVibrationChamber te) { - super( ip, te, null ); - myte = te; - - addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, te, 0, 80, 37, invPlayer ) ); - - bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 ); - } - - public int aePerTick = 5; - - @GuiSync(0) - public int burnProgress = 0; - - @GuiSync(1) - public int burnSpeed = 100; - - @Override - public void detectAndSendChanges() - { - if ( Platform.isServer() ) - { - this.burnProgress = (int) (this.myte.maxBurnTime <= 0 ? 0 : 12 * this.myte.burnTime / this.myte.maxBurnTime); - this.burnSpeed = this.myte.burnSpeed; - } - - super.detectAndSendChanges(); - } - -} +package appeng.container.implementations; + +import net.minecraft.entity.player.InventoryPlayer; +import appeng.container.AEBaseContainer; +import appeng.container.guisync.GuiSync; +import appeng.container.slot.SlotRestrictedInput; +import appeng.tile.misc.TileVibrationChamber; +import appeng.util.Platform; + +public class ContainerVibrationChamber extends AEBaseContainer +{ + + TileVibrationChamber myte; + + public ContainerVibrationChamber(InventoryPlayer ip, TileVibrationChamber te) { + super( ip, te, null ); + myte = te; + + addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, te, 0, 80, 37, invPlayer ) ); + + bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 ); + } + + public int aePerTick = 5; + + @GuiSync(0) + public int burnProgress = 0; + + @GuiSync(1) + public int burnSpeed = 100; + + @Override + public void detectAndSendChanges() + { + if ( Platform.isServer() ) + { + this.burnProgress = (int) (this.myte.maxBurnTime <= 0 ? 0 : 12 * this.myte.burnTime / this.myte.maxBurnTime); + this.burnSpeed = this.myte.burnSpeed; + } + + super.detectAndSendChanges(); + } + +} diff --git a/container/implementations/ContainerWireless.java b/src/main/java/appeng/container/implementations/ContainerWireless.java similarity index 100% rename from container/implementations/ContainerWireless.java rename to src/main/java/appeng/container/implementations/ContainerWireless.java diff --git a/container/implementations/ContainerWirelessTerm.java b/src/main/java/appeng/container/implementations/ContainerWirelessTerm.java similarity index 100% rename from container/implementations/ContainerWirelessTerm.java rename to src/main/java/appeng/container/implementations/ContainerWirelessTerm.java diff --git a/container/implementations/CraftingCPURecord.java b/src/main/java/appeng/container/implementations/CraftingCPURecord.java similarity index 100% rename from container/implementations/CraftingCPURecord.java rename to src/main/java/appeng/container/implementations/CraftingCPURecord.java diff --git a/container/slot/AppEngCraftingSlot.java b/src/main/java/appeng/container/slot/AppEngCraftingSlot.java similarity index 100% rename from container/slot/AppEngCraftingSlot.java rename to src/main/java/appeng/container/slot/AppEngCraftingSlot.java diff --git a/container/slot/AppEngSlot.java b/src/main/java/appeng/container/slot/AppEngSlot.java similarity index 100% rename from container/slot/AppEngSlot.java rename to src/main/java/appeng/container/slot/AppEngSlot.java diff --git a/container/slot/IOptionalSlotHost.java b/src/main/java/appeng/container/slot/IOptionalSlotHost.java similarity index 100% rename from container/slot/IOptionalSlotHost.java rename to src/main/java/appeng/container/slot/IOptionalSlotHost.java diff --git a/container/slot/NullSlot.java b/src/main/java/appeng/container/slot/NullSlot.java similarity index 100% rename from container/slot/NullSlot.java rename to src/main/java/appeng/container/slot/NullSlot.java diff --git a/container/slot/OptionalSlotFake.java b/src/main/java/appeng/container/slot/OptionalSlotFake.java similarity index 100% rename from container/slot/OptionalSlotFake.java rename to src/main/java/appeng/container/slot/OptionalSlotFake.java diff --git a/container/slot/OptionalSlotFakeTypeOnly.java b/src/main/java/appeng/container/slot/OptionalSlotFakeTypeOnly.java similarity index 100% rename from container/slot/OptionalSlotFakeTypeOnly.java rename to src/main/java/appeng/container/slot/OptionalSlotFakeTypeOnly.java diff --git a/container/slot/OptionalSlotNormal.java b/src/main/java/appeng/container/slot/OptionalSlotNormal.java similarity index 100% rename from container/slot/OptionalSlotNormal.java rename to src/main/java/appeng/container/slot/OptionalSlotNormal.java diff --git a/container/slot/OptionalSlotRestrictedInput.java b/src/main/java/appeng/container/slot/OptionalSlotRestrictedInput.java similarity index 100% rename from container/slot/OptionalSlotRestrictedInput.java rename to src/main/java/appeng/container/slot/OptionalSlotRestrictedInput.java diff --git a/container/slot/QuartzKnifeOutput.java b/src/main/java/appeng/container/slot/QuartzKnifeOutput.java similarity index 100% rename from container/slot/QuartzKnifeOutput.java rename to src/main/java/appeng/container/slot/QuartzKnifeOutput.java diff --git a/container/slot/SlotCraftingMatrix.java b/src/main/java/appeng/container/slot/SlotCraftingMatrix.java similarity index 94% rename from container/slot/SlotCraftingMatrix.java rename to src/main/java/appeng/container/slot/SlotCraftingMatrix.java index b33c4d2d5..47682f9ff 100644 --- a/container/slot/SlotCraftingMatrix.java +++ b/src/main/java/appeng/container/slot/SlotCraftingMatrix.java @@ -1,45 +1,45 @@ -package appeng.container.slot; - -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class SlotCraftingMatrix extends AppEngSlot -{ - - Container c; - - public SlotCraftingMatrix(Container c, IInventory par1iInventory, int par2, int par3, int par4) { - super( par1iInventory, par2, par3, par4 ); - this.c = c; - } - - @Override - public boolean isPlayerSide() - { - return true; - } - - @Override - public void clearStack() - { - super.clearStack(); - c.onCraftMatrixChanged( inventory ); - } - - @Override - public ItemStack decrStackSize(int par1) - { - ItemStack is = super.decrStackSize( par1 ); - c.onCraftMatrixChanged( inventory ); - return is; - } - - @Override - public void putStack(ItemStack par1ItemStack) - { - super.putStack( par1ItemStack ); - c.onCraftMatrixChanged( inventory ); - } - -} +package appeng.container.slot; + +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public class SlotCraftingMatrix extends AppEngSlot +{ + + Container c; + + public SlotCraftingMatrix(Container c, IInventory par1iInventory, int par2, int par3, int par4) { + super( par1iInventory, par2, par3, par4 ); + this.c = c; + } + + @Override + public boolean isPlayerSide() + { + return true; + } + + @Override + public void clearStack() + { + super.clearStack(); + c.onCraftMatrixChanged( inventory ); + } + + @Override + public ItemStack decrStackSize(int par1) + { + ItemStack is = super.decrStackSize( par1 ); + c.onCraftMatrixChanged( inventory ); + return is; + } + + @Override + public void putStack(ItemStack par1ItemStack) + { + super.putStack( par1ItemStack ); + c.onCraftMatrixChanged( inventory ); + } + +} diff --git a/container/slot/SlotCraftingTerm.java b/src/main/java/appeng/container/slot/SlotCraftingTerm.java similarity index 100% rename from container/slot/SlotCraftingTerm.java rename to src/main/java/appeng/container/slot/SlotCraftingTerm.java diff --git a/container/slot/SlotDisabled.java b/src/main/java/appeng/container/slot/SlotDisabled.java similarity index 100% rename from container/slot/SlotDisabled.java rename to src/main/java/appeng/container/slot/SlotDisabled.java diff --git a/container/slot/SlotFake.java b/src/main/java/appeng/container/slot/SlotFake.java similarity index 100% rename from container/slot/SlotFake.java rename to src/main/java/appeng/container/slot/SlotFake.java diff --git a/container/slot/SlotFakeBlacklist.java b/src/main/java/appeng/container/slot/SlotFakeBlacklist.java similarity index 100% rename from container/slot/SlotFakeBlacklist.java rename to src/main/java/appeng/container/slot/SlotFakeBlacklist.java diff --git a/container/slot/SlotFakeCraftingMatrix.java b/src/main/java/appeng/container/slot/SlotFakeCraftingMatrix.java similarity index 100% rename from container/slot/SlotFakeCraftingMatrix.java rename to src/main/java/appeng/container/slot/SlotFakeCraftingMatrix.java diff --git a/container/slot/SlotFakeTypeOnly.java b/src/main/java/appeng/container/slot/SlotFakeTypeOnly.java similarity index 100% rename from container/slot/SlotFakeTypeOnly.java rename to src/main/java/appeng/container/slot/SlotFakeTypeOnly.java diff --git a/container/slot/SlotInaccessible.java b/src/main/java/appeng/container/slot/SlotInaccessible.java similarity index 100% rename from container/slot/SlotInaccessible.java rename to src/main/java/appeng/container/slot/SlotInaccessible.java diff --git a/container/slot/SlotInaccessibleHD.java b/src/main/java/appeng/container/slot/SlotInaccessibleHD.java similarity index 100% rename from container/slot/SlotInaccessibleHD.java rename to src/main/java/appeng/container/slot/SlotInaccessibleHD.java diff --git a/container/slot/SlotMACPattern.java b/src/main/java/appeng/container/slot/SlotMACPattern.java similarity index 100% rename from container/slot/SlotMACPattern.java rename to src/main/java/appeng/container/slot/SlotMACPattern.java diff --git a/container/slot/SlotNormal.java b/src/main/java/appeng/container/slot/SlotNormal.java similarity index 100% rename from container/slot/SlotNormal.java rename to src/main/java/appeng/container/slot/SlotNormal.java diff --git a/container/slot/SlotOutput.java b/src/main/java/appeng/container/slot/SlotOutput.java similarity index 100% rename from container/slot/SlotOutput.java rename to src/main/java/appeng/container/slot/SlotOutput.java diff --git a/container/slot/SlotPatternOutputs.java b/src/main/java/appeng/container/slot/SlotPatternOutputs.java similarity index 100% rename from container/slot/SlotPatternOutputs.java rename to src/main/java/appeng/container/slot/SlotPatternOutputs.java diff --git a/container/slot/SlotPatternTerm.java b/src/main/java/appeng/container/slot/SlotPatternTerm.java similarity index 100% rename from container/slot/SlotPatternTerm.java rename to src/main/java/appeng/container/slot/SlotPatternTerm.java diff --git a/container/slot/SlotPlayerHotBar.java b/src/main/java/appeng/container/slot/SlotPlayerHotBar.java similarity index 100% rename from container/slot/SlotPlayerHotBar.java rename to src/main/java/appeng/container/slot/SlotPlayerHotBar.java diff --git a/container/slot/SlotPlayerInv.java b/src/main/java/appeng/container/slot/SlotPlayerInv.java similarity index 100% rename from container/slot/SlotPlayerInv.java rename to src/main/java/appeng/container/slot/SlotPlayerInv.java diff --git a/container/slot/SlotRestrictedInput.java b/src/main/java/appeng/container/slot/SlotRestrictedInput.java similarity index 100% rename from container/slot/SlotRestrictedInput.java rename to src/main/java/appeng/container/slot/SlotRestrictedInput.java diff --git a/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java similarity index 100% rename from core/AEConfig.java rename to src/main/java/appeng/core/AEConfig.java diff --git a/core/AELog.java b/src/main/java/appeng/core/AELog.java similarity index 95% rename from core/AELog.java rename to src/main/java/appeng/core/AELog.java index fc3d6519d..61dfb892b 100644 --- a/core/AELog.java +++ b/src/main/java/appeng/core/AELog.java @@ -1,82 +1,82 @@ -package appeng.core; - -import org.apache.logging.log4j.Level; - -import appeng.core.features.AEFeature; -import appeng.tile.AEBaseTile; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.FMLRelaunchLog; - -public class AELog -{ - - public static cpw.mods.fml.relauncher.FMLRelaunchLog instance = cpw.mods.fml.relauncher.FMLRelaunchLog.log; - - private AELog() { - } - - private static void log(Level level, String format, Object... data) - { - if ( AEConfig.instance == null || AEConfig.instance.isFeatureEnabled( AEFeature.Logging ) ) - { - FMLRelaunchLog.log( "AE2:" + (Platform.isServer() ? "S" : "C"), level, format, data ); - } - } - - public static void severe(String format, Object... data) - { - log( Level.ERROR, format, data ); - } - - public static void warning(String format, Object... data) - { - log( Level.WARN, format, data ); - } - - public static void info(String format, Object... data) - { - log( Level.INFO, format, data ); - } - - public static void grinder(String o) - { - if ( AEConfig.instance.isFeatureEnabled( AEFeature.GrinderLogging ) ) - { - log( Level.DEBUG, "grinder: " + o ); - } - } - - public static void error(Throwable e) - { - if ( AEConfig.instance.isFeatureEnabled( AEFeature.Logging ) ) - { - severe( "Error: " + e.getClass().getName() + " : " + e.getMessage() ); - e.printStackTrace(); - } - } - - public static void integration(Throwable exception) - { - if ( AEConfig.instance.isFeatureEnabled( AEFeature.IntegrationLogging ) ) - { - error( exception ); - } - } - - public static void blockUpdate(int xCoord, int yCoord, int zCoord, AEBaseTile aeBaseTile) - { - if ( AEConfig.instance.isFeatureEnabled( AEFeature.UpdateLogging ) ) - { - info( aeBaseTile.getClass().getName() + " @ " + xCoord + ", " + yCoord + ", " + zCoord ); - } - } - - public static void crafting(String format, Object... data) - { - if ( AEConfig.instance.isFeatureEnabled( AEFeature.CraftingLog ) ) - { - log( Level.INFO, format, data ); - } - } - -} +package appeng.core; + +import org.apache.logging.log4j.Level; + +import appeng.core.features.AEFeature; +import appeng.tile.AEBaseTile; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.FMLRelaunchLog; + +public class AELog +{ + + public static cpw.mods.fml.relauncher.FMLRelaunchLog instance = cpw.mods.fml.relauncher.FMLRelaunchLog.log; + + private AELog() { + } + + private static void log(Level level, String format, Object... data) + { + if ( AEConfig.instance == null || AEConfig.instance.isFeatureEnabled( AEFeature.Logging ) ) + { + FMLRelaunchLog.log( "AE2:" + (Platform.isServer() ? "S" : "C"), level, format, data ); + } + } + + public static void severe(String format, Object... data) + { + log( Level.ERROR, format, data ); + } + + public static void warning(String format, Object... data) + { + log( Level.WARN, format, data ); + } + + public static void info(String format, Object... data) + { + log( Level.INFO, format, data ); + } + + public static void grinder(String o) + { + if ( AEConfig.instance.isFeatureEnabled( AEFeature.GrinderLogging ) ) + { + log( Level.DEBUG, "grinder: " + o ); + } + } + + public static void error(Throwable e) + { + if ( AEConfig.instance.isFeatureEnabled( AEFeature.Logging ) ) + { + severe( "Error: " + e.getClass().getName() + " : " + e.getMessage() ); + e.printStackTrace(); + } + } + + public static void integration(Throwable exception) + { + if ( AEConfig.instance.isFeatureEnabled( AEFeature.IntegrationLogging ) ) + { + error( exception ); + } + } + + public static void blockUpdate(int xCoord, int yCoord, int zCoord, AEBaseTile aeBaseTile) + { + if ( AEConfig.instance.isFeatureEnabled( AEFeature.UpdateLogging ) ) + { + info( aeBaseTile.getClass().getName() + " @ " + xCoord + ", " + yCoord + ", " + zCoord ); + } + } + + public static void crafting(String format, Object... data) + { + if ( AEConfig.instance.isFeatureEnabled( AEFeature.CraftingLog ) ) + { + log( Level.INFO, format, data ); + } + } + +} diff --git a/core/Api.java b/src/main/java/appeng/core/Api.java similarity index 95% rename from core/Api.java rename to src/main/java/appeng/core/Api.java index dd910be2b..f1fe1c972 100644 --- a/core/Api.java +++ b/src/main/java/appeng/core/Api.java @@ -1,99 +1,99 @@ -package appeng.core; - -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.IAppEngApi; -import appeng.api.definitions.Blocks; -import appeng.api.definitions.Items; -import appeng.api.definitions.Materials; -import appeng.api.definitions.Parts; -import appeng.api.exceptions.FailedConnection; -import appeng.api.features.IRegistryContainer; -import appeng.api.networking.IGridBlock; -import appeng.api.networking.IGridConnection; -import appeng.api.networking.IGridNode; -import appeng.api.parts.IPartHelper; -import appeng.api.storage.IStorageHelper; -import appeng.core.api.ApiPart; -import appeng.core.api.ApiStorage; -import appeng.core.features.registries.RegistryContainer; -import appeng.me.GridConnection; -import appeng.me.GridNode; -import appeng.util.Platform; - -public class Api implements IAppEngApi -{ - - public static final Api instance = new Api(); - - private Api() { - - } - - // private MovableTileRegistry MovableRegistry = new MovableTileRegistry(); - private RegistryContainer rc = new RegistryContainer(); - private ApiStorage storageHelper = new ApiStorage(); - - public ApiPart partHelper = new ApiPart(); - - private Materials materials = new Materials(); - private Items items = new Items(); - private Blocks blocks = new Blocks(); - private Parts parts = new Parts(); - - @Override - public IRegistryContainer registries() - { - return rc; - } - - @Override - public Items items() - { - return items; - } - - @Override - public Materials materials() - { - return materials; - } - - @Override - public Blocks blocks() - { - return blocks; - } - - @Override - public Parts parts() - { - return parts; - } - - @Override - public IStorageHelper storage() - { - return storageHelper; - } - - @Override - public IPartHelper partHelper() - { - return partHelper; - } - - @Override - public IGridNode createGridNode(IGridBlock blk) - { - if ( Platform.isClient() ) - throw new RuntimeException( "Grid Features are Server Side Only." ); - return new GridNode( blk ); - } - - @Override - public IGridConnection createGridConnection(IGridNode a, IGridNode b) throws FailedConnection - { - return new GridConnection( a, b, ForgeDirection.UNKNOWN ); - } - -} +package appeng.core; + +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.IAppEngApi; +import appeng.api.definitions.Blocks; +import appeng.api.definitions.Items; +import appeng.api.definitions.Materials; +import appeng.api.definitions.Parts; +import appeng.api.exceptions.FailedConnection; +import appeng.api.features.IRegistryContainer; +import appeng.api.networking.IGridBlock; +import appeng.api.networking.IGridConnection; +import appeng.api.networking.IGridNode; +import appeng.api.parts.IPartHelper; +import appeng.api.storage.IStorageHelper; +import appeng.core.api.ApiPart; +import appeng.core.api.ApiStorage; +import appeng.core.features.registries.RegistryContainer; +import appeng.me.GridConnection; +import appeng.me.GridNode; +import appeng.util.Platform; + +public class Api implements IAppEngApi +{ + + public static final Api instance = new Api(); + + private Api() { + + } + + // private MovableTileRegistry MovableRegistry = new MovableTileRegistry(); + private RegistryContainer rc = new RegistryContainer(); + private ApiStorage storageHelper = new ApiStorage(); + + public ApiPart partHelper = new ApiPart(); + + private Materials materials = new Materials(); + private Items items = new Items(); + private Blocks blocks = new Blocks(); + private Parts parts = new Parts(); + + @Override + public IRegistryContainer registries() + { + return rc; + } + + @Override + public Items items() + { + return items; + } + + @Override + public Materials materials() + { + return materials; + } + + @Override + public Blocks blocks() + { + return blocks; + } + + @Override + public Parts parts() + { + return parts; + } + + @Override + public IStorageHelper storage() + { + return storageHelper; + } + + @Override + public IPartHelper partHelper() + { + return partHelper; + } + + @Override + public IGridNode createGridNode(IGridBlock blk) + { + if ( Platform.isClient() ) + throw new RuntimeException( "Grid Features are Server Side Only." ); + return new GridNode( blk ); + } + + @Override + public IGridConnection createGridConnection(IGridNode a, IGridNode b) throws FailedConnection + { + return new GridConnection( a, b, ForgeDirection.UNKNOWN ); + } + +} diff --git a/core/AppEng.java b/src/main/java/appeng/core/AppEng.java similarity index 100% rename from core/AppEng.java rename to src/main/java/appeng/core/AppEng.java diff --git a/core/AppEng.java.rej b/src/main/java/appeng/core/AppEng.java.rej similarity index 100% rename from core/AppEng.java.rej rename to src/main/java/appeng/core/AppEng.java.rej diff --git a/core/CommonHelper.java b/src/main/java/appeng/core/CommonHelper.java similarity index 96% rename from core/CommonHelper.java rename to src/main/java/appeng/core/CommonHelper.java index 8bcc1b863..bad7301b3 100644 --- a/core/CommonHelper.java +++ b/src/main/java/appeng/core/CommonHelper.java @@ -1,50 +1,50 @@ -package appeng.core; - -import java.util.List; -import java.util.Random; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.world.World; -import appeng.api.parts.CableRenderMode; -import appeng.block.AEBaseBlock; -import appeng.client.EffectType; -import appeng.core.sync.AppEngPacket; -import cpw.mods.fml.common.SidedProxy; - -public abstract class CommonHelper -{ - - @SidedProxy(clientSide = "appeng.client.ClientHelper", serverSide = "appeng.server.ServerHelper") - public static CommonHelper proxy; - - public abstract void init(); - - public abstract World getWorld(); - - public abstract void bindTileEntitySpecialRenderer(Class tile, AEBaseBlock blk); - - public abstract List getPlayers(); - - public abstract void sendToAllNearExcept(EntityPlayer p, double x, double y, double z, double dist, World w, AppEngPacket packet); - - public abstract void spawnEffect(EffectType effect, World worldObj, double posX, double posY, double posZ, Object extra); - - public abstract boolean shouldAddParticles(Random r); - - public abstract MovingObjectPosition getMOP(); - - public abstract void doRenderItem(ItemStack itemstack, World w); - - public abstract void postinit(); - - public abstract CableRenderMode getRenderMode(); - - public abstract void triggerUpdates(); - - public abstract void updateRenderMode(EntityPlayer player); - - public abstract void missingCoreMod(); - -} +package appeng.core; + +import java.util.List; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import appeng.api.parts.CableRenderMode; +import appeng.block.AEBaseBlock; +import appeng.client.EffectType; +import appeng.core.sync.AppEngPacket; +import cpw.mods.fml.common.SidedProxy; + +public abstract class CommonHelper +{ + + @SidedProxy(clientSide = "appeng.client.ClientHelper", serverSide = "appeng.server.ServerHelper") + public static CommonHelper proxy; + + public abstract void init(); + + public abstract World getWorld(); + + public abstract void bindTileEntitySpecialRenderer(Class tile, AEBaseBlock blk); + + public abstract List getPlayers(); + + public abstract void sendToAllNearExcept(EntityPlayer p, double x, double y, double z, double dist, World w, AppEngPacket packet); + + public abstract void spawnEffect(EffectType effect, World worldObj, double posX, double posY, double posZ, Object extra); + + public abstract boolean shouldAddParticles(Random r); + + public abstract MovingObjectPosition getMOP(); + + public abstract void doRenderItem(ItemStack itemstack, World w); + + public abstract void postinit(); + + public abstract CableRenderMode getRenderMode(); + + public abstract void triggerUpdates(); + + public abstract void updateRenderMode(EntityPlayer player); + + public abstract void missingCoreMod(); + +} diff --git a/core/CreativeTab.java b/src/main/java/appeng/core/CreativeTab.java similarity index 96% rename from core/CreativeTab.java rename to src/main/java/appeng/core/CreativeTab.java index 30ada923a..0cfc9b755 100644 --- a/core/CreativeTab.java +++ b/src/main/java/appeng/core/CreativeTab.java @@ -1,50 +1,50 @@ -package appeng.core; - -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import appeng.api.AEApi; -import appeng.api.util.AEItemDefinition; - -public final class CreativeTab extends CreativeTabs -{ - - public static CreativeTab instance = null; - - public CreativeTab() { - super( "appliedenergistics2" ); - } - - @Override - public Item getTabIconItem() - { - return getIconItemStack().getItem(); - } - - @Override - public ItemStack getIconItemStack() - { - return findFirst( AEApi.instance().blocks().blockController, AEApi.instance().blocks().blockChest, AEApi.instance().blocks().blockCellWorkbench, AEApi - .instance().blocks().blockFluix, AEApi.instance().items().itemCell1k, AEApi.instance().items().itemNetworkTool, - AEApi.instance().materials().materialFluixCrystal, AEApi.instance().materials().materialCertusQuartzCrystal ); - } - - private ItemStack findFirst(AEItemDefinition... choices) - { - for (AEItemDefinition a : choices) - { - ItemStack is = a.stack( 1 ); - if ( is != null ) - return is; - } - - return new ItemStack( Blocks.chest ); - } - - public static void init() - { - instance = new CreativeTab(); - } - +package appeng.core; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import appeng.api.AEApi; +import appeng.api.util.AEItemDefinition; + +public final class CreativeTab extends CreativeTabs +{ + + public static CreativeTab instance = null; + + public CreativeTab() { + super( "appliedenergistics2" ); + } + + @Override + public Item getTabIconItem() + { + return getIconItemStack().getItem(); + } + + @Override + public ItemStack getIconItemStack() + { + return findFirst( AEApi.instance().blocks().blockController, AEApi.instance().blocks().blockChest, AEApi.instance().blocks().blockCellWorkbench, AEApi + .instance().blocks().blockFluix, AEApi.instance().items().itemCell1k, AEApi.instance().items().itemNetworkTool, + AEApi.instance().materials().materialFluixCrystal, AEApi.instance().materials().materialCertusQuartzCrystal ); + } + + private ItemStack findFirst(AEItemDefinition... choices) + { + for (AEItemDefinition a : choices) + { + ItemStack is = a.stack( 1 ); + if ( is != null ) + return is; + } + + return new ItemStack( Blocks.chest ); + } + + public static void init() + { + instance = new CreativeTab(); + } + } \ No newline at end of file diff --git a/core/CreativeTabFacade.java b/src/main/java/appeng/core/CreativeTabFacade.java similarity index 100% rename from core/CreativeTabFacade.java rename to src/main/java/appeng/core/CreativeTabFacade.java diff --git a/core/FacadeConfig.java b/src/main/java/appeng/core/FacadeConfig.java similarity index 100% rename from core/FacadeConfig.java rename to src/main/java/appeng/core/FacadeConfig.java diff --git a/core/Registration.java b/src/main/java/appeng/core/Registration.java similarity index 97% rename from core/Registration.java rename to src/main/java/appeng/core/Registration.java index 659ed10fa..d1cfa8dbf 100644 --- a/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -1,779 +1,779 @@ -package appeng.core; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; - -import net.minecraft.item.crafting.CraftingManager; -import net.minecraft.util.WeightedRandomChestContent; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraftforge.common.ChestGenHooks; -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.oredict.OreDictionary; -import net.minecraftforge.oredict.RecipeSorter; -import net.minecraftforge.oredict.RecipeSorter.Category; -import appeng.api.AEApi; -import appeng.api.config.Upgrades; -import appeng.api.definitions.Blocks; -import appeng.api.definitions.Items; -import appeng.api.definitions.Materials; -import appeng.api.definitions.Parts; -import appeng.api.features.IRecipeHandlerRegistry; -import appeng.api.features.IWirelessTermHandler; -import appeng.api.features.IWorldGen.WorldGenType; -import appeng.api.movable.IMovableRegistry; -import appeng.api.networking.IGridCacheRegistry; -import appeng.api.networking.crafting.ICraftingGrid; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.pathing.IPathingGrid; -import appeng.api.networking.security.ISecurityGrid; -import appeng.api.networking.spatial.ISpatialCache; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.networking.ticking.ITickManager; -import appeng.api.parts.IPartHelper; -import appeng.api.util.AEColor; -import appeng.api.util.AEItemDefinition; -import appeng.block.crafting.BlockCraftingMonitor; -import appeng.block.crafting.BlockCraftingStorage; -import appeng.block.crafting.BlockCraftingUnit; -import appeng.block.crafting.BlockMolecularAssembler; -import appeng.block.grindstone.BlockCrank; -import appeng.block.grindstone.BlockGrinder; -import appeng.block.misc.BlockCellWorkbench; -import appeng.block.misc.BlockCharger; -import appeng.block.misc.BlockCondenser; -import appeng.block.misc.BlockInscriber; -import appeng.block.misc.BlockInterface; -import appeng.block.misc.BlockLightDetector; -import appeng.block.misc.BlockPaint; -import appeng.block.misc.BlockQuartzGrowthAccelerator; -import appeng.block.misc.BlockQuartzTorch; -import appeng.block.misc.BlockSecurity; -import appeng.block.misc.BlockSkyCompass; -import appeng.block.misc.BlockTinyTNT; -import appeng.block.misc.BlockVibrationChamber; -import appeng.block.networking.BlockCableBus; -import appeng.block.networking.BlockController; -import appeng.block.networking.BlockCreativeEnergyCell; -import appeng.block.networking.BlockDenseEnergyCell; -import appeng.block.networking.BlockEnergyAcceptor; -import appeng.block.networking.BlockEnergyCell; -import appeng.block.networking.BlockWireless; -import appeng.block.qnb.BlockQuantumLinkChamber; -import appeng.block.qnb.BlockQuantumRing; -import appeng.block.solids.BlockFluix; -import appeng.block.solids.BlockQuartz; -import appeng.block.solids.BlockQuartzChiseled; -import appeng.block.solids.BlockQuartzGlass; -import appeng.block.solids.BlockQuartzLamp; -import appeng.block.solids.BlockQuartzPillar; -import appeng.block.solids.BlockSkyStone; -import appeng.block.solids.OreQuartz; -import appeng.block.solids.OreQuartzCharged; -import appeng.block.spatial.BlockMatrixFrame; -import appeng.block.spatial.BlockSpatialIOPort; -import appeng.block.spatial.BlockSpatialPylon; -import appeng.block.storage.BlockChest; -import appeng.block.storage.BlockDrive; -import appeng.block.storage.BlockIOPort; -import appeng.block.storage.BlockSkyChest; -import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; -import appeng.core.features.ColoredItemDefinition; -import appeng.core.features.DamagedItemDefinition; -import appeng.core.features.IAEFeature; -import appeng.core.features.IStackSrc; -import appeng.core.features.ItemStackSrc; -import appeng.core.features.NullItemDefinition; -import appeng.core.features.WrappedDamageItemDefinition; -import appeng.core.features.registries.P2PTunnelRegistry; -import appeng.core.features.registries.entries.BasicCellHandler; -import appeng.core.features.registries.entries.CreativeCellHandler; -import appeng.core.localization.GuiText; -import appeng.core.localization.PlayerMessages; -import appeng.core.stats.PlayerStatsRegistration; -import appeng.debug.BlockChunkloader; -import appeng.debug.BlockCubeGenerator; -import appeng.debug.BlockItemGen; -import appeng.debug.BlockPhantomNode; -import appeng.debug.ToolDebugCard; -import appeng.debug.ToolEraser; -import appeng.debug.ToolMeteoritePlacer; -import appeng.debug.ToolReplicatorCard; -import appeng.hooks.AETrading; -import appeng.hooks.MeteoriteWorldGen; -import appeng.hooks.QuartzWorldGen; -import appeng.hooks.TickHandler; -import appeng.integration.IntegrationType; -import appeng.items.materials.ItemMultiMaterial; -import appeng.items.materials.MaterialType; -import appeng.items.misc.ItemCrystalSeed; -import appeng.items.misc.ItemEncodedPattern; -import appeng.items.misc.ItemPaintBall; -import appeng.items.parts.ItemFacade; -import appeng.items.parts.ItemMultiPart; -import appeng.items.parts.PartType; -import appeng.items.storage.ItemBasicStorageCell; -import appeng.items.storage.ItemCreativeStorageCell; -import appeng.items.storage.ItemSpatialStorageCell; -import appeng.items.storage.ItemViewCell; -import appeng.items.tools.ToolBiometricCard; -import appeng.items.tools.ToolMemoryCard; -import appeng.items.tools.ToolNetworkTool; -import appeng.items.tools.powered.ToolChargedStaff; -import appeng.items.tools.powered.ToolColorApplicator; -import appeng.items.tools.powered.ToolEntropyManipulator; -import appeng.items.tools.powered.ToolMassCannon; -import appeng.items.tools.powered.ToolPortableCell; -import appeng.items.tools.powered.ToolWirelessTerminal; -import appeng.items.tools.quartz.ToolQuartzAxe; -import appeng.items.tools.quartz.ToolQuartzCuttingKnife; -import appeng.items.tools.quartz.ToolQuartzHoe; -import appeng.items.tools.quartz.ToolQuartzPickaxe; -import appeng.items.tools.quartz.ToolQuartzSpade; -import appeng.items.tools.quartz.ToolQuartzSword; -import appeng.items.tools.quartz.ToolQuartzWrench; -import appeng.me.cache.CraftingGridCache; -import appeng.me.cache.EnergyGridCache; -import appeng.me.cache.GridStorageCache; -import appeng.me.cache.P2PCache; -import appeng.me.cache.PathGridCache; -import appeng.me.cache.SecurityCache; -import appeng.me.cache.SpatialPylonCache; -import appeng.me.cache.TickManagerCache; -import appeng.me.storage.AEExternalHandler; -import appeng.parts.PartPlacement; -import appeng.recipes.AEItemResolver; -import appeng.recipes.RecipeHandler; -import appeng.recipes.game.DisassembleRecipe; -import appeng.recipes.game.FacadeRecipe; -import appeng.recipes.game.ShapedRecipe; -import appeng.recipes.game.ShapelessRecipe; -import appeng.recipes.handlers.Crusher; -import appeng.recipes.handlers.Grind; -import appeng.recipes.handlers.GrindFZ; -import appeng.recipes.handlers.HCCrusher; -import appeng.recipes.handlers.Inscribe; -import appeng.recipes.handlers.Macerator; -import appeng.recipes.handlers.MekCrusher; -import appeng.recipes.handlers.MekEnrichment; -import appeng.recipes.handlers.Press; -import appeng.recipes.handlers.Pulverizer; -import appeng.recipes.handlers.Shaped; -import appeng.recipes.handlers.Shapeless; -import appeng.recipes.handlers.Smelt; -import appeng.recipes.loader.ConfigLoader; -import appeng.recipes.loader.JarLoader; -import appeng.recipes.ores.OreDictionaryHandler; -import appeng.spatial.BiomeGenStorage; -import appeng.spatial.StorageWorldProvider; -import appeng.tile.AEBaseTile; -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 -{ - - final public static Registration instance = new Registration(); - - public RecipeHandler recipeHandler; - public BiomeGenBase storageBiome; - - private Registration() - { - recipeHandler = new RecipeHandler(); - } - - final private Multimap featuresToEntities = ArrayListMultimap.create(); - - public void PreInit(FMLPreInitializationEvent event) - { - registerSpatial( false ); - - IRecipeHandlerRegistry recipeRegistry = AEApi.instance().registries().recipes(); - recipeRegistry.addNewSubItemResolver( new AEItemResolver() ); - - recipeRegistry.addNewCraftHandler( "hccrusher", HCCrusher.class ); - recipeRegistry.addNewCraftHandler( "mekcrusher", MekCrusher.class ); - recipeRegistry.addNewCraftHandler( "mekechamber", MekEnrichment.class ); - recipeRegistry.addNewCraftHandler( "grind", Grind.class ); - recipeRegistry.addNewCraftHandler( "crusher", Crusher.class ); - recipeRegistry.addNewCraftHandler( "grindfz", GrindFZ.class ); - recipeRegistry.addNewCraftHandler( "pulverizer", Pulverizer.class ); - recipeRegistry.addNewCraftHandler( "macerator", Macerator.class ); - - recipeRegistry.addNewCraftHandler( "smelt", Smelt.class ); - recipeRegistry.addNewCraftHandler( "inscribe", Inscribe.class ); - recipeRegistry.addNewCraftHandler( "press", Press.class ); - - recipeRegistry.addNewCraftHandler( "shaped", Shaped.class ); - recipeRegistry.addNewCraftHandler( "shapeless", Shapeless.class ); - - RecipeSorter.register( "AE2-Facade", FacadeRecipe.class, Category.SHAPED, "" ); - RecipeSorter.register( "AE2-Shaped", ShapedRecipe.class, Category.SHAPED, "" ); - RecipeSorter.register( "AE2-Shapeless", ShapelessRecipe.class, Category.SHAPELESS, "" ); - - MinecraftForge.EVENT_BUS.register( OreDictionaryHandler.instance ); - - Items items = appeng.core.Api.instance.items(); - Materials materials = appeng.core.Api.instance.materials(); - Parts parts = appeng.core.Api.instance.parts(); - Blocks blocks = appeng.core.Api.instance.blocks(); - - AEItemDefinition materialItem = (AEFeatureHandler) addFeature( ItemMultiMaterial.class ); - - Class materialClass = materials.getClass(); - for (MaterialType mat : MaterialType.values()) - { - try - { - if ( mat == MaterialType.InvalidType ) - ((ItemMultiMaterial) materialItem.item()).createMaterial( mat ); - else - { - Field f = materialClass.getField( "material" + mat.name() ); - 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) - { - AELog.severe( "Error creating material: " + mat.name() ); - throw new RuntimeException( err ); - } - } - - AEItemDefinition partItem = (AEFeatureHandler) addFeature( ItemMultiPart.class ); - - Class partClass = parts.getClass(); - for (PartType type : PartType.values()) - { - try - { - if ( type == PartType.InvalidType ) - ((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 ); - if ( is != null ) - f.set( parts, new DamagedItemDefinition( is ) ); - else - f.set( parts, new NullItemDefinition() ); - } - else - { - if ( variants[0] instanceof AEColor ) - { - ColoredItemDefinition def = new ColoredItemDefinition(); - - for (Enum v : variants) - { - ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, v ); - if ( is != null ) - def.add( (AEColor) v, is ); - } - - f.set( parts, def ); - } - } - } - } - catch (Throwable err) - { - AELog.severe( "Error creating part: " + type.name() ); - throw new RuntimeException( err ); - } - } - - // very important block! - blocks.blockMultiPart = addFeature( BlockCableBus.class ); - - blocks.blockCraftingUnit = addFeature( BlockCraftingUnit.class ); - blocks.blockCraftingAccelerator = new WrappedDamageItemDefinition( blocks.blockCraftingUnit, 1 ); - blocks.blockCraftingMonitor = addFeature( BlockCraftingMonitor.class ); - blocks.blockCraftingStorage1k = addFeature( BlockCraftingStorage.class ); - blocks.blockCraftingStorage4k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 1 ); - blocks.blockCraftingStorage16k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 2 ); - blocks.blockCraftingStorage64k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 3 ); - blocks.blockMolecularAssembler = addFeature( BlockMolecularAssembler.class ); - - blocks.blockQuartzOre = addFeature( OreQuartz.class ); - blocks.blockQuartzOreCharged = addFeature( OreQuartzCharged.class ); - blocks.blockMatrixFrame = addFeature( BlockMatrixFrame.class ); - blocks.blockQuartz = addFeature( BlockQuartz.class ); - blocks.blockFluix = addFeature( BlockFluix.class ); - blocks.blockSkyStone = addFeature( BlockSkyStone.class ); - blocks.blockSkyChest = addFeature( BlockSkyChest.class ); - blocks.blockSkyCompass = addFeature( BlockSkyCompass.class ); - - blocks.blockQuartzGlass = addFeature( BlockQuartzGlass.class ); - blocks.blockQuartzVibrantGlass = addFeature( BlockQuartzLamp.class ); - blocks.blockQuartzPillar = addFeature( BlockQuartzPillar.class ); - blocks.blockQuartzChiseled = addFeature( BlockQuartzChiseled.class ); - blocks.blockQuartzTorch = addFeature( BlockQuartzTorch.class ); - blocks.blockLightDetector = addFeature( BlockLightDetector.class ); - blocks.blockCharger = addFeature( BlockCharger.class ); - blocks.blockQuartzGrowthAccelerator = addFeature( BlockQuartzGrowthAccelerator.class ); - - blocks.blockGrindStone = addFeature( BlockGrinder.class ); - blocks.blockCrankHandle = addFeature( BlockCrank.class ); - blocks.blockInscriber = addFeature( BlockInscriber.class ); - blocks.blockWireless = addFeature( BlockWireless.class ); - blocks.blockTinyTNT = addFeature( BlockTinyTNT.class ); - - blocks.blockQuantumRing = addFeature( BlockQuantumRing.class ); - blocks.blockQuantumLink = addFeature( BlockQuantumLinkChamber.class ); - - blocks.blockSpatialPylon = addFeature( BlockSpatialPylon.class ); - blocks.blockSpatialIOPort = addFeature( BlockSpatialIOPort.class ); - - blocks.blockController = addFeature( BlockController.class ); - blocks.blockDrive = addFeature( BlockDrive.class ); - blocks.blockChest = addFeature( BlockChest.class ); - blocks.blockInterface = addFeature( BlockInterface.class ); - blocks.blockCellWorkbench = addFeature( BlockCellWorkbench.class ); - blocks.blockIOPort = addFeature( BlockIOPort.class ); - blocks.blockCondenser = addFeature( BlockCondenser.class ); - blocks.blockEnergyAcceptor = addFeature( BlockEnergyAcceptor.class ); - blocks.blockVibrationChamber = addFeature( BlockVibrationChamber.class ); - - blocks.blockEnergyCell = addFeature( BlockEnergyCell.class ); - blocks.blockEnergyCellDense = addFeature( BlockDenseEnergyCell.class ); - blocks.blockEnergyCellCreative = addFeature( BlockCreativeEnergyCell.class ); - - blocks.blockSecurity = addFeature( BlockSecurity.class ); - blocks.blockPaint = addFeature( BlockPaint.class ); - - items.itemCellCreative = addFeature( ItemCreativeStorageCell.class ); - items.itemViewCell = addFeature( ItemViewCell.class ); - items.itemEncodedPattern = addFeature( ItemEncodedPattern.class ); - - items.itemCell1k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell1kPart, 1 ); - items.itemCell4k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell4kPart, 4 ); - items.itemCell16k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell16kPart, 16 ); - items.itemCell64k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell64kPart, 64 ); - - items.itemSpatialCell2 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell2SpatialPart, 2 ); - items.itemSpatialCell16 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell16SpatialPart, 16 ); - items.itemSpatialCell128 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell128SpatialPart, 128 ); - - items.itemCertusQuartzKnife = addFeature( ToolQuartzCuttingKnife.class, AEFeature.CertusQuartzTools ); - items.itemCertusQuartzWrench = addFeature( ToolQuartzWrench.class, AEFeature.CertusQuartzTools ); - items.itemCertusQuartzAxe = addFeature( ToolQuartzAxe.class, AEFeature.CertusQuartzTools ); - items.itemCertusQuartzHoe = addFeature( ToolQuartzHoe.class, AEFeature.CertusQuartzTools ); - items.itemCertusQuartzPick = addFeature( ToolQuartzPickaxe.class, AEFeature.CertusQuartzTools ); - items.itemCertusQuartzShovel = addFeature( ToolQuartzSpade.class, AEFeature.CertusQuartzTools ); - items.itemCertusQuartzSword = addFeature( ToolQuartzSword.class, AEFeature.CertusQuartzTools ); - - items.itemNetherQuartzKnife = addFeature( ToolQuartzCuttingKnife.class, AEFeature.NetherQuartzTools ); - items.itemNetherQuartzWrench = addFeature( ToolQuartzWrench.class, AEFeature.NetherQuartzTools ); - items.itemNetherQuartzAxe = addFeature( ToolQuartzAxe.class, AEFeature.NetherQuartzTools ); - items.itemNetherQuartzHoe = addFeature( ToolQuartzHoe.class, AEFeature.NetherQuartzTools ); - items.itemNetherQuartzPick = addFeature( ToolQuartzPickaxe.class, AEFeature.NetherQuartzTools ); - items.itemNetherQuartzShovel = addFeature( ToolQuartzSpade.class, AEFeature.NetherQuartzTools ); - items.itemNetherQuartzSword = addFeature( ToolQuartzSword.class, AEFeature.NetherQuartzTools ); - - items.itemMassCannon = addFeature( ToolMassCannon.class ); - items.itemMemoryCard = addFeature( ToolMemoryCard.class ); - items.itemChargedStaff = addFeature( ToolChargedStaff.class ); - items.itemEntropyManipulator = addFeature( ToolEntropyManipulator.class ); - items.itemColorApplicator = addFeature( ToolColorApplicator.class ); - - items.itemWirelessTerminal = addFeature( ToolWirelessTerminal.class ); - items.itemNetworkTool = addFeature( ToolNetworkTool.class ); - items.itemPortableCell = addFeature( ToolPortableCell.class ); - items.itemBiometricCard = addFeature( ToolBiometricCard.class ); - - items.itemFacade = addFeature( ItemFacade.class ); - items.itemCrystalSeed = addFeature( ItemCrystalSeed.class ); - - ColoredItemDefinition pbreg, pbregl; - items.itemPaintBall = pbreg = new ColoredItemDefinition(); - items.itemLumenPaintBall = pbregl = new ColoredItemDefinition(); - AEItemDefinition pb = addFeature( ItemPaintBall.class ); - - for (AEColor c : AEColor.values()) - { - if ( c != AEColor.Transparent ) - { - pbreg.add( c, new ItemStackSrc( pb.item(), c.ordinal() ) ); - pbregl.add( c, new ItemStackSrc( pb.item(), 20 + c.ordinal() ) ); - } - } - - addFeature( ToolEraser.class ); - addFeature( ToolMeteoritePlacer.class ); - addFeature( ToolDebugCard.class ); - addFeature( ToolReplicatorCard.class ); - addFeature( BlockItemGen.class ); - addFeature( BlockChunkloader.class ); - addFeature( BlockPhantomNode.class ); - addFeature( BlockCubeGenerator.class ); - } - - private AEItemDefinition addFeature(Class c, Object... Args) - { - - try - { - java.lang.reflect.Constructor[] con = c.getConstructors(); - Object obj = null; - - for (Constructor conItem : con) - { - Class paramTypes[] = conItem.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 ) - { - obj = conItem.newInstance( Args ); - break; - } - } - } - - 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" ); - - } - catch (Throwable e) - { - throw new RuntimeException( "Error with Feature: " + c.getName(), e ); - } - } - - 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 ); - - if ( expected == got || expected.isAssignableFrom( got ) ) - return true; - - return false; - } - - 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; - } - - public void Init(FMLInitializationEvent event) - { - // Perform ore camouflage! - ItemMultiMaterial.instance.unduplicate(); - - if ( AEConfig.instance.isFeatureEnabled( AEFeature.CustomRecipes ) ) - recipeHandler.parseRecipes( new ConfigLoader( AppEng.instance.getConfigPath() ), "index.recipe" ); - else - recipeHandler.parseRecipes( new JarLoader( "/assets/appliedenergistics2/recipes/" ), "index.recipe" ); - - IPartHelper ph = AEApi.instance().partHelper(); - ph.registerNewLayer( "appeng.parts.layers.LayerISidedInventory", "net.minecraft.inventory.ISidedInventory" ); - ph.registerNewLayer( "appeng.parts.layers.LayerIFluidHandler", "net.minecraftforge.fluids.IFluidHandler" ); - ph.registerNewLayer( "appeng.parts.layers.LayerITileStorageMonitorable", "appeng.api.implementations.tiles.ITileStorageMonitorable" ); - - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) ) - { - ph.registerNewLayer( "appeng.parts.layers.LayerIEnergySink", "ic2.api.energy.tile.IEnergySink" ); - ph.registerNewLayer( "appeng.parts.layers.LayerIEnergySource", "ic2.api.energy.tile.IEnergySource" ); - } - - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) ) - { - ph.registerNewLayer( "appeng.parts.layers.LayerIPowerEmitter", "buildcraft.api.power.IPowerEmitter" ); - ph.registerNewLayer( "appeng.parts.layers.LayerIPowerReceptor", "buildcraft.api.power.IPowerReceptor" ); - } - - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.MJ6 ) ) - ph.registerNewLayer( "appeng.parts.layers.LayerIBatteryProvider", "buildcraft.api.mj.IBatteryProvider" ); - - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.RF ) ) - ph.registerNewLayer( "appeng.parts.layers.LayerIEnergyHandler", "cofh.api.energy.IEnergyHandler" ); - - FMLCommonHandler.instance().bus().register( TickHandler.instance ); - MinecraftForge.EVENT_BUS.register( TickHandler.instance ); - - PartPlacement pp = new PartPlacement(); - MinecraftForge.EVENT_BUS.register( pp ); - FMLCommonHandler.instance().bus().register( pp ); - - IGridCacheRegistry gcr = AEApi.instance().registries().gridCache(); - gcr.registerGridCache( ITickManager.class, TickManagerCache.class ); - gcr.registerGridCache( IEnergyGrid.class, EnergyGridCache.class ); - gcr.registerGridCache( IPathingGrid.class, PathGridCache.class ); - gcr.registerGridCache( IStorageGrid.class, GridStorageCache.class ); - gcr.registerGridCache( P2PCache.class, P2PCache.class ); - gcr.registerGridCache( ISpatialCache.class, SpatialPylonCache.class ); - gcr.registerGridCache( ISecurityGrid.class, SecurityCache.class ); - gcr.registerGridCache( ICraftingGrid.class, CraftingGridCache.class ); - - AEApi.instance().registries().externalStorage().addExternalStorageInterface( new AEExternalHandler() ); - - AEApi.instance().registries().cell().addCellHandler( new BasicCellHandler() ); - AEApi.instance().registries().cell().addCellHandler( new CreativeCellHandler() ); - - AEApi.instance().registries().matterCannon().registerAmmo( AEApi.instance().materials().materialMatterBall.stack( 1 ), 32.0 ); - - recipeHandler.injectRecipes(); - - PlayerStatsRegistration.instance.init(); - - if ( AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting ) ) - CraftingManager.getInstance().getRecipeList().add( new DisassembleRecipe() ); - - if ( AEConfig.instance.isFeatureEnabled( AEFeature.enableFacadeCrafting ) ) - CraftingManager.getInstance().getRecipeList().add( new FacadeRecipe() ); - } - - public void PostInit(FMLPostInitializationEvent event) - { - registerSpatial( true ); - - // default settings.. - ((P2PTunnelRegistry) AEApi.instance().registries().p2pTunnel()).configure(); - - // add to localizaiton.. - PlayerMessages.values(); - GuiText.values(); - - Api.instance.partHelper.initFMPSupport(); - ((BlockCableBus) AEApi.instance().blocks().blockMultiPart.block()).setupTile(); - - // Interface - Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partInterface.stack( 1 ), 1 ); - Upgrades.CRAFTING.registerItem( AEApi.instance().blocks().blockInterface.stack( 1 ), 1 ); - - // IO Port! - Upgrades.SPEED.registerItem( AEApi.instance().blocks().blockIOPort.stack( 1 ), 3 ); - Upgrades.REDSTONE.registerItem( AEApi.instance().blocks().blockIOPort.stack( 1 ), 1 ); - - // Level Emitter! - Upgrades.FUZZY.registerItem( AEApi.instance().parts().partLevelEmitter.stack( 1 ), 1 ); - Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partLevelEmitter.stack( 1 ), 1 ); - - // Import Bus - Upgrades.FUZZY.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 1 ); - Upgrades.REDSTONE.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 1 ); - Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 2 ); - Upgrades.SPEED.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 4 ); - - // Export Bus - Upgrades.FUZZY.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 ); - Upgrades.REDSTONE.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 ); - Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 2 ); - Upgrades.SPEED.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 4 ); - Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 ); - - // Storage Cells - Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell1k.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell1k.stack( 1 ), 1 ); - - Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell4k.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell4k.stack( 1 ), 1 ); - - Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell16k.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell16k.stack( 1 ), 1 ); - - Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell64k.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell64k.stack( 1 ), 1 ); - - Upgrades.FUZZY.registerItem( AEApi.instance().items().itemPortableCell.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().items().itemPortableCell.stack( 1 ), 1 ); - - Upgrades.FUZZY.registerItem( AEApi.instance().items().itemViewCell.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().items().itemViewCell.stack( 1 ), 1 ); - - // Storage Bus - Upgrades.FUZZY.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 1 ); - Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 5 ); - - // Formation Plane - Upgrades.FUZZY.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 1 ); - Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 5 ); - - // Matter Cannon - Upgrades.FUZZY.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 1 ); - Upgrades.INVERTER.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 1 ); - Upgrades.SPEED.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 4 ); - - // Molecular Assembler - Upgrades.SPEED.registerItem( AEApi.instance().blocks().blockMolecularAssembler.stack( 1 ), 5 ); - - AEApi.instance().registries().wireless().registerWirelessHandler( (IWirelessTermHandler) AEApi.instance().items().itemWirelessTerminal.item() ); - - if ( AEConfig.instance.isFeatureEnabled( AEFeature.ChestLoot ) ) - { - ChestGenHooks d = ChestGenHooks.getInfo( ChestGenHooks.MINESHAFT_CORRIDOR ); - d.addItem( new WeightedRandomChestContent( AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), 1, 4, 2 ) ); - d.addItem( new WeightedRandomChestContent( AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ), 1, 4, 2 ) ); - } - - // add villager trading to black smiths for a few basic materials - if ( AEConfig.instance.isFeatureEnabled( AEFeature.VillagerTrading ) ) - VillagerRegistry.instance().registerVillageTradeHandler( 3, new AETrading() ); - - if ( AEConfig.instance.isFeatureEnabled( AEFeature.CertusQuartzWorldGen ) ) - GameRegistry.registerWorldGenerator( new QuartzWorldGen(), 0 ); - - if ( AEConfig.instance.isFeatureEnabled( AEFeature.MeteoriteWorldGen ) ) - GameRegistry.registerWorldGenerator( new MeteoriteWorldGen(), 0 ); - - IMovableRegistry mr = AEApi.instance().registries().movable(); - - /** - * You can't move bed rock. - */ - mr.blacklistBlock( net.minecraft.init.Blocks.bedrock ); - - /* - * White List Vanilla... - */ - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityBeacon.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityBrewingStand.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityChest.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityCommandBlock.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityComparator.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityDaylightDetector.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityDispenser.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityDropper.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityEnchantmentTable.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityEnderChest.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityEndPortal.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntitySkull.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityFurnace.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityMobSpawner.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntitySign.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityPiston.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityFlowerPot.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityNote.class ); - mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityHopper.class ); - - // very silly fix cause Reika decided to pair the item with a block. - OreDictionary.registerOre( "itemWheat", net.minecraft.init.Items.wheat ); - - /** - * Whitelist AE2 - */ - mr.whiteListTileEntity( AEBaseTile.class ); - - /** - * world gen - */ - for (WorldGenType type : WorldGenType.values()) - { - AEApi.instance().registries().worldgen().disableWorldGenForProviderID( type, StorageWorldProvider.class ); - - // end - AEApi.instance().registries().worldgen().disableWorldGenForDimension( type, 1 ); - - // nether - AEApi.instance().registries().worldgen().disableWorldGenForDimension( type, -1 ); - } - - /** - * initial recipe bake, if ore dictionary changes after this it re-bakes. - */ - 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(); - } - } - -} +package appeng.core; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; + +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.ChestGenHooks; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.oredict.RecipeSorter; +import net.minecraftforge.oredict.RecipeSorter.Category; +import appeng.api.AEApi; +import appeng.api.config.Upgrades; +import appeng.api.definitions.Blocks; +import appeng.api.definitions.Items; +import appeng.api.definitions.Materials; +import appeng.api.definitions.Parts; +import appeng.api.features.IRecipeHandlerRegistry; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.features.IWorldGen.WorldGenType; +import appeng.api.movable.IMovableRegistry; +import appeng.api.networking.IGridCacheRegistry; +import appeng.api.networking.crafting.ICraftingGrid; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.pathing.IPathingGrid; +import appeng.api.networking.security.ISecurityGrid; +import appeng.api.networking.spatial.ISpatialCache; +import appeng.api.networking.storage.IStorageGrid; +import appeng.api.networking.ticking.ITickManager; +import appeng.api.parts.IPartHelper; +import appeng.api.util.AEColor; +import appeng.api.util.AEItemDefinition; +import appeng.block.crafting.BlockCraftingMonitor; +import appeng.block.crafting.BlockCraftingStorage; +import appeng.block.crafting.BlockCraftingUnit; +import appeng.block.crafting.BlockMolecularAssembler; +import appeng.block.grindstone.BlockCrank; +import appeng.block.grindstone.BlockGrinder; +import appeng.block.misc.BlockCellWorkbench; +import appeng.block.misc.BlockCharger; +import appeng.block.misc.BlockCondenser; +import appeng.block.misc.BlockInscriber; +import appeng.block.misc.BlockInterface; +import appeng.block.misc.BlockLightDetector; +import appeng.block.misc.BlockPaint; +import appeng.block.misc.BlockQuartzGrowthAccelerator; +import appeng.block.misc.BlockQuartzTorch; +import appeng.block.misc.BlockSecurity; +import appeng.block.misc.BlockSkyCompass; +import appeng.block.misc.BlockTinyTNT; +import appeng.block.misc.BlockVibrationChamber; +import appeng.block.networking.BlockCableBus; +import appeng.block.networking.BlockController; +import appeng.block.networking.BlockCreativeEnergyCell; +import appeng.block.networking.BlockDenseEnergyCell; +import appeng.block.networking.BlockEnergyAcceptor; +import appeng.block.networking.BlockEnergyCell; +import appeng.block.networking.BlockWireless; +import appeng.block.qnb.BlockQuantumLinkChamber; +import appeng.block.qnb.BlockQuantumRing; +import appeng.block.solids.BlockFluix; +import appeng.block.solids.BlockQuartz; +import appeng.block.solids.BlockQuartzChiseled; +import appeng.block.solids.BlockQuartzGlass; +import appeng.block.solids.BlockQuartzLamp; +import appeng.block.solids.BlockQuartzPillar; +import appeng.block.solids.BlockSkyStone; +import appeng.block.solids.OreQuartz; +import appeng.block.solids.OreQuartzCharged; +import appeng.block.spatial.BlockMatrixFrame; +import appeng.block.spatial.BlockSpatialIOPort; +import appeng.block.spatial.BlockSpatialPylon; +import appeng.block.storage.BlockChest; +import appeng.block.storage.BlockDrive; +import appeng.block.storage.BlockIOPort; +import appeng.block.storage.BlockSkyChest; +import appeng.core.features.AEFeature; +import appeng.core.features.AEFeatureHandler; +import appeng.core.features.ColoredItemDefinition; +import appeng.core.features.DamagedItemDefinition; +import appeng.core.features.IAEFeature; +import appeng.core.features.IStackSrc; +import appeng.core.features.ItemStackSrc; +import appeng.core.features.NullItemDefinition; +import appeng.core.features.WrappedDamageItemDefinition; +import appeng.core.features.registries.P2PTunnelRegistry; +import appeng.core.features.registries.entries.BasicCellHandler; +import appeng.core.features.registries.entries.CreativeCellHandler; +import appeng.core.localization.GuiText; +import appeng.core.localization.PlayerMessages; +import appeng.core.stats.PlayerStatsRegistration; +import appeng.debug.BlockChunkloader; +import appeng.debug.BlockCubeGenerator; +import appeng.debug.BlockItemGen; +import appeng.debug.BlockPhantomNode; +import appeng.debug.ToolDebugCard; +import appeng.debug.ToolEraser; +import appeng.debug.ToolMeteoritePlacer; +import appeng.debug.ToolReplicatorCard; +import appeng.hooks.AETrading; +import appeng.hooks.MeteoriteWorldGen; +import appeng.hooks.QuartzWorldGen; +import appeng.hooks.TickHandler; +import appeng.integration.IntegrationType; +import appeng.items.materials.ItemMultiMaterial; +import appeng.items.materials.MaterialType; +import appeng.items.misc.ItemCrystalSeed; +import appeng.items.misc.ItemEncodedPattern; +import appeng.items.misc.ItemPaintBall; +import appeng.items.parts.ItemFacade; +import appeng.items.parts.ItemMultiPart; +import appeng.items.parts.PartType; +import appeng.items.storage.ItemBasicStorageCell; +import appeng.items.storage.ItemCreativeStorageCell; +import appeng.items.storage.ItemSpatialStorageCell; +import appeng.items.storage.ItemViewCell; +import appeng.items.tools.ToolBiometricCard; +import appeng.items.tools.ToolMemoryCard; +import appeng.items.tools.ToolNetworkTool; +import appeng.items.tools.powered.ToolChargedStaff; +import appeng.items.tools.powered.ToolColorApplicator; +import appeng.items.tools.powered.ToolEntropyManipulator; +import appeng.items.tools.powered.ToolMassCannon; +import appeng.items.tools.powered.ToolPortableCell; +import appeng.items.tools.powered.ToolWirelessTerminal; +import appeng.items.tools.quartz.ToolQuartzAxe; +import appeng.items.tools.quartz.ToolQuartzCuttingKnife; +import appeng.items.tools.quartz.ToolQuartzHoe; +import appeng.items.tools.quartz.ToolQuartzPickaxe; +import appeng.items.tools.quartz.ToolQuartzSpade; +import appeng.items.tools.quartz.ToolQuartzSword; +import appeng.items.tools.quartz.ToolQuartzWrench; +import appeng.me.cache.CraftingGridCache; +import appeng.me.cache.EnergyGridCache; +import appeng.me.cache.GridStorageCache; +import appeng.me.cache.P2PCache; +import appeng.me.cache.PathGridCache; +import appeng.me.cache.SecurityCache; +import appeng.me.cache.SpatialPylonCache; +import appeng.me.cache.TickManagerCache; +import appeng.me.storage.AEExternalHandler; +import appeng.parts.PartPlacement; +import appeng.recipes.AEItemResolver; +import appeng.recipes.RecipeHandler; +import appeng.recipes.game.DisassembleRecipe; +import appeng.recipes.game.FacadeRecipe; +import appeng.recipes.game.ShapedRecipe; +import appeng.recipes.game.ShapelessRecipe; +import appeng.recipes.handlers.Crusher; +import appeng.recipes.handlers.Grind; +import appeng.recipes.handlers.GrindFZ; +import appeng.recipes.handlers.HCCrusher; +import appeng.recipes.handlers.Inscribe; +import appeng.recipes.handlers.Macerator; +import appeng.recipes.handlers.MekCrusher; +import appeng.recipes.handlers.MekEnrichment; +import appeng.recipes.handlers.Press; +import appeng.recipes.handlers.Pulverizer; +import appeng.recipes.handlers.Shaped; +import appeng.recipes.handlers.Shapeless; +import appeng.recipes.handlers.Smelt; +import appeng.recipes.loader.ConfigLoader; +import appeng.recipes.loader.JarLoader; +import appeng.recipes.ores.OreDictionaryHandler; +import appeng.spatial.BiomeGenStorage; +import appeng.spatial.StorageWorldProvider; +import appeng.tile.AEBaseTile; +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 +{ + + final public static Registration instance = new Registration(); + + public RecipeHandler recipeHandler; + public BiomeGenBase storageBiome; + + private Registration() + { + recipeHandler = new RecipeHandler(); + } + + final private Multimap featuresToEntities = ArrayListMultimap.create(); + + public void PreInit(FMLPreInitializationEvent event) + { + registerSpatial( false ); + + IRecipeHandlerRegistry recipeRegistry = AEApi.instance().registries().recipes(); + recipeRegistry.addNewSubItemResolver( new AEItemResolver() ); + + recipeRegistry.addNewCraftHandler( "hccrusher", HCCrusher.class ); + recipeRegistry.addNewCraftHandler( "mekcrusher", MekCrusher.class ); + recipeRegistry.addNewCraftHandler( "mekechamber", MekEnrichment.class ); + recipeRegistry.addNewCraftHandler( "grind", Grind.class ); + recipeRegistry.addNewCraftHandler( "crusher", Crusher.class ); + recipeRegistry.addNewCraftHandler( "grindfz", GrindFZ.class ); + recipeRegistry.addNewCraftHandler( "pulverizer", Pulverizer.class ); + recipeRegistry.addNewCraftHandler( "macerator", Macerator.class ); + + recipeRegistry.addNewCraftHandler( "smelt", Smelt.class ); + recipeRegistry.addNewCraftHandler( "inscribe", Inscribe.class ); + recipeRegistry.addNewCraftHandler( "press", Press.class ); + + recipeRegistry.addNewCraftHandler( "shaped", Shaped.class ); + recipeRegistry.addNewCraftHandler( "shapeless", Shapeless.class ); + + RecipeSorter.register( "AE2-Facade", FacadeRecipe.class, Category.SHAPED, "" ); + RecipeSorter.register( "AE2-Shaped", ShapedRecipe.class, Category.SHAPED, "" ); + RecipeSorter.register( "AE2-Shapeless", ShapelessRecipe.class, Category.SHAPELESS, "" ); + + MinecraftForge.EVENT_BUS.register( OreDictionaryHandler.instance ); + + Items items = appeng.core.Api.instance.items(); + Materials materials = appeng.core.Api.instance.materials(); + Parts parts = appeng.core.Api.instance.parts(); + Blocks blocks = appeng.core.Api.instance.blocks(); + + AEItemDefinition materialItem = (AEFeatureHandler) addFeature( ItemMultiMaterial.class ); + + Class materialClass = materials.getClass(); + for (MaterialType mat : MaterialType.values()) + { + try + { + if ( mat == MaterialType.InvalidType ) + ((ItemMultiMaterial) materialItem.item()).createMaterial( mat ); + else + { + Field f = materialClass.getField( "material" + mat.name() ); + 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) + { + AELog.severe( "Error creating material: " + mat.name() ); + throw new RuntimeException( err ); + } + } + + AEItemDefinition partItem = (AEFeatureHandler) addFeature( ItemMultiPart.class ); + + Class partClass = parts.getClass(); + for (PartType type : PartType.values()) + { + try + { + if ( type == PartType.InvalidType ) + ((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 ); + if ( is != null ) + f.set( parts, new DamagedItemDefinition( is ) ); + else + f.set( parts, new NullItemDefinition() ); + } + else + { + if ( variants[0] instanceof AEColor ) + { + ColoredItemDefinition def = new ColoredItemDefinition(); + + for (Enum v : variants) + { + ItemStackSrc is = ((ItemMultiPart) partItem.item()).createPart( type, v ); + if ( is != null ) + def.add( (AEColor) v, is ); + } + + f.set( parts, def ); + } + } + } + } + catch (Throwable err) + { + AELog.severe( "Error creating part: " + type.name() ); + throw new RuntimeException( err ); + } + } + + // very important block! + blocks.blockMultiPart = addFeature( BlockCableBus.class ); + + blocks.blockCraftingUnit = addFeature( BlockCraftingUnit.class ); + blocks.blockCraftingAccelerator = new WrappedDamageItemDefinition( blocks.blockCraftingUnit, 1 ); + blocks.blockCraftingMonitor = addFeature( BlockCraftingMonitor.class ); + blocks.blockCraftingStorage1k = addFeature( BlockCraftingStorage.class ); + blocks.blockCraftingStorage4k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 1 ); + blocks.blockCraftingStorage16k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 2 ); + blocks.blockCraftingStorage64k = new WrappedDamageItemDefinition( blocks.blockCraftingStorage1k, 3 ); + blocks.blockMolecularAssembler = addFeature( BlockMolecularAssembler.class ); + + blocks.blockQuartzOre = addFeature( OreQuartz.class ); + blocks.blockQuartzOreCharged = addFeature( OreQuartzCharged.class ); + blocks.blockMatrixFrame = addFeature( BlockMatrixFrame.class ); + blocks.blockQuartz = addFeature( BlockQuartz.class ); + blocks.blockFluix = addFeature( BlockFluix.class ); + blocks.blockSkyStone = addFeature( BlockSkyStone.class ); + blocks.blockSkyChest = addFeature( BlockSkyChest.class ); + blocks.blockSkyCompass = addFeature( BlockSkyCompass.class ); + + blocks.blockQuartzGlass = addFeature( BlockQuartzGlass.class ); + blocks.blockQuartzVibrantGlass = addFeature( BlockQuartzLamp.class ); + blocks.blockQuartzPillar = addFeature( BlockQuartzPillar.class ); + blocks.blockQuartzChiseled = addFeature( BlockQuartzChiseled.class ); + blocks.blockQuartzTorch = addFeature( BlockQuartzTorch.class ); + blocks.blockLightDetector = addFeature( BlockLightDetector.class ); + blocks.blockCharger = addFeature( BlockCharger.class ); + blocks.blockQuartzGrowthAccelerator = addFeature( BlockQuartzGrowthAccelerator.class ); + + blocks.blockGrindStone = addFeature( BlockGrinder.class ); + blocks.blockCrankHandle = addFeature( BlockCrank.class ); + blocks.blockInscriber = addFeature( BlockInscriber.class ); + blocks.blockWireless = addFeature( BlockWireless.class ); + blocks.blockTinyTNT = addFeature( BlockTinyTNT.class ); + + blocks.blockQuantumRing = addFeature( BlockQuantumRing.class ); + blocks.blockQuantumLink = addFeature( BlockQuantumLinkChamber.class ); + + blocks.blockSpatialPylon = addFeature( BlockSpatialPylon.class ); + blocks.blockSpatialIOPort = addFeature( BlockSpatialIOPort.class ); + + blocks.blockController = addFeature( BlockController.class ); + blocks.blockDrive = addFeature( BlockDrive.class ); + blocks.blockChest = addFeature( BlockChest.class ); + blocks.blockInterface = addFeature( BlockInterface.class ); + blocks.blockCellWorkbench = addFeature( BlockCellWorkbench.class ); + blocks.blockIOPort = addFeature( BlockIOPort.class ); + blocks.blockCondenser = addFeature( BlockCondenser.class ); + blocks.blockEnergyAcceptor = addFeature( BlockEnergyAcceptor.class ); + blocks.blockVibrationChamber = addFeature( BlockVibrationChamber.class ); + + blocks.blockEnergyCell = addFeature( BlockEnergyCell.class ); + blocks.blockEnergyCellDense = addFeature( BlockDenseEnergyCell.class ); + blocks.blockEnergyCellCreative = addFeature( BlockCreativeEnergyCell.class ); + + blocks.blockSecurity = addFeature( BlockSecurity.class ); + blocks.blockPaint = addFeature( BlockPaint.class ); + + items.itemCellCreative = addFeature( ItemCreativeStorageCell.class ); + items.itemViewCell = addFeature( ItemViewCell.class ); + items.itemEncodedPattern = addFeature( ItemEncodedPattern.class ); + + items.itemCell1k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell1kPart, 1 ); + items.itemCell4k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell4kPart, 4 ); + items.itemCell16k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell16kPart, 16 ); + items.itemCell64k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell64kPart, 64 ); + + items.itemSpatialCell2 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell2SpatialPart, 2 ); + items.itemSpatialCell16 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell16SpatialPart, 16 ); + items.itemSpatialCell128 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell128SpatialPart, 128 ); + + items.itemCertusQuartzKnife = addFeature( ToolQuartzCuttingKnife.class, AEFeature.CertusQuartzTools ); + items.itemCertusQuartzWrench = addFeature( ToolQuartzWrench.class, AEFeature.CertusQuartzTools ); + items.itemCertusQuartzAxe = addFeature( ToolQuartzAxe.class, AEFeature.CertusQuartzTools ); + items.itemCertusQuartzHoe = addFeature( ToolQuartzHoe.class, AEFeature.CertusQuartzTools ); + items.itemCertusQuartzPick = addFeature( ToolQuartzPickaxe.class, AEFeature.CertusQuartzTools ); + items.itemCertusQuartzShovel = addFeature( ToolQuartzSpade.class, AEFeature.CertusQuartzTools ); + items.itemCertusQuartzSword = addFeature( ToolQuartzSword.class, AEFeature.CertusQuartzTools ); + + items.itemNetherQuartzKnife = addFeature( ToolQuartzCuttingKnife.class, AEFeature.NetherQuartzTools ); + items.itemNetherQuartzWrench = addFeature( ToolQuartzWrench.class, AEFeature.NetherQuartzTools ); + items.itemNetherQuartzAxe = addFeature( ToolQuartzAxe.class, AEFeature.NetherQuartzTools ); + items.itemNetherQuartzHoe = addFeature( ToolQuartzHoe.class, AEFeature.NetherQuartzTools ); + items.itemNetherQuartzPick = addFeature( ToolQuartzPickaxe.class, AEFeature.NetherQuartzTools ); + items.itemNetherQuartzShovel = addFeature( ToolQuartzSpade.class, AEFeature.NetherQuartzTools ); + items.itemNetherQuartzSword = addFeature( ToolQuartzSword.class, AEFeature.NetherQuartzTools ); + + items.itemMassCannon = addFeature( ToolMassCannon.class ); + items.itemMemoryCard = addFeature( ToolMemoryCard.class ); + items.itemChargedStaff = addFeature( ToolChargedStaff.class ); + items.itemEntropyManipulator = addFeature( ToolEntropyManipulator.class ); + items.itemColorApplicator = addFeature( ToolColorApplicator.class ); + + items.itemWirelessTerminal = addFeature( ToolWirelessTerminal.class ); + items.itemNetworkTool = addFeature( ToolNetworkTool.class ); + items.itemPortableCell = addFeature( ToolPortableCell.class ); + items.itemBiometricCard = addFeature( ToolBiometricCard.class ); + + items.itemFacade = addFeature( ItemFacade.class ); + items.itemCrystalSeed = addFeature( ItemCrystalSeed.class ); + + ColoredItemDefinition pbreg, pbregl; + items.itemPaintBall = pbreg = new ColoredItemDefinition(); + items.itemLumenPaintBall = pbregl = new ColoredItemDefinition(); + AEItemDefinition pb = addFeature( ItemPaintBall.class ); + + for (AEColor c : AEColor.values()) + { + if ( c != AEColor.Transparent ) + { + pbreg.add( c, new ItemStackSrc( pb.item(), c.ordinal() ) ); + pbregl.add( c, new ItemStackSrc( pb.item(), 20 + c.ordinal() ) ); + } + } + + addFeature( ToolEraser.class ); + addFeature( ToolMeteoritePlacer.class ); + addFeature( ToolDebugCard.class ); + addFeature( ToolReplicatorCard.class ); + addFeature( BlockItemGen.class ); + addFeature( BlockChunkloader.class ); + addFeature( BlockPhantomNode.class ); + addFeature( BlockCubeGenerator.class ); + } + + private AEItemDefinition addFeature(Class c, Object... Args) + { + + try + { + java.lang.reflect.Constructor[] con = c.getConstructors(); + Object obj = null; + + for (Constructor conItem : con) + { + Class paramTypes[] = conItem.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 ) + { + obj = conItem.newInstance( Args ); + break; + } + } + } + + 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" ); + + } + catch (Throwable e) + { + throw new RuntimeException( "Error with Feature: " + c.getName(), e ); + } + } + + 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 ); + + if ( expected == got || expected.isAssignableFrom( got ) ) + return true; + + return false; + } + + 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; + } + + public void Init(FMLInitializationEvent event) + { + // Perform ore camouflage! + ItemMultiMaterial.instance.unduplicate(); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.CustomRecipes ) ) + recipeHandler.parseRecipes( new ConfigLoader( AppEng.instance.getConfigPath() ), "index.recipe" ); + else + recipeHandler.parseRecipes( new JarLoader( "/assets/appliedenergistics2/recipes/" ), "index.recipe" ); + + IPartHelper ph = AEApi.instance().partHelper(); + ph.registerNewLayer( "appeng.parts.layers.LayerISidedInventory", "net.minecraft.inventory.ISidedInventory" ); + ph.registerNewLayer( "appeng.parts.layers.LayerIFluidHandler", "net.minecraftforge.fluids.IFluidHandler" ); + ph.registerNewLayer( "appeng.parts.layers.LayerITileStorageMonitorable", "appeng.api.implementations.tiles.ITileStorageMonitorable" ); + + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) ) + { + ph.registerNewLayer( "appeng.parts.layers.LayerIEnergySink", "ic2.api.energy.tile.IEnergySink" ); + ph.registerNewLayer( "appeng.parts.layers.LayerIEnergySource", "ic2.api.energy.tile.IEnergySource" ); + } + + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) ) + { + ph.registerNewLayer( "appeng.parts.layers.LayerIPowerEmitter", "buildcraft.api.power.IPowerEmitter" ); + ph.registerNewLayer( "appeng.parts.layers.LayerIPowerReceptor", "buildcraft.api.power.IPowerReceptor" ); + } + + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.MJ6 ) ) + ph.registerNewLayer( "appeng.parts.layers.LayerIBatteryProvider", "buildcraft.api.mj.IBatteryProvider" ); + + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.RF ) ) + ph.registerNewLayer( "appeng.parts.layers.LayerIEnergyHandler", "cofh.api.energy.IEnergyHandler" ); + + FMLCommonHandler.instance().bus().register( TickHandler.instance ); + MinecraftForge.EVENT_BUS.register( TickHandler.instance ); + + PartPlacement pp = new PartPlacement(); + MinecraftForge.EVENT_BUS.register( pp ); + FMLCommonHandler.instance().bus().register( pp ); + + IGridCacheRegistry gcr = AEApi.instance().registries().gridCache(); + gcr.registerGridCache( ITickManager.class, TickManagerCache.class ); + gcr.registerGridCache( IEnergyGrid.class, EnergyGridCache.class ); + gcr.registerGridCache( IPathingGrid.class, PathGridCache.class ); + gcr.registerGridCache( IStorageGrid.class, GridStorageCache.class ); + gcr.registerGridCache( P2PCache.class, P2PCache.class ); + gcr.registerGridCache( ISpatialCache.class, SpatialPylonCache.class ); + gcr.registerGridCache( ISecurityGrid.class, SecurityCache.class ); + gcr.registerGridCache( ICraftingGrid.class, CraftingGridCache.class ); + + AEApi.instance().registries().externalStorage().addExternalStorageInterface( new AEExternalHandler() ); + + AEApi.instance().registries().cell().addCellHandler( new BasicCellHandler() ); + AEApi.instance().registries().cell().addCellHandler( new CreativeCellHandler() ); + + AEApi.instance().registries().matterCannon().registerAmmo( AEApi.instance().materials().materialMatterBall.stack( 1 ), 32.0 ); + + recipeHandler.injectRecipes(); + + PlayerStatsRegistration.instance.init(); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting ) ) + CraftingManager.getInstance().getRecipeList().add( new DisassembleRecipe() ); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.enableFacadeCrafting ) ) + CraftingManager.getInstance().getRecipeList().add( new FacadeRecipe() ); + } + + public void PostInit(FMLPostInitializationEvent event) + { + registerSpatial( true ); + + // default settings.. + ((P2PTunnelRegistry) AEApi.instance().registries().p2pTunnel()).configure(); + + // add to localizaiton.. + PlayerMessages.values(); + GuiText.values(); + + Api.instance.partHelper.initFMPSupport(); + ((BlockCableBus) AEApi.instance().blocks().blockMultiPart.block()).setupTile(); + + // Interface + Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partInterface.stack( 1 ), 1 ); + Upgrades.CRAFTING.registerItem( AEApi.instance().blocks().blockInterface.stack( 1 ), 1 ); + + // IO Port! + Upgrades.SPEED.registerItem( AEApi.instance().blocks().blockIOPort.stack( 1 ), 3 ); + Upgrades.REDSTONE.registerItem( AEApi.instance().blocks().blockIOPort.stack( 1 ), 1 ); + + // Level Emitter! + Upgrades.FUZZY.registerItem( AEApi.instance().parts().partLevelEmitter.stack( 1 ), 1 ); + Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partLevelEmitter.stack( 1 ), 1 ); + + // Import Bus + Upgrades.FUZZY.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 1 ); + Upgrades.REDSTONE.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 1 ); + Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 2 ); + Upgrades.SPEED.registerItem( AEApi.instance().parts().partImportBus.stack( 1 ), 4 ); + + // Export Bus + Upgrades.FUZZY.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 ); + Upgrades.REDSTONE.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 ); + Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 2 ); + Upgrades.SPEED.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 4 ); + Upgrades.CRAFTING.registerItem( AEApi.instance().parts().partExportBus.stack( 1 ), 1 ); + + // Storage Cells + Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell1k.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell1k.stack( 1 ), 1 ); + + Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell4k.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell4k.stack( 1 ), 1 ); + + Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell16k.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell16k.stack( 1 ), 1 ); + + Upgrades.FUZZY.registerItem( AEApi.instance().items().itemCell64k.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().items().itemCell64k.stack( 1 ), 1 ); + + Upgrades.FUZZY.registerItem( AEApi.instance().items().itemPortableCell.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().items().itemPortableCell.stack( 1 ), 1 ); + + Upgrades.FUZZY.registerItem( AEApi.instance().items().itemViewCell.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().items().itemViewCell.stack( 1 ), 1 ); + + // Storage Bus + Upgrades.FUZZY.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 1 ); + Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partStorageBus.stack( 1 ), 5 ); + + // Formation Plane + Upgrades.FUZZY.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 1 ); + Upgrades.CAPACITY.registerItem( AEApi.instance().parts().partFormationPlane.stack( 1 ), 5 ); + + // Matter Cannon + Upgrades.FUZZY.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 1 ); + Upgrades.INVERTER.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 1 ); + Upgrades.SPEED.registerItem( AEApi.instance().items().itemMassCannon.stack( 1 ), 4 ); + + // Molecular Assembler + Upgrades.SPEED.registerItem( AEApi.instance().blocks().blockMolecularAssembler.stack( 1 ), 5 ); + + AEApi.instance().registries().wireless().registerWirelessHandler( (IWirelessTermHandler) AEApi.instance().items().itemWirelessTerminal.item() ); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.ChestLoot ) ) + { + ChestGenHooks d = ChestGenHooks.getInfo( ChestGenHooks.MINESHAFT_CORRIDOR ); + d.addItem( new WeightedRandomChestContent( AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), 1, 4, 2 ) ); + d.addItem( new WeightedRandomChestContent( AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ), 1, 4, 2 ) ); + } + + // add villager trading to black smiths for a few basic materials + if ( AEConfig.instance.isFeatureEnabled( AEFeature.VillagerTrading ) ) + VillagerRegistry.instance().registerVillageTradeHandler( 3, new AETrading() ); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.CertusQuartzWorldGen ) ) + GameRegistry.registerWorldGenerator( new QuartzWorldGen(), 0 ); + + if ( AEConfig.instance.isFeatureEnabled( AEFeature.MeteoriteWorldGen ) ) + GameRegistry.registerWorldGenerator( new MeteoriteWorldGen(), 0 ); + + IMovableRegistry mr = AEApi.instance().registries().movable(); + + /** + * You can't move bed rock. + */ + mr.blacklistBlock( net.minecraft.init.Blocks.bedrock ); + + /* + * White List Vanilla... + */ + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityBeacon.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityBrewingStand.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityChest.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityCommandBlock.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityComparator.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityDaylightDetector.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityDispenser.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityDropper.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityEnchantmentTable.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityEnderChest.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityEndPortal.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntitySkull.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityFurnace.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityMobSpawner.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntitySign.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityPiston.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityFlowerPot.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityNote.class ); + mr.whiteListTileEntity( net.minecraft.tileentity.TileEntityHopper.class ); + + // very silly fix cause Reika decided to pair the item with a block. + OreDictionary.registerOre( "itemWheat", net.minecraft.init.Items.wheat ); + + /** + * Whitelist AE2 + */ + mr.whiteListTileEntity( AEBaseTile.class ); + + /** + * world gen + */ + for (WorldGenType type : WorldGenType.values()) + { + AEApi.instance().registries().worldgen().disableWorldGenForProviderID( type, StorageWorldProvider.class ); + + // end + AEApi.instance().registries().worldgen().disableWorldGenForDimension( type, 1 ); + + // nether + AEApi.instance().registries().worldgen().disableWorldGenForDimension( type, -1 ); + } + + /** + * initial recipe bake, if ore dictionary changes after this it re-bakes. + */ + 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/core/WorldSettings.java b/src/main/java/appeng/core/WorldSettings.java similarity index 100% rename from core/WorldSettings.java rename to src/main/java/appeng/core/WorldSettings.java diff --git a/core/api/ApiPart.java b/src/main/java/appeng/core/api/ApiPart.java similarity index 96% rename from core/api/ApiPart.java rename to src/main/java/appeng/core/api/ApiPart.java index d7a9ffe3c..1eb275cf8 100644 --- a/core/api/ApiPart.java +++ b/src/main/java/appeng/core/api/ApiPart.java @@ -1,356 +1,356 @@ -package appeng.core.api; - -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.client.MinecraftForgeClient; - -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.commons.Remapper; -import org.objectweb.asm.commons.RemappingClassAdapter; -import org.objectweb.asm.tree.AbstractInsnNode; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; - -import appeng.api.parts.CableRenderMode; -import appeng.api.parts.IPartHelper; -import appeng.api.parts.IPartItem; -import appeng.api.parts.LayerBase; -import appeng.client.render.BusRenderer; -import appeng.core.AELog; -import appeng.core.AppEng; -import appeng.core.CommonHelper; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.IFMP; -import appeng.parts.PartPlacement; -import appeng.tile.networking.TileCableBus; -import appeng.util.Platform; - -import com.google.common.base.Joiner; - -public class ApiPart implements IPartHelper -{ - - int classNum = 1; - - HashMap TileImplementations = new HashMap(); - HashMap readerCache = new HashMap(); - HashMap interfaces2Layer = new HashMap(); - HashMap roots = new HashMap(); - - List desc = new LinkedList(); - - public void initFMPSupport() - { - for (Class layerInterface : interfaces2Layer.keySet()) - { - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) ) - ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).registerPassThrough( layerInterface ); - } - } - - private Class loadClass(String Name, byte[] b) - { - // override classDefine (as it is protected) and define the class. - Class clazz = null; - try - { - ClassLoader loader = getClass().getClassLoader();// ClassLoader.getSystemClassLoader(); - Class root = ClassLoader.class; - Class cls = loader.getClass(); - java.lang.reflect.Method defineClassMethod = root.getDeclaredMethod( "defineClass", - new Class[] { String.class, byte[].class, int.class, int.class } ); - java.lang.reflect.Method runTransformersMethod = cls - .getDeclaredMethod( "runTransformers", new Class[] { String.class, String.class, byte[].class } ); - - runTransformersMethod.setAccessible( true ); - defineClassMethod.setAccessible( true ); - try - { - Object[] argsA = new Object[] { Name, Name, b }; - b = (byte[]) runTransformersMethod.invoke( loader, argsA ); - - Object[] args = new Object[] { Name, b, new Integer( 0 ), new Integer( b.length ) }; - clazz = (Class) defineClassMethod.invoke( loader, args ); - } - finally - { - runTransformersMethod.setAccessible( false ); - defineClassMethod.setAccessible( false ); - } - } - catch (Exception e) - { - AELog.error( e ); - throw new RuntimeException( "Unable to manage part API.", e ); - } - return clazz; - } - - public ClassNode getReader(String name) throws IOException - { - try - { - ClassReader cr; - String path = "/" + name.replace( ".", "/" ) + ".class"; - InputStream is = getClass().getResourceAsStream( path ); - cr = new ClassReader( is ); - ClassNode cn = new ClassNode(); - cr.accept( cn, ClassReader.EXPAND_FRAMES ); - return cn; - } - catch (Throwable t) - { - throw new RuntimeException( "Error loading " + name, t ); - } - } - - public Class getCombinedInstance(String base) - { - if ( desc.size() == 0 ) - { - try - { - return Class.forName( base ); - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } - } - - String description = base + ":" + Joiner.on( ";" ).skipNulls().join( desc.iterator() ); - - if ( TileImplementations.get( description ) != null ) - { - try - { - return TileImplementations.get( description ); - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } - } - - String f = base;// TileCableBus.class.getName(); - String Addendum = ""; - try - { - Addendum = Class.forName( base ).getSimpleName(); - } - catch (ClassNotFoundException e) - { - AELog.error( e ); - } - Class myCLass; - - try - { - myCLass = Class.forName( f ); - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } - - String path = f; - - for (String name : desc) - { - try - { - String newPath = path + ";" + name; - myCLass = getClassByDesc( Addendum, newPath, f, interfaces2Layer.get( Class.forName( name ) ) ); - path = newPath; - } - catch (Throwable t) - { - AELog.warning( "Error loading " + name ); - AELog.error( t ); - // throw new RuntimeException( t ); - } - f = myCLass.getName(); - } - - TileImplementations.put( description, myCLass ); - - try - { - return myCLass; - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } - } - - class DefaultPackageClassNameRemapper extends Remapper - { - - public HashMap inputOutput = new HashMap(); - - @Override - public String map(String typeName) - { - String o = inputOutput.get( typeName ); - if ( o == null ) - return typeName; - return o; - } - - } - - public Class getClassByDesc(String Addendum, String fullPath, String root, String next) throws IOException - { - if ( roots.get( fullPath ) != null ) - return roots.get( fullPath ); - - ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS ); - ClassNode n = getReader( next ); - String originalName = n.name; - - try - { - n.name = n.name + "_" + Addendum; - n.superName = Class.forName( root ).getName().replace( ".", "/" ); - } - catch (Throwable t) - { - AELog.error( t ); - } - - for (MethodNode mn : n.methods) - { - Iterator i = mn.instructions.iterator(); - while (i.hasNext()) - { - processNode( i.next(), n.superName ); - } - } - - DefaultPackageClassNameRemapper remapper = new DefaultPackageClassNameRemapper(); - remapper.inputOutput.put( "appeng/api/parts/LayerBase", n.superName ); - remapper.inputOutput.put( originalName, n.name ); - n.accept( new RemappingClassAdapter( cw, remapper ) ); - // n.accept( cw ); - - // n.accept( new TraceClassVisitor( new PrintWriter( System.out ) ) ); - byte[] barray = cw.toByteArray(); - int size = barray.length; - Class nclass = loadClass( n.name.replace( "/", "." ), barray ); - - try - { - Object fish = nclass.newInstance(); - Class rootC = Class.forName( root ); - - boolean bads = false; - - if ( !rootC.isInstance( fish ) ) - { - bads = true; - AELog.severe( "Error, Expected layer to implement " + root + " did not." ); - } - - if ( fish instanceof LayerBase ) - { - bads = true; - AELog.severe( "Error, Expected layer to NOT implement LayerBase but it DID." ); - } - - if ( !fullPath.contains( ".fmp." ) ) - { - if ( !(fish instanceof TileCableBus) ) - { - bads = true; - AELog.severe( "Error, Expected layer to implement TileCableBus did not." ); - } - - if ( !(fish instanceof TileEntity) ) - { - bads = true; - AELog.severe( "Error, Expected layer to implement TileEntity did not." ); - } - } - - if ( !bads ) - { - AELog.info( "Layer: " + n.name + " loaded successfully - " + size + " bytes" ); - } - - } - catch (Throwable t) - { - AELog.severe( "Layer: " + n.name + " Failed." ); - AELog.error( t ); - } - - roots.put( fullPath, nclass ); - return nclass; - } - - private void processNode(AbstractInsnNode next, String nePar) - { - if ( next instanceof MethodInsnNode ) - { - MethodInsnNode min = (MethodInsnNode) next; - if ( min.owner.equals( "appeng/api/parts/LayerBase" ) ) - { - min.owner = nePar; - } - } - } - - @Override - public void setItemBusRenderer(IPartItem i) - { - if ( Platform.isClient() && i instanceof Item ) - MinecraftForgeClient.registerItemRenderer( (Item) i, BusRenderer.instance ); - } - - @Override - public boolean placeBus(ItemStack is, int x, int y, int z, int side, EntityPlayer player, World w) - { - return PartPlacement.place( is, x, y, z, side, player, w, PartPlacement.PlaceType.PLACE_ITEM, 0 ); - } - - @Override - public boolean registerNewLayer(String layer, String layerInterface) - { - try - { - if ( interfaces2Layer.get( layerInterface ) == null ) - { - interfaces2Layer.put( Class.forName( layerInterface ), layer ); - desc.add( layerInterface ); - return true; - } - else - AELog.info( "Layer " + layer + " not registered, " + layerInterface + " already has a layer." ); - } - catch (Throwable t) - { - } - - return false; - } - - @Override - public CableRenderMode getCableRenderMode() - { - return CommonHelper.proxy.getRenderMode(); - } - -} +package appeng.core.api; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.client.MinecraftForgeClient; + +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.commons.Remapper; +import org.objectweb.asm.commons.RemappingClassAdapter; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; + +import appeng.api.parts.CableRenderMode; +import appeng.api.parts.IPartHelper; +import appeng.api.parts.IPartItem; +import appeng.api.parts.LayerBase; +import appeng.client.render.BusRenderer; +import appeng.core.AELog; +import appeng.core.AppEng; +import appeng.core.CommonHelper; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.IFMP; +import appeng.parts.PartPlacement; +import appeng.tile.networking.TileCableBus; +import appeng.util.Platform; + +import com.google.common.base.Joiner; + +public class ApiPart implements IPartHelper +{ + + int classNum = 1; + + HashMap TileImplementations = new HashMap(); + HashMap readerCache = new HashMap(); + HashMap interfaces2Layer = new HashMap(); + HashMap roots = new HashMap(); + + List desc = new LinkedList(); + + public void initFMPSupport() + { + for (Class layerInterface : interfaces2Layer.keySet()) + { + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) ) + ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).registerPassThrough( layerInterface ); + } + } + + private Class loadClass(String Name, byte[] b) + { + // override classDefine (as it is protected) and define the class. + Class clazz = null; + try + { + ClassLoader loader = getClass().getClassLoader();// ClassLoader.getSystemClassLoader(); + Class root = ClassLoader.class; + Class cls = loader.getClass(); + java.lang.reflect.Method defineClassMethod = root.getDeclaredMethod( "defineClass", + new Class[] { String.class, byte[].class, int.class, int.class } ); + java.lang.reflect.Method runTransformersMethod = cls + .getDeclaredMethod( "runTransformers", new Class[] { String.class, String.class, byte[].class } ); + + runTransformersMethod.setAccessible( true ); + defineClassMethod.setAccessible( true ); + try + { + Object[] argsA = new Object[] { Name, Name, b }; + b = (byte[]) runTransformersMethod.invoke( loader, argsA ); + + Object[] args = new Object[] { Name, b, new Integer( 0 ), new Integer( b.length ) }; + clazz = (Class) defineClassMethod.invoke( loader, args ); + } + finally + { + runTransformersMethod.setAccessible( false ); + defineClassMethod.setAccessible( false ); + } + } + catch (Exception e) + { + AELog.error( e ); + throw new RuntimeException( "Unable to manage part API.", e ); + } + return clazz; + } + + public ClassNode getReader(String name) throws IOException + { + try + { + ClassReader cr; + String path = "/" + name.replace( ".", "/" ) + ".class"; + InputStream is = getClass().getResourceAsStream( path ); + cr = new ClassReader( is ); + ClassNode cn = new ClassNode(); + cr.accept( cn, ClassReader.EXPAND_FRAMES ); + return cn; + } + catch (Throwable t) + { + throw new RuntimeException( "Error loading " + name, t ); + } + } + + public Class getCombinedInstance(String base) + { + if ( desc.size() == 0 ) + { + try + { + return Class.forName( base ); + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + } + + String description = base + ":" + Joiner.on( ";" ).skipNulls().join( desc.iterator() ); + + if ( TileImplementations.get( description ) != null ) + { + try + { + return TileImplementations.get( description ); + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + } + + String f = base;// TileCableBus.class.getName(); + String Addendum = ""; + try + { + Addendum = Class.forName( base ).getSimpleName(); + } + catch (ClassNotFoundException e) + { + AELog.error( e ); + } + Class myCLass; + + try + { + myCLass = Class.forName( f ); + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + + String path = f; + + for (String name : desc) + { + try + { + String newPath = path + ";" + name; + myCLass = getClassByDesc( Addendum, newPath, f, interfaces2Layer.get( Class.forName( name ) ) ); + path = newPath; + } + catch (Throwable t) + { + AELog.warning( "Error loading " + name ); + AELog.error( t ); + // throw new RuntimeException( t ); + } + f = myCLass.getName(); + } + + TileImplementations.put( description, myCLass ); + + try + { + return myCLass; + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + } + + class DefaultPackageClassNameRemapper extends Remapper + { + + public HashMap inputOutput = new HashMap(); + + @Override + public String map(String typeName) + { + String o = inputOutput.get( typeName ); + if ( o == null ) + return typeName; + return o; + } + + } + + public Class getClassByDesc(String Addendum, String fullPath, String root, String next) throws IOException + { + if ( roots.get( fullPath ) != null ) + return roots.get( fullPath ); + + ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS ); + ClassNode n = getReader( next ); + String originalName = n.name; + + try + { + n.name = n.name + "_" + Addendum; + n.superName = Class.forName( root ).getName().replace( ".", "/" ); + } + catch (Throwable t) + { + AELog.error( t ); + } + + for (MethodNode mn : n.methods) + { + Iterator i = mn.instructions.iterator(); + while (i.hasNext()) + { + processNode( i.next(), n.superName ); + } + } + + DefaultPackageClassNameRemapper remapper = new DefaultPackageClassNameRemapper(); + remapper.inputOutput.put( "appeng/api/parts/LayerBase", n.superName ); + remapper.inputOutput.put( originalName, n.name ); + n.accept( new RemappingClassAdapter( cw, remapper ) ); + // n.accept( cw ); + + // n.accept( new TraceClassVisitor( new PrintWriter( System.out ) ) ); + byte[] barray = cw.toByteArray(); + int size = barray.length; + Class nclass = loadClass( n.name.replace( "/", "." ), barray ); + + try + { + Object fish = nclass.newInstance(); + Class rootC = Class.forName( root ); + + boolean bads = false; + + if ( !rootC.isInstance( fish ) ) + { + bads = true; + AELog.severe( "Error, Expected layer to implement " + root + " did not." ); + } + + if ( fish instanceof LayerBase ) + { + bads = true; + AELog.severe( "Error, Expected layer to NOT implement LayerBase but it DID." ); + } + + if ( !fullPath.contains( ".fmp." ) ) + { + if ( !(fish instanceof TileCableBus) ) + { + bads = true; + AELog.severe( "Error, Expected layer to implement TileCableBus did not." ); + } + + if ( !(fish instanceof TileEntity) ) + { + bads = true; + AELog.severe( "Error, Expected layer to implement TileEntity did not." ); + } + } + + if ( !bads ) + { + AELog.info( "Layer: " + n.name + " loaded successfully - " + size + " bytes" ); + } + + } + catch (Throwable t) + { + AELog.severe( "Layer: " + n.name + " Failed." ); + AELog.error( t ); + } + + roots.put( fullPath, nclass ); + return nclass; + } + + private void processNode(AbstractInsnNode next, String nePar) + { + if ( next instanceof MethodInsnNode ) + { + MethodInsnNode min = (MethodInsnNode) next; + if ( min.owner.equals( "appeng/api/parts/LayerBase" ) ) + { + min.owner = nePar; + } + } + } + + @Override + public void setItemBusRenderer(IPartItem i) + { + if ( Platform.isClient() && i instanceof Item ) + MinecraftForgeClient.registerItemRenderer( (Item) i, BusRenderer.instance ); + } + + @Override + public boolean placeBus(ItemStack is, int x, int y, int z, int side, EntityPlayer player, World w) + { + return PartPlacement.place( is, x, y, z, side, player, w, PartPlacement.PlaceType.PLACE_ITEM, 0 ); + } + + @Override + public boolean registerNewLayer(String layer, String layerInterface) + { + try + { + if ( interfaces2Layer.get( layerInterface ) == null ) + { + interfaces2Layer.put( Class.forName( layerInterface ), layer ); + desc.add( layerInterface ); + return true; + } + else + AELog.info( "Layer " + layer + " not registered, " + layerInterface + " already has a layer." ); + } + catch (Throwable t) + { + } + + return false; + } + + @Override + public CableRenderMode getCableRenderMode() + { + return CommonHelper.proxy.getRenderMode(); + } + +} diff --git a/core/api/ApiStorage.java b/src/main/java/appeng/core/api/ApiStorage.java similarity index 96% rename from core/api/ApiStorage.java rename to src/main/java/appeng/core/api/ApiStorage.java index c30817bf8..f1854ebbb 100644 --- a/core/api/ApiStorage.java +++ b/src/main/java/appeng/core/api/ApiStorage.java @@ -1,81 +1,81 @@ -package appeng.core.api; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fluids.FluidStack; -import appeng.api.networking.crafting.ICraftingLink; -import appeng.api.networking.crafting.ICraftingRequester; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IStorageHelper; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.crafting.CraftingLink; -import appeng.util.Platform; -import appeng.util.item.AEFluidStack; -import appeng.util.item.AEItemStack; -import appeng.util.item.ItemList; - -public class ApiStorage implements IStorageHelper -{ - - @Override - public IAEItemStack createItemStack(ItemStack is) - { - return AEItemStack.create( is ); - } - - @Override - public IAEFluidStack createFluidStack(FluidStack is) - { - return AEFluidStack.create( is ); - } - - @Override - public IItemList createItemList() - { - return new ItemList( IAEItemStack.class ); - } - - @Override - public IItemList createFluidList() - { - return new ItemList( IAEFluidStack.class ); - } - - @Override - public IAEItemStack poweredExtraction(IEnergySource energy, IMEInventory cell, IAEItemStack request, BaseActionSource src) - { - return Platform.poweredExtraction( energy, cell, request, src ); - } - - @Override - public IAEItemStack poweredInsert(IEnergySource energy, IMEInventory cell, IAEItemStack input, BaseActionSource src) - { - return Platform.poweredInsert( energy, cell, input, src ); - } - - @Override - public IAEItemStack readItemFromPacket(ByteBuf input) throws IOException - { - return AEItemStack.loadItemStackFromPacket( input ); - } - - @Override - public IAEFluidStack readFluidFromPacket(ByteBuf input) throws IOException - { - return AEFluidStack.loadFluidStackFromPacket( input ); - } - - @Override - public ICraftingLink loadCraftingLink(NBTTagCompound data, ICraftingRequester req) - { - return new CraftingLink( data, req ); - } -} +package appeng.core.api; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; +import appeng.api.networking.crafting.ICraftingLink; +import appeng.api.networking.crafting.ICraftingRequester; +import appeng.api.networking.energy.IEnergySource; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IStorageHelper; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.crafting.CraftingLink; +import appeng.util.Platform; +import appeng.util.item.AEFluidStack; +import appeng.util.item.AEItemStack; +import appeng.util.item.ItemList; + +public class ApiStorage implements IStorageHelper +{ + + @Override + public IAEItemStack createItemStack(ItemStack is) + { + return AEItemStack.create( is ); + } + + @Override + public IAEFluidStack createFluidStack(FluidStack is) + { + return AEFluidStack.create( is ); + } + + @Override + public IItemList createItemList() + { + return new ItemList( IAEItemStack.class ); + } + + @Override + public IItemList createFluidList() + { + return new ItemList( IAEFluidStack.class ); + } + + @Override + public IAEItemStack poweredExtraction(IEnergySource energy, IMEInventory cell, IAEItemStack request, BaseActionSource src) + { + return Platform.poweredExtraction( energy, cell, request, src ); + } + + @Override + public IAEItemStack poweredInsert(IEnergySource energy, IMEInventory cell, IAEItemStack input, BaseActionSource src) + { + return Platform.poweredInsert( energy, cell, input, src ); + } + + @Override + public IAEItemStack readItemFromPacket(ByteBuf input) throws IOException + { + return AEItemStack.loadItemStackFromPacket( input ); + } + + @Override + public IAEFluidStack readFluidFromPacket(ByteBuf input) throws IOException + { + return AEFluidStack.loadFluidStackFromPacket( input ); + } + + @Override + public ICraftingLink loadCraftingLink(NBTTagCompound data, ICraftingRequester req) + { + return new CraftingLink( data, req ); + } +} diff --git a/core/api/IIMCHandler.java b/src/main/java/appeng/core/api/IIMCHandler.java similarity index 100% rename from core/api/IIMCHandler.java rename to src/main/java/appeng/core/api/IIMCHandler.java diff --git a/core/api/imc/IMCBlackListSpatial.java b/src/main/java/appeng/core/api/imc/IMCBlackListSpatial.java similarity index 100% rename from core/api/imc/IMCBlackListSpatial.java rename to src/main/java/appeng/core/api/imc/IMCBlackListSpatial.java diff --git a/core/api/imc/IMCGrinder.java b/src/main/java/appeng/core/api/imc/IMCGrinder.java similarity index 100% rename from core/api/imc/IMCGrinder.java rename to src/main/java/appeng/core/api/imc/IMCGrinder.java diff --git a/core/api/imc/IMCMatterCannon.java b/src/main/java/appeng/core/api/imc/IMCMatterCannon.java similarity index 100% rename from core/api/imc/IMCMatterCannon.java rename to src/main/java/appeng/core/api/imc/IMCMatterCannon.java diff --git a/core/api/imc/IMCP2PAttunement.java b/src/main/java/appeng/core/api/imc/IMCP2PAttunement.java similarity index 100% rename from core/api/imc/IMCP2PAttunement.java rename to src/main/java/appeng/core/api/imc/IMCP2PAttunement.java diff --git a/core/api/imc/IMCSpatial.java b/src/main/java/appeng/core/api/imc/IMCSpatial.java similarity index 100% rename from core/api/imc/IMCSpatial.java rename to src/main/java/appeng/core/api/imc/IMCSpatial.java diff --git a/core/crash/CrashEnhancement.java b/src/main/java/appeng/core/crash/CrashEnhancement.java similarity index 95% rename from core/crash/CrashEnhancement.java rename to src/main/java/appeng/core/crash/CrashEnhancement.java index 47253716a..a26826940 100644 --- a/core/crash/CrashEnhancement.java +++ b/src/main/java/appeng/core/crash/CrashEnhancement.java @@ -1,53 +1,53 @@ -package appeng.core.crash; - -import appeng.core.AEConfig; -import appeng.integration.IntegrationRegistry; -import cpw.mods.fml.common.ICrashCallable; - -public class CrashEnhancement implements ICrashCallable -{ - - private final String name; - private final String value; - - private final String ModVersion = AEConfig.CHANNEL + " " + AEConfig.VERSION + " for Forge " + // WHAT? - net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion - + net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion - + net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion - + net.minecraftforge.common.ForgeVersion.buildVersion; - - public CrashEnhancement(CrashInfo Output) { - - if ( Output == CrashInfo.MOD_VERSION ) - { - name = "AE2 Version"; - value = ModVersion; - } - else if ( Output == CrashInfo.INTEGRATION ) - { - name ="AE2 Integration"; - if ( IntegrationRegistry.instance != null ) - value = IntegrationRegistry.instance.getStatus(); - else - value = "N/A"; - } - else - { - name = "AE2_UNKNOWN"; - value = "UNKNOWN_VALUE"; - } - } - - @Override - public String call() throws Exception - { - return value; - } - - @Override - public String getLabel() - { - return name; - } - -} +package appeng.core.crash; + +import appeng.core.AEConfig; +import appeng.integration.IntegrationRegistry; +import cpw.mods.fml.common.ICrashCallable; + +public class CrashEnhancement implements ICrashCallable +{ + + private final String name; + private final String value; + + private final String ModVersion = AEConfig.CHANNEL + " " + AEConfig.VERSION + " for Forge " + // WHAT? + net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion + + net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion + + net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion + + net.minecraftforge.common.ForgeVersion.buildVersion; + + public CrashEnhancement(CrashInfo Output) { + + if ( Output == CrashInfo.MOD_VERSION ) + { + name = "AE2 Version"; + value = ModVersion; + } + else if ( Output == CrashInfo.INTEGRATION ) + { + name ="AE2 Integration"; + if ( IntegrationRegistry.instance != null ) + value = IntegrationRegistry.instance.getStatus(); + else + value = "N/A"; + } + else + { + name = "AE2_UNKNOWN"; + value = "UNKNOWN_VALUE"; + } + } + + @Override + public String call() throws Exception + { + return value; + } + + @Override + public String getLabel() + { + return name; + } + +} diff --git a/core/crash/CrashInfo.java b/src/main/java/appeng/core/crash/CrashInfo.java similarity index 93% rename from core/crash/CrashInfo.java rename to src/main/java/appeng/core/crash/CrashInfo.java index 8aab2115d..a85158a80 100644 --- a/core/crash/CrashInfo.java +++ b/src/main/java/appeng/core/crash/CrashInfo.java @@ -1,6 +1,6 @@ -package appeng.core.crash; - -public enum CrashInfo -{ - MOD_VERSION, INTEGRATION -} +package appeng.core.crash; + +public enum CrashInfo +{ + MOD_VERSION, INTEGRATION +} diff --git a/core/features/AEFeature.java b/src/main/java/appeng/core/features/AEFeature.java similarity index 97% rename from core/features/AEFeature.java rename to src/main/java/appeng/core/features/AEFeature.java index 163a6f9ef..0c0bf5418 100644 --- a/core/features/AEFeature.java +++ b/src/main/java/appeng/core/features/AEFeature.java @@ -1,88 +1,88 @@ -package appeng.core.features; - -public enum AEFeature -{ - Core(null), // stuff that has no reason for ever being turned off, or that - // is just flat out required by tons of - // important stuff. - - CertusQuartzWorldGen("World"), MeteoriteWorldGen("World"), - - DecorativeLights("World"), DecorativeQuartzBlocks("World"), SkyStoneChests("World"), SpawnPressesInMeteorites("World"), - - GrindStone("World"), Flour("World"), Inscriber("World"), - - ChestLoot("World"), VillagerTrading("World"), - - TinyTNT("World"), - - PoweredTools("ToolsClassifications"), - - CertusQuartzTools("ToolsClassifications"), - - NetherQuartzTools("ToolsClassifications"), - - QuartzHoe("Tools"), QuartzSpade("Tools"), QuartzSword("Tools"), QuartzPickaxe("Tools"), QuartzAxe("Tools"), QuartzKnife("Tools"), QuartzWrench("Tools"), - - ChargedStaff("Tools"), EntropyManipulator("Tools"), MatterCannon("Tools"), WirelessAccessTerminal("Tools"), ColorApplicator("Tools"), - - CraftingCPU("CraftingFeatures"), PowerGen("NetworkFeatures"), Security("NetworkFeatures"), - - SpatialIO("NetworkFeatures"), QuantumNetworkBridge("NetworkFeatures"), Channels("NetworkFeatures"), - - LevelEmitter("NetworkBuses"), CraftingTerminal("NetworkBuses"), StorageMonitor("NetworkBuses"), P2PTunnel("NetworkBuses"), FormationPlane("NetworkBuses"), AnnihilationPlane( - "NetworkBuses"), ImportBus("NetworkBuses"), ExportBus("NetworkBuses"), StorageBus("NetworkBuses"), PartConversionMonitor("NetworkBuses"), - - StorageCells("Storage"), PortableCell("PortableCell"), MEChest("Storage"), MEDrive("Storage"), IOPort("Storage"), - - NetworkTool("NetworkTool"), - - DenseEnergyCells("HigherCapacity"), DenseCables("HigherCapacity"), - - P2PTunnelRF("P2PTunnels"), P2PTunnelME("P2PTunnels"), P2PTunnelItems("P2PTunnels"), P2PTunnelRedstone("P2PTunnels"), P2PTunnelEU("P2PTunnels"), P2PTunnelMJ( - "P2PTunnels"), P2PTunnelLiquids("P2PTunnels"), P2PTunnelLight("P2PTunnels"), - - MassCannonBlockDamage("BlockFeatures"), TinyTNTBlockDamage("BlockFeatures"), Facades("Facades"), - - VersionChecker("Services"), UnsupportedDeveloperTools("Misc", false), Creative("Misc"), - - GrinderLogging("Misc", false), Logging("Misc"), IntegrationLogging("Misc", false), CustomRecipes("Crafting", false), WebsiteRecipes("Misc", false), - - enableFacadeCrafting("Crafting"), inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false), - - AlphaPass("Rendering"), PaintBalls("Tools"), PacketLogging("Misc", false), CraftingLog("Misc", false), InterfaceTerminal("Crafting"), LightDetector("Misc"), - - enableDisassemblyCrafting("Crafting"), MolecularAssembler("CraftingFeatures"), MeteoriteCompass("Tools"), Patterns("CraftingFeatures"), - - ChunkLoggerTrace("Commands", false), LogSecurityAudits("Misc", false), Achievements("Misc"); - - String Category; - boolean visible = true; - boolean defValue = true; - - private AEFeature(String cat) { - Category = cat; - visible = !this.name().equals( "Core" ); - } - - private AEFeature(String cat, boolean defv) { - this( cat ); - defValue = defv; - } - - public String getCategory() - { - return Category; - } - - public Boolean defaultValue() - { - return defValue; - } - - public Boolean isVisible() - { - return visible; - } - -} +package appeng.core.features; + +public enum AEFeature +{ + Core(null), // stuff that has no reason for ever being turned off, or that + // is just flat out required by tons of + // important stuff. + + CertusQuartzWorldGen("World"), MeteoriteWorldGen("World"), + + DecorativeLights("World"), DecorativeQuartzBlocks("World"), SkyStoneChests("World"), SpawnPressesInMeteorites("World"), + + GrindStone("World"), Flour("World"), Inscriber("World"), + + ChestLoot("World"), VillagerTrading("World"), + + TinyTNT("World"), + + PoweredTools("ToolsClassifications"), + + CertusQuartzTools("ToolsClassifications"), + + NetherQuartzTools("ToolsClassifications"), + + QuartzHoe("Tools"), QuartzSpade("Tools"), QuartzSword("Tools"), QuartzPickaxe("Tools"), QuartzAxe("Tools"), QuartzKnife("Tools"), QuartzWrench("Tools"), + + ChargedStaff("Tools"), EntropyManipulator("Tools"), MatterCannon("Tools"), WirelessAccessTerminal("Tools"), ColorApplicator("Tools"), + + CraftingCPU("CraftingFeatures"), PowerGen("NetworkFeatures"), Security("NetworkFeatures"), + + SpatialIO("NetworkFeatures"), QuantumNetworkBridge("NetworkFeatures"), Channels("NetworkFeatures"), + + LevelEmitter("NetworkBuses"), CraftingTerminal("NetworkBuses"), StorageMonitor("NetworkBuses"), P2PTunnel("NetworkBuses"), FormationPlane("NetworkBuses"), AnnihilationPlane( + "NetworkBuses"), ImportBus("NetworkBuses"), ExportBus("NetworkBuses"), StorageBus("NetworkBuses"), PartConversionMonitor("NetworkBuses"), + + StorageCells("Storage"), PortableCell("PortableCell"), MEChest("Storage"), MEDrive("Storage"), IOPort("Storage"), + + NetworkTool("NetworkTool"), + + DenseEnergyCells("HigherCapacity"), DenseCables("HigherCapacity"), + + P2PTunnelRF("P2PTunnels"), P2PTunnelME("P2PTunnels"), P2PTunnelItems("P2PTunnels"), P2PTunnelRedstone("P2PTunnels"), P2PTunnelEU("P2PTunnels"), P2PTunnelMJ( + "P2PTunnels"), P2PTunnelLiquids("P2PTunnels"), P2PTunnelLight("P2PTunnels"), + + MassCannonBlockDamage("BlockFeatures"), TinyTNTBlockDamage("BlockFeatures"), Facades("Facades"), + + VersionChecker("Services"), UnsupportedDeveloperTools("Misc", false), Creative("Misc"), + + GrinderLogging("Misc", false), Logging("Misc"), IntegrationLogging("Misc", false), CustomRecipes("Crafting", false), WebsiteRecipes("Misc", false), + + enableFacadeCrafting("Crafting"), inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false), + + AlphaPass("Rendering"), PaintBalls("Tools"), PacketLogging("Misc", false), CraftingLog("Misc", false), InterfaceTerminal("Crafting"), LightDetector("Misc"), + + enableDisassemblyCrafting("Crafting"), MolecularAssembler("CraftingFeatures"), MeteoriteCompass("Tools"), Patterns("CraftingFeatures"), + + ChunkLoggerTrace("Commands", false), LogSecurityAudits("Misc", false), Achievements("Misc"); + + String Category; + boolean visible = true; + boolean defValue = true; + + private AEFeature(String cat) { + Category = cat; + visible = !this.name().equals( "Core" ); + } + + private AEFeature(String cat, boolean defv) { + this( cat ); + defValue = defv; + } + + public String getCategory() + { + return Category; + } + + public Boolean defaultValue() + { + return defValue; + } + + public Boolean isVisible() + { + return visible; + } + +} diff --git a/core/features/AEFeatureHandler.java b/src/main/java/appeng/core/features/AEFeatureHandler.java similarity index 95% rename from core/features/AEFeatureHandler.java rename to src/main/java/appeng/core/features/AEFeatureHandler.java index 05202c9ab..22088423f 100644 --- a/core/features/AEFeatureHandler.java +++ b/src/main/java/appeng/core/features/AEFeatureHandler.java @@ -1,194 +1,194 @@ -package appeng.core.features; - -import java.util.EnumSet; - -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.block.AEBaseBlock; -import appeng.block.AEBaseItemBlock; -import appeng.core.AEConfig; -import appeng.core.CommonHelper; -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 -{ - - private final EnumSet myFeatures; - - private final String subname; - private IAEFeature obj; - - private Item ItemData; - private Block BlockData; - - public AEFeatureHandler(EnumSet featureSet, IAEFeature _obj, String _subname) { - myFeatures = featureSet; - obj = _obj; - subname = _subname; - } - - public void register() - { - if ( isFeatureAvailable() ) - { - if ( obj instanceof Item ) - initItem( (Item) obj ); - if ( obj instanceof Block ) - initBlock( (Block) obj ); - } - } - - public static String getName(Class o, String subname) - { - String name = o.getSimpleName(); - - if ( name.startsWith( "ItemMultiPart" ) ) - name = name.replace( "ItemMultiPart", "ItemPart" ); - else if ( name.startsWith( "ItemMultiMaterial" ) ) - name = name.replace( "ItemMultiMaterial", "ItemMaterial" ); - - if ( subname != null ) - { - // 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"; - - if ( subname.equals( "CertusQuartzTools" ) ) - return name.replace( "Quartz", "CertusQuartz" ); - if ( subname.equals( "NetherQuartzTools" ) ) - return name.replace( "Quartz", "NetherQuartz" ); - - name += "." + subname; - } - - 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 myFeatures.clone(); - } - - public boolean isFeatureAvailable() - { - boolean enabled = true; - - for (AEFeature f : myFeatures) - enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); - - return enabled; - } - - @Override - public Block block() - { - return BlockData; - } - - @Override - public Class entity() - { - if ( BlockData instanceof AEBaseBlock ) - { - AEBaseBlock bb = (AEBaseBlock) BlockData; - return bb.getTileEntityClass(); - } - - return null; - } - - @Override - public Item item() - { - if ( ItemData == null && BlockData != null ) - return Item.getItemFromBlock( BlockData ); - return ItemData; - } - - @Override - public ItemStack stack(int stackSize) - { - if ( isFeatureAvailable() ) - { - ItemStack rv = null; - - if ( ItemData != null ) - rv = new ItemStack( ItemData ); - else - rv = new ItemStack( BlockData ); - - rv.stackSize = stackSize; - return rv; - } - return null; - } - - @Override - public boolean sameAsStack(ItemStack is) - { - if ( isFeatureAvailable() ) - return Platform.isSameItemType( is, stack( 1 ) ); - return false; - } - - @Override - public boolean sameAsBlock(IBlockAccess world, int x, int y, int z) - { - if ( isFeatureAvailable() && BlockData != null ) - return world.getBlock( x, y, z ) == block(); - return false; - } - -} +package appeng.core.features; + +import java.util.EnumSet; + +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.block.AEBaseBlock; +import appeng.block.AEBaseItemBlock; +import appeng.core.AEConfig; +import appeng.core.CommonHelper; +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 +{ + + private final EnumSet myFeatures; + + private final String subname; + private IAEFeature obj; + + private Item ItemData; + private Block BlockData; + + public AEFeatureHandler(EnumSet featureSet, IAEFeature _obj, String _subname) { + myFeatures = featureSet; + obj = _obj; + subname = _subname; + } + + public void register() + { + if ( isFeatureAvailable() ) + { + if ( obj instanceof Item ) + initItem( (Item) obj ); + if ( obj instanceof Block ) + initBlock( (Block) obj ); + } + } + + public static String getName(Class o, String subname) + { + String name = o.getSimpleName(); + + if ( name.startsWith( "ItemMultiPart" ) ) + name = name.replace( "ItemMultiPart", "ItemPart" ); + else if ( name.startsWith( "ItemMultiMaterial" ) ) + name = name.replace( "ItemMultiMaterial", "ItemMaterial" ); + + if ( subname != null ) + { + // 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"; + + if ( subname.equals( "CertusQuartzTools" ) ) + return name.replace( "Quartz", "CertusQuartz" ); + if ( subname.equals( "NetherQuartzTools" ) ) + return name.replace( "Quartz", "NetherQuartz" ); + + name += "." + subname; + } + + 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 myFeatures.clone(); + } + + public boolean isFeatureAvailable() + { + boolean enabled = true; + + for (AEFeature f : myFeatures) + enabled = enabled && AEConfig.instance.isFeatureEnabled( f ); + + return enabled; + } + + @Override + public Block block() + { + return BlockData; + } + + @Override + public Class entity() + { + if ( BlockData instanceof AEBaseBlock ) + { + AEBaseBlock bb = (AEBaseBlock) BlockData; + return bb.getTileEntityClass(); + } + + return null; + } + + @Override + public Item item() + { + if ( ItemData == null && BlockData != null ) + return Item.getItemFromBlock( BlockData ); + return ItemData; + } + + @Override + public ItemStack stack(int stackSize) + { + if ( isFeatureAvailable() ) + { + ItemStack rv = null; + + if ( ItemData != null ) + rv = new ItemStack( ItemData ); + else + rv = new ItemStack( BlockData ); + + rv.stackSize = stackSize; + return rv; + } + return null; + } + + @Override + public boolean sameAsStack(ItemStack is) + { + if ( isFeatureAvailable() ) + return Platform.isSameItemType( is, stack( 1 ) ); + return false; + } + + @Override + public boolean sameAsBlock(IBlockAccess world, int x, int y, int z) + { + if ( isFeatureAvailable() && BlockData != null ) + return world.getBlock( x, y, z ) == block(); + return false; + } + +} diff --git a/core/features/ColoredItemDefinition.java b/src/main/java/appeng/core/features/ColoredItemDefinition.java similarity index 95% rename from core/features/ColoredItemDefinition.java rename to src/main/java/appeng/core/features/ColoredItemDefinition.java index 5a2b1521e..ae6bf60f6 100644 --- a/core/features/ColoredItemDefinition.java +++ b/src/main/java/appeng/core/features/ColoredItemDefinition.java @@ -1,74 +1,74 @@ -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 appeng.api.util.AEColor; -import appeng.api.util.AEColoredItemDefinition; - -public class ColoredItemDefinition implements AEColoredItemDefinition -{ - - ItemStackSrc colors[] = new ItemStackSrc[17]; - - @Override - public Item item(AEColor color) - { - ItemStackSrc is = colors[color.ordinal()]; - - if ( is == null ) - return null; - - return is.item; - } - - @Override - public ItemStack stack(AEColor color, int stackSize) - { - ItemStackSrc is = colors[color.ordinal()]; - - if ( is == null ) - return null; - - return is.stack( stackSize ); - } - - @Override - public boolean sameAs(AEColor color, ItemStack comparableItem) - { - ItemStackSrc is = colors[color.ordinal()]; - - if ( comparableItem == null || is == null ) - return false; - - return comparableItem.getItem() == is.item && comparableItem.getItemDamage() == is.damage; - } - - public void add(AEColor v, ItemStackSrc is) - { - colors[v.ordinal()] = is; - } - - @Override - public Block block(AEColor color) - { - return null; - } - - @Override - public Class entity(AEColor color) - { - return null; - } - - @Override - public ItemStack[] allStacks(int stackSize) - { - ItemStack is[] = new ItemStack[colors.length]; - for (int x = 0; x < is.length; x++) - is[x] = colors[x].stack( 1 ); - return is; - } - -} +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 appeng.api.util.AEColor; +import appeng.api.util.AEColoredItemDefinition; + +public class ColoredItemDefinition implements AEColoredItemDefinition +{ + + ItemStackSrc colors[] = new ItemStackSrc[17]; + + @Override + public Item item(AEColor color) + { + ItemStackSrc is = colors[color.ordinal()]; + + if ( is == null ) + return null; + + return is.item; + } + + @Override + public ItemStack stack(AEColor color, int stackSize) + { + ItemStackSrc is = colors[color.ordinal()]; + + if ( is == null ) + return null; + + return is.stack( stackSize ); + } + + @Override + public boolean sameAs(AEColor color, ItemStack comparableItem) + { + ItemStackSrc is = colors[color.ordinal()]; + + if ( comparableItem == null || is == null ) + return false; + + return comparableItem.getItem() == is.item && comparableItem.getItemDamage() == is.damage; + } + + public void add(AEColor v, ItemStackSrc is) + { + colors[v.ordinal()] = is; + } + + @Override + public Block block(AEColor color) + { + return null; + } + + @Override + public Class entity(AEColor color) + { + return null; + } + + @Override + public ItemStack[] allStacks(int stackSize) + { + ItemStack is[] = new ItemStack[colors.length]; + for (int x = 0; x < is.length; x++) + is[x] = colors[x].stack( 1 ); + return is; + } + +} diff --git a/core/features/DamagedItemDefinition.java b/src/main/java/appeng/core/features/DamagedItemDefinition.java similarity index 100% rename from core/features/DamagedItemDefinition.java rename to src/main/java/appeng/core/features/DamagedItemDefinition.java diff --git a/core/features/IAEFeature.java b/src/main/java/appeng/core/features/IAEFeature.java similarity index 92% rename from core/features/IAEFeature.java rename to src/main/java/appeng/core/features/IAEFeature.java index aee4671d0..bdaa02767 100644 --- a/core/features/IAEFeature.java +++ b/src/main/java/appeng/core/features/IAEFeature.java @@ -1,10 +1,10 @@ -package appeng.core.features; - -public interface IAEFeature -{ - - public AEFeatureHandler feature(); - - void postInit(); - -} +package appeng.core.features; + +public interface IAEFeature +{ + + public AEFeatureHandler feature(); + + void postInit(); + +} diff --git a/core/features/IStackSrc.java b/src/main/java/appeng/core/features/IStackSrc.java similarity index 100% rename from core/features/IStackSrc.java rename to src/main/java/appeng/core/features/IStackSrc.java diff --git a/core/features/ItemStackSrc.java b/src/main/java/appeng/core/features/ItemStackSrc.java similarity index 100% rename from core/features/ItemStackSrc.java rename to src/main/java/appeng/core/features/ItemStackSrc.java diff --git a/core/features/MaterialStackSrc.java b/src/main/java/appeng/core/features/MaterialStackSrc.java similarity index 100% rename from core/features/MaterialStackSrc.java rename to src/main/java/appeng/core/features/MaterialStackSrc.java diff --git a/core/features/NullItemDefinition.java b/src/main/java/appeng/core/features/NullItemDefinition.java similarity index 94% rename from core/features/NullItemDefinition.java rename to src/main/java/appeng/core/features/NullItemDefinition.java index 4e394f336..afb4a671f 100644 --- a/core/features/NullItemDefinition.java +++ b/src/main/java/appeng/core/features/NullItemDefinition.java @@ -1,49 +1,49 @@ -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; - -public class NullItemDefinition implements AEItemDefinition -{ - - @Override - public Block block() - { - return null; - } - - @Override - public Item item() - { - return null; - } - - @Override - public Class entity() - { - return null; - } - - @Override - public ItemStack stack(int stackSize) - { - return null; - } - - @Override - public boolean sameAsStack(ItemStack comparableItem) - { - return false; - } - - @Override - public boolean sameAsBlock(IBlockAccess world, int x, int y, int z) - { - return false; - } - -} +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; + +public class NullItemDefinition implements AEItemDefinition +{ + + @Override + public Block block() + { + return null; + } + + @Override + public Item item() + { + return null; + } + + @Override + public Class entity() + { + return null; + } + + @Override + public ItemStack stack(int stackSize) + { + return null; + } + + @Override + public boolean sameAsStack(ItemStack comparableItem) + { + return false; + } + + @Override + public boolean sameAsBlock(IBlockAccess world, int x, int y, int z) + { + return false; + } + +} diff --git a/core/features/WrappedDamageItemDefinition.java b/src/main/java/appeng/core/features/WrappedDamageItemDefinition.java similarity index 100% rename from core/features/WrappedDamageItemDefinition.java rename to src/main/java/appeng/core/features/WrappedDamageItemDefinition.java diff --git a/core/features/registries/CellRegistry.java b/src/main/java/appeng/core/features/registries/CellRegistry.java similarity index 94% rename from core/features/registries/CellRegistry.java rename to src/main/java/appeng/core/features/registries/CellRegistry.java index b934bb5df..74d6af862 100644 --- a/core/features/registries/CellRegistry.java +++ b/src/main/java/appeng/core/features/registries/CellRegistry.java @@ -1,69 +1,69 @@ -package appeng.core.features.registries; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.item.ItemStack; -import appeng.api.storage.ICellHandler; -import appeng.api.storage.ICellRegistry; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.ISaveProvider; -import appeng.api.storage.StorageChannel; - -public class CellRegistry implements ICellRegistry -{ - - List handlers; - - public CellRegistry() { - handlers = new ArrayList(); - } - - @Override - public void addCellHandler(ICellHandler h) - { - if ( h != null ) - handlers.add( h ); - } - - @Override - public boolean isCellHandled(ItemStack is) - { - if ( is == null ) - return false; - for (ICellHandler ch : handlers) - if ( ch.isCell( is ) ) - return true; - return false; - } - - @Override - public ICellHandler getHandler(ItemStack is) - { - if ( is == null ) - return null; - for (ICellHandler ch : handlers) - { - if ( ch.isCell( is ) ) - { - return ch; - } - } - return null; - } - - @Override - public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel chan) - { - if ( is == null ) - return null; - for (ICellHandler ch : handlers) - { - if ( ch.isCell( is ) ) - { - return ch.getCellInventory( is, container, chan ); - } - } - return null; - } -} +package appeng.core.features.registries; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import appeng.api.storage.ICellHandler; +import appeng.api.storage.ICellRegistry; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.ISaveProvider; +import appeng.api.storage.StorageChannel; + +public class CellRegistry implements ICellRegistry +{ + + List handlers; + + public CellRegistry() { + handlers = new ArrayList(); + } + + @Override + public void addCellHandler(ICellHandler h) + { + if ( h != null ) + handlers.add( h ); + } + + @Override + public boolean isCellHandled(ItemStack is) + { + if ( is == null ) + return false; + for (ICellHandler ch : handlers) + if ( ch.isCell( is ) ) + return true; + return false; + } + + @Override + public ICellHandler getHandler(ItemStack is) + { + if ( is == null ) + return null; + for (ICellHandler ch : handlers) + { + if ( ch.isCell( is ) ) + { + return ch; + } + } + return null; + } + + @Override + public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel chan) + { + if ( is == null ) + return null; + for (ICellHandler ch : handlers) + { + if ( ch.isCell( is ) ) + { + return ch.getCellInventory( is, container, chan ); + } + } + return null; + } +} diff --git a/core/features/registries/ExternalStorageRegistry.java b/src/main/java/appeng/core/features/registries/ExternalStorageRegistry.java similarity index 96% rename from core/features/registries/ExternalStorageRegistry.java rename to src/main/java/appeng/core/features/registries/ExternalStorageRegistry.java index c7efc2583..c776291fc 100644 --- a/core/features/registries/ExternalStorageRegistry.java +++ b/src/main/java/appeng/core/features/registries/ExternalStorageRegistry.java @@ -1,45 +1,45 @@ -package appeng.core.features.registries; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IExternalStorageHandler; -import appeng.api.storage.IExternalStorageRegistry; -import appeng.api.storage.StorageChannel; -import appeng.core.features.registries.entries.ExternalIInv; - -public class ExternalStorageRegistry implements IExternalStorageRegistry -{ - - List Handlers; - final ExternalIInv lastHandler = new ExternalIInv(); - - public ExternalStorageRegistry() { - Handlers = new ArrayList(); - } - - @Override - public IExternalStorageHandler getHandler(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource mySrc) - { - for (IExternalStorageHandler x : Handlers) - { - if ( x.canHandle( te, d, chan, mySrc ) ) - return x; - } - - if ( lastHandler.canHandle( te, d, chan, mySrc ) ) - return lastHandler; - - return null; - } - - @Override - public void addExternalStorageInterface(IExternalStorageHandler ei) - { - Handlers.add( ei ); - } - -} +package appeng.core.features.registries; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IExternalStorageHandler; +import appeng.api.storage.IExternalStorageRegistry; +import appeng.api.storage.StorageChannel; +import appeng.core.features.registries.entries.ExternalIInv; + +public class ExternalStorageRegistry implements IExternalStorageRegistry +{ + + List Handlers; + final ExternalIInv lastHandler = new ExternalIInv(); + + public ExternalStorageRegistry() { + Handlers = new ArrayList(); + } + + @Override + public IExternalStorageHandler getHandler(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource mySrc) + { + for (IExternalStorageHandler x : Handlers) + { + if ( x.canHandle( te, d, chan, mySrc ) ) + return x; + } + + if ( lastHandler.canHandle( te, d, chan, mySrc ) ) + return lastHandler; + + return null; + } + + @Override + public void addExternalStorageInterface(IExternalStorageHandler ei) + { + Handlers.add( ei ); + } + +} diff --git a/core/features/registries/GridCacheRegistry.java b/src/main/java/appeng/core/features/registries/GridCacheRegistry.java similarity index 96% rename from core/features/registries/GridCacheRegistry.java rename to src/main/java/appeng/core/features/registries/GridCacheRegistry.java index 0f7920d23..d74233ea6 100644 --- a/core/features/registries/GridCacheRegistry.java +++ b/src/main/java/appeng/core/features/registries/GridCacheRegistry.java @@ -1,46 +1,46 @@ -package appeng.core.features.registries; - -import java.lang.reflect.Constructor; -import java.util.HashMap; - -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridCache; -import appeng.api.networking.IGridCacheRegistry; -import appeng.core.AELog; - -public class GridCacheRegistry implements IGridCacheRegistry -{ - - final private HashMap, Class> caches = new HashMap(); - - @Override - public void registerGridCache(Class iface, Class implementation) - { - if ( iface.isAssignableFrom( implementation ) ) - caches.put( iface, implementation ); - else - throw new RuntimeException( "Invalid setup, grid cache must either be the same class, or an interface that the implementation implements" ); - } - - @Override - public HashMap, IGridCache> createCacheInstance(IGrid g) - { - HashMap, IGridCache> map = new HashMap(); - - for (Class iface : caches.keySet()) - { - try - { - Constructor c = caches.get( iface ).getConstructor( IGrid.class ); - map.put( iface, c.newInstance( g ) ); - } - catch (Throwable e) - { - AELog.severe( "Grid Caches must have a constructor with IGrid as the single param." ); - throw new RuntimeException( e ); - } - } - - return map; - } -} +package appeng.core.features.registries; + +import java.lang.reflect.Constructor; +import java.util.HashMap; + +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridCache; +import appeng.api.networking.IGridCacheRegistry; +import appeng.core.AELog; + +public class GridCacheRegistry implements IGridCacheRegistry +{ + + final private HashMap, Class> caches = new HashMap(); + + @Override + public void registerGridCache(Class iface, Class implementation) + { + if ( iface.isAssignableFrom( implementation ) ) + caches.put( iface, implementation ); + else + throw new RuntimeException( "Invalid setup, grid cache must either be the same class, or an interface that the implementation implements" ); + } + + @Override + public HashMap, IGridCache> createCacheInstance(IGrid g) + { + HashMap, IGridCache> map = new HashMap(); + + for (Class iface : caches.keySet()) + { + try + { + Constructor c = caches.get( iface ).getConstructor( IGrid.class ); + map.put( iface, c.newInstance( g ) ); + } + catch (Throwable e) + { + AELog.severe( "Grid Caches must have a constructor with IGrid as the single param." ); + throw new RuntimeException( e ); + } + } + + return map; + } +} diff --git a/core/features/registries/GrinderRecipeManager.java b/src/main/java/appeng/core/features/registries/GrinderRecipeManager.java similarity index 96% rename from core/features/registries/GrinderRecipeManager.java rename to src/main/java/appeng/core/features/registries/GrinderRecipeManager.java index 8145029f1..0c05015d9 100644 --- a/core/features/registries/GrinderRecipeManager.java +++ b/src/main/java/appeng/core/features/registries/GrinderRecipeManager.java @@ -1,250 +1,250 @@ -package appeng.core.features.registries; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import appeng.api.features.IGrinderEntry; -import appeng.api.features.IGrinderRegistry; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.features.registries.entries.AppEngGrinderRecipe; -import appeng.recipes.ores.IOreListener; -import appeng.recipes.ores.OreDictionaryHandler; -import appeng.util.Platform; - -public class GrinderRecipeManager implements IGrinderRegistry, IOreListener -{ - - public List RecipeList; - - private ItemStack copy(ItemStack is) - { - if ( is != null ) - return is.copy(); - return null; - } - - public GrinderRecipeManager() { - RecipeList = new ArrayList(); - - addOre( "Coal", new ItemStack( Items.coal ) ); - addOre( "Charcoal", new ItemStack( Items.coal, 1, 1 ) ); - - addOre( "NetherQuartz", new ItemStack( Blocks.quartz_ore ) ); - addIngot( "NetherQuartz", new ItemStack( Items.quartz ) ); - - addOre( "Gold", new ItemStack( Blocks.gold_ore ) ); - addIngot( "Gold", new ItemStack( Items.gold_ingot ) ); - - addOre( "Iron", new ItemStack( Blocks.iron_ore ) ); - addIngot( "Iron", new ItemStack( Items.iron_ingot ) ); - - addOre( "Obsidian", new ItemStack( Blocks.obsidian ) ); - - addIngot( "Ender", new ItemStack( Items.ender_pearl ) ); - addIngot( "EnderPearl", new ItemStack( Items.ender_pearl ) ); - - addIngot( "Wheat", new ItemStack( Items.wheat ) ); - - OreDictionaryHandler.instance.observe( this ); - } - - @Override - public List getRecipes() - { - log( "API - getRecipes" ); - return RecipeList; - } - - private void injectRecipe(AppEngGrinderRecipe appEngGrinderRecipe) - { - for (IGrinderEntry gr : RecipeList) - if ( Platform.isSameItemPrecise( gr.getInput(), appEngGrinderRecipe.getInput() ) ) - return; - - RecipeList.add( appEngGrinderRecipe ); - } - - @Override - public void addRecipe(ItemStack in, ItemStack out, int cost) - { - if ( in == null || out == null ) - { - log( "Invalid Grinder Recipe Specified." ); - return; - } - - log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " for " + cost ); - injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), cost ) ); - } - - @Override - public void addRecipe(ItemStack in, ItemStack out, ItemStack optional, float chance, int cost) - { - if ( in == null || (optional == null && out == null) ) - { - log( "Invalid Grinder Recipe Specified." ); - return; - } - - log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " with optional " - + Platform.getItemDisplayName( optional ) + " for " + cost ); - injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) ); - } - - @Override - public void addRecipe(ItemStack in, ItemStack out, ItemStack optional, float chance, ItemStack optional2, float chance2, int cost) - { - if ( in == null || (optional == null && out == null && optional2 == null) ) - { - log( "Invalid Grinder Recipe Specified." ); - return; - } - - log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " with optional " - + Platform.getItemDisplayName( optional ) + " for " + cost ); - injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) ); - } - - @Override - public IGrinderEntry getRecipeForInput(ItemStack input) - { - log( "Looking up recipe for " + Platform.getItemDisplayName( input ) ); - if ( input != null ) - { - for (IGrinderEntry r : RecipeList) - { - if ( Platform.isSameItem( input, r.getInput() ) ) - { - log( "Recipe for " + input.getUnlocalizedName() + " found " + Platform.getItemDisplayName( r.getOutput() ) ); - return r; - } - } - - log( "Could not find recipe for " + Platform.getItemDisplayName( input ) ); - } - - return null; - } - - public void log(String o) - { - AELog.grinder( o ); - } - - private int getDustToOreRatio(String name) - { - if ( name.equals( "Obsidian" ) ) - return 1; - if ( name.equals( "Charcoal" ) ) - return 1; - if ( name.equals( "Coal" ) ) - return 1; - return 2; - } - - public Map Ores = new HashMap(); - public Map Ingots = new HashMap(); - public Map Dusts = new HashMap(); - - private void addOre(String name, ItemStack item) - { - if ( item == null ) - return; - log( "Adding Ore - " + name + " : " + Platform.getItemDisplayName( item ) ); - - Ores.put( item, name ); - - if ( Dusts.containsKey( name ) ) - { - ItemStack is = Dusts.get( name ).copy(); - int ratio = getDustToOreRatio( name ); - if ( ratio > 1 ) - { - ItemStack extra = is.copy(); - extra.stackSize = ratio - 1; - addRecipe( item, is, extra, (float) (AEConfig.instance.oreDoublePercentage / 100.0), 8 ); - } - else - addRecipe( item, is, 8 ); - } - } - - private void addIngot(String name, ItemStack item) - { - if ( item == null ) - return; - log( "Adding Ingot - " + name + " : " + Platform.getItemDisplayName( item ) ); - - Ingots.put( item, name ); - - if ( Dusts.containsKey( name ) ) - { - addRecipe( item, Dusts.get( name ), 4 ); - } - } - - private void addDust(String name, ItemStack item) - { - if ( item == null ) - return; - if ( Dusts.containsKey( name ) ) - { - log( "Rejecting Dust - " + name + " : " + Platform.getItemDisplayName( item ) ); - return; - } - - log( "Adding Dust - " + name + " : " + Platform.getItemDisplayName( item ) ); - - Dusts.put( name, item ); - - for (Entry d : Ores.entrySet()) - if ( name.equals( d.getValue() ) ) - { - ItemStack is = item.copy(); - is.stackSize = 1; - int ratio = getDustToOreRatio( name ); - if ( ratio > 1 ) - { - ItemStack extra = is.copy(); - extra.stackSize = ratio - 1; - addRecipe( d.getKey(), is, extra, (float) (AEConfig.instance.oreDoublePercentage / 100.0), 8 ); - } - else - addRecipe( d.getKey(), is, 8 ); - } - - for (Entry d : Ingots.entrySet()) - if ( name.equals( d.getValue() ) ) - addRecipe( d.getKey(), item, 4 ); - } - - @Override - public void oreRegistered(String Name, ItemStack item) - { - if ( Name.startsWith( "ore" ) || Name.startsWith( "crystal" ) || Name.startsWith( "gem" ) || Name.startsWith( "ingot" ) || Name.startsWith( "dust" ) ) - { - for (String ore : AEConfig.instance.grinderOres) - { - if ( Name.equals( "ore" + ore ) ) - { - addOre( ore, item ); - } - else if ( Name.equals( "crystal" + ore ) || Name.equals( "ingot" + ore ) || Name.equals( "gem" + ore ) ) - { - addIngot( ore, item ); - } - else if ( Name.equals( "dust" + ore ) ) - { - addDust( ore, item ); - } - } - } - } -} +package appeng.core.features.registries; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import appeng.api.features.IGrinderEntry; +import appeng.api.features.IGrinderRegistry; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.features.registries.entries.AppEngGrinderRecipe; +import appeng.recipes.ores.IOreListener; +import appeng.recipes.ores.OreDictionaryHandler; +import appeng.util.Platform; + +public class GrinderRecipeManager implements IGrinderRegistry, IOreListener +{ + + public List RecipeList; + + private ItemStack copy(ItemStack is) + { + if ( is != null ) + return is.copy(); + return null; + } + + public GrinderRecipeManager() { + RecipeList = new ArrayList(); + + addOre( "Coal", new ItemStack( Items.coal ) ); + addOre( "Charcoal", new ItemStack( Items.coal, 1, 1 ) ); + + addOre( "NetherQuartz", new ItemStack( Blocks.quartz_ore ) ); + addIngot( "NetherQuartz", new ItemStack( Items.quartz ) ); + + addOre( "Gold", new ItemStack( Blocks.gold_ore ) ); + addIngot( "Gold", new ItemStack( Items.gold_ingot ) ); + + addOre( "Iron", new ItemStack( Blocks.iron_ore ) ); + addIngot( "Iron", new ItemStack( Items.iron_ingot ) ); + + addOre( "Obsidian", new ItemStack( Blocks.obsidian ) ); + + addIngot( "Ender", new ItemStack( Items.ender_pearl ) ); + addIngot( "EnderPearl", new ItemStack( Items.ender_pearl ) ); + + addIngot( "Wheat", new ItemStack( Items.wheat ) ); + + OreDictionaryHandler.instance.observe( this ); + } + + @Override + public List getRecipes() + { + log( "API - getRecipes" ); + return RecipeList; + } + + private void injectRecipe(AppEngGrinderRecipe appEngGrinderRecipe) + { + for (IGrinderEntry gr : RecipeList) + if ( Platform.isSameItemPrecise( gr.getInput(), appEngGrinderRecipe.getInput() ) ) + return; + + RecipeList.add( appEngGrinderRecipe ); + } + + @Override + public void addRecipe(ItemStack in, ItemStack out, int cost) + { + if ( in == null || out == null ) + { + log( "Invalid Grinder Recipe Specified." ); + return; + } + + log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " for " + cost ); + injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), cost ) ); + } + + @Override + public void addRecipe(ItemStack in, ItemStack out, ItemStack optional, float chance, int cost) + { + if ( in == null || (optional == null && out == null) ) + { + log( "Invalid Grinder Recipe Specified." ); + return; + } + + log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " with optional " + + Platform.getItemDisplayName( optional ) + " for " + cost ); + injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) ); + } + + @Override + public void addRecipe(ItemStack in, ItemStack out, ItemStack optional, float chance, ItemStack optional2, float chance2, int cost) + { + if ( in == null || (optional == null && out == null && optional2 == null) ) + { + log( "Invalid Grinder Recipe Specified." ); + return; + } + + log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " with optional " + + Platform.getItemDisplayName( optional ) + " for " + cost ); + injectRecipe( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) ); + } + + @Override + public IGrinderEntry getRecipeForInput(ItemStack input) + { + log( "Looking up recipe for " + Platform.getItemDisplayName( input ) ); + if ( input != null ) + { + for (IGrinderEntry r : RecipeList) + { + if ( Platform.isSameItem( input, r.getInput() ) ) + { + log( "Recipe for " + input.getUnlocalizedName() + " found " + Platform.getItemDisplayName( r.getOutput() ) ); + return r; + } + } + + log( "Could not find recipe for " + Platform.getItemDisplayName( input ) ); + } + + return null; + } + + public void log(String o) + { + AELog.grinder( o ); + } + + private int getDustToOreRatio(String name) + { + if ( name.equals( "Obsidian" ) ) + return 1; + if ( name.equals( "Charcoal" ) ) + return 1; + if ( name.equals( "Coal" ) ) + return 1; + return 2; + } + + public Map Ores = new HashMap(); + public Map Ingots = new HashMap(); + public Map Dusts = new HashMap(); + + private void addOre(String name, ItemStack item) + { + if ( item == null ) + return; + log( "Adding Ore - " + name + " : " + Platform.getItemDisplayName( item ) ); + + Ores.put( item, name ); + + if ( Dusts.containsKey( name ) ) + { + ItemStack is = Dusts.get( name ).copy(); + int ratio = getDustToOreRatio( name ); + if ( ratio > 1 ) + { + ItemStack extra = is.copy(); + extra.stackSize = ratio - 1; + addRecipe( item, is, extra, (float) (AEConfig.instance.oreDoublePercentage / 100.0), 8 ); + } + else + addRecipe( item, is, 8 ); + } + } + + private void addIngot(String name, ItemStack item) + { + if ( item == null ) + return; + log( "Adding Ingot - " + name + " : " + Platform.getItemDisplayName( item ) ); + + Ingots.put( item, name ); + + if ( Dusts.containsKey( name ) ) + { + addRecipe( item, Dusts.get( name ), 4 ); + } + } + + private void addDust(String name, ItemStack item) + { + if ( item == null ) + return; + if ( Dusts.containsKey( name ) ) + { + log( "Rejecting Dust - " + name + " : " + Platform.getItemDisplayName( item ) ); + return; + } + + log( "Adding Dust - " + name + " : " + Platform.getItemDisplayName( item ) ); + + Dusts.put( name, item ); + + for (Entry d : Ores.entrySet()) + if ( name.equals( d.getValue() ) ) + { + ItemStack is = item.copy(); + is.stackSize = 1; + int ratio = getDustToOreRatio( name ); + if ( ratio > 1 ) + { + ItemStack extra = is.copy(); + extra.stackSize = ratio - 1; + addRecipe( d.getKey(), is, extra, (float) (AEConfig.instance.oreDoublePercentage / 100.0), 8 ); + } + else + addRecipe( d.getKey(), is, 8 ); + } + + for (Entry d : Ingots.entrySet()) + if ( name.equals( d.getValue() ) ) + addRecipe( d.getKey(), item, 4 ); + } + + @Override + public void oreRegistered(String Name, ItemStack item) + { + if ( Name.startsWith( "ore" ) || Name.startsWith( "crystal" ) || Name.startsWith( "gem" ) || Name.startsWith( "ingot" ) || Name.startsWith( "dust" ) ) + { + for (String ore : AEConfig.instance.grinderOres) + { + if ( Name.equals( "ore" + ore ) ) + { + addOre( ore, item ); + } + else if ( Name.equals( "crystal" + ore ) || Name.equals( "ingot" + ore ) || Name.equals( "gem" + ore ) ) + { + addIngot( ore, item ); + } + else if ( Name.equals( "dust" + ore ) ) + { + addDust( ore, item ); + } + } + } + } +} diff --git a/core/features/registries/LocatableRegistry.java b/src/main/java/appeng/core/features/registries/LocatableRegistry.java similarity index 100% rename from core/features/registries/LocatableRegistry.java rename to src/main/java/appeng/core/features/registries/LocatableRegistry.java diff --git a/core/features/registries/MatterCannonAmmoRegistry.java b/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java similarity index 97% rename from core/features/registries/MatterCannonAmmoRegistry.java rename to src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java index ece123742..03e3f89cc 100644 --- a/core/features/registries/MatterCannonAmmoRegistry.java +++ b/src/main/java/appeng/core/features/registries/MatterCannonAmmoRegistry.java @@ -1,126 +1,126 @@ -package appeng.core.features.registries; - -import java.util.HashMap; - -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import appeng.api.features.IMatterCannonAmmoRegistry; -import appeng.recipes.ores.IOreListener; -import appeng.recipes.ores.OreDictionaryHandler; -import appeng.util.Platform; - -public class MatterCannonAmmoRegistry implements IOreListener, IMatterCannonAmmoRegistry -{ - - private HashMap DamageModifiers = new HashMap(); - - @Override - public void registerAmmo(ItemStack ammo, double weight) - { - DamageModifiers.put( ammo, weight ); - } - - private void considerItem(String ore, ItemStack item, String Name, double weight) - { - if ( ore.equals( "berry" + Name ) || ore.equals( "nugget" + Name ) ) - { - registerAmmo( item, weight ); - } - } - - @Override - public void oreRegistered(String Name, ItemStack item) - { - if ( !(Name.startsWith( "berry" ) || Name.startsWith( "nugget" )) ) - return; - - // addNugget( "Cobble", 18 ); // ? - considerItem( Name, item, "MeatRaw", 32 ); - considerItem( Name, item, "MeatCooked", 32 ); - considerItem( Name, item, "Meat", 32 ); - considerItem( Name, item, "Chicken", 32 ); - considerItem( Name, item, "Beef", 32 ); - considerItem( Name, item, "Sheep", 32 ); - considerItem( Name, item, "Fish", 32 ); - - // real world... - considerItem( Name, item, "Lithium", 6.941 ); - considerItem( Name, item, "Beryllium", 9.0122 ); - considerItem( Name, item, "Boron", 10.811 ); - considerItem( Name, item, "Carbon", 12.0107 ); - considerItem( Name, item, "Coal", 12.0107 ); - considerItem( Name, item, "Charcoal", 12.0107 ); - considerItem( Name, item, "Sodium", 22.9897 ); - considerItem( Name, item, "Magnesium", 24.305 ); - considerItem( Name, item, "Aluminum", 26.9815 ); - considerItem( Name, item, "Silicon", 28.0855 ); - considerItem( Name, item, "Phosphorus", 30.9738 ); - considerItem( Name, item, "Sulfur", 32.065 ); - considerItem( Name, item, "Potassium", 39.0983 ); - considerItem( Name, item, "Calcium", 40.078 ); - considerItem( Name, item, "Scandium", 44.9559 ); - considerItem( Name, item, "Titanium", 47.867 ); - considerItem( Name, item, "Vanadium", 50.9415 ); - considerItem( Name, item, "Manganese", 54.938 ); - considerItem( Name, item, "Iron", 55.845 ); - considerItem( Name, item, "Nickel", 58.6934 ); - considerItem( Name, item, "Cobalt", 58.9332 ); - considerItem( Name, item, "Copper", 63.546 ); - considerItem( Name, item, "Zinc", 65.39 ); - considerItem( Name, item, "Gallium", 69.723 ); - considerItem( Name, item, "Germanium", 72.64 ); - considerItem( Name, item, "Bromine", 79.904 ); - considerItem( Name, item, "Krypton", 83.8 ); - considerItem( Name, item, "Rubidium", 85.4678 ); - considerItem( Name, item, "Strontium", 87.62 ); - considerItem( Name, item, "Yttrium", 88.9059 ); - considerItem( Name, item, "Zirconiumm", 91.224 ); - considerItem( Name, item, "Niobiumm", 92.9064 ); - considerItem( Name, item, "Technetium", 98 ); - considerItem( Name, item, "Ruthenium", 101.07 ); - considerItem( Name, item, "Rhodium", 102.9055 ); - considerItem( Name, item, "Palladium", 106.42 ); - considerItem( Name, item, "Silver", 107.8682 ); - considerItem( Name, item, "Cadmium", 112.411 ); - considerItem( Name, item, "Indium", 114.818 ); - considerItem( Name, item, "Tin", 118.71 ); - considerItem( Name, item, "Antimony", 121.76 ); - considerItem( Name, item, "Iodine", 126.9045 ); - considerItem( Name, item, "Tellurium", 127.6 ); - considerItem( Name, item, "Xenon", 131.293 ); - considerItem( Name, item, "Cesium", 132.9055 ); - considerItem( Name, item, "Barium", 137.327 ); - considerItem( Name, item, "Lanthanum", 138.9055 ); - considerItem( Name, item, "Cerium", 140.116 ); - considerItem( Name, item, "Tantalum", 180.9479 ); - considerItem( Name, item, "Tungsten", 183.84 ); - considerItem( Name, item, "Osmium", 190.23 ); - considerItem( Name, item, "Iridium", 192.217 ); - considerItem( Name, item, "Platinum", 195.078 ); - considerItem( Name, item, "Lead", 207.2 ); - considerItem( Name, item, "Bismuth", 208.9804 ); - considerItem( Name, item, "Uranium", 238.0289 ); - considerItem( Name, item, "Plutonium", 244 ); - - // TE stuff... - considerItem( Name, item, "Invar", (58.6934 + 55.845 + 55.845) / 3.0 ); - considerItem( Name, item, "Electrum", (107.8682 + 196.96655) / 2.0 ); - } - - public MatterCannonAmmoRegistry() { - OreDictionaryHandler.instance.observe( this ); - registerAmmo( new ItemStack( Items.gold_nugget ), 196.96655 ); - } - - @Override - public float getPenetration(ItemStack is) - { - for (ItemStack o : DamageModifiers.keySet()) - { - if ( Platform.isSameItem( o, is ) ) - return DamageModifiers.get( o ).floatValue(); - } - return 0; - } - -} +package appeng.core.features.registries; + +import java.util.HashMap; + +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import appeng.api.features.IMatterCannonAmmoRegistry; +import appeng.recipes.ores.IOreListener; +import appeng.recipes.ores.OreDictionaryHandler; +import appeng.util.Platform; + +public class MatterCannonAmmoRegistry implements IOreListener, IMatterCannonAmmoRegistry +{ + + private HashMap DamageModifiers = new HashMap(); + + @Override + public void registerAmmo(ItemStack ammo, double weight) + { + DamageModifiers.put( ammo, weight ); + } + + private void considerItem(String ore, ItemStack item, String Name, double weight) + { + if ( ore.equals( "berry" + Name ) || ore.equals( "nugget" + Name ) ) + { + registerAmmo( item, weight ); + } + } + + @Override + public void oreRegistered(String Name, ItemStack item) + { + if ( !(Name.startsWith( "berry" ) || Name.startsWith( "nugget" )) ) + return; + + // addNugget( "Cobble", 18 ); // ? + considerItem( Name, item, "MeatRaw", 32 ); + considerItem( Name, item, "MeatCooked", 32 ); + considerItem( Name, item, "Meat", 32 ); + considerItem( Name, item, "Chicken", 32 ); + considerItem( Name, item, "Beef", 32 ); + considerItem( Name, item, "Sheep", 32 ); + considerItem( Name, item, "Fish", 32 ); + + // real world... + considerItem( Name, item, "Lithium", 6.941 ); + considerItem( Name, item, "Beryllium", 9.0122 ); + considerItem( Name, item, "Boron", 10.811 ); + considerItem( Name, item, "Carbon", 12.0107 ); + considerItem( Name, item, "Coal", 12.0107 ); + considerItem( Name, item, "Charcoal", 12.0107 ); + considerItem( Name, item, "Sodium", 22.9897 ); + considerItem( Name, item, "Magnesium", 24.305 ); + considerItem( Name, item, "Aluminum", 26.9815 ); + considerItem( Name, item, "Silicon", 28.0855 ); + considerItem( Name, item, "Phosphorus", 30.9738 ); + considerItem( Name, item, "Sulfur", 32.065 ); + considerItem( Name, item, "Potassium", 39.0983 ); + considerItem( Name, item, "Calcium", 40.078 ); + considerItem( Name, item, "Scandium", 44.9559 ); + considerItem( Name, item, "Titanium", 47.867 ); + considerItem( Name, item, "Vanadium", 50.9415 ); + considerItem( Name, item, "Manganese", 54.938 ); + considerItem( Name, item, "Iron", 55.845 ); + considerItem( Name, item, "Nickel", 58.6934 ); + considerItem( Name, item, "Cobalt", 58.9332 ); + considerItem( Name, item, "Copper", 63.546 ); + considerItem( Name, item, "Zinc", 65.39 ); + considerItem( Name, item, "Gallium", 69.723 ); + considerItem( Name, item, "Germanium", 72.64 ); + considerItem( Name, item, "Bromine", 79.904 ); + considerItem( Name, item, "Krypton", 83.8 ); + considerItem( Name, item, "Rubidium", 85.4678 ); + considerItem( Name, item, "Strontium", 87.62 ); + considerItem( Name, item, "Yttrium", 88.9059 ); + considerItem( Name, item, "Zirconiumm", 91.224 ); + considerItem( Name, item, "Niobiumm", 92.9064 ); + considerItem( Name, item, "Technetium", 98 ); + considerItem( Name, item, "Ruthenium", 101.07 ); + considerItem( Name, item, "Rhodium", 102.9055 ); + considerItem( Name, item, "Palladium", 106.42 ); + considerItem( Name, item, "Silver", 107.8682 ); + considerItem( Name, item, "Cadmium", 112.411 ); + considerItem( Name, item, "Indium", 114.818 ); + considerItem( Name, item, "Tin", 118.71 ); + considerItem( Name, item, "Antimony", 121.76 ); + considerItem( Name, item, "Iodine", 126.9045 ); + considerItem( Name, item, "Tellurium", 127.6 ); + considerItem( Name, item, "Xenon", 131.293 ); + considerItem( Name, item, "Cesium", 132.9055 ); + considerItem( Name, item, "Barium", 137.327 ); + considerItem( Name, item, "Lanthanum", 138.9055 ); + considerItem( Name, item, "Cerium", 140.116 ); + considerItem( Name, item, "Tantalum", 180.9479 ); + considerItem( Name, item, "Tungsten", 183.84 ); + considerItem( Name, item, "Osmium", 190.23 ); + considerItem( Name, item, "Iridium", 192.217 ); + considerItem( Name, item, "Platinum", 195.078 ); + considerItem( Name, item, "Lead", 207.2 ); + considerItem( Name, item, "Bismuth", 208.9804 ); + considerItem( Name, item, "Uranium", 238.0289 ); + considerItem( Name, item, "Plutonium", 244 ); + + // TE stuff... + considerItem( Name, item, "Invar", (58.6934 + 55.845 + 55.845) / 3.0 ); + considerItem( Name, item, "Electrum", (107.8682 + 196.96655) / 2.0 ); + } + + public MatterCannonAmmoRegistry() { + OreDictionaryHandler.instance.observe( this ); + registerAmmo( new ItemStack( Items.gold_nugget ), 196.96655 ); + } + + @Override + public float getPenetration(ItemStack is) + { + for (ItemStack o : DamageModifiers.keySet()) + { + if ( Platform.isSameItem( o, is ) ) + return DamageModifiers.get( o ).floatValue(); + } + return 0; + } + +} diff --git a/core/features/registries/MovableTileRegistry.java b/src/main/java/appeng/core/features/registries/MovableTileRegistry.java similarity index 100% rename from core/features/registries/MovableTileRegistry.java rename to src/main/java/appeng/core/features/registries/MovableTileRegistry.java diff --git a/core/features/registries/P2PTunnelRegistry.java b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java similarity index 97% rename from core/features/registries/P2PTunnelRegistry.java rename to src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java index 1e50aa19c..84a4bfb17 100644 --- a/core/features/registries/P2PTunnelRegistry.java +++ b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java @@ -1,128 +1,128 @@ -package appeng.core.features.registries; - -import java.util.HashMap; - -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.oredict.OreDictionary; -import appeng.api.AEApi; -import appeng.api.config.TunnelType; -import appeng.api.definitions.Parts; -import appeng.api.features.IP2PTunnelRegistry; -import appeng.api.util.AEColor; -import appeng.util.Platform; -import cpw.mods.fml.common.registry.GameRegistry; - -public class P2PTunnelRegistry implements IP2PTunnelRegistry -{ - - HashMap Tunnels = new HashMap(); - - public ItemStack getModItem(String modID, String Name, int meta) - { - ItemStack myItemStack = GameRegistry.findItemStack( modID, Name, 1 ); - - if ( myItemStack == null ) - return null; - - myItemStack.setItemDamage( meta ); - return myItemStack; - } - - public void configure() - { - /** - * light! - */ - addNewAttunement( new ItemStack( Blocks.torch ), TunnelType.LIGHT ); - addNewAttunement( new ItemStack( Blocks.glowstone ), TunnelType.LIGHT ); - - /** - * attune based on most redstone base items. - */ - addNewAttunement( new ItemStack( Items.redstone ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Items.repeater ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.redstone_lamp ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.unpowered_comparator ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.powered_comparator ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.powered_repeater ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.unpowered_repeater ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.daylight_detector ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.redstone_wire ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.redstone_block ), TunnelType.REDSTONE ); - addNewAttunement( new ItemStack( Blocks.lever ), TunnelType.REDSTONE ); - addNewAttunement( getModItem( "EnderIO", "itemRedstoneConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.REDSTONE ); - - /** - * attune based on lots of random item related stuff - */ - appeng.api.definitions.Blocks AEBlocks = AEApi.instance().blocks(); - Parts Parts = AEApi.instance().parts(); - - addNewAttunement( AEBlocks.blockInterface.stack( 1 ), TunnelType.ITEM ); - addNewAttunement( Parts.partInterface.stack( 1 ), TunnelType.ITEM ); - addNewAttunement( Parts.partStorageBus.stack( 1 ), TunnelType.ITEM ); - addNewAttunement( Parts.partImportBus.stack( 1 ), TunnelType.ITEM ); - addNewAttunement( Parts.partExportBus.stack( 1 ), TunnelType.ITEM ); - addNewAttunement( new ItemStack( Blocks.hopper ), TunnelType.ITEM ); - addNewAttunement( new ItemStack( Blocks.chest ), TunnelType.ITEM ); - addNewAttunement( new ItemStack( Blocks.trapped_chest ), TunnelType.ITEM ); - addNewAttunement( getModItem( "ExtraUtilities", "extractor_base", 0 ), TunnelType.ITEM ); - addNewAttunement( getModItem( "Mekanism", "PartTransmitter", 9 ), TunnelType.ITEM ); - addNewAttunement( getModItem( "EnderIO", "itemItemConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.ITEM ); - - /** - * attune based on lots of random item related stuff - */ - addNewAttunement( new ItemStack( Items.bucket ), TunnelType.FLUID ); - addNewAttunement( new ItemStack( Items.lava_bucket ), TunnelType.FLUID ); - addNewAttunement( new ItemStack( Items.milk_bucket ), TunnelType.FLUID ); - addNewAttunement( new ItemStack( Items.water_bucket ), TunnelType.FLUID ); - addNewAttunement( getModItem( "Mekanism", "MachineBlock2", 11 ), TunnelType.FLUID ); - addNewAttunement( getModItem( "Mekanism", "PartTransmitter", 4 ), TunnelType.FLUID ); - addNewAttunement( getModItem( "ExtraUtilities", "extractor_base", 6 ), TunnelType.FLUID ); - addNewAttunement( getModItem( "ExtraUtilities", "drum", OreDictionary.WILDCARD_VALUE ), TunnelType.FLUID ); - addNewAttunement( getModItem( "EnderIO", "itemLiquidConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.FLUID ); - - for (AEColor c : AEColor.values()) - { - addNewAttunement( Parts.partCableGlass.stack( c, 1 ), TunnelType.ME ); - addNewAttunement( Parts.partCableCovered.stack( c, 1 ), TunnelType.ME ); - addNewAttunement( Parts.partCableSmart.stack( c, 1 ), TunnelType.ME ); - addNewAttunement( Parts.partCableDense.stack( c, 1 ), TunnelType.ME ); - } - } - - @Override - public void addNewAttunement(ItemStack trigger, TunnelType type) - { - if ( type == null || trigger == null ) - return; - - Tunnels.put( trigger, type ); - } - - @Override - public TunnelType getTunnelTypeByItem(ItemStack trigger) - { - if ( trigger != null ) - { - if ( FluidContainerRegistry.isContainer( trigger ) ) - return TunnelType.FLUID; - - for (ItemStack is : Tunnels.keySet()) - { - if ( is.getItem() == trigger.getItem() && is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) - return Tunnels.get( is ); - - if ( Platform.isSameItem( is, trigger ) ) - return Tunnels.get( is ); - } - } - - return null; - } - -} +package appeng.core.features.registries; + +import java.util.HashMap; + +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.oredict.OreDictionary; +import appeng.api.AEApi; +import appeng.api.config.TunnelType; +import appeng.api.definitions.Parts; +import appeng.api.features.IP2PTunnelRegistry; +import appeng.api.util.AEColor; +import appeng.util.Platform; +import cpw.mods.fml.common.registry.GameRegistry; + +public class P2PTunnelRegistry implements IP2PTunnelRegistry +{ + + HashMap Tunnels = new HashMap(); + + public ItemStack getModItem(String modID, String Name, int meta) + { + ItemStack myItemStack = GameRegistry.findItemStack( modID, Name, 1 ); + + if ( myItemStack == null ) + return null; + + myItemStack.setItemDamage( meta ); + return myItemStack; + } + + public void configure() + { + /** + * light! + */ + addNewAttunement( new ItemStack( Blocks.torch ), TunnelType.LIGHT ); + addNewAttunement( new ItemStack( Blocks.glowstone ), TunnelType.LIGHT ); + + /** + * attune based on most redstone base items. + */ + addNewAttunement( new ItemStack( Items.redstone ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Items.repeater ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.redstone_lamp ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.unpowered_comparator ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.powered_comparator ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.powered_repeater ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.unpowered_repeater ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.daylight_detector ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.redstone_wire ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.redstone_block ), TunnelType.REDSTONE ); + addNewAttunement( new ItemStack( Blocks.lever ), TunnelType.REDSTONE ); + addNewAttunement( getModItem( "EnderIO", "itemRedstoneConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.REDSTONE ); + + /** + * attune based on lots of random item related stuff + */ + appeng.api.definitions.Blocks AEBlocks = AEApi.instance().blocks(); + Parts Parts = AEApi.instance().parts(); + + addNewAttunement( AEBlocks.blockInterface.stack( 1 ), TunnelType.ITEM ); + addNewAttunement( Parts.partInterface.stack( 1 ), TunnelType.ITEM ); + addNewAttunement( Parts.partStorageBus.stack( 1 ), TunnelType.ITEM ); + addNewAttunement( Parts.partImportBus.stack( 1 ), TunnelType.ITEM ); + addNewAttunement( Parts.partExportBus.stack( 1 ), TunnelType.ITEM ); + addNewAttunement( new ItemStack( Blocks.hopper ), TunnelType.ITEM ); + addNewAttunement( new ItemStack( Blocks.chest ), TunnelType.ITEM ); + addNewAttunement( new ItemStack( Blocks.trapped_chest ), TunnelType.ITEM ); + addNewAttunement( getModItem( "ExtraUtilities", "extractor_base", 0 ), TunnelType.ITEM ); + addNewAttunement( getModItem( "Mekanism", "PartTransmitter", 9 ), TunnelType.ITEM ); + addNewAttunement( getModItem( "EnderIO", "itemItemConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.ITEM ); + + /** + * attune based on lots of random item related stuff + */ + addNewAttunement( new ItemStack( Items.bucket ), TunnelType.FLUID ); + addNewAttunement( new ItemStack( Items.lava_bucket ), TunnelType.FLUID ); + addNewAttunement( new ItemStack( Items.milk_bucket ), TunnelType.FLUID ); + addNewAttunement( new ItemStack( Items.water_bucket ), TunnelType.FLUID ); + addNewAttunement( getModItem( "Mekanism", "MachineBlock2", 11 ), TunnelType.FLUID ); + addNewAttunement( getModItem( "Mekanism", "PartTransmitter", 4 ), TunnelType.FLUID ); + addNewAttunement( getModItem( "ExtraUtilities", "extractor_base", 6 ), TunnelType.FLUID ); + addNewAttunement( getModItem( "ExtraUtilities", "drum", OreDictionary.WILDCARD_VALUE ), TunnelType.FLUID ); + addNewAttunement( getModItem( "EnderIO", "itemLiquidConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.FLUID ); + + for (AEColor c : AEColor.values()) + { + addNewAttunement( Parts.partCableGlass.stack( c, 1 ), TunnelType.ME ); + addNewAttunement( Parts.partCableCovered.stack( c, 1 ), TunnelType.ME ); + addNewAttunement( Parts.partCableSmart.stack( c, 1 ), TunnelType.ME ); + addNewAttunement( Parts.partCableDense.stack( c, 1 ), TunnelType.ME ); + } + } + + @Override + public void addNewAttunement(ItemStack trigger, TunnelType type) + { + if ( type == null || trigger == null ) + return; + + Tunnels.put( trigger, type ); + } + + @Override + public TunnelType getTunnelTypeByItem(ItemStack trigger) + { + if ( trigger != null ) + { + if ( FluidContainerRegistry.isContainer( trigger ) ) + return TunnelType.FLUID; + + for (ItemStack is : Tunnels.keySet()) + { + if ( is.getItem() == trigger.getItem() && is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) + return Tunnels.get( is ); + + if ( Platform.isSameItem( is, trigger ) ) + return Tunnels.get( is ); + } + } + + return null; + } + +} diff --git a/core/features/registries/PlayerRegistry.java b/src/main/java/appeng/core/features/registries/PlayerRegistry.java similarity index 100% rename from core/features/registries/PlayerRegistry.java rename to src/main/java/appeng/core/features/registries/PlayerRegistry.java diff --git a/core/features/registries/RecipeHandlerRegistry.java b/src/main/java/appeng/core/features/registries/RecipeHandlerRegistry.java similarity index 95% rename from core/features/registries/RecipeHandlerRegistry.java rename to src/main/java/appeng/core/features/registries/RecipeHandlerRegistry.java index 7c262662f..5b1862437 100644 --- a/core/features/registries/RecipeHandlerRegistry.java +++ b/src/main/java/appeng/core/features/registries/RecipeHandlerRegistry.java @@ -1,79 +1,79 @@ -package appeng.core.features.registries; - -import java.util.HashMap; -import java.util.LinkedList; - -import appeng.api.features.IRecipeHandlerRegistry; -import appeng.api.recipes.ICraftHandler; -import appeng.api.recipes.IRecipeHandler; -import appeng.api.recipes.ISubItemResolver; -import appeng.core.AELog; -import appeng.recipes.RecipeHandler; - -public class RecipeHandlerRegistry implements IRecipeHandlerRegistry -{ - - HashMap> handlers = new HashMap>(); - LinkedList resolvers = new LinkedList(); - - @Override - public void addNewCraftHandler(String name, Class handler) - { - handlers.put( name.toLowerCase(), handler ); - } - - @Override - public ICraftHandler getCraftHandlerFor(String name) - { - Class clz = handlers.get( name ); - if ( clz == null ) - return null; - try - { - return clz.newInstance(); - } - catch (Throwable e) - { - AELog.severe( "Error Caused when trying to construct " + clz.getName() ); - AELog.error( e ); - handlers.put( name, null ); // clear it.. - return null; - } - } - - @Override - public IRecipeHandler createNewRecipehandler() - { - return new RecipeHandler(); - } - - @Override - public void addNewSubItemResolver(ISubItemResolver sir) - { - resolvers.add( sir ); - } - - @Override - public Object resolveItem(String nameSpace, String itemName) - { - for (ISubItemResolver sir : resolvers) - { - Object rr = null; - - try - { - rr = sir.resolveItemByName( nameSpace, itemName ); - } - catch (Throwable t) - { - AELog.error( t ); - } - - if ( rr != null ) - return rr; - } - - return null; - } - -} +package appeng.core.features.registries; + +import java.util.HashMap; +import java.util.LinkedList; + +import appeng.api.features.IRecipeHandlerRegistry; +import appeng.api.recipes.ICraftHandler; +import appeng.api.recipes.IRecipeHandler; +import appeng.api.recipes.ISubItemResolver; +import appeng.core.AELog; +import appeng.recipes.RecipeHandler; + +public class RecipeHandlerRegistry implements IRecipeHandlerRegistry +{ + + HashMap> handlers = new HashMap>(); + LinkedList resolvers = new LinkedList(); + + @Override + public void addNewCraftHandler(String name, Class handler) + { + handlers.put( name.toLowerCase(), handler ); + } + + @Override + public ICraftHandler getCraftHandlerFor(String name) + { + Class clz = handlers.get( name ); + if ( clz == null ) + return null; + try + { + return clz.newInstance(); + } + catch (Throwable e) + { + AELog.severe( "Error Caused when trying to construct " + clz.getName() ); + AELog.error( e ); + handlers.put( name, null ); // clear it.. + return null; + } + } + + @Override + public IRecipeHandler createNewRecipehandler() + { + return new RecipeHandler(); + } + + @Override + public void addNewSubItemResolver(ISubItemResolver sir) + { + resolvers.add( sir ); + } + + @Override + public Object resolveItem(String nameSpace, String itemName) + { + for (ISubItemResolver sir : resolvers) + { + Object rr = null; + + try + { + rr = sir.resolveItemByName( nameSpace, itemName ); + } + catch (Throwable t) + { + AELog.error( t ); + } + + if ( rr != null ) + return rr; + } + + return null; + } + +} diff --git a/core/features/registries/RegistryContainer.java b/src/main/java/appeng/core/features/registries/RegistryContainer.java similarity index 96% rename from core/features/registries/RegistryContainer.java rename to src/main/java/appeng/core/features/registries/RegistryContainer.java index 274862cc3..7b38a91c4 100644 --- a/core/features/registries/RegistryContainer.java +++ b/src/main/java/appeng/core/features/registries/RegistryContainer.java @@ -1,112 +1,112 @@ -package appeng.core.features.registries; - -import appeng.api.features.IGrinderRegistry; -import appeng.api.features.ILocatableRegistry; -import appeng.api.features.IMatterCannonAmmoRegistry; -import appeng.api.features.IP2PTunnelRegistry; -import appeng.api.features.IPlayerRegistry; -import appeng.api.features.IRecipeHandlerRegistry; -import appeng.api.features.IRegistryContainer; -import appeng.api.features.ISpecialComparisonRegistry; -import appeng.api.features.IWirelessTermRegistry; -import appeng.api.features.IWorldGen; -import appeng.api.movable.IMovableRegistry; -import appeng.api.networking.IGridCacheRegistry; -import appeng.api.storage.ICellRegistry; -import appeng.api.storage.IExternalStorageRegistry; - -public class RegistryContainer implements IRegistryContainer -{ - - private GrinderRecipeManager GrinderRecipes = new GrinderRecipeManager(); - private ExternalStorageRegistry ExternalStorageHandlers = new ExternalStorageRegistry(); - private CellRegistry CellRegistry = new CellRegistry(); - private LocatableRegistry LocatableRegistry = new LocatableRegistry(); - private SpecialComparisonRegistry SpecialComparisonRegistry = new SpecialComparisonRegistry(); - private WirelessRegistry WirelessRegistry = new WirelessRegistry(); - private GridCacheRegistry GridCacheRegistry = new GridCacheRegistry(); - private P2PTunnelRegistry P2PRegistry = new P2PTunnelRegistry(); - private MovableTileRegistry MovableReg = new MovableTileRegistry(); - private MatterCannonAmmoRegistry matterCannonReg = new MatterCannonAmmoRegistry(); - private PlayerRegistry playerreg = new PlayerRegistry(); - private IRecipeHandlerRegistry recipeReg = new RecipeHandlerRegistry(); - - @Override - public IWirelessTermRegistry wireless() - { - return WirelessRegistry; - } - - @Override - public ICellRegistry cell() - { - return CellRegistry; - } - - @Override - public IGrinderRegistry grinder() - { - return GrinderRecipes; - } - - @Override - public ISpecialComparisonRegistry specialComparison() - { - return SpecialComparisonRegistry; - } - - @Override - public IExternalStorageRegistry externalStorage() - { - return ExternalStorageHandlers; - } - - @Override - public ILocatableRegistry locatable() - { - return LocatableRegistry; - } - - @Override - public IGridCacheRegistry gridCache() - { - return GridCacheRegistry; - } - - @Override - public IMovableRegistry movable() - { - return MovableReg; - } - - @Override - public IP2PTunnelRegistry p2pTunnel() - { - return P2PRegistry; - } - - @Override - public IMatterCannonAmmoRegistry matterCannon() - { - return matterCannonReg; - } - - @Override - public IPlayerRegistry players() - { - return playerreg; - } - - @Override - public IRecipeHandlerRegistry recipes() - { - return recipeReg; - } - - @Override - public IWorldGen worldgen() - { - return WorldGenRegistry.instance; - } - -} +package appeng.core.features.registries; + +import appeng.api.features.IGrinderRegistry; +import appeng.api.features.ILocatableRegistry; +import appeng.api.features.IMatterCannonAmmoRegistry; +import appeng.api.features.IP2PTunnelRegistry; +import appeng.api.features.IPlayerRegistry; +import appeng.api.features.IRecipeHandlerRegistry; +import appeng.api.features.IRegistryContainer; +import appeng.api.features.ISpecialComparisonRegistry; +import appeng.api.features.IWirelessTermRegistry; +import appeng.api.features.IWorldGen; +import appeng.api.movable.IMovableRegistry; +import appeng.api.networking.IGridCacheRegistry; +import appeng.api.storage.ICellRegistry; +import appeng.api.storage.IExternalStorageRegistry; + +public class RegistryContainer implements IRegistryContainer +{ + + private GrinderRecipeManager GrinderRecipes = new GrinderRecipeManager(); + private ExternalStorageRegistry ExternalStorageHandlers = new ExternalStorageRegistry(); + private CellRegistry CellRegistry = new CellRegistry(); + private LocatableRegistry LocatableRegistry = new LocatableRegistry(); + private SpecialComparisonRegistry SpecialComparisonRegistry = new SpecialComparisonRegistry(); + private WirelessRegistry WirelessRegistry = new WirelessRegistry(); + private GridCacheRegistry GridCacheRegistry = new GridCacheRegistry(); + private P2PTunnelRegistry P2PRegistry = new P2PTunnelRegistry(); + private MovableTileRegistry MovableReg = new MovableTileRegistry(); + private MatterCannonAmmoRegistry matterCannonReg = new MatterCannonAmmoRegistry(); + private PlayerRegistry playerreg = new PlayerRegistry(); + private IRecipeHandlerRegistry recipeReg = new RecipeHandlerRegistry(); + + @Override + public IWirelessTermRegistry wireless() + { + return WirelessRegistry; + } + + @Override + public ICellRegistry cell() + { + return CellRegistry; + } + + @Override + public IGrinderRegistry grinder() + { + return GrinderRecipes; + } + + @Override + public ISpecialComparisonRegistry specialComparison() + { + return SpecialComparisonRegistry; + } + + @Override + public IExternalStorageRegistry externalStorage() + { + return ExternalStorageHandlers; + } + + @Override + public ILocatableRegistry locatable() + { + return LocatableRegistry; + } + + @Override + public IGridCacheRegistry gridCache() + { + return GridCacheRegistry; + } + + @Override + public IMovableRegistry movable() + { + return MovableReg; + } + + @Override + public IP2PTunnelRegistry p2pTunnel() + { + return P2PRegistry; + } + + @Override + public IMatterCannonAmmoRegistry matterCannon() + { + return matterCannonReg; + } + + @Override + public IPlayerRegistry players() + { + return playerreg; + } + + @Override + public IRecipeHandlerRegistry recipes() + { + return recipeReg; + } + + @Override + public IWorldGen worldgen() + { + return WorldGenRegistry.instance; + } + +} diff --git a/core/features/registries/SpecialComparisonRegistry.java b/src/main/java/appeng/core/features/registries/SpecialComparisonRegistry.java similarity index 95% rename from core/features/registries/SpecialComparisonRegistry.java rename to src/main/java/appeng/core/features/registries/SpecialComparisonRegistry.java index 78a6c9cb8..8bc1cc17d 100644 --- a/core/features/registries/SpecialComparisonRegistry.java +++ b/src/main/java/appeng/core/features/registries/SpecialComparisonRegistry.java @@ -1,41 +1,41 @@ -package appeng.core.features.registries; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.item.ItemStack; -import appeng.api.features.IItemComparisonProvider; -import appeng.api.features.IItemComparison; -import appeng.api.features.ISpecialComparisonRegistry; - -public class SpecialComparisonRegistry implements ISpecialComparisonRegistry -{ - - private List CompRegistry; - - public SpecialComparisonRegistry() { - CompRegistry = new ArrayList(); - } - - @Override - public IItemComparison getSpecialComparison(ItemStack stack) - { - for (IItemComparisonProvider i : CompRegistry) - { - IItemComparison comp = i.getComparison( stack ); - if ( comp != null ) - { - return comp; - } - } - - return null; - } - - @Override - public void addComparisonProvider(IItemComparisonProvider prov) - { - CompRegistry.add( prov ); - } - -} +package appeng.core.features.registries; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import appeng.api.features.IItemComparisonProvider; +import appeng.api.features.IItemComparison; +import appeng.api.features.ISpecialComparisonRegistry; + +public class SpecialComparisonRegistry implements ISpecialComparisonRegistry +{ + + private List CompRegistry; + + public SpecialComparisonRegistry() { + CompRegistry = new ArrayList(); + } + + @Override + public IItemComparison getSpecialComparison(ItemStack stack) + { + for (IItemComparisonProvider i : CompRegistry) + { + IItemComparison comp = i.getComparison( stack ); + if ( comp != null ) + { + return comp; + } + } + + return null; + } + + @Override + public void addComparisonProvider(IItemComparisonProvider prov) + { + CompRegistry.add( prov ); + } + +} diff --git a/core/features/registries/WirelessRangeResult.java b/src/main/java/appeng/core/features/registries/WirelessRangeResult.java similarity index 94% rename from core/features/registries/WirelessRangeResult.java rename to src/main/java/appeng/core/features/registries/WirelessRangeResult.java index 0a2626c99..3cfa4a96a 100644 --- a/core/features/registries/WirelessRangeResult.java +++ b/src/main/java/appeng/core/features/registries/WirelessRangeResult.java @@ -1,16 +1,16 @@ -package appeng.core.features.registries; - -import net.minecraft.tileentity.TileEntity; - -public class WirelessRangeResult -{ - - public WirelessRangeResult(TileEntity t, float d) { - dist = d; - te = t; - } - - final public float dist; - final public TileEntity te; - -} +package appeng.core.features.registries; + +import net.minecraft.tileentity.TileEntity; + +public class WirelessRangeResult +{ + + public WirelessRangeResult(TileEntity t, float d) { + dist = d; + te = t; + } + + final public float dist; + final public TileEntity te; + +} diff --git a/core/features/registries/WirelessRegistry.java b/src/main/java/appeng/core/features/registries/WirelessRegistry.java similarity index 95% rename from core/features/registries/WirelessRegistry.java rename to src/main/java/appeng/core/features/registries/WirelessRegistry.java index b6a6b6556..ff8af8790 100644 --- a/core/features/registries/WirelessRegistry.java +++ b/src/main/java/appeng/core/features/registries/WirelessRegistry.java @@ -1,76 +1,76 @@ -package appeng.core.features.registries; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentText; -import net.minecraft.world.World; -import appeng.api.features.IWirelessTermHandler; -import appeng.api.features.IWirelessTermRegistry; -import appeng.core.localization.PlayerMessages; -import appeng.core.sync.GuiBridge; -import appeng.util.Platform; - -public class WirelessRegistry implements IWirelessTermRegistry -{ - - List handlers; - - public WirelessRegistry() { - handlers = new ArrayList(); - } - - @Override - public void registerWirelessHandler(IWirelessTermHandler handler) - { - if ( handler != null ) - handlers.add( handler ); - } - - @Override - public boolean isWirelessTerminal(ItemStack is) - { - for (IWirelessTermHandler h : handlers) - { - if ( h.canHandle( is ) ) - return true; - } - return false; - } - - @Override - public IWirelessTermHandler getWirelessTerminalHandler(ItemStack is) - { - for (IWirelessTermHandler h : handlers) - { - if ( h.canHandle( is ) ) - return h; - } - return null; - } - - @Override - public void openWirelessTerminalGui(ItemStack item, World w, EntityPlayer player) - { - if ( Platform.isClient() ) - return; - - IWirelessTermHandler handler = getWirelessTerminalHandler( item ); - if ( handler == null ) - { - player.addChatMessage( new ChatComponentText( "Item is not a wireless terminal." ) ); - return; - } - - if ( handler.hasPower( player, 0.5, item ) ) - { - Platform.openGUI( player, null, null, GuiBridge.GUI_WIRELESS_TERM ); - } - else - player.addChatMessage( PlayerMessages.DeviceNotPowered.get() ); - - } - -} +package appeng.core.features.registries; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.features.IWirelessTermRegistry; +import appeng.core.localization.PlayerMessages; +import appeng.core.sync.GuiBridge; +import appeng.util.Platform; + +public class WirelessRegistry implements IWirelessTermRegistry +{ + + List handlers; + + public WirelessRegistry() { + handlers = new ArrayList(); + } + + @Override + public void registerWirelessHandler(IWirelessTermHandler handler) + { + if ( handler != null ) + handlers.add( handler ); + } + + @Override + public boolean isWirelessTerminal(ItemStack is) + { + for (IWirelessTermHandler h : handlers) + { + if ( h.canHandle( is ) ) + return true; + } + return false; + } + + @Override + public IWirelessTermHandler getWirelessTerminalHandler(ItemStack is) + { + for (IWirelessTermHandler h : handlers) + { + if ( h.canHandle( is ) ) + return h; + } + return null; + } + + @Override + public void openWirelessTerminalGui(ItemStack item, World w, EntityPlayer player) + { + if ( Platform.isClient() ) + return; + + IWirelessTermHandler handler = getWirelessTerminalHandler( item ); + if ( handler == null ) + { + player.addChatMessage( new ChatComponentText( "Item is not a wireless terminal." ) ); + return; + } + + if ( handler.hasPower( player, 0.5, item ) ) + { + Platform.openGUI( player, null, null, GuiBridge.GUI_WIRELESS_TERM ); + } + else + player.addChatMessage( PlayerMessages.DeviceNotPowered.get() ); + + } + +} diff --git a/core/features/registries/WorldGenRegistry.java b/src/main/java/appeng/core/features/registries/WorldGenRegistry.java similarity index 100% rename from core/features/registries/WorldGenRegistry.java rename to src/main/java/appeng/core/features/registries/WorldGenRegistry.java diff --git a/core/features/registries/entries/AppEngGrinderRecipe.java b/src/main/java/appeng/core/features/registries/entries/AppEngGrinderRecipe.java similarity index 94% rename from core/features/registries/entries/AppEngGrinderRecipe.java rename to src/main/java/appeng/core/features/registries/entries/AppEngGrinderRecipe.java index ea8832a34..64bc5a149 100644 --- a/core/features/registries/entries/AppEngGrinderRecipe.java +++ b/src/main/java/appeng/core/features/registries/entries/AppEngGrinderRecipe.java @@ -1,123 +1,123 @@ -package appeng.core.features.registries.entries; - -import net.minecraft.item.ItemStack; -import appeng.api.features.IGrinderEntry; - -public class AppEngGrinderRecipe implements IGrinderEntry -{ - - private ItemStack in; - private ItemStack out; - - private float optionalChance; - private ItemStack optionalOutput; - - private float optionalChance2; - private ItemStack optionalOutput2; - - private int energy; - - public AppEngGrinderRecipe(ItemStack a, ItemStack b, int cost) { - in = a; - out = b; - energy = cost; - } - - public AppEngGrinderRecipe(ItemStack a, ItemStack b, ItemStack c, float chance, int cost) { - in = a; - out = b; - - optionalOutput = c; - optionalChance = chance; - - energy = cost; - } - - public AppEngGrinderRecipe(ItemStack a, ItemStack b, ItemStack c, ItemStack d, float chance, float chance2, int cost) { - in = a; - out = b; - - optionalOutput = c; - optionalChance = chance; - - optionalOutput2 = d; - optionalChance2 = chance2; - - energy = cost; - } - - @Override - public ItemStack getInput() - { - return in; - } - - @Override - public void setInput(ItemStack i) - { - in = i.copy(); - } - - @Override - public ItemStack getOutput() - { - return out; - } - - @Override - public void setOutput(ItemStack o) - { - out = o.copy(); - } - - @Override - public int getEnergyCost() - { - return energy; - } - - @Override - public void setEnergyCost(int c) - { - energy = c; - } - - @Override - public ItemStack getOptionalOutput() - { - return optionalOutput; - } - - @Override - public void setOptionalOutput(ItemStack output, float chance) - { - optionalOutput = output.copy(); - optionalChance = chance; - } - - @Override - public float getOptionalChance() - { - return optionalChance; - } - - @Override - public ItemStack getSecondOptionalOutput() - { - return optionalOutput2; - } - - @Override - public void setSecondOptionalOutput(ItemStack output, float chance) - { - optionalChance2 = chance; - optionalOutput2 = output.copy(); - } - - @Override - public float getSecondOptionalChance() - { - return optionalChance2; - } - -} +package appeng.core.features.registries.entries; + +import net.minecraft.item.ItemStack; +import appeng.api.features.IGrinderEntry; + +public class AppEngGrinderRecipe implements IGrinderEntry +{ + + private ItemStack in; + private ItemStack out; + + private float optionalChance; + private ItemStack optionalOutput; + + private float optionalChance2; + private ItemStack optionalOutput2; + + private int energy; + + public AppEngGrinderRecipe(ItemStack a, ItemStack b, int cost) { + in = a; + out = b; + energy = cost; + } + + public AppEngGrinderRecipe(ItemStack a, ItemStack b, ItemStack c, float chance, int cost) { + in = a; + out = b; + + optionalOutput = c; + optionalChance = chance; + + energy = cost; + } + + public AppEngGrinderRecipe(ItemStack a, ItemStack b, ItemStack c, ItemStack d, float chance, float chance2, int cost) { + in = a; + out = b; + + optionalOutput = c; + optionalChance = chance; + + optionalOutput2 = d; + optionalChance2 = chance2; + + energy = cost; + } + + @Override + public ItemStack getInput() + { + return in; + } + + @Override + public void setInput(ItemStack i) + { + in = i.copy(); + } + + @Override + public ItemStack getOutput() + { + return out; + } + + @Override + public void setOutput(ItemStack o) + { + out = o.copy(); + } + + @Override + public int getEnergyCost() + { + return energy; + } + + @Override + public void setEnergyCost(int c) + { + energy = c; + } + + @Override + public ItemStack getOptionalOutput() + { + return optionalOutput; + } + + @Override + public void setOptionalOutput(ItemStack output, float chance) + { + optionalOutput = output.copy(); + optionalChance = chance; + } + + @Override + public float getOptionalChance() + { + return optionalChance; + } + + @Override + public ItemStack getSecondOptionalOutput() + { + return optionalOutput2; + } + + @Override + public void setSecondOptionalOutput(ItemStack output, float chance) + { + optionalChance2 = chance; + optionalOutput2 = output.copy(); + } + + @Override + public float getSecondOptionalChance() + { + return optionalChance2; + } + +} diff --git a/core/features/registries/entries/BasicCellHandler.java b/src/main/java/appeng/core/features/registries/entries/BasicCellHandler.java similarity index 96% rename from core/features/registries/entries/BasicCellHandler.java rename to src/main/java/appeng/core/features/registries/entries/BasicCellHandler.java index a8bb8df3a..04c56442a 100644 --- a/core/features/registries/entries/BasicCellHandler.java +++ b/src/main/java/appeng/core/features/registries/entries/BasicCellHandler.java @@ -1,79 +1,79 @@ -package appeng.core.features.registries.entries; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import appeng.api.implementations.tiles.IChestOrDrive; -import appeng.api.storage.ICellHandler; -import appeng.api.storage.ICellInventory; -import appeng.api.storage.ICellInventoryHandler; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.ISaveProvider; -import appeng.api.storage.StorageChannel; -import appeng.client.texture.ExtraBlockTextures; -import appeng.core.sync.GuiBridge; -import appeng.me.storage.CellInventory; -import appeng.me.storage.CellInventoryHandler; -import appeng.tile.AEBaseTile; -import appeng.util.Platform; - -public class BasicCellHandler implements ICellHandler -{ - - @Override - public boolean isCell(ItemStack is) - { - return CellInventory.isCell( is ); - } - - @Override - public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel channel) - { - if ( channel == StorageChannel.ITEMS ) - return CellInventory.getCell( is, container ); - return null; - } - - @Override - public IIcon getTopTexture_Dark() - { - return ExtraBlockTextures.BlockMEChestItems_Dark.getIcon(); - } - - @Override - public IIcon getTopTexture_Light() - { - return ExtraBlockTextures.BlockMEChestItems_Light.getIcon(); - } - - @Override - public IIcon getTopTexture_Medium() - { - return ExtraBlockTextures.BlockMEChestItems_Medium.getIcon(); - } - - @Override - public void openChestGui(EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler inv, ItemStack is, StorageChannel chan) - { - Platform.openGUI( player, (AEBaseTile) chest, chest.getUp(), GuiBridge.GUI_ME ); - } - - @Override - public int getStatusForCell(ItemStack is, IMEInventory handler) - { - if ( handler instanceof CellInventoryHandler ) - { - CellInventoryHandler ci = (CellInventoryHandler) handler; - return ci.getStatusForCell(); - } - return 0; - } - - @Override - public double cellIdleDrain(ItemStack is, IMEInventory handler) - { - ICellInventory inv = ((ICellInventoryHandler) handler).getCellInv(); - return inv.getIdleDrain(); - } -} +package appeng.core.features.registries.entries; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import appeng.api.implementations.tiles.IChestOrDrive; +import appeng.api.storage.ICellHandler; +import appeng.api.storage.ICellInventory; +import appeng.api.storage.ICellInventoryHandler; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.ISaveProvider; +import appeng.api.storage.StorageChannel; +import appeng.client.texture.ExtraBlockTextures; +import appeng.core.sync.GuiBridge; +import appeng.me.storage.CellInventory; +import appeng.me.storage.CellInventoryHandler; +import appeng.tile.AEBaseTile; +import appeng.util.Platform; + +public class BasicCellHandler implements ICellHandler +{ + + @Override + public boolean isCell(ItemStack is) + { + return CellInventory.isCell( is ); + } + + @Override + public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel channel) + { + if ( channel == StorageChannel.ITEMS ) + return CellInventory.getCell( is, container ); + return null; + } + + @Override + public IIcon getTopTexture_Dark() + { + return ExtraBlockTextures.BlockMEChestItems_Dark.getIcon(); + } + + @Override + public IIcon getTopTexture_Light() + { + return ExtraBlockTextures.BlockMEChestItems_Light.getIcon(); + } + + @Override + public IIcon getTopTexture_Medium() + { + return ExtraBlockTextures.BlockMEChestItems_Medium.getIcon(); + } + + @Override + public void openChestGui(EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler inv, ItemStack is, StorageChannel chan) + { + Platform.openGUI( player, (AEBaseTile) chest, chest.getUp(), GuiBridge.GUI_ME ); + } + + @Override + public int getStatusForCell(ItemStack is, IMEInventory handler) + { + if ( handler instanceof CellInventoryHandler ) + { + CellInventoryHandler ci = (CellInventoryHandler) handler; + return ci.getStatusForCell(); + } + return 0; + } + + @Override + public double cellIdleDrain(ItemStack is, IMEInventory handler) + { + ICellInventory inv = ((ICellInventoryHandler) handler).getCellInv(); + return inv.getIdleDrain(); + } +} diff --git a/core/features/registries/entries/CreativeCellHandler.java b/src/main/java/appeng/core/features/registries/entries/CreativeCellHandler.java similarity index 96% rename from core/features/registries/entries/CreativeCellHandler.java rename to src/main/java/appeng/core/features/registries/entries/CreativeCellHandler.java index fb497d978..c114637ec 100644 --- a/core/features/registries/entries/CreativeCellHandler.java +++ b/src/main/java/appeng/core/features/registries/entries/CreativeCellHandler.java @@ -1,72 +1,72 @@ -package appeng.core.features.registries.entries; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import appeng.api.implementations.tiles.IChestOrDrive; -import appeng.api.storage.ICellHandler; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.ISaveProvider; -import appeng.api.storage.StorageChannel; -import appeng.client.texture.ExtraBlockTextures; -import appeng.core.sync.GuiBridge; -import appeng.items.storage.ItemCreativeStorageCell; -import appeng.me.storage.CreativeCellInventory; -import appeng.tile.AEBaseTile; -import appeng.util.Platform; - -public class CreativeCellHandler implements ICellHandler -{ - - @Override - public boolean isCell(ItemStack is) - { - return is != null && is.getItem() instanceof ItemCreativeStorageCell; - } - - @Override - public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel channel) - { - if ( channel == StorageChannel.ITEMS && is != null && is.getItem() instanceof ItemCreativeStorageCell ) - return CreativeCellInventory.getCell( is ); - return null; - } - - @Override - public void openChestGui(EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler inv, ItemStack is, StorageChannel chan) - { - Platform.openGUI( player, (AEBaseTile) chest, chest.getUp(), GuiBridge.GUI_ME ); - } - - @Override - public int getStatusForCell(ItemStack is, IMEInventory handler) - { - return 2; - } - - @Override - public double cellIdleDrain(ItemStack is, IMEInventory handler) - { - return 0; - } - - @Override - public IIcon getTopTexture_Light() - { - return ExtraBlockTextures.BlockMEChestItems_Light.getIcon(); - } - - @Override - public IIcon getTopTexture_Medium() - { - return ExtraBlockTextures.BlockMEChestItems_Medium.getIcon(); - } - - @Override - public IIcon getTopTexture_Dark() - { - return ExtraBlockTextures.BlockMEChestItems_Dark.getIcon(); - } - -} +package appeng.core.features.registries.entries; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import appeng.api.implementations.tiles.IChestOrDrive; +import appeng.api.storage.ICellHandler; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.ISaveProvider; +import appeng.api.storage.StorageChannel; +import appeng.client.texture.ExtraBlockTextures; +import appeng.core.sync.GuiBridge; +import appeng.items.storage.ItemCreativeStorageCell; +import appeng.me.storage.CreativeCellInventory; +import appeng.tile.AEBaseTile; +import appeng.util.Platform; + +public class CreativeCellHandler implements ICellHandler +{ + + @Override + public boolean isCell(ItemStack is) + { + return is != null && is.getItem() instanceof ItemCreativeStorageCell; + } + + @Override + public IMEInventoryHandler getCellInventory(ItemStack is, ISaveProvider container, StorageChannel channel) + { + if ( channel == StorageChannel.ITEMS && is != null && is.getItem() instanceof ItemCreativeStorageCell ) + return CreativeCellInventory.getCell( is ); + return null; + } + + @Override + public void openChestGui(EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler inv, ItemStack is, StorageChannel chan) + { + Platform.openGUI( player, (AEBaseTile) chest, chest.getUp(), GuiBridge.GUI_ME ); + } + + @Override + public int getStatusForCell(ItemStack is, IMEInventory handler) + { + return 2; + } + + @Override + public double cellIdleDrain(ItemStack is, IMEInventory handler) + { + return 0; + } + + @Override + public IIcon getTopTexture_Light() + { + return ExtraBlockTextures.BlockMEChestItems_Light.getIcon(); + } + + @Override + public IIcon getTopTexture_Medium() + { + return ExtraBlockTextures.BlockMEChestItems_Medium.getIcon(); + } + + @Override + public IIcon getTopTexture_Dark() + { + return ExtraBlockTextures.BlockMEChestItems_Dark.getIcon(); + } + +} diff --git a/core/features/registries/entries/ExternalIInv.java b/src/main/java/appeng/core/features/registries/entries/ExternalIInv.java similarity index 100% rename from core/features/registries/entries/ExternalIInv.java rename to src/main/java/appeng/core/features/registries/entries/ExternalIInv.java diff --git a/core/localization/ButtonToolTips.java b/src/main/java/appeng/core/localization/ButtonToolTips.java similarity index 96% rename from core/localization/ButtonToolTips.java rename to src/main/java/appeng/core/localization/ButtonToolTips.java index 16f149254..91acb1242 100644 --- a/core/localization/ButtonToolTips.java +++ b/src/main/java/appeng/core/localization/ButtonToolTips.java @@ -1,61 +1,61 @@ -package appeng.core.localization; - -import net.minecraft.util.StatCollector; - -public enum ButtonToolTips -{ - PowerUnits, IOMode, CondenserOutput, RedstoneMode, MatchingFuzzy, - - MatchingMode, TransferDirection, SortOrder, SortBy, View, - - PartitionStorage, Clear, FuzzyMode, OperationMode, TrashController, - - InterfaceBlockingMode, InterfaceCraftingMode, Trash, MatterBalls, - - Singularity, Read, Write, ReadWrite, AlwaysActive, - - ActiveWithoutSignal, ActiveWithSignal, ActiveOnPulse, - - EmitLevelsBelow, EmitLevelAbove, MatchingExact, TransferToNetwork, - - TransferToStorageCell, ToggleSortDirection, SearchMode_Auto, - - SearchMode_Standard, SearchMode_NEIAuto, SearchMode_NEIStandard, - - SearchMode, ItemName, NumberOfItems, PartitionStorageHint, - - ClearSettings, StoredItems, StoredCraftable, Craftable, - - FZPercent_25, FZPercent_50, FZPercent_75, FZPercent_99, FZIgnoreAll, - - MoveWhenEmpty, MoveWhenWorkIsDone, MoveWhenFull, Disabled, Enable, - - Blocking, NonBlocking, - - LevelType, LevelType_Energy, LevelType_Item, InventoryTweaks, TerminalStyle, TerminalStyle_Full, TerminalStyle_Tall, TerminalStyle_Small, - - Stash, StashDesc, Encode, EncodeDescription, Substitutions, SubstitutionsOn, SubstitutionsOff, SubstitutionsDesc, CraftOnly, CraftEither, - - Craft, Mod, DoesntDespawn, EmitterMode, CraftViaRedstone, EmitWhenCrafting, ReportInaccessibleItems, ReportInaccessibleItemsYes, ReportInaccessibleItemsNo; - - String root; - - ButtonToolTips() { - root = "gui.tooltips.appliedenergistics2"; - } - - ButtonToolTips(String r) { - root = r; - } - - public String getUnlocalized() - { - return root + "." + toString(); - } - - public String getLocal() - { - return StatCollector.translateToLocal( getUnlocalized() ); - } - -} +package appeng.core.localization; + +import net.minecraft.util.StatCollector; + +public enum ButtonToolTips +{ + PowerUnits, IOMode, CondenserOutput, RedstoneMode, MatchingFuzzy, + + MatchingMode, TransferDirection, SortOrder, SortBy, View, + + PartitionStorage, Clear, FuzzyMode, OperationMode, TrashController, + + InterfaceBlockingMode, InterfaceCraftingMode, Trash, MatterBalls, + + Singularity, Read, Write, ReadWrite, AlwaysActive, + + ActiveWithoutSignal, ActiveWithSignal, ActiveOnPulse, + + EmitLevelsBelow, EmitLevelAbove, MatchingExact, TransferToNetwork, + + TransferToStorageCell, ToggleSortDirection, SearchMode_Auto, + + SearchMode_Standard, SearchMode_NEIAuto, SearchMode_NEIStandard, + + SearchMode, ItemName, NumberOfItems, PartitionStorageHint, + + ClearSettings, StoredItems, StoredCraftable, Craftable, + + FZPercent_25, FZPercent_50, FZPercent_75, FZPercent_99, FZIgnoreAll, + + MoveWhenEmpty, MoveWhenWorkIsDone, MoveWhenFull, Disabled, Enable, + + Blocking, NonBlocking, + + LevelType, LevelType_Energy, LevelType_Item, InventoryTweaks, TerminalStyle, TerminalStyle_Full, TerminalStyle_Tall, TerminalStyle_Small, + + Stash, StashDesc, Encode, EncodeDescription, Substitutions, SubstitutionsOn, SubstitutionsOff, SubstitutionsDesc, CraftOnly, CraftEither, + + Craft, Mod, DoesntDespawn, EmitterMode, CraftViaRedstone, EmitWhenCrafting, ReportInaccessibleItems, ReportInaccessibleItemsYes, ReportInaccessibleItemsNo; + + String root; + + ButtonToolTips() { + root = "gui.tooltips.appliedenergistics2"; + } + + ButtonToolTips(String r) { + root = r; + } + + public String getUnlocalized() + { + return root + "." + toString(); + } + + public String getLocal() + { + return StatCollector.translateToLocal( getUnlocalized() ); + } + +} diff --git a/core/localization/GuiText.java b/src/main/java/appeng/core/localization/GuiText.java similarity index 96% rename from core/localization/GuiText.java rename to src/main/java/appeng/core/localization/GuiText.java index 51879ecad..f0d183312 100644 --- a/core/localization/GuiText.java +++ b/src/main/java/appeng/core/localization/GuiText.java @@ -1,75 +1,75 @@ -package appeng.core.localization; - -import net.minecraft.util.StatCollector; - -public enum GuiText -{ - inventory("container"), // mc's default Inventory localization. - - Chest, StoredEnergy, Of, Condenser, Drive, GrindStone, SkyChest, - - VibrationChamber, SpatialIOPort, LevelEmitter, Terminal, - - Interface, Config, StoredItems, Patterns, ImportBus, ExportBus, - - CellWorkbench, NetworkDetails, StorageCells, IOBuses, - - IOPort, BytesUsed, Types, QuantumLinkChamber, PortableCell, - - NetworkTool, PowerUsageRate, PowerInputRate, Installed, EnergyDrain, - - StorageBus, Priority, Security, Encoded, Blank, Unlinked, Linked, - - SecurityCardEditor, NoPermissions, WirelessTerminal, Wireless, - - CraftingTerminal, FormationPlane, Inscriber, QuartzCuttingKnife, - - METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel, - - StoredSize, CopyMode, CopyModeDesc, PatternTerminal, CraftingPattern, - - ProcessingPattern, Crafts, Creates, And, With, MolecularAssembler, - - StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, - - inWorldFluix, inWorldPurificationCertus, inWorldPurificationNether, - - inWorldPurificationFluix, inWorldSingularity, ChargedQuartz, OfSecondOutput, - - NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, - - ConfirmCrafting, Stored, Crafting, Scheduled, CraftingStatus, Cancel, - - FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, - - CraftingCPU, Automatic, CoProcessors, Simulation, Missing, - - InterfaceTerminal, NoCraftingCPUs, LightTunnel, Clean, InvalidPattern, - - InterfaceTerminalHint, Range, TransparentFacades, TransparentFacadesHint, - - NoCraftingJobs, CPUs, FacadeCrafting, inWorldCraftingPresses, ChargedQuartzFind, - - Included, Excluded, Partitioned, Precise, Fuzzy; - - String root; - - GuiText() { - root = "gui.appliedenergistics2"; - } - - GuiText(String r) { - root = r; - } - - public String getUnlocalized() - { - return root + "." + toString(); - } - - public String getLocal() - { - return StatCollector.translateToLocal( getUnlocalized() ); - } - -} +package appeng.core.localization; + +import net.minecraft.util.StatCollector; + +public enum GuiText +{ + inventory("container"), // mc's default Inventory localization. + + Chest, StoredEnergy, Of, Condenser, Drive, GrindStone, SkyChest, + + VibrationChamber, SpatialIOPort, LevelEmitter, Terminal, + + Interface, Config, StoredItems, Patterns, ImportBus, ExportBus, + + CellWorkbench, NetworkDetails, StorageCells, IOBuses, + + IOPort, BytesUsed, Types, QuantumLinkChamber, PortableCell, + + NetworkTool, PowerUsageRate, PowerInputRate, Installed, EnergyDrain, + + StorageBus, Priority, Security, Encoded, Blank, Unlinked, Linked, + + SecurityCardEditor, NoPermissions, WirelessTerminal, Wireless, + + CraftingTerminal, FormationPlane, Inscriber, QuartzCuttingKnife, + + METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel, + + StoredSize, CopyMode, CopyModeDesc, PatternTerminal, CraftingPattern, + + ProcessingPattern, Crafts, Creates, And, With, MolecularAssembler, + + StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, + + inWorldFluix, inWorldPurificationCertus, inWorldPurificationNether, + + inWorldPurificationFluix, inWorldSingularity, ChargedQuartz, OfSecondOutput, + + NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, + + ConfirmCrafting, Stored, Crafting, Scheduled, CraftingStatus, Cancel, + + FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, + + CraftingCPU, Automatic, CoProcessors, Simulation, Missing, + + InterfaceTerminal, NoCraftingCPUs, LightTunnel, Clean, InvalidPattern, + + InterfaceTerminalHint, Range, TransparentFacades, TransparentFacadesHint, + + NoCraftingJobs, CPUs, FacadeCrafting, inWorldCraftingPresses, ChargedQuartzFind, + + Included, Excluded, Partitioned, Precise, Fuzzy; + + String root; + + GuiText() { + root = "gui.appliedenergistics2"; + } + + GuiText(String r) { + root = r; + } + + public String getUnlocalized() + { + return root + "." + toString(); + } + + public String getLocal() + { + return StatCollector.translateToLocal( getUnlocalized() ); + } + +} diff --git a/core/localization/PlayerMessages.java b/src/main/java/appeng/core/localization/PlayerMessages.java similarity index 96% rename from core/localization/PlayerMessages.java rename to src/main/java/appeng/core/localization/PlayerMessages.java index 64424fba8..22248746c 100644 --- a/core/localization/PlayerMessages.java +++ b/src/main/java/appeng/core/localization/PlayerMessages.java @@ -1,22 +1,22 @@ -package appeng.core.localization; - -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.IChatComponent; - -public enum PlayerMessages -{ - ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered, - - isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered, SettingCleared; - - String getName() - { - return "chat.appliedenergistics2." + toString(); - } - - public IChatComponent get() - { - return new ChatComponentTranslation( getName() ); - } - -} +package appeng.core.localization; + +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.IChatComponent; + +public enum PlayerMessages +{ + ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered, + + isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered, SettingCleared; + + String getName() + { + return "chat.appliedenergistics2." + toString(); + } + + public IChatComponent get() + { + return new ChatComponentTranslation( getName() ); + } + +} diff --git a/core/localization/WailaText.java b/src/main/java/appeng/core/localization/WailaText.java similarity index 100% rename from core/localization/WailaText.java rename to src/main/java/appeng/core/localization/WailaText.java diff --git a/core/settings/TickRates.java b/src/main/java/appeng/core/settings/TickRates.java similarity index 94% rename from core/settings/TickRates.java rename to src/main/java/appeng/core/settings/TickRates.java index cec48ba9b..a180b8d14 100644 --- a/core/settings/TickRates.java +++ b/src/main/java/appeng/core/settings/TickRates.java @@ -1,49 +1,49 @@ -package appeng.core.settings; - -import appeng.core.AEConfig; - -public enum TickRates -{ - - Interface(5, 120), - - ImportBus(5, 40), - - ExportBus(5, 60), - - AnnihilationPlane(2, 120), - - MJTunnel(1, 20), - - METunnel(5, 20), - - Inscriber(1, 1), - - IOPort(1, 5), - - VibrationChamber(10, 40), - - StorageBus(5, 60), - - ItemTunnel(5, 60), - - LightTunnel(5, 120); - - public int min; - public int max; - - private TickRates(int min, int max) { - this.min = min; - this.max = max; - } - - public void Load(AEConfig config) - { - config.addCustomCategoryComment( - "TickRates", - " Min / Max Tickrates for dynamic ticking, most of these components also use sleeping, to prevent constant ticking, adjust with care, non standard rates are not supported or tested." ); - min = config.get( "TickRates", name() + ".min", min ).getInt( min ); - max = config.get( "TickRates", name() + ".max", max ).getInt( max ); - } - -} +package appeng.core.settings; + +import appeng.core.AEConfig; + +public enum TickRates +{ + + Interface(5, 120), + + ImportBus(5, 40), + + ExportBus(5, 60), + + AnnihilationPlane(2, 120), + + MJTunnel(1, 20), + + METunnel(5, 20), + + Inscriber(1, 1), + + IOPort(1, 5), + + VibrationChamber(10, 40), + + StorageBus(5, 60), + + ItemTunnel(5, 60), + + LightTunnel(5, 120); + + public int min; + public int max; + + private TickRates(int min, int max) { + this.min = min; + this.max = max; + } + + public void Load(AEConfig config) + { + config.addCustomCategoryComment( + "TickRates", + " Min / Max Tickrates for dynamic ticking, most of these components also use sleeping, to prevent constant ticking, adjust with care, non standard rates are not supported or tested." ); + min = config.get( "TickRates", name() + ".min", min ).getInt( min ); + max = config.get( "TickRates", name() + ".max", max ).getInt( max ); + } + +} diff --git a/core/stats/AchievementType.java b/src/main/java/appeng/core/stats/AchievementType.java similarity index 100% rename from core/stats/AchievementType.java rename to src/main/java/appeng/core/stats/AchievementType.java diff --git a/core/stats/Achievements.java b/src/main/java/appeng/core/stats/Achievements.java similarity index 100% rename from core/stats/Achievements.java rename to src/main/java/appeng/core/stats/Achievements.java diff --git a/core/stats/PlayerStatsRegistration.java b/src/main/java/appeng/core/stats/PlayerStatsRegistration.java similarity index 100% rename from core/stats/PlayerStatsRegistration.java rename to src/main/java/appeng/core/stats/PlayerStatsRegistration.java diff --git a/core/stats/Stats.java b/src/main/java/appeng/core/stats/Stats.java similarity index 100% rename from core/stats/Stats.java rename to src/main/java/appeng/core/stats/Stats.java diff --git a/core/sync/AppEngPacket.java b/src/main/java/appeng/core/sync/AppEngPacket.java similarity index 100% rename from core/sync/AppEngPacket.java rename to src/main/java/appeng/core/sync/AppEngPacket.java diff --git a/core/sync/AppEngPacketHandlerBase.java b/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java similarity index 100% rename from core/sync/AppEngPacketHandlerBase.java rename to src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java diff --git a/core/sync/GuiBridge.java b/src/main/java/appeng/core/sync/GuiBridge.java similarity index 97% rename from core/sync/GuiBridge.java rename to src/main/java/appeng/core/sync/GuiBridge.java index 24697d6c6..041e5b737 100644 --- a/core/sync/GuiBridge.java +++ b/src/main/java/appeng/core/sync/GuiBridge.java @@ -1,497 +1,497 @@ -package appeng.core.sync; - -import static appeng.core.sync.GuiHostType.ITEM; -import static appeng.core.sync.GuiHostType.ITEM_OR_WORLD; -import static appeng.core.sync.GuiHostType.WORLD; - -import java.lang.reflect.Constructor; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.config.SecurityPermissions; -import appeng.api.definitions.Materials; -import appeng.api.exceptions.AppEngException; -import appeng.api.features.IWirelessTermHandler; -import appeng.api.implementations.IUpgradeableHost; -import appeng.api.implementations.guiobjects.IGuiItem; -import appeng.api.implementations.guiobjects.INetworkTool; -import appeng.api.implementations.guiobjects.IPortableCell; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.security.IActionHost; -import appeng.api.networking.security.ISecurityGrid; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartHost; -import appeng.api.storage.ITerminalHost; -import appeng.api.util.DimensionalCoord; -import appeng.client.gui.GuiNull; -import appeng.container.AEBaseContainer; -import appeng.container.ContainerNull; -import appeng.container.ContainerOpenContext; -import appeng.container.implementations.ContainerCellWorkbench; -import appeng.container.implementations.ContainerChest; -import appeng.container.implementations.ContainerCondenser; -import appeng.container.implementations.ContainerCraftAmount; -import appeng.container.implementations.ContainerCraftConfirm; -import appeng.container.implementations.ContainerCraftingCPU; -import appeng.container.implementations.ContainerCraftingStatus; -import appeng.container.implementations.ContainerCraftingTerm; -import appeng.container.implementations.ContainerDrive; -import appeng.container.implementations.ContainerFormationPlane; -import appeng.container.implementations.ContainerGrinder; -import appeng.container.implementations.ContainerIOPort; -import appeng.container.implementations.ContainerInscriber; -import appeng.container.implementations.ContainerInterface; -import appeng.container.implementations.ContainerInterfaceTerminal; -import appeng.container.implementations.ContainerLevelEmitter; -import appeng.container.implementations.ContainerMAC; -import appeng.container.implementations.ContainerMEMonitorable; -import appeng.container.implementations.ContainerMEPortableCell; -import appeng.container.implementations.ContainerNetworkStatus; -import appeng.container.implementations.ContainerNetworkTool; -import appeng.container.implementations.ContainerPatternTerm; -import appeng.container.implementations.ContainerPriority; -import appeng.container.implementations.ContainerQNB; -import appeng.container.implementations.ContainerQuartzKnife; -import appeng.container.implementations.ContainerSecurity; -import appeng.container.implementations.ContainerSkyChest; -import appeng.container.implementations.ContainerSpatialIOPort; -import appeng.container.implementations.ContainerStorageBus; -import appeng.container.implementations.ContainerUpgradeable; -import appeng.container.implementations.ContainerVibrationChamber; -import appeng.container.implementations.ContainerWireless; -import appeng.container.implementations.ContainerWirelessTerm; -import appeng.core.stats.Achievements; -import appeng.helpers.IInterfaceHost; -import appeng.helpers.IPriorityHost; -import appeng.helpers.WirelessTerminalGuiObject; -import appeng.items.contents.QuartzKnifeObj; -import appeng.parts.automation.PartFormationPlane; -import appeng.parts.automation.PartLevelEmitter; -import appeng.parts.misc.PartStorageBus; -import appeng.parts.reporting.PartCraftingTerminal; -import appeng.parts.reporting.PartMonitor; -import appeng.parts.reporting.PartPatternTerminal; -import appeng.tile.crafting.TileCraftingTile; -import appeng.tile.crafting.TileMolecularAssembler; -import appeng.tile.grindstone.TileGrinder; -import appeng.tile.misc.TileCellWorkbench; -import appeng.tile.misc.TileCondenser; -import appeng.tile.misc.TileInscriber; -import appeng.tile.misc.TileSecurity; -import appeng.tile.misc.TileVibrationChamber; -import appeng.tile.networking.TileWireless; -import appeng.tile.qnb.TileQuantumBridge; -import appeng.tile.spatial.TileSpatialIOPort; -import appeng.tile.storage.TileChest; -import appeng.tile.storage.TileDrive; -import appeng.tile.storage.TileIOPort; -import appeng.tile.storage.TileSkyChest; -import appeng.util.Platform; -import cpw.mods.fml.common.network.IGuiHandler; -import cpw.mods.fml.relauncher.ReflectionHelper; - -public enum GuiBridge implements IGuiHandler -{ - GUI_Handler(), - - GUI_GRINDER(ContainerGrinder.class, TileGrinder.class, WORLD, null), - - GUI_QNB(ContainerQNB.class, TileQuantumBridge.class, WORLD, SecurityPermissions.BUILD), - - GUI_SKYCHEST(ContainerSkyChest.class, TileSkyChest.class, WORLD, null), - - GUI_CHEST(ContainerChest.class, TileChest.class, WORLD, SecurityPermissions.BUILD), - - GUI_WIRELESS(ContainerWireless.class, TileWireless.class, WORLD, SecurityPermissions.BUILD), - - GUI_ME(ContainerMEMonitorable.class, ITerminalHost.class, WORLD, null), - - GUI_PORTABLE_CELL(ContainerMEPortableCell.class, IPortableCell.class, ITEM, null), - - GUI_WIRELESS_TERM(ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, ITEM, null), - - GUI_NETWORK_STATUS(ContainerNetworkStatus.class, INetworkTool.class, ITEM, null), - - GUI_CRAFTING_CPU(ContainerCraftingCPU.class, TileCraftingTile.class, WORLD, SecurityPermissions.CRAFT), - - GUI_NETWORK_TOOL(ContainerNetworkTool.class, INetworkTool.class, ITEM, null), - - GUI_QUARTZ_KNIFE(ContainerQuartzKnife.class, QuartzKnifeObj.class, ITEM, null), - - GUI_DRIVE(ContainerDrive.class, TileDrive.class, WORLD, SecurityPermissions.BUILD), - - GUI_VIBRATIONCHAMBER(ContainerVibrationChamber.class, TileVibrationChamber.class, WORLD, null), - - GUI_CONDENSER(ContainerCondenser.class, TileCondenser.class, WORLD, null), - - GUI_INTERFACE(ContainerInterface.class, IInterfaceHost.class, WORLD, SecurityPermissions.BUILD), - - GUI_BUS(ContainerUpgradeable.class, IUpgradeableHost.class, WORLD, SecurityPermissions.BUILD), - - GUI_IOPORT(ContainerIOPort.class, TileIOPort.class, WORLD, SecurityPermissions.BUILD), - - GUI_STORAGEBUS(ContainerStorageBus.class, PartStorageBus.class, WORLD, SecurityPermissions.BUILD), - - GUI_FPLANE(ContainerFormationPlane.class, PartFormationPlane.class, WORLD, SecurityPermissions.BUILD), - - GUI_PRIORITY(ContainerPriority.class, IPriorityHost.class, WORLD, SecurityPermissions.BUILD), - - GUI_SECURITY(ContainerSecurity.class, TileSecurity.class, WORLD, SecurityPermissions.SECURITY), - - GUI_CRAFTING_TERMINAL(ContainerCraftingTerm.class, PartCraftingTerminal.class, WORLD, SecurityPermissions.CRAFT), - - GUI_PATTERN_TERMINAL(ContainerPatternTerm.class, PartPatternTerminal.class, WORLD, SecurityPermissions.CRAFT), - - // extends (Container/Gui) + Bus - GUI_LEVELEMITTER(ContainerLevelEmitter.class, PartLevelEmitter.class, WORLD, SecurityPermissions.BUILD), - - GUI_SPATIALIOPORT(ContainerSpatialIOPort.class, TileSpatialIOPort.class, WORLD, SecurityPermissions.BUILD), - - GUI_INSCRIBER(ContainerInscriber.class, TileInscriber.class, WORLD, null), - - GUI_CELLWORKBENCH(ContainerCellWorkbench.class, TileCellWorkbench.class, WORLD, null), - - GUI_MAC(ContainerMAC.class, TileMolecularAssembler.class, WORLD, null), - - GUI_CRAFTING_AMOUNT(ContainerCraftAmount.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT), - - GUI_CRAFTING_CONFIRM(ContainerCraftConfirm.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT), - - GUI_INTERFACE_TERMINAL(ContainerInterfaceTerminal.class, PartMonitor.class, WORLD, SecurityPermissions.BUILD), - - GUI_CRAFTING_STATUS(ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT); - - private Class Tile; - private Class Gui; - private Class Container; - private GuiHostType type; - private SecurityPermissions requiredPermission; - - private GuiBridge() { - Tile = null; - Gui = null; - Container = null; - } - - /** - * I honestly wish I could just use the GuiClass Names myself, but I can't access them without MC's Server - * Exploding. - */ - private void getGui() - { - if ( Platform.isClient() ) - { - String start = Container.getName(); - String GuiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" ); - if ( start.equals( GuiClass ) ) - throw new RuntimeException( "Unable to find gui class" ); - Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), GuiClass ); - if ( Gui == null ) - throw new RuntimeException( "Cannot Load class: " + GuiClass ); - } - } - - private GuiBridge(Class _Container, SecurityPermissions requiredPermission) { - this.requiredPermission = requiredPermission; - Container = _Container; - Tile = null; - getGui(); - } - - private GuiBridge(Class _Container, Class _Tile, GuiHostType type, SecurityPermissions requiredPermission) { - this.requiredPermission = requiredPermission; - Container = _Container; - this.type = type; - Tile = _Tile; - getGui(); - } - - public boolean CorrectTileOrPart(Object tE) - { - if ( Tile == null ) - throw new RuntimeException( "This Gui Cannot use the standard Handler." ); - - return Tile.isInstance( tE ); - } - - public Object ConstructContainer(InventoryPlayer inventory, ForgeDirection side, Object tE) - { - try - { - Constructor[] c = Container.getConstructors(); - if ( c.length == 0 ) - throw new AppEngException( "Invalid Gui Class" ); - - Constructor target = findConstructor( c, inventory, tE ); - - if ( target == null ) - { - throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" ); - } - - Object o = target.newInstance( inventory, tE ); - - /** - * triggers achievement when the player sees presses. - */ - if ( o instanceof AEBaseContainer ) - { - AEBaseContainer bc = (AEBaseContainer) o; - for (Object so : bc.inventorySlots) - { - if ( so instanceof Slot ) - { - ItemStack is = ((Slot) so).getStack(); - - Materials m = AEApi.instance().materials(); - if ( m.materialLogicProcessorPress.sameAsStack( is ) || m.materialEngProcessorPress.sameAsStack( is ) - || m.materialCalcProcessorPress.sameAsStack( is ) || m.materialSiliconPress.sameAsStack( is ) ) - { - Achievements.Presses.addToPlayer( inventory.player ); - } - } - } - } - - return o; - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } - } - - public Object ConstructGui(InventoryPlayer inventory, ForgeDirection side, Object tE) - { - try - { - Constructor[] c = Gui.getConstructors(); - if ( c.length == 0 ) - throw new AppEngException( "Invalid Gui Class" ); - - Constructor target = findConstructor( c, inventory, tE ); - - if ( target == null ) - { - throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" ); - } - - return target.newInstance( inventory, tE ); - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } - } - - private String typeName(Object inventory) - { - if ( inventory == null ) - return "NULL"; - - return inventory.getClass().getName(); - } - - private Constructor findConstructor(Constructor[] c, InventoryPlayer inventory, Object tE) - { - for (Constructor con : c) - { - Class[] types = con.getParameterTypes(); - if ( types.length == 2 ) - { - if ( types[0].isAssignableFrom( inventory.getClass() ) && types[1].isAssignableFrom( tE.getClass() ) ) - return con; - } - } - return null; - } - - private Object updateGui(Object newContainer, World w, int x, int y, int z, ForgeDirection side, Object myItem) - { - if ( newContainer instanceof AEBaseContainer ) - { - AEBaseContainer bc = (AEBaseContainer) newContainer; - bc.openContext = new ContainerOpenContext( myItem ); - bc.openContext.w = w; - bc.openContext.x = x; - bc.openContext.y = y; - bc.openContext.z = z; - bc.openContext.side = side; - } - - return newContainer; - } - - @Override - public Object getServerGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z) - { - ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 ); - GuiBridge ID = values()[ID_ORDINAL >> 4]; - boolean istem = ((ID_ORDINAL >> 3) & 1) == 1; - - if ( ID.type.isItem() && istem ) - { - ItemStack it = player.inventory.getCurrentItem(); - Object myItem = getGuiObject( it, player, w, x, y, z ); - if ( myItem != null && ID.CorrectTileOrPart( myItem ) ) - return updateGui( ID.ConstructContainer( player.inventory, side, myItem ), w, x, y, z, side, myItem ); - } - - if ( ID.type.isTile() ) - { - TileEntity TE = w.getTileEntity( x, y, z ); - if ( TE instanceof IPartHost ) - { - ((IPartHost) TE).getPart( side ); - IPart part = ((IPartHost) TE).getPart( side ); - if ( ID.CorrectTileOrPart( part ) ) - return updateGui( ID.ConstructContainer( player.inventory, side, part ), w, x, y, z, side, part ); - } - else - { - if ( ID.CorrectTileOrPart( TE ) ) - return updateGui( ID.ConstructContainer( player.inventory, side, TE ), w, x, y, z, side, TE ); - } - } - - return new ContainerNull(); - } - - private Object getGuiObject(ItemStack it, EntityPlayer player, World w, int x, int y, int z) - { - if ( it != null ) - { - if ( it.getItem() instanceof IGuiItem ) - { - return ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z ); - } - - IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler( it ); - if ( wh != null ) - return new WirelessTerminalGuiObject( wh, it, player, w, x, y, z ); - } - - return null; - } - - @Override - public Object getClientGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z) - { - ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 ); - GuiBridge ID = values()[ID_ORDINAL >> 4]; - boolean istem = ((ID_ORDINAL >> 3) & 1) == 1; - - if ( ID.type.isItem() && istem ) - { - ItemStack it = player.inventory.getCurrentItem(); - Object myItem = getGuiObject( it, player, w, x, y, z ); - if ( ID.CorrectTileOrPart( myItem ) ) - return ID.ConstructGui( player.inventory, side, myItem ); - } - - if ( ID.type.isTile() ) - { - TileEntity TE = w.getTileEntity( x, y, z ); - - if ( TE instanceof IPartHost ) - { - ((IPartHost) TE).getPart( side ); - IPart part = ((IPartHost) TE).getPart( side ); - if ( ID.CorrectTileOrPart( part ) ) - return ID.ConstructGui( player.inventory, side, part ); - } - else - { - if ( ID.CorrectTileOrPart( TE ) ) - return ID.ConstructGui( player.inventory, side, TE ); - } - } - - return new GuiNull( new ContainerNull() ); - } - - public boolean hasPermissions(TileEntity te, int x, int y, int z, ForgeDirection side, EntityPlayer player) - { - World w = player.getEntityWorld(); - - if ( Platform.hasPermissions( te != null ? new DimensionalCoord( te ) : new DimensionalCoord( player.worldObj, x, y, z ), player ) ) - { - if ( type.isItem() ) - { - ItemStack it = player.inventory.getCurrentItem(); - if ( it != null && it.getItem() instanceof IGuiItem ) - { - Object myItem = ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z ); - if ( CorrectTileOrPart( myItem ) ) - { - return true; - } - } - } - - if ( type.isTile() ) - { - TileEntity TE = w.getTileEntity( x, y, z ); - if ( TE instanceof IPartHost ) - { - ((IPartHost) TE).getPart( side ); - IPart part = ((IPartHost) TE).getPart( side ); - if ( CorrectTileOrPart( part ) ) - return securityCheck( part, player ); - } - else - { - if ( CorrectTileOrPart( TE ) ) - return securityCheck( TE, player ); - } - } - } - return false; - } - - private boolean securityCheck(Object te, EntityPlayer player) - { - if ( te instanceof IActionHost && requiredPermission != null ) - { - boolean requirePower = false; - - IGridNode gn = ((IActionHost) te).getActionableNode(); - if ( gn != null ) - { - IGrid g = gn.getGrid(); - if ( g != null ) - { - if ( requirePower ) - { - IEnergyGrid eg = g.getCache( IEnergyGrid.class ); - if ( !eg.isNetworkPowered() ) - { - return false; - } - } - - ISecurityGrid sg = g.getCache( ISecurityGrid.class ); - if ( sg.hasPermission( player, requiredPermission ) ) - return true; - } - } - - return false; - } - return true; - } - - public GuiHostType getType() - { - return type; - } - -} +package appeng.core.sync; + +import static appeng.core.sync.GuiHostType.ITEM; +import static appeng.core.sync.GuiHostType.ITEM_OR_WORLD; +import static appeng.core.sync.GuiHostType.WORLD; + +import java.lang.reflect.Constructor; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.config.SecurityPermissions; +import appeng.api.definitions.Materials; +import appeng.api.exceptions.AppEngException; +import appeng.api.features.IWirelessTermHandler; +import appeng.api.implementations.IUpgradeableHost; +import appeng.api.implementations.guiobjects.IGuiItem; +import appeng.api.implementations.guiobjects.INetworkTool; +import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.security.IActionHost; +import appeng.api.networking.security.ISecurityGrid; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartHost; +import appeng.api.storage.ITerminalHost; +import appeng.api.util.DimensionalCoord; +import appeng.client.gui.GuiNull; +import appeng.container.AEBaseContainer; +import appeng.container.ContainerNull; +import appeng.container.ContainerOpenContext; +import appeng.container.implementations.ContainerCellWorkbench; +import appeng.container.implementations.ContainerChest; +import appeng.container.implementations.ContainerCondenser; +import appeng.container.implementations.ContainerCraftAmount; +import appeng.container.implementations.ContainerCraftConfirm; +import appeng.container.implementations.ContainerCraftingCPU; +import appeng.container.implementations.ContainerCraftingStatus; +import appeng.container.implementations.ContainerCraftingTerm; +import appeng.container.implementations.ContainerDrive; +import appeng.container.implementations.ContainerFormationPlane; +import appeng.container.implementations.ContainerGrinder; +import appeng.container.implementations.ContainerIOPort; +import appeng.container.implementations.ContainerInscriber; +import appeng.container.implementations.ContainerInterface; +import appeng.container.implementations.ContainerInterfaceTerminal; +import appeng.container.implementations.ContainerLevelEmitter; +import appeng.container.implementations.ContainerMAC; +import appeng.container.implementations.ContainerMEMonitorable; +import appeng.container.implementations.ContainerMEPortableCell; +import appeng.container.implementations.ContainerNetworkStatus; +import appeng.container.implementations.ContainerNetworkTool; +import appeng.container.implementations.ContainerPatternTerm; +import appeng.container.implementations.ContainerPriority; +import appeng.container.implementations.ContainerQNB; +import appeng.container.implementations.ContainerQuartzKnife; +import appeng.container.implementations.ContainerSecurity; +import appeng.container.implementations.ContainerSkyChest; +import appeng.container.implementations.ContainerSpatialIOPort; +import appeng.container.implementations.ContainerStorageBus; +import appeng.container.implementations.ContainerUpgradeable; +import appeng.container.implementations.ContainerVibrationChamber; +import appeng.container.implementations.ContainerWireless; +import appeng.container.implementations.ContainerWirelessTerm; +import appeng.core.stats.Achievements; +import appeng.helpers.IInterfaceHost; +import appeng.helpers.IPriorityHost; +import appeng.helpers.WirelessTerminalGuiObject; +import appeng.items.contents.QuartzKnifeObj; +import appeng.parts.automation.PartFormationPlane; +import appeng.parts.automation.PartLevelEmitter; +import appeng.parts.misc.PartStorageBus; +import appeng.parts.reporting.PartCraftingTerminal; +import appeng.parts.reporting.PartMonitor; +import appeng.parts.reporting.PartPatternTerminal; +import appeng.tile.crafting.TileCraftingTile; +import appeng.tile.crafting.TileMolecularAssembler; +import appeng.tile.grindstone.TileGrinder; +import appeng.tile.misc.TileCellWorkbench; +import appeng.tile.misc.TileCondenser; +import appeng.tile.misc.TileInscriber; +import appeng.tile.misc.TileSecurity; +import appeng.tile.misc.TileVibrationChamber; +import appeng.tile.networking.TileWireless; +import appeng.tile.qnb.TileQuantumBridge; +import appeng.tile.spatial.TileSpatialIOPort; +import appeng.tile.storage.TileChest; +import appeng.tile.storage.TileDrive; +import appeng.tile.storage.TileIOPort; +import appeng.tile.storage.TileSkyChest; +import appeng.util.Platform; +import cpw.mods.fml.common.network.IGuiHandler; +import cpw.mods.fml.relauncher.ReflectionHelper; + +public enum GuiBridge implements IGuiHandler +{ + GUI_Handler(), + + GUI_GRINDER(ContainerGrinder.class, TileGrinder.class, WORLD, null), + + GUI_QNB(ContainerQNB.class, TileQuantumBridge.class, WORLD, SecurityPermissions.BUILD), + + GUI_SKYCHEST(ContainerSkyChest.class, TileSkyChest.class, WORLD, null), + + GUI_CHEST(ContainerChest.class, TileChest.class, WORLD, SecurityPermissions.BUILD), + + GUI_WIRELESS(ContainerWireless.class, TileWireless.class, WORLD, SecurityPermissions.BUILD), + + GUI_ME(ContainerMEMonitorable.class, ITerminalHost.class, WORLD, null), + + GUI_PORTABLE_CELL(ContainerMEPortableCell.class, IPortableCell.class, ITEM, null), + + GUI_WIRELESS_TERM(ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, ITEM, null), + + GUI_NETWORK_STATUS(ContainerNetworkStatus.class, INetworkTool.class, ITEM, null), + + GUI_CRAFTING_CPU(ContainerCraftingCPU.class, TileCraftingTile.class, WORLD, SecurityPermissions.CRAFT), + + GUI_NETWORK_TOOL(ContainerNetworkTool.class, INetworkTool.class, ITEM, null), + + GUI_QUARTZ_KNIFE(ContainerQuartzKnife.class, QuartzKnifeObj.class, ITEM, null), + + GUI_DRIVE(ContainerDrive.class, TileDrive.class, WORLD, SecurityPermissions.BUILD), + + GUI_VIBRATIONCHAMBER(ContainerVibrationChamber.class, TileVibrationChamber.class, WORLD, null), + + GUI_CONDENSER(ContainerCondenser.class, TileCondenser.class, WORLD, null), + + GUI_INTERFACE(ContainerInterface.class, IInterfaceHost.class, WORLD, SecurityPermissions.BUILD), + + GUI_BUS(ContainerUpgradeable.class, IUpgradeableHost.class, WORLD, SecurityPermissions.BUILD), + + GUI_IOPORT(ContainerIOPort.class, TileIOPort.class, WORLD, SecurityPermissions.BUILD), + + GUI_STORAGEBUS(ContainerStorageBus.class, PartStorageBus.class, WORLD, SecurityPermissions.BUILD), + + GUI_FPLANE(ContainerFormationPlane.class, PartFormationPlane.class, WORLD, SecurityPermissions.BUILD), + + GUI_PRIORITY(ContainerPriority.class, IPriorityHost.class, WORLD, SecurityPermissions.BUILD), + + GUI_SECURITY(ContainerSecurity.class, TileSecurity.class, WORLD, SecurityPermissions.SECURITY), + + GUI_CRAFTING_TERMINAL(ContainerCraftingTerm.class, PartCraftingTerminal.class, WORLD, SecurityPermissions.CRAFT), + + GUI_PATTERN_TERMINAL(ContainerPatternTerm.class, PartPatternTerminal.class, WORLD, SecurityPermissions.CRAFT), + + // extends (Container/Gui) + Bus + GUI_LEVELEMITTER(ContainerLevelEmitter.class, PartLevelEmitter.class, WORLD, SecurityPermissions.BUILD), + + GUI_SPATIALIOPORT(ContainerSpatialIOPort.class, TileSpatialIOPort.class, WORLD, SecurityPermissions.BUILD), + + GUI_INSCRIBER(ContainerInscriber.class, TileInscriber.class, WORLD, null), + + GUI_CELLWORKBENCH(ContainerCellWorkbench.class, TileCellWorkbench.class, WORLD, null), + + GUI_MAC(ContainerMAC.class, TileMolecularAssembler.class, WORLD, null), + + GUI_CRAFTING_AMOUNT(ContainerCraftAmount.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT), + + GUI_CRAFTING_CONFIRM(ContainerCraftConfirm.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT), + + GUI_INTERFACE_TERMINAL(ContainerInterfaceTerminal.class, PartMonitor.class, WORLD, SecurityPermissions.BUILD), + + GUI_CRAFTING_STATUS(ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT); + + private Class Tile; + private Class Gui; + private Class Container; + private GuiHostType type; + private SecurityPermissions requiredPermission; + + private GuiBridge() { + Tile = null; + Gui = null; + Container = null; + } + + /** + * I honestly wish I could just use the GuiClass Names myself, but I can't access them without MC's Server + * Exploding. + */ + private void getGui() + { + if ( Platform.isClient() ) + { + String start = Container.getName(); + String GuiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" ); + if ( start.equals( GuiClass ) ) + throw new RuntimeException( "Unable to find gui class" ); + Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), GuiClass ); + if ( Gui == null ) + throw new RuntimeException( "Cannot Load class: " + GuiClass ); + } + } + + private GuiBridge(Class _Container, SecurityPermissions requiredPermission) { + this.requiredPermission = requiredPermission; + Container = _Container; + Tile = null; + getGui(); + } + + private GuiBridge(Class _Container, Class _Tile, GuiHostType type, SecurityPermissions requiredPermission) { + this.requiredPermission = requiredPermission; + Container = _Container; + this.type = type; + Tile = _Tile; + getGui(); + } + + public boolean CorrectTileOrPart(Object tE) + { + if ( Tile == null ) + throw new RuntimeException( "This Gui Cannot use the standard Handler." ); + + return Tile.isInstance( tE ); + } + + public Object ConstructContainer(InventoryPlayer inventory, ForgeDirection side, Object tE) + { + try + { + Constructor[] c = Container.getConstructors(); + if ( c.length == 0 ) + throw new AppEngException( "Invalid Gui Class" ); + + Constructor target = findConstructor( c, inventory, tE ); + + if ( target == null ) + { + throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" ); + } + + Object o = target.newInstance( inventory, tE ); + + /** + * triggers achievement when the player sees presses. + */ + if ( o instanceof AEBaseContainer ) + { + AEBaseContainer bc = (AEBaseContainer) o; + for (Object so : bc.inventorySlots) + { + if ( so instanceof Slot ) + { + ItemStack is = ((Slot) so).getStack(); + + Materials m = AEApi.instance().materials(); + if ( m.materialLogicProcessorPress.sameAsStack( is ) || m.materialEngProcessorPress.sameAsStack( is ) + || m.materialCalcProcessorPress.sameAsStack( is ) || m.materialSiliconPress.sameAsStack( is ) ) + { + Achievements.Presses.addToPlayer( inventory.player ); + } + } + } + } + + return o; + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + } + + public Object ConstructGui(InventoryPlayer inventory, ForgeDirection side, Object tE) + { + try + { + Constructor[] c = Gui.getConstructors(); + if ( c.length == 0 ) + throw new AppEngException( "Invalid Gui Class" ); + + Constructor target = findConstructor( c, inventory, tE ); + + if ( target == null ) + { + throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" ); + } + + return target.newInstance( inventory, tE ); + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + } + + private String typeName(Object inventory) + { + if ( inventory == null ) + return "NULL"; + + return inventory.getClass().getName(); + } + + private Constructor findConstructor(Constructor[] c, InventoryPlayer inventory, Object tE) + { + for (Constructor con : c) + { + Class[] types = con.getParameterTypes(); + if ( types.length == 2 ) + { + if ( types[0].isAssignableFrom( inventory.getClass() ) && types[1].isAssignableFrom( tE.getClass() ) ) + return con; + } + } + return null; + } + + private Object updateGui(Object newContainer, World w, int x, int y, int z, ForgeDirection side, Object myItem) + { + if ( newContainer instanceof AEBaseContainer ) + { + AEBaseContainer bc = (AEBaseContainer) newContainer; + bc.openContext = new ContainerOpenContext( myItem ); + bc.openContext.w = w; + bc.openContext.x = x; + bc.openContext.y = y; + bc.openContext.z = z; + bc.openContext.side = side; + } + + return newContainer; + } + + @Override + public Object getServerGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z) + { + ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 ); + GuiBridge ID = values()[ID_ORDINAL >> 4]; + boolean istem = ((ID_ORDINAL >> 3) & 1) == 1; + + if ( ID.type.isItem() && istem ) + { + ItemStack it = player.inventory.getCurrentItem(); + Object myItem = getGuiObject( it, player, w, x, y, z ); + if ( myItem != null && ID.CorrectTileOrPart( myItem ) ) + return updateGui( ID.ConstructContainer( player.inventory, side, myItem ), w, x, y, z, side, myItem ); + } + + if ( ID.type.isTile() ) + { + TileEntity TE = w.getTileEntity( x, y, z ); + if ( TE instanceof IPartHost ) + { + ((IPartHost) TE).getPart( side ); + IPart part = ((IPartHost) TE).getPart( side ); + if ( ID.CorrectTileOrPart( part ) ) + return updateGui( ID.ConstructContainer( player.inventory, side, part ), w, x, y, z, side, part ); + } + else + { + if ( ID.CorrectTileOrPart( TE ) ) + return updateGui( ID.ConstructContainer( player.inventory, side, TE ), w, x, y, z, side, TE ); + } + } + + return new ContainerNull(); + } + + private Object getGuiObject(ItemStack it, EntityPlayer player, World w, int x, int y, int z) + { + if ( it != null ) + { + if ( it.getItem() instanceof IGuiItem ) + { + return ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z ); + } + + IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler( it ); + if ( wh != null ) + return new WirelessTerminalGuiObject( wh, it, player, w, x, y, z ); + } + + return null; + } + + @Override + public Object getClientGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z) + { + ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 ); + GuiBridge ID = values()[ID_ORDINAL >> 4]; + boolean istem = ((ID_ORDINAL >> 3) & 1) == 1; + + if ( ID.type.isItem() && istem ) + { + ItemStack it = player.inventory.getCurrentItem(); + Object myItem = getGuiObject( it, player, w, x, y, z ); + if ( ID.CorrectTileOrPart( myItem ) ) + return ID.ConstructGui( player.inventory, side, myItem ); + } + + if ( ID.type.isTile() ) + { + TileEntity TE = w.getTileEntity( x, y, z ); + + if ( TE instanceof IPartHost ) + { + ((IPartHost) TE).getPart( side ); + IPart part = ((IPartHost) TE).getPart( side ); + if ( ID.CorrectTileOrPart( part ) ) + return ID.ConstructGui( player.inventory, side, part ); + } + else + { + if ( ID.CorrectTileOrPart( TE ) ) + return ID.ConstructGui( player.inventory, side, TE ); + } + } + + return new GuiNull( new ContainerNull() ); + } + + public boolean hasPermissions(TileEntity te, int x, int y, int z, ForgeDirection side, EntityPlayer player) + { + World w = player.getEntityWorld(); + + if ( Platform.hasPermissions( te != null ? new DimensionalCoord( te ) : new DimensionalCoord( player.worldObj, x, y, z ), player ) ) + { + if ( type.isItem() ) + { + ItemStack it = player.inventory.getCurrentItem(); + if ( it != null && it.getItem() instanceof IGuiItem ) + { + Object myItem = ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z ); + if ( CorrectTileOrPart( myItem ) ) + { + return true; + } + } + } + + if ( type.isTile() ) + { + TileEntity TE = w.getTileEntity( x, y, z ); + if ( TE instanceof IPartHost ) + { + ((IPartHost) TE).getPart( side ); + IPart part = ((IPartHost) TE).getPart( side ); + if ( CorrectTileOrPart( part ) ) + return securityCheck( part, player ); + } + else + { + if ( CorrectTileOrPart( TE ) ) + return securityCheck( TE, player ); + } + } + } + return false; + } + + private boolean securityCheck(Object te, EntityPlayer player) + { + if ( te instanceof IActionHost && requiredPermission != null ) + { + boolean requirePower = false; + + IGridNode gn = ((IActionHost) te).getActionableNode(); + if ( gn != null ) + { + IGrid g = gn.getGrid(); + if ( g != null ) + { + if ( requirePower ) + { + IEnergyGrid eg = g.getCache( IEnergyGrid.class ); + if ( !eg.isNetworkPowered() ) + { + return false; + } + } + + ISecurityGrid sg = g.getCache( ISecurityGrid.class ); + if ( sg.hasPermission( player, requiredPermission ) ) + return true; + } + } + + return false; + } + return true; + } + + public GuiHostType getType() + { + return type; + } + +} diff --git a/core/sync/GuiHostType.java b/src/main/java/appeng/core/sync/GuiHostType.java similarity index 100% rename from core/sync/GuiHostType.java rename to src/main/java/appeng/core/sync/GuiHostType.java diff --git a/core/sync/network/AppEngClientPacketHandler.java b/src/main/java/appeng/core/sync/network/AppEngClientPacketHandler.java similarity index 100% rename from core/sync/network/AppEngClientPacketHandler.java rename to src/main/java/appeng/core/sync/network/AppEngClientPacketHandler.java diff --git a/core/sync/network/AppEngServerPacketHandler.java b/src/main/java/appeng/core/sync/network/AppEngServerPacketHandler.java similarity index 100% rename from core/sync/network/AppEngServerPacketHandler.java rename to src/main/java/appeng/core/sync/network/AppEngServerPacketHandler.java diff --git a/core/sync/network/INetworkInfo.java b/src/main/java/appeng/core/sync/network/INetworkInfo.java similarity index 100% rename from core/sync/network/INetworkInfo.java rename to src/main/java/appeng/core/sync/network/INetworkInfo.java diff --git a/core/sync/network/IPacketHandler.java b/src/main/java/appeng/core/sync/network/IPacketHandler.java similarity index 100% rename from core/sync/network/IPacketHandler.java rename to src/main/java/appeng/core/sync/network/IPacketHandler.java diff --git a/core/sync/network/NetworkHandler.java b/src/main/java/appeng/core/sync/network/NetworkHandler.java similarity index 100% rename from core/sync/network/NetworkHandler.java rename to src/main/java/appeng/core/sync/network/NetworkHandler.java diff --git a/core/sync/packets/PacketAssemblerAnimation.java b/src/main/java/appeng/core/sync/packets/PacketAssemblerAnimation.java similarity index 100% rename from core/sync/packets/PacketAssemblerAnimation.java rename to src/main/java/appeng/core/sync/packets/PacketAssemblerAnimation.java diff --git a/core/sync/packets/PacketClick.java b/src/main/java/appeng/core/sync/packets/PacketClick.java similarity index 100% rename from core/sync/packets/PacketClick.java rename to src/main/java/appeng/core/sync/packets/PacketClick.java diff --git a/core/sync/packets/PacketCompassRequest.java b/src/main/java/appeng/core/sync/packets/PacketCompassRequest.java similarity index 100% rename from core/sync/packets/PacketCompassRequest.java rename to src/main/java/appeng/core/sync/packets/PacketCompassRequest.java diff --git a/core/sync/packets/PacketCompassResponse.java b/src/main/java/appeng/core/sync/packets/PacketCompassResponse.java similarity index 100% rename from core/sync/packets/PacketCompassResponse.java rename to src/main/java/appeng/core/sync/packets/PacketCompassResponse.java diff --git a/core/sync/packets/PacketCompressedNBT.java b/src/main/java/appeng/core/sync/packets/PacketCompressedNBT.java similarity index 100% rename from core/sync/packets/PacketCompressedNBT.java rename to src/main/java/appeng/core/sync/packets/PacketCompressedNBT.java diff --git a/core/sync/packets/PacketConfigButton.java b/src/main/java/appeng/core/sync/packets/PacketConfigButton.java similarity index 100% rename from core/sync/packets/PacketConfigButton.java rename to src/main/java/appeng/core/sync/packets/PacketConfigButton.java diff --git a/core/sync/packets/PacketCraftRequest.java b/src/main/java/appeng/core/sync/packets/PacketCraftRequest.java similarity index 100% rename from core/sync/packets/PacketCraftRequest.java rename to src/main/java/appeng/core/sync/packets/PacketCraftRequest.java diff --git a/core/sync/packets/PacketInventoryAction.java b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java similarity index 100% rename from core/sync/packets/PacketInventoryAction.java rename to src/main/java/appeng/core/sync/packets/PacketInventoryAction.java diff --git a/core/sync/packets/PacketLightning.java b/src/main/java/appeng/core/sync/packets/PacketLightning.java similarity index 100% rename from core/sync/packets/PacketLightning.java rename to src/main/java/appeng/core/sync/packets/PacketLightning.java diff --git a/core/sync/packets/PacketMEInventoryUpdate.java b/src/main/java/appeng/core/sync/packets/PacketMEInventoryUpdate.java similarity index 100% rename from core/sync/packets/PacketMEInventoryUpdate.java rename to src/main/java/appeng/core/sync/packets/PacketMEInventoryUpdate.java diff --git a/core/sync/packets/PacketMatterCannon.java b/src/main/java/appeng/core/sync/packets/PacketMatterCannon.java similarity index 100% rename from core/sync/packets/PacketMatterCannon.java rename to src/main/java/appeng/core/sync/packets/PacketMatterCannon.java diff --git a/core/sync/packets/PacketMockExplosion.java b/src/main/java/appeng/core/sync/packets/PacketMockExplosion.java similarity index 100% rename from core/sync/packets/PacketMockExplosion.java rename to src/main/java/appeng/core/sync/packets/PacketMockExplosion.java diff --git a/core/sync/packets/PacketMultiPart.java b/src/main/java/appeng/core/sync/packets/PacketMultiPart.java similarity index 100% rename from core/sync/packets/PacketMultiPart.java rename to src/main/java/appeng/core/sync/packets/PacketMultiPart.java diff --git a/core/sync/packets/PacketNEIRecipe.java b/src/main/java/appeng/core/sync/packets/PacketNEIRecipe.java similarity index 100% rename from core/sync/packets/PacketNEIRecipe.java rename to src/main/java/appeng/core/sync/packets/PacketNEIRecipe.java diff --git a/core/sync/packets/PacketNewStorageDimension.java b/src/main/java/appeng/core/sync/packets/PacketNewStorageDimension.java similarity index 100% rename from core/sync/packets/PacketNewStorageDimension.java rename to src/main/java/appeng/core/sync/packets/PacketNewStorageDimension.java diff --git a/core/sync/packets/PacketPaintedEntity.java b/src/main/java/appeng/core/sync/packets/PacketPaintedEntity.java similarity index 100% rename from core/sync/packets/PacketPaintedEntity.java rename to src/main/java/appeng/core/sync/packets/PacketPaintedEntity.java diff --git a/core/sync/packets/PacketPartPlacement.java b/src/main/java/appeng/core/sync/packets/PacketPartPlacement.java similarity index 100% rename from core/sync/packets/PacketPartPlacement.java rename to src/main/java/appeng/core/sync/packets/PacketPartPlacement.java diff --git a/core/sync/packets/PacketPartialItem.java b/src/main/java/appeng/core/sync/packets/PacketPartialItem.java similarity index 100% rename from core/sync/packets/PacketPartialItem.java rename to src/main/java/appeng/core/sync/packets/PacketPartialItem.java diff --git a/core/sync/packets/PacketPatternSlot.java b/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java similarity index 100% rename from core/sync/packets/PacketPatternSlot.java rename to src/main/java/appeng/core/sync/packets/PacketPatternSlot.java diff --git a/core/sync/packets/PacketProgressBar.java b/src/main/java/appeng/core/sync/packets/PacketProgressBar.java similarity index 100% rename from core/sync/packets/PacketProgressBar.java rename to src/main/java/appeng/core/sync/packets/PacketProgressBar.java diff --git a/core/sync/packets/PacketSwapSlots.java b/src/main/java/appeng/core/sync/packets/PacketSwapSlots.java similarity index 100% rename from core/sync/packets/PacketSwapSlots.java rename to src/main/java/appeng/core/sync/packets/PacketSwapSlots.java diff --git a/core/sync/packets/PacketSwitchGuis.java b/src/main/java/appeng/core/sync/packets/PacketSwitchGuis.java similarity index 100% rename from core/sync/packets/PacketSwitchGuis.java rename to src/main/java/appeng/core/sync/packets/PacketSwitchGuis.java diff --git a/core/sync/packets/PacketTransitionEffect.java b/src/main/java/appeng/core/sync/packets/PacketTransitionEffect.java similarity index 100% rename from core/sync/packets/PacketTransitionEffect.java rename to src/main/java/appeng/core/sync/packets/PacketTransitionEffect.java diff --git a/core/sync/packets/PacketValueConfig.java b/src/main/java/appeng/core/sync/packets/PacketValueConfig.java similarity index 100% rename from core/sync/packets/PacketValueConfig.java rename to src/main/java/appeng/core/sync/packets/PacketValueConfig.java diff --git a/crafting/CraftBranchFailure.java b/src/main/java/appeng/crafting/CraftBranchFailure.java similarity index 100% rename from crafting/CraftBranchFailure.java rename to src/main/java/appeng/crafting/CraftBranchFailure.java diff --git a/crafting/CraftingCalculationFailure.java b/src/main/java/appeng/crafting/CraftingCalculationFailure.java similarity index 100% rename from crafting/CraftingCalculationFailure.java rename to src/main/java/appeng/crafting/CraftingCalculationFailure.java diff --git a/crafting/CraftingJob.java b/src/main/java/appeng/crafting/CraftingJob.java similarity index 100% rename from crafting/CraftingJob.java rename to src/main/java/appeng/crafting/CraftingJob.java diff --git a/crafting/CraftingLink.java b/src/main/java/appeng/crafting/CraftingLink.java similarity index 100% rename from crafting/CraftingLink.java rename to src/main/java/appeng/crafting/CraftingLink.java diff --git a/crafting/CraftingLinkNexus.java b/src/main/java/appeng/crafting/CraftingLinkNexus.java similarity index 100% rename from crafting/CraftingLinkNexus.java rename to src/main/java/appeng/crafting/CraftingLinkNexus.java diff --git a/crafting/CraftingTreeNode.java b/src/main/java/appeng/crafting/CraftingTreeNode.java similarity index 100% rename from crafting/CraftingTreeNode.java rename to src/main/java/appeng/crafting/CraftingTreeNode.java diff --git a/crafting/CraftingTreeProcess.java b/src/main/java/appeng/crafting/CraftingTreeProcess.java similarity index 100% rename from crafting/CraftingTreeProcess.java rename to src/main/java/appeng/crafting/CraftingTreeProcess.java diff --git a/crafting/CraftingWatcher.java b/src/main/java/appeng/crafting/CraftingWatcher.java similarity index 100% rename from crafting/CraftingWatcher.java rename to src/main/java/appeng/crafting/CraftingWatcher.java diff --git a/crafting/MECraftingInventory.java b/src/main/java/appeng/crafting/MECraftingInventory.java similarity index 100% rename from crafting/MECraftingInventory.java rename to src/main/java/appeng/crafting/MECraftingInventory.java diff --git a/debug/BlockChunkloader.java b/src/main/java/appeng/debug/BlockChunkloader.java similarity index 96% rename from debug/BlockChunkloader.java rename to src/main/java/appeng/debug/BlockChunkloader.java index 0a1947a24..65163a445 100644 --- a/debug/BlockChunkloader.java +++ b/src/main/java/appeng/debug/BlockChunkloader.java @@ -1,38 +1,38 @@ -package appeng.debug; - -import java.util.EnumSet; -import java.util.List; - -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.world.World; -import net.minecraftforge.common.ForgeChunkManager; -import net.minecraftforge.common.ForgeChunkManager.LoadingCallback; -import net.minecraftforge.common.ForgeChunkManager.Ticket; -import appeng.block.AEBaseBlock; -import appeng.core.AppEng; -import appeng.core.features.AEFeature; - -public class BlockChunkloader extends AEBaseBlock implements LoadingCallback -{ - - public BlockChunkloader() { - super( BlockChunkloader.class, Material.iron ); - setFeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) ); - setTileEntity( TileChunkLoader.class ); - ForgeChunkManager.setForcedChunkLoadingCallback( AppEng.instance, this ); - } - - @Override - public void ticketsLoaded(List tickets, World world) - { - - } - - @Override - public void registerBlockIcons(IIconRegister iconRegistry) - { - registerNoIcons(); - } - -} +package appeng.debug; + +import java.util.EnumSet; +import java.util.List; + +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeChunkManager; +import net.minecraftforge.common.ForgeChunkManager.LoadingCallback; +import net.minecraftforge.common.ForgeChunkManager.Ticket; +import appeng.block.AEBaseBlock; +import appeng.core.AppEng; +import appeng.core.features.AEFeature; + +public class BlockChunkloader extends AEBaseBlock implements LoadingCallback +{ + + public BlockChunkloader() { + super( BlockChunkloader.class, Material.iron ); + setFeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) ); + setTileEntity( TileChunkLoader.class ); + ForgeChunkManager.setForcedChunkLoadingCallback( AppEng.instance, this ); + } + + @Override + public void ticketsLoaded(List tickets, World world) + { + + } + + @Override + public void registerBlockIcons(IIconRegister iconRegistry) + { + registerNoIcons(); + } + +} diff --git a/debug/BlockCubeGenerator.java b/src/main/java/appeng/debug/BlockCubeGenerator.java similarity index 96% rename from debug/BlockCubeGenerator.java rename to src/main/java/appeng/debug/BlockCubeGenerator.java index bda1664e8..0653cbfc1 100644 --- a/debug/BlockCubeGenerator.java +++ b/src/main/java/appeng/debug/BlockCubeGenerator.java @@ -1,38 +1,38 @@ -package appeng.debug; - -import java.util.EnumSet; - -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; -import appeng.block.AEBaseBlock; -import appeng.core.features.AEFeature; - -public class BlockCubeGenerator extends AEBaseBlock -{ - - public BlockCubeGenerator() { - super( BlockCubeGenerator.class, Material.iron ); - setFeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) ); - setTileEntity( TileCubeGenerator.class ); - } - - @Override - public boolean onActivated(World w, int x, int y, int z, - EntityPlayer player, int side, float hitX, float hitY, float hitZ) { - - TileCubeGenerator tcg = getTileEntity(w, x, y, z); - if ( tcg != null ) - tcg.click( player ); - - return true; - } - - @Override - public void registerBlockIcons(IIconRegister iconRegistry) - { - registerNoIcons(); - } - -} +package appeng.debug; + +import java.util.EnumSet; + +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import appeng.block.AEBaseBlock; +import appeng.core.features.AEFeature; + +public class BlockCubeGenerator extends AEBaseBlock +{ + + public BlockCubeGenerator() { + super( BlockCubeGenerator.class, Material.iron ); + setFeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) ); + setTileEntity( TileCubeGenerator.class ); + } + + @Override + public boolean onActivated(World w, int x, int y, int z, + EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + + TileCubeGenerator tcg = getTileEntity(w, x, y, z); + if ( tcg != null ) + tcg.click( player ); + + return true; + } + + @Override + public void registerBlockIcons(IIconRegister iconRegistry) + { + registerNoIcons(); + } + +} diff --git a/debug/BlockItemGen.java b/src/main/java/appeng/debug/BlockItemGen.java similarity index 95% rename from debug/BlockItemGen.java rename to src/main/java/appeng/debug/BlockItemGen.java index b651755ea..60c900a8b 100644 --- a/debug/BlockItemGen.java +++ b/src/main/java/appeng/debug/BlockItemGen.java @@ -1,25 +1,25 @@ -package appeng.debug; - -import java.util.EnumSet; - -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; -import appeng.block.AEBaseBlock; -import appeng.core.features.AEFeature; - -public class BlockItemGen extends AEBaseBlock -{ - - public BlockItemGen() { - super( BlockItemGen.class, Material.iron ); - setFeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) ); - setTileEntity( TileItemGen.class ); - } - - @Override - public void registerBlockIcons(IIconRegister iconRegistry) - { - registerNoIcons(); - } - -} +package appeng.debug; + +import java.util.EnumSet; + +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import appeng.block.AEBaseBlock; +import appeng.core.features.AEFeature; + +public class BlockItemGen extends AEBaseBlock +{ + + public BlockItemGen() { + super( BlockItemGen.class, Material.iron ); + setFeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) ); + setTileEntity( TileItemGen.class ); + } + + @Override + public void registerBlockIcons(IIconRegister iconRegistry) + { + registerNoIcons(); + } + +} diff --git a/debug/BlockPhantomNode.java b/src/main/java/appeng/debug/BlockPhantomNode.java similarity index 100% rename from debug/BlockPhantomNode.java rename to src/main/java/appeng/debug/BlockPhantomNode.java diff --git a/debug/TileChunkLoader.java b/src/main/java/appeng/debug/TileChunkLoader.java similarity index 96% rename from debug/TileChunkLoader.java rename to src/main/java/appeng/debug/TileChunkLoader.java index 828ed60e8..cc23911ed 100644 --- a/debug/TileChunkLoader.java +++ b/src/main/java/appeng/debug/TileChunkLoader.java @@ -1,70 +1,70 @@ -package appeng.debug; - -import java.util.List; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.ChatComponentText; -import net.minecraft.world.ChunkCoordIntPair; -import net.minecraftforge.common.ForgeChunkManager; -import net.minecraftforge.common.ForgeChunkManager.Ticket; -import net.minecraftforge.common.ForgeChunkManager.Type; -import appeng.core.AELog; -import appeng.core.AppEng; -import appeng.tile.AEBaseTile; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.util.Platform; -import cpw.mods.fml.common.FMLCommonHandler; - -public class TileChunkLoader extends AEBaseTile -{ - - boolean requestTicket = true; - Ticket ct; - - @TileEvent(TileEventType.TICK) - public void Tick_TileChunkLoader() - { - if ( requestTicket ) - { - requestTicket = false; - initTicket(); - } - } - - void initTicket() - { - if ( Platform.isClient() ) - return; - - ct = ForgeChunkManager.requestTicket( AppEng.instance, worldObj, Type.NORMAL ); - - if ( ct == null ) - { - MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); - if ( server != null ) - { - List pl = server.getConfigurationManager().playerEntityList; - for (EntityPlayerMP p : pl) - { - p.addChatMessage( new ChatComponentText( "Can't chunk load.." ) ); - } - } - return; - } - - AELog.info( "New Ticket " + ct.toString() ); - ForgeChunkManager.forceChunk( ct, new ChunkCoordIntPair( xCoord >> 4, zCoord >> 4 ) ); - } - - @Override - public void invalidate() - { - if ( Platform.isClient() ) - return; - - AELog.info( "Released Ticket " + ct.toString() ); - ForgeChunkManager.releaseTicket( ct ); - } -} +package appeng.debug; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraftforge.common.ForgeChunkManager; +import net.minecraftforge.common.ForgeChunkManager.Ticket; +import net.minecraftforge.common.ForgeChunkManager.Type; +import appeng.core.AELog; +import appeng.core.AppEng; +import appeng.tile.AEBaseTile; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.util.Platform; +import cpw.mods.fml.common.FMLCommonHandler; + +public class TileChunkLoader extends AEBaseTile +{ + + boolean requestTicket = true; + Ticket ct; + + @TileEvent(TileEventType.TICK) + public void Tick_TileChunkLoader() + { + if ( requestTicket ) + { + requestTicket = false; + initTicket(); + } + } + + void initTicket() + { + if ( Platform.isClient() ) + return; + + ct = ForgeChunkManager.requestTicket( AppEng.instance, worldObj, Type.NORMAL ); + + if ( ct == null ) + { + MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); + if ( server != null ) + { + List pl = server.getConfigurationManager().playerEntityList; + for (EntityPlayerMP p : pl) + { + p.addChatMessage( new ChatComponentText( "Can't chunk load.." ) ); + } + } + return; + } + + AELog.info( "New Ticket " + ct.toString() ); + ForgeChunkManager.forceChunk( ct, new ChunkCoordIntPair( xCoord >> 4, zCoord >> 4 ) ); + } + + @Override + public void invalidate() + { + if ( Platform.isClient() ) + return; + + AELog.info( "Released Ticket " + ct.toString() ); + ForgeChunkManager.releaseTicket( ct ); + } +} diff --git a/debug/TileCubeGenerator.java b/src/main/java/appeng/debug/TileCubeGenerator.java similarity index 95% rename from debug/TileCubeGenerator.java rename to src/main/java/appeng/debug/TileCubeGenerator.java index 8c9024f64..995e2239c 100644 --- a/debug/TileCubeGenerator.java +++ b/src/main/java/appeng/debug/TileCubeGenerator.java @@ -1,94 +1,94 @@ -package appeng.debug; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentText; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.core.CommonHelper; -import appeng.tile.AEBaseTile; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.util.Platform; - -public class TileCubeGenerator extends AEBaseTile -{ - - int size = 3; - ItemStack is = null; - int countdown = 20 * 10; - EntityPlayer who; - - @TileEvent(TileEventType.TICK) - public void TCG_Tick() - { - if ( is != null && Platform.isServer() ) - { - countdown--; - - if ( countdown % 20 == 0 ) - { - for (EntityPlayer e : CommonHelper.proxy.getPlayers()) - { - e.addChatMessage( new ChatComponentText( "Spawning in... " + (countdown / 20) ) ); - } - } - - if ( countdown <= 0 ) - spawn(); - } - } - - void spawn() - { - worldObj.setBlock( xCoord, yCoord, zCoord, Platform.air, 0, 3 ); - - Item i = is.getItem(); - int side = ForgeDirection.UP.ordinal(); - - int half = (int) Math.floor( size / 2 ); - - for (int y = 0; y < size; y++) - { - for (int x = -half; x < half; x++) - { - for (int z = -half; z < half; z++) - { - i.onItemUse( is.copy(), who, worldObj, x + xCoord, y + yCoord - 1, z + zCoord, side, 0.5f, 0.0f, 0.5f ); - } - } - } - } - - public void click(EntityPlayer player) - { - if ( Platform.isServer() ) - { - ItemStack hand = player.inventory.getCurrentItem(); - who = player; - - if ( hand == null ) - { - is = null; - - if ( player.isSneaking() ) - size--; - else - size++; - - if ( size < 3 ) - size = 3; - if ( size > 64 ) - size = 64; - - player.addChatMessage( new ChatComponentText( "Size: " + size ) ); - } - else - { - countdown = 20 * 10; - is = hand; - } - } - } - -} +package appeng.debug; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.core.CommonHelper; +import appeng.tile.AEBaseTile; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.util.Platform; + +public class TileCubeGenerator extends AEBaseTile +{ + + int size = 3; + ItemStack is = null; + int countdown = 20 * 10; + EntityPlayer who; + + @TileEvent(TileEventType.TICK) + public void TCG_Tick() + { + if ( is != null && Platform.isServer() ) + { + countdown--; + + if ( countdown % 20 == 0 ) + { + for (EntityPlayer e : CommonHelper.proxy.getPlayers()) + { + e.addChatMessage( new ChatComponentText( "Spawning in... " + (countdown / 20) ) ); + } + } + + if ( countdown <= 0 ) + spawn(); + } + } + + void spawn() + { + worldObj.setBlock( xCoord, yCoord, zCoord, Platform.air, 0, 3 ); + + Item i = is.getItem(); + int side = ForgeDirection.UP.ordinal(); + + int half = (int) Math.floor( size / 2 ); + + for (int y = 0; y < size; y++) + { + for (int x = -half; x < half; x++) + { + for (int z = -half; z < half; z++) + { + i.onItemUse( is.copy(), who, worldObj, x + xCoord, y + yCoord - 1, z + zCoord, side, 0.5f, 0.0f, 0.5f ); + } + } + } + } + + public void click(EntityPlayer player) + { + if ( Platform.isServer() ) + { + ItemStack hand = player.inventory.getCurrentItem(); + who = player; + + if ( hand == null ) + { + is = null; + + if ( player.isSneaking() ) + size--; + else + size++; + + if ( size < 3 ) + size = 3; + if ( size > 64 ) + size = 64; + + player.addChatMessage( new ChatComponentText( "Size: " + size ) ); + } + else + { + countdown = 20 * 10; + is = hand; + } + } + } + +} diff --git a/debug/TileItemGen.java b/src/main/java/appeng/debug/TileItemGen.java similarity index 94% rename from debug/TileItemGen.java rename to src/main/java/appeng/debug/TileItemGen.java index d535e9056..8e0c0664b 100644 --- a/debug/TileItemGen.java +++ b/src/main/java/appeng/debug/TileItemGen.java @@ -1,124 +1,124 @@ -package appeng.debug; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import appeng.tile.AEBaseTile; - -public class TileItemGen extends AEBaseTile implements IInventory -{ - - public static Queue possibleItems = new LinkedList(); - - public TileItemGen() { - if ( possibleItems.isEmpty() ) - { - for (Object obj : Item.itemRegistry) - { - Item mi = (Item) obj; - if ( mi != null ) - { - if ( mi.isDamageable() ) - { - for (int dmg = 0; dmg < mi.getMaxDamage(); dmg++) - possibleItems.add( new ItemStack( mi, 1, dmg ) ); - } - else - { - List list = new ArrayList(); - mi.getSubItems( mi, mi.getCreativeTab(), list ); - possibleItems.addAll( list ); - } - } - } - } - } - - @Override - public int getSizeInventory() - { - return 1; - } - - @Override - public ItemStack getStackInSlot(int i) - { - return getRandomItem(); - } - - private ItemStack getRandomItem() - { - return possibleItems.peek(); - } - - @Override - public ItemStack decrStackSize(int i, int j) - { - ItemStack a = possibleItems.poll(); - ItemStack out = a.copy(); - possibleItems.add( a ); - return out; - } - - @Override - public ItemStack getStackInSlotOnClosing(int i) - { - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) - { - ItemStack a = possibleItems.poll(); - possibleItems.add( a ); - } - - @Override - public String getInventoryName() - { - return null; - } - - @Override - public boolean hasCustomInventoryName() - { - return false; - } - - @Override - public int getInventoryStackLimit() - { - return 1; - } - - @Override - public void openInventory() - { - - } - - @Override - public void closeInventory() - { - - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) - { - return false; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return false; - } - -} +package appeng.debug; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import appeng.tile.AEBaseTile; + +public class TileItemGen extends AEBaseTile implements IInventory +{ + + public static Queue possibleItems = new LinkedList(); + + public TileItemGen() { + if ( possibleItems.isEmpty() ) + { + for (Object obj : Item.itemRegistry) + { + Item mi = (Item) obj; + if ( mi != null ) + { + if ( mi.isDamageable() ) + { + for (int dmg = 0; dmg < mi.getMaxDamage(); dmg++) + possibleItems.add( new ItemStack( mi, 1, dmg ) ); + } + else + { + List list = new ArrayList(); + mi.getSubItems( mi, mi.getCreativeTab(), list ); + possibleItems.addAll( list ); + } + } + } + } + } + + @Override + public int getSizeInventory() + { + return 1; + } + + @Override + public ItemStack getStackInSlot(int i) + { + return getRandomItem(); + } + + private ItemStack getRandomItem() + { + return possibleItems.peek(); + } + + @Override + public ItemStack decrStackSize(int i, int j) + { + ItemStack a = possibleItems.poll(); + ItemStack out = a.copy(); + possibleItems.add( a ); + return out; + } + + @Override + public ItemStack getStackInSlotOnClosing(int i) + { + return null; + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) + { + ItemStack a = possibleItems.poll(); + possibleItems.add( a ); + } + + @Override + public String getInventoryName() + { + return null; + } + + @Override + public boolean hasCustomInventoryName() + { + return false; + } + + @Override + public int getInventoryStackLimit() + { + return 1; + } + + @Override + public void openInventory() + { + + } + + @Override + public void closeInventory() + { + + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) + { + return false; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return false; + } + +} diff --git a/debug/TilePhantomNode.java b/src/main/java/appeng/debug/TilePhantomNode.java similarity index 100% rename from debug/TilePhantomNode.java rename to src/main/java/appeng/debug/TilePhantomNode.java diff --git a/debug/ToolDebugCard.java b/src/main/java/appeng/debug/ToolDebugCard.java similarity index 100% rename from debug/ToolDebugCard.java rename to src/main/java/appeng/debug/ToolDebugCard.java diff --git a/debug/ToolEraser.java b/src/main/java/appeng/debug/ToolEraser.java similarity index 100% rename from debug/ToolEraser.java rename to src/main/java/appeng/debug/ToolEraser.java diff --git a/debug/ToolMeteoritePlacer.java b/src/main/java/appeng/debug/ToolMeteoritePlacer.java similarity index 100% rename from debug/ToolMeteoritePlacer.java rename to src/main/java/appeng/debug/ToolMeteoritePlacer.java diff --git a/debug/ToolReplicatorCard.java b/src/main/java/appeng/debug/ToolReplicatorCard.java similarity index 100% rename from debug/ToolReplicatorCard.java rename to src/main/java/appeng/debug/ToolReplicatorCard.java diff --git a/entity/EntityChargedQuartz.java b/src/main/java/appeng/entity/EntityChargedQuartz.java similarity index 100% rename from entity/EntityChargedQuartz.java rename to src/main/java/appeng/entity/EntityChargedQuartz.java diff --git a/entity/EntityFloatingItem.java b/src/main/java/appeng/entity/EntityFloatingItem.java similarity index 100% rename from entity/EntityFloatingItem.java rename to src/main/java/appeng/entity/EntityFloatingItem.java diff --git a/entity/EntityGrowingCrystal.java b/src/main/java/appeng/entity/EntityGrowingCrystal.java similarity index 100% rename from entity/EntityGrowingCrystal.java rename to src/main/java/appeng/entity/EntityGrowingCrystal.java diff --git a/entity/EntityIds.java b/src/main/java/appeng/entity/EntityIds.java similarity index 100% rename from entity/EntityIds.java rename to src/main/java/appeng/entity/EntityIds.java diff --git a/entity/EntitySingularity.java b/src/main/java/appeng/entity/EntitySingularity.java similarity index 100% rename from entity/EntitySingularity.java rename to src/main/java/appeng/entity/EntitySingularity.java diff --git a/entity/EntityTinyTNTPrimed.java b/src/main/java/appeng/entity/EntityTinyTNTPrimed.java similarity index 100% rename from entity/EntityTinyTNTPrimed.java rename to src/main/java/appeng/entity/EntityTinyTNTPrimed.java diff --git a/entity/RenderFloatingItem.java b/src/main/java/appeng/entity/RenderFloatingItem.java similarity index 100% rename from entity/RenderFloatingItem.java rename to src/main/java/appeng/entity/RenderFloatingItem.java diff --git a/entity/RenderTinyTNTPrimed.java b/src/main/java/appeng/entity/RenderTinyTNTPrimed.java similarity index 100% rename from entity/RenderTinyTNTPrimed.java rename to src/main/java/appeng/entity/RenderTinyTNTPrimed.java diff --git a/facade/FacadeContainer.java b/src/main/java/appeng/facade/FacadeContainer.java similarity index 96% rename from facade/FacadeContainer.java rename to src/main/java/appeng/facade/FacadeContainer.java index 3cc46c29d..58c6dc42c 100644 --- a/facade/FacadeContainer.java +++ b/src/main/java/appeng/facade/FacadeContainer.java @@ -1,197 +1,197 @@ -package appeng.facade; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.parts.IFacadeContainer; -import appeng.api.parts.IFacadePart; -import appeng.api.parts.IPartHost; -import appeng.core.AppEng; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.IBC; -import appeng.items.parts.ItemFacade; -import appeng.parts.CableBusStorage; - -public class FacadeContainer implements IFacadeContainer -{ - - final int facades = 6; - final CableBusStorage storage; - - public FacadeContainer(CableBusStorage cbs) { - storage = cbs; - } - - public void writeToStream(ByteBuf out) throws IOException - { - int facadeSides = 0; - for (int x = 0; x < facades; x++) - { - if ( getFacade( ForgeDirection.getOrientation( x ) ) != null ) - facadeSides = facadeSides | (1 << x); - } - out.writeByte( (byte) facadeSides ); - - for (int x = 0; x < facades; x++) - { - IFacadePart part = getFacade( ForgeDirection.getOrientation( x ) ); - if ( part != null ) - { - int itemID = Item.getIdFromItem( part.getItem() ); - int dmgValue = part.getItemDamage(); - out.writeInt( itemID * (part.isBC() ? -1 : 1) ); - out.writeInt( dmgValue ); - } - } - } - - public boolean readFromStream(ByteBuf out) throws IOException - { - int facadeSides = out.readByte(); - - boolean changed = false; - - int ids[] = new int[2]; - for (int x = 0; x < facades; x++) - { - ForgeDirection side = ForgeDirection.getOrientation( x ); - int ix = (1 << x); - if ( (facadeSides & ix) == ix ) - { - ids[0] = out.readInt(); - ids[1] = out.readInt(); - boolean isBC = ids[0] < 0; - ids[0] = Math.abs( ids[0] ); - - if ( isBC && AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) ) - { - IBC bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC ); - changed = changed || storage.getFacade( x ) == null; - storage.setFacade( x, bc.createFacadePart( (Block) Block.blockRegistry.getObjectById( ids[0] ), ids[1], side ) ); - } - else if ( !isBC ) - { - ItemFacade ifa = (ItemFacade) AEApi.instance().items().itemFacade.item(); - ItemStack facade = ifa.createFromInts( ids ); - if ( facade != null ) - { - changed = changed || storage.getFacade( x ) == null; - storage.setFacade( x, ifa.createPartFromItemStack( facade, side ) ); - } - } - } - else - { - changed = changed || storage.getFacade( x ) != null; - storage.setFacade( x, null ); - } - } - - return changed; - } - - public void readFromNBT(NBTTagCompound c) - { - for (int x = 0; x < facades; x++) - { - storage.setFacade( x, null ); - - NBTTagCompound t = c.getCompoundTag( "facade:" + x ); - if ( t != null ) - { - ItemStack is = ItemStack.loadItemStackFromNBT( t ); - if ( is != null ) - { - Item i = is.getItem(); - if ( i instanceof IFacadeItem ) - storage.setFacade( x, ((IFacadeItem) i).createPartFromItemStack( is, ForgeDirection.getOrientation( x ) ) ); - else - { - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) ) - { - IBC bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC ); - if ( bc.isFacade( is ) ) - storage.setFacade( x, bc.createFacadePart( is, ForgeDirection.getOrientation( x ) ) ); - } - } - } - } - } - } - - public void writeToNBT(NBTTagCompound c) - { - for (int x = 0; x < facades; x++) - { - if ( storage.getFacade( x ) != null ) - { - NBTTagCompound data = new NBTTagCompound(); - storage.getFacade( x ).getItemStack().writeToNBT( data ); - c.setTag( "facade:" + x, data ); - } - } - } - - @Override - public boolean addFacade(IFacadePart a) - { - if ( getFacade( a.getSide() ) == null ) - { - storage.setFacade( a.getSide().ordinal(), a ); - return true; - } - return false; - } - - @Override - public void removeFacade(IPartHost host, ForgeDirection side) - { - if ( side != null && side != ForgeDirection.UNKNOWN ) - { - if ( storage.getFacade( side.ordinal() ) != null ) - { - storage.setFacade( side.ordinal(), null ); - if ( host != null ) - host.markForUpdate(); - } - } - } - - @Override - public IFacadePart getFacade(ForgeDirection s) - { - return storage.getFacade( s.ordinal() ); - } - - public boolean isEmpty() - { - for (int x = 0; x < facades; x++) - if ( storage.getFacade( x ) != null ) - return false; - return true; - } - - public void rotateLeft() - { - IFacadePart newfacades[] = new FacadePart[6]; - - newfacades[ForgeDirection.UP.ordinal()] = storage.getFacade( ForgeDirection.UP.ordinal() ); - newfacades[ForgeDirection.DOWN.ordinal()] = storage.getFacade( ForgeDirection.DOWN.ordinal() ); - - newfacades[ForgeDirection.EAST.ordinal()] = storage.getFacade( ForgeDirection.NORTH.ordinal() ); - newfacades[ForgeDirection.SOUTH.ordinal()] = storage.getFacade( ForgeDirection.EAST.ordinal() ); - - newfacades[ForgeDirection.WEST.ordinal()] = storage.getFacade( ForgeDirection.SOUTH.ordinal() ); - newfacades[ForgeDirection.NORTH.ordinal()] = storage.getFacade( ForgeDirection.WEST.ordinal() ); - - for (int x = 0; x < facades; x++) - storage.setFacade( x, newfacades[x] ); - } -} +package appeng.facade; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.parts.IFacadeContainer; +import appeng.api.parts.IFacadePart; +import appeng.api.parts.IPartHost; +import appeng.core.AppEng; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.IBC; +import appeng.items.parts.ItemFacade; +import appeng.parts.CableBusStorage; + +public class FacadeContainer implements IFacadeContainer +{ + + final int facades = 6; + final CableBusStorage storage; + + public FacadeContainer(CableBusStorage cbs) { + storage = cbs; + } + + public void writeToStream(ByteBuf out) throws IOException + { + int facadeSides = 0; + for (int x = 0; x < facades; x++) + { + if ( getFacade( ForgeDirection.getOrientation( x ) ) != null ) + facadeSides = facadeSides | (1 << x); + } + out.writeByte( (byte) facadeSides ); + + for (int x = 0; x < facades; x++) + { + IFacadePart part = getFacade( ForgeDirection.getOrientation( x ) ); + if ( part != null ) + { + int itemID = Item.getIdFromItem( part.getItem() ); + int dmgValue = part.getItemDamage(); + out.writeInt( itemID * (part.isBC() ? -1 : 1) ); + out.writeInt( dmgValue ); + } + } + } + + public boolean readFromStream(ByteBuf out) throws IOException + { + int facadeSides = out.readByte(); + + boolean changed = false; + + int ids[] = new int[2]; + for (int x = 0; x < facades; x++) + { + ForgeDirection side = ForgeDirection.getOrientation( x ); + int ix = (1 << x); + if ( (facadeSides & ix) == ix ) + { + ids[0] = out.readInt(); + ids[1] = out.readInt(); + boolean isBC = ids[0] < 0; + ids[0] = Math.abs( ids[0] ); + + if ( isBC && AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) ) + { + IBC bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC ); + changed = changed || storage.getFacade( x ) == null; + storage.setFacade( x, bc.createFacadePart( (Block) Block.blockRegistry.getObjectById( ids[0] ), ids[1], side ) ); + } + else if ( !isBC ) + { + ItemFacade ifa = (ItemFacade) AEApi.instance().items().itemFacade.item(); + ItemStack facade = ifa.createFromInts( ids ); + if ( facade != null ) + { + changed = changed || storage.getFacade( x ) == null; + storage.setFacade( x, ifa.createPartFromItemStack( facade, side ) ); + } + } + } + else + { + changed = changed || storage.getFacade( x ) != null; + storage.setFacade( x, null ); + } + } + + return changed; + } + + public void readFromNBT(NBTTagCompound c) + { + for (int x = 0; x < facades; x++) + { + storage.setFacade( x, null ); + + NBTTagCompound t = c.getCompoundTag( "facade:" + x ); + if ( t != null ) + { + ItemStack is = ItemStack.loadItemStackFromNBT( t ); + if ( is != null ) + { + Item i = is.getItem(); + if ( i instanceof IFacadeItem ) + storage.setFacade( x, ((IFacadeItem) i).createPartFromItemStack( is, ForgeDirection.getOrientation( x ) ) ); + else + { + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) ) + { + IBC bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC ); + if ( bc.isFacade( is ) ) + storage.setFacade( x, bc.createFacadePart( is, ForgeDirection.getOrientation( x ) ) ); + } + } + } + } + } + } + + public void writeToNBT(NBTTagCompound c) + { + for (int x = 0; x < facades; x++) + { + if ( storage.getFacade( x ) != null ) + { + NBTTagCompound data = new NBTTagCompound(); + storage.getFacade( x ).getItemStack().writeToNBT( data ); + c.setTag( "facade:" + x, data ); + } + } + } + + @Override + public boolean addFacade(IFacadePart a) + { + if ( getFacade( a.getSide() ) == null ) + { + storage.setFacade( a.getSide().ordinal(), a ); + return true; + } + return false; + } + + @Override + public void removeFacade(IPartHost host, ForgeDirection side) + { + if ( side != null && side != ForgeDirection.UNKNOWN ) + { + if ( storage.getFacade( side.ordinal() ) != null ) + { + storage.setFacade( side.ordinal(), null ); + if ( host != null ) + host.markForUpdate(); + } + } + } + + @Override + public IFacadePart getFacade(ForgeDirection s) + { + return storage.getFacade( s.ordinal() ); + } + + public boolean isEmpty() + { + for (int x = 0; x < facades; x++) + if ( storage.getFacade( x ) != null ) + return false; + return true; + } + + public void rotateLeft() + { + IFacadePart newfacades[] = new FacadePart[6]; + + newfacades[ForgeDirection.UP.ordinal()] = storage.getFacade( ForgeDirection.UP.ordinal() ); + newfacades[ForgeDirection.DOWN.ordinal()] = storage.getFacade( ForgeDirection.DOWN.ordinal() ); + + newfacades[ForgeDirection.EAST.ordinal()] = storage.getFacade( ForgeDirection.NORTH.ordinal() ); + newfacades[ForgeDirection.SOUTH.ordinal()] = storage.getFacade( ForgeDirection.EAST.ordinal() ); + + newfacades[ForgeDirection.WEST.ordinal()] = storage.getFacade( ForgeDirection.SOUTH.ordinal() ); + newfacades[ForgeDirection.NORTH.ordinal()] = storage.getFacade( ForgeDirection.WEST.ordinal() ); + + for (int x = 0; x < facades; x++) + storage.setFacade( x, newfacades[x] ); + } +} diff --git a/facade/FacadePart.java b/src/main/java/appeng/facade/FacadePart.java similarity index 100% rename from facade/FacadePart.java rename to src/main/java/appeng/facade/FacadePart.java diff --git a/facade/IFacadeItem.java b/src/main/java/appeng/facade/IFacadeItem.java similarity index 95% rename from facade/IFacadeItem.java rename to src/main/java/appeng/facade/IFacadeItem.java index 502079a11..2994aac50 100644 --- a/facade/IFacadeItem.java +++ b/src/main/java/appeng/facade/IFacadeItem.java @@ -1,18 +1,18 @@ -package appeng.facade; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -public interface IFacadeItem -{ - - FacadePart createPartFromItemStack(ItemStack is, ForgeDirection side); - - ItemStack getTextureItem(ItemStack is); - - int getMeta(ItemStack is); - - Block getBlock(ItemStack is); - -} +package appeng.facade; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +public interface IFacadeItem +{ + + FacadePart createPartFromItemStack(ItemStack is, ForgeDirection side); + + ItemStack getTextureItem(ItemStack is); + + int getMeta(ItemStack is); + + Block getBlock(ItemStack is); + +} diff --git a/fmp/CableBusPart.java b/src/main/java/appeng/fmp/CableBusPart.java similarity index 95% rename from fmp/CableBusPart.java rename to src/main/java/appeng/fmp/CableBusPart.java index e1f14465f..1b0d9b5ac 100644 --- a/fmp/CableBusPart.java +++ b/src/main/java/appeng/fmp/CableBusPart.java @@ -1,624 +1,624 @@ -package appeng.fmp; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.implementations.parts.IPartCable; -import appeng.api.networking.IGridNode; -import appeng.api.parts.IFacadeContainer; -import appeng.api.parts.IFacadePart; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartItem; -import appeng.api.parts.LayerFlags; -import appeng.api.parts.PartItemStack; -import appeng.api.parts.SelectedPart; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.api.util.DimensionalCoord; -import appeng.client.render.BusRenderHelper; -import appeng.client.render.BusRenderer; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.features.AEFeature; -import appeng.helpers.AEMultiTile; -import appeng.parts.BusCollisionHelper; -import appeng.parts.CableBusContainer; -import appeng.parts.PartPlacement; -import appeng.tile.networking.TileCableBus; -import appeng.util.Platform; -import codechicken.lib.data.MCDataInput; -import codechicken.lib.data.MCDataOutput; -import codechicken.lib.raytracer.IndexedCuboid6; -import codechicken.lib.vec.Cuboid6; -import codechicken.lib.vec.Vector3; -import codechicken.multipart.IRedstonePart; -import codechicken.multipart.JCuboidPart; -import codechicken.multipart.JNormalOcclusion; -import codechicken.multipart.NormalOcclusionTest; -import codechicken.multipart.NormallyOccludedPart; -import codechicken.multipart.TMultiPart; -import codechicken.multipart.scalatraits.TIInventoryTile; - -/** - * Implementing these might help improve visuals for hollow covers - * - * TSlottedPart,ISidedHollowConnect - */ -public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IRedstonePart, IPartHost, AEMultiTile -{ - - final static Cuboid6 sideTests[] = new Cuboid6[] { - - new Cuboid6( 6.0 / 16.0, 0, 6.0 / 16.0, 10.0 / 16.0, 6.0 / 16.0, 10.0 / 16.0 ), // DOWN(0, -1, 0), - - new Cuboid6( 6.0 / 16.0, 10.0 / 16.0, 6.0 / 16.0, 10.0 / 16.0, 1.0, 10.0 / 16.0 ), // UP(0, 1, 0), - - new Cuboid6( 6.0 / 16.0, 6.0 / 16.0, 0.0, 10.0 / 16.0, 10.0 / 16.0, 6.0 / 16.0 ),// NORTH(0, 0, -1), - - new Cuboid6( 6.0 / 16.0, 6.0 / 16.0, 10.0 / 16.0, 10.0 / 16.0, 10.0 / 16.0, 1.0 ),// SOUTH(0, 0, 1), - - new Cuboid6( 0.0, 6.0 / 16.0, 6.0 / 16.0, 6.0 / 16.0, 10.0 / 16.0, 10.0 / 16.0 ),// WEST(-1, 0, 0), - - new Cuboid6( 10.0 / 16.0, 6.0 / 16.0, 6.0 / 16.0, 1.0, 10.0 / 16.0, 10.0 / 16.0 ),// EAST(1, 0, 0), - }; - - public static ThreadLocal disableFacadeOcclusion = new ThreadLocal(); - public CableBusContainer cb = new CableBusContainer( this ); - - @Override - public boolean isInWorld() - { - return cb.isInWorld(); - } - - @Override - public boolean doesTick() - { - return false; - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return cb.getCableConnectionType( dir ); - } - - @Override - public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) - { - return cb.recolourBlock( side, colour, who ); - } - - @Override - public AEColor getColor() - { - return cb.getColor(); - } - - @Override - public void save(NBTTagCompound tag) - { - cb.writeToNBT( tag ); - } - - @Override - public void load(NBTTagCompound tag) - { - cb.readFromNBT( tag ); - } - - @Override - public void writeDesc(MCDataOutput packet) - { - ByteBuf stream = Unpooled.buffer(); - - try - { - cb.writeToStream( stream ); - packet.writeInt( stream.readableBytes() ); - stream.capacity( stream.readableBytes() ); - packet.writeByteArray( stream.array() ); - } - catch (IOException e) - { - AELog.error( e ); - } - - } - - @Override - public void readDesc(MCDataInput packet) - { - int len = packet.readInt(); - byte data[] = packet.readByteArray( len ); - - try - { - if ( len > 0 ) - { - ByteBuf bybuff = Unpooled.wrappedBuffer( data ); - cb.readFromStream( bybuff ); - } - } - catch (IOException e) - { - AELog.error( e ); - } - } - - @Override - public Cuboid6 getBounds() - { - AxisAlignedBB b = null; - - for (AxisAlignedBB bx : cb.getSelectedBoundingBoxsFromPool( false, true, null, true )) - { - if ( b == null ) - b = bx; - else - { - double minX = Math.min( b.minX, bx.minX ); - double minY = Math.min( b.minY, bx.minY ); - double minZ = Math.min( b.minZ, bx.minZ ); - double maxX = Math.max( b.maxX, bx.maxX ); - double maxY = Math.max( b.maxY, bx.maxY ); - double maxZ = Math.max( b.maxZ, bx.maxZ ); - b.setBounds( minX, minY, minZ, maxX, maxY, maxZ ); - } - } - - if ( b == null ) - return new Cuboid6( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ); - - return new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ); - } - - @Override - public String getType() - { - return PartRegistry.CableBusPart.getName(); - } - - @Override - public void onPartChanged(TMultiPart part) - { - cb.updateConnections(); - } - - @Override - public ItemStack pickItem(MovingObjectPosition hit) - { - Vec3 v3 = hit.hitVec.addVector( -hit.blockX, -hit.blockY, -hit.blockZ ); - SelectedPart sp = cb.selectPart( v3 ); - if ( sp != null ) - { - if ( sp.part != null ) - return sp.part.getItemStack( PartItemStack.Break ); - if ( sp.facade != null ) - return sp.facade.getItemStack(); - } - return null; - } - - @Override - public Iterable getDrops() - { - return cb.getDrops( new ArrayList() ); - } - - @Override - public void onEntityCollision(Entity entity) - { - cb.onEntityCollision( entity ); - } - - @Override - public void onWorldJoin() - { - canUpdate = true; - cb.updateConnections(); - cb.addToWorld(); - } - - @Override - public void onWorldSeparate() - { - canUpdate = false; - cb.removeFromWorld(); - }; - - @Override - public boolean canConnectRedstone(int side) - { - return cb.canConnectRedstone( EnumSet.of( ForgeDirection.getOrientation( side ) ) ); - } - - @Override - public int strongPowerLevel(int side) - { - return cb.isProvidingStrongPower( ForgeDirection.getOrientation( side ) ); - } - - @Override - public int weakPowerLevel(int side) - { - return cb.isProvidingWeakPower( ForgeDirection.getOrientation( side ) ); - } - - @Override - public void onNeighborChanged() - { - cb.onNeighborChanged(); - } - - @Override - public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item) - { - return cb.activate( player, hit.hitVec.addVector( -hit.blockX, -hit.blockY, -hit.blockZ ) ); - } - - @Override - public void renderDynamic(Vector3 pos, float frame, int pass) - { - if ( pass == 0 || (pass == 1 && AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass )) ) - { - BusRenderHelper.instance.setPass( pass ); - cb.renderDynamic( pos.x, pos.y, pos.z ); - } - } - - @Override - public boolean renderStatic(Vector3 pos, int pass) - { - if ( pass == 0 || (pass == 1 && AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass )) ) - { - BusRenderHelper.instance.setPass( pass ); - BusRenderer.instance.renderer.renderAllFaces = true; - BusRenderer.instance.renderer.blockAccess = world(); - BusRenderer.instance.renderer.overrideBlockTexture = null; - cb.renderStatic( pos.x, pos.y, pos.z ); - return BusRenderHelper.instance.getItemsRendered() > 0; - } - return false; - } - - @Override - public int getLightValue() - { - return cb.getLightValue(); - } - - @Override - public boolean canAddPart(ItemStack is, ForgeDirection side) - { - IFacadePart fp = PartPlacement.isFacade( is, side ); - if ( fp != null ) - { - if ( !(side == null || side == ForgeDirection.UNKNOWN || tile() == null) ) - { - List boxes = new ArrayList(); - IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); - fp.getBoxes( bch, null ); - for (AxisAlignedBB bb : boxes) - { - disableFacadeOcclusion.set( true ); - boolean canAdd = tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) ); - disableFacadeOcclusion.remove(); - if ( !canAdd ) - { - return false; - } - } - } - return true; - } - - if ( is.getItem() instanceof IPartItem ) - { - IPartItem bi = (IPartItem) is.getItem(); - - is = is.copy(); - is.stackSize = 1; - - IPart bp = bi.createPartFromItemStack( is ); - if ( !(side == null || side == ForgeDirection.UNKNOWN || tile() == null) ) - { - List boxes = new ArrayList(); - IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); - bp.getBoxes( bch ); - for (AxisAlignedBB bb : boxes) - { - if ( !tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) ) ) - { - return false; - } - } - } - } - - return cb.canAddPart( is, side ); - } - - @Override - public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer owner) - { - return cb.addPart( is, side, owner ); - } - - @Override - public IPart getPart(ForgeDirection side) - { - return cb.getPart( side ); - } - - @Override - public void removePart(ForgeDirection side, boolean suppressUpdate) - { - cb.removePart( side, suppressUpdate ); - } - - boolean canUpdate = false; - - @Override - public void markForUpdate() - { - if ( Platform.isServer() && canUpdate ) - sendDescUpdate(); - } - - @Override - public DimensionalCoord getLocation() - { - return new DimensionalCoord( getTile() ); - } - - @Override - public void invalidateConvertedTile() - { - cb.setHost( this ); - } - - public void convertFromTile(TileEntity blockTileEntity) - { - TileCableBus tcb = (TileCableBus) blockTileEntity; - cb = tcb.cb; - } - - @Override - public boolean occlusionTest(TMultiPart npart) - { - return NormalOcclusionTest.apply( this, npart ); - } - - @Override - public Iterable getCollisionBoxes() - { - LinkedList l = new LinkedList(); - for (AxisAlignedBB b : cb.getSelectedBoundingBoxsFromPool( false, true, null, false )) - { - l.add( new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ) ); - } - return l; - - } - - @Override - public Iterable getSubParts() - { - LinkedList l = new LinkedList(); - for (Cuboid6 c : getCollisionBoxes()) - { - l.add( new IndexedCuboid6( 0, c ) ); - } - return l; - } - - @Override - public Iterable getOcclusionBoxes() - { - LinkedList l = new LinkedList(); - for (AxisAlignedBB b : cb.getSelectedBoundingBoxsFromPool( true, disableFacadeOcclusion.get() == null, null, true )) - { - l.add( new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ) ); - } - return l; - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) - { - return cb.getGridNode( dir ); - } - - @Override - public IFacadeContainer getFacadeContainer() - { - return cb.getFacadeContainer(); - } - - @Override - public void clearContainer() - { - cb = new CableBusContainer( this ); - } - - @Override - public boolean isBlocked(ForgeDirection side) - { - if ( side == null || side == ForgeDirection.UNKNOWN || tile() == null ) - return false; - - disableFacadeOcclusion.set( true ); - boolean blocked = !tile().canAddPart( new NormallyOccludedPart( sideTests[side.ordinal()] ) ); - disableFacadeOcclusion.remove(); - - return blocked; - } - - @Override - public SelectedPart selectPart(Vec3 pos) - { - return cb.selectPart( pos ); - } - - @Override - public void partChanged() - { - if ( isInWorld() ) - notifyNeighbors(); - } - - @Override - public Set getLayerFlags() - { - return cb.getLayerFlags(); - } - - @Override - public void markForSave() - { - // mark the chunk for save... - TileEntity te = getTile(); - if ( te != null && te.getWorldObj() != null ) - te.getWorldObj().getChunkFromBlockCoords( x(), z() ).isModified = true; - } - - @Override - public boolean hasRedstone(ForgeDirection side) - { - return cb.hasRedstone( side ); - } - - @Override - public void securityBreak() - { - cb.securityBreak(); - } - - @Override - public boolean isEmpty() - { - return cb.isEmpty(); - } - - @Override - public void cleanup() - { - tile().remPart( this ); - } - - @Override - public void notifyNeighbors() - { - if ( tile() instanceof TIInventoryTile ) - ((TIInventoryTile) tile()).rebuildSlotMap(); - - if ( world() != null && world().blockExists( x(), y(), z() ) && !CableBusContainer.isLoading() ) - Platform.notifyBlocksOfNeighbors(world(), x(), y(), z() ); - } - - // @Override - public int getHollowSize(int side) - { - IPartCable cable = (IPartCable) getPart( ForgeDirection.UNKNOWN ); - - ForgeDirection dir = ForgeDirection.getOrientation( side ); - if ( cable != null && cable.isConnected( dir ) ) - { - List boxes = new ArrayList(); - - BusCollisionHelper bch = new BusCollisionHelper( boxes, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH, null, true ); - - for (ForgeDirection whichSide : ForgeDirection.values()) - { - IPart fPart = getPart( whichSide ); - - if ( fPart != null ) - fPart.getBoxes( bch ); - } - - AxisAlignedBB b = null; - AxisAlignedBB pb = Platform.getPrimaryBox( dir, 2 ); - - for (AxisAlignedBB bb : boxes) - { - if ( bb.intersectsWith( pb ) ) - { - if ( b == null ) - b = bb; - else - { - b.maxX = Math.max( b.maxX, bb.maxX ); - b.maxY = Math.max( b.maxY, bb.maxY ); - b.maxZ = Math.max( b.maxZ, bb.maxZ ); - b.minX = Math.min( b.minX, bb.minX ); - b.minY = Math.min( b.minY, bb.minY ); - b.minZ = Math.min( b.minZ, bb.minZ ); - } - } - } - - if ( b == null ) - return 0; - - switch (dir) - { - case WEST: - case EAST: - return getSize( b.minZ, b.maxZ, b.minY, b.maxY ); - case DOWN: - case NORTH: - return getSize( b.minX, b.maxX, b.minZ, b.maxZ ); - case SOUTH: - case UP: - return getSize( b.minX, b.maxX, b.minY, b.maxY ); - default: - } - } - - return 12; - } - - int getSize(double a, double b, double c, double d) - { - double r = Math.abs( a - 0.5 ); - r = Math.max( Math.abs( b - 0.5 ), r ); - r = Math.max( Math.abs( c - 0.5 ), r ); - return (8 * (int) Math.max( Math.abs( d - 0.5 ), r )); - } - - // @Override - public int getSlotMask() - { - int mask = 0; - - for (ForgeDirection side : ForgeDirection.values()) - { - if ( getPart( side ) != null ) - mask |= 1 << side.ordinal(); - else if ( side != ForgeDirection.UNKNOWN && getFacadeContainer().getFacade( side ) != null ) - mask |= 1 << side.ordinal(); - } - - return mask; - } - -} +package appeng.fmp; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.implementations.parts.IPartCable; +import appeng.api.networking.IGridNode; +import appeng.api.parts.IFacadeContainer; +import appeng.api.parts.IFacadePart; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartItem; +import appeng.api.parts.LayerFlags; +import appeng.api.parts.PartItemStack; +import appeng.api.parts.SelectedPart; +import appeng.api.util.AECableType; +import appeng.api.util.AEColor; +import appeng.api.util.DimensionalCoord; +import appeng.client.render.BusRenderHelper; +import appeng.client.render.BusRenderer; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.features.AEFeature; +import appeng.helpers.AEMultiTile; +import appeng.parts.BusCollisionHelper; +import appeng.parts.CableBusContainer; +import appeng.parts.PartPlacement; +import appeng.tile.networking.TileCableBus; +import appeng.util.Platform; +import codechicken.lib.data.MCDataInput; +import codechicken.lib.data.MCDataOutput; +import codechicken.lib.raytracer.IndexedCuboid6; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Vector3; +import codechicken.multipart.IRedstonePart; +import codechicken.multipart.JCuboidPart; +import codechicken.multipart.JNormalOcclusion; +import codechicken.multipart.NormalOcclusionTest; +import codechicken.multipart.NormallyOccludedPart; +import codechicken.multipart.TMultiPart; +import codechicken.multipart.scalatraits.TIInventoryTile; + +/** + * Implementing these might help improve visuals for hollow covers + * + * TSlottedPart,ISidedHollowConnect + */ +public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IRedstonePart, IPartHost, AEMultiTile +{ + + final static Cuboid6 sideTests[] = new Cuboid6[] { + + new Cuboid6( 6.0 / 16.0, 0, 6.0 / 16.0, 10.0 / 16.0, 6.0 / 16.0, 10.0 / 16.0 ), // DOWN(0, -1, 0), + + new Cuboid6( 6.0 / 16.0, 10.0 / 16.0, 6.0 / 16.0, 10.0 / 16.0, 1.0, 10.0 / 16.0 ), // UP(0, 1, 0), + + new Cuboid6( 6.0 / 16.0, 6.0 / 16.0, 0.0, 10.0 / 16.0, 10.0 / 16.0, 6.0 / 16.0 ),// NORTH(0, 0, -1), + + new Cuboid6( 6.0 / 16.0, 6.0 / 16.0, 10.0 / 16.0, 10.0 / 16.0, 10.0 / 16.0, 1.0 ),// SOUTH(0, 0, 1), + + new Cuboid6( 0.0, 6.0 / 16.0, 6.0 / 16.0, 6.0 / 16.0, 10.0 / 16.0, 10.0 / 16.0 ),// WEST(-1, 0, 0), + + new Cuboid6( 10.0 / 16.0, 6.0 / 16.0, 6.0 / 16.0, 1.0, 10.0 / 16.0, 10.0 / 16.0 ),// EAST(1, 0, 0), + }; + + public static ThreadLocal disableFacadeOcclusion = new ThreadLocal(); + public CableBusContainer cb = new CableBusContainer( this ); + + @Override + public boolean isInWorld() + { + return cb.isInWorld(); + } + + @Override + public boolean doesTick() + { + return false; + } + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return cb.getCableConnectionType( dir ); + } + + @Override + public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) + { + return cb.recolourBlock( side, colour, who ); + } + + @Override + public AEColor getColor() + { + return cb.getColor(); + } + + @Override + public void save(NBTTagCompound tag) + { + cb.writeToNBT( tag ); + } + + @Override + public void load(NBTTagCompound tag) + { + cb.readFromNBT( tag ); + } + + @Override + public void writeDesc(MCDataOutput packet) + { + ByteBuf stream = Unpooled.buffer(); + + try + { + cb.writeToStream( stream ); + packet.writeInt( stream.readableBytes() ); + stream.capacity( stream.readableBytes() ); + packet.writeByteArray( stream.array() ); + } + catch (IOException e) + { + AELog.error( e ); + } + + } + + @Override + public void readDesc(MCDataInput packet) + { + int len = packet.readInt(); + byte data[] = packet.readByteArray( len ); + + try + { + if ( len > 0 ) + { + ByteBuf bybuff = Unpooled.wrappedBuffer( data ); + cb.readFromStream( bybuff ); + } + } + catch (IOException e) + { + AELog.error( e ); + } + } + + @Override + public Cuboid6 getBounds() + { + AxisAlignedBB b = null; + + for (AxisAlignedBB bx : cb.getSelectedBoundingBoxsFromPool( false, true, null, true )) + { + if ( b == null ) + b = bx; + else + { + double minX = Math.min( b.minX, bx.minX ); + double minY = Math.min( b.minY, bx.minY ); + double minZ = Math.min( b.minZ, bx.minZ ); + double maxX = Math.max( b.maxX, bx.maxX ); + double maxY = Math.max( b.maxY, bx.maxY ); + double maxZ = Math.max( b.maxZ, bx.maxZ ); + b.setBounds( minX, minY, minZ, maxX, maxY, maxZ ); + } + } + + if ( b == null ) + return new Cuboid6( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ); + + return new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ); + } + + @Override + public String getType() + { + return PartRegistry.CableBusPart.getName(); + } + + @Override + public void onPartChanged(TMultiPart part) + { + cb.updateConnections(); + } + + @Override + public ItemStack pickItem(MovingObjectPosition hit) + { + Vec3 v3 = hit.hitVec.addVector( -hit.blockX, -hit.blockY, -hit.blockZ ); + SelectedPart sp = cb.selectPart( v3 ); + if ( sp != null ) + { + if ( sp.part != null ) + return sp.part.getItemStack( PartItemStack.Break ); + if ( sp.facade != null ) + return sp.facade.getItemStack(); + } + return null; + } + + @Override + public Iterable getDrops() + { + return cb.getDrops( new ArrayList() ); + } + + @Override + public void onEntityCollision(Entity entity) + { + cb.onEntityCollision( entity ); + } + + @Override + public void onWorldJoin() + { + canUpdate = true; + cb.updateConnections(); + cb.addToWorld(); + } + + @Override + public void onWorldSeparate() + { + canUpdate = false; + cb.removeFromWorld(); + }; + + @Override + public boolean canConnectRedstone(int side) + { + return cb.canConnectRedstone( EnumSet.of( ForgeDirection.getOrientation( side ) ) ); + } + + @Override + public int strongPowerLevel(int side) + { + return cb.isProvidingStrongPower( ForgeDirection.getOrientation( side ) ); + } + + @Override + public int weakPowerLevel(int side) + { + return cb.isProvidingWeakPower( ForgeDirection.getOrientation( side ) ); + } + + @Override + public void onNeighborChanged() + { + cb.onNeighborChanged(); + } + + @Override + public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item) + { + return cb.activate( player, hit.hitVec.addVector( -hit.blockX, -hit.blockY, -hit.blockZ ) ); + } + + @Override + public void renderDynamic(Vector3 pos, float frame, int pass) + { + if ( pass == 0 || (pass == 1 && AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass )) ) + { + BusRenderHelper.instance.setPass( pass ); + cb.renderDynamic( pos.x, pos.y, pos.z ); + } + } + + @Override + public boolean renderStatic(Vector3 pos, int pass) + { + if ( pass == 0 || (pass == 1 && AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass )) ) + { + BusRenderHelper.instance.setPass( pass ); + BusRenderer.instance.renderer.renderAllFaces = true; + BusRenderer.instance.renderer.blockAccess = world(); + BusRenderer.instance.renderer.overrideBlockTexture = null; + cb.renderStatic( pos.x, pos.y, pos.z ); + return BusRenderHelper.instance.getItemsRendered() > 0; + } + return false; + } + + @Override + public int getLightValue() + { + return cb.getLightValue(); + } + + @Override + public boolean canAddPart(ItemStack is, ForgeDirection side) + { + IFacadePart fp = PartPlacement.isFacade( is, side ); + if ( fp != null ) + { + if ( !(side == null || side == ForgeDirection.UNKNOWN || tile() == null) ) + { + List boxes = new ArrayList(); + IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); + fp.getBoxes( bch, null ); + for (AxisAlignedBB bb : boxes) + { + disableFacadeOcclusion.set( true ); + boolean canAdd = tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) ); + disableFacadeOcclusion.remove(); + if ( !canAdd ) + { + return false; + } + } + } + return true; + } + + if ( is.getItem() instanceof IPartItem ) + { + IPartItem bi = (IPartItem) is.getItem(); + + is = is.copy(); + is.stackSize = 1; + + IPart bp = bi.createPartFromItemStack( is ); + if ( !(side == null || side == ForgeDirection.UNKNOWN || tile() == null) ) + { + List boxes = new ArrayList(); + IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); + bp.getBoxes( bch ); + for (AxisAlignedBB bb : boxes) + { + if ( !tile().canAddPart( new NormallyOccludedPart( new Cuboid6( bb ) ) ) ) + { + return false; + } + } + } + } + + return cb.canAddPart( is, side ); + } + + @Override + public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer owner) + { + return cb.addPart( is, side, owner ); + } + + @Override + public IPart getPart(ForgeDirection side) + { + return cb.getPart( side ); + } + + @Override + public void removePart(ForgeDirection side, boolean suppressUpdate) + { + cb.removePart( side, suppressUpdate ); + } + + boolean canUpdate = false; + + @Override + public void markForUpdate() + { + if ( Platform.isServer() && canUpdate ) + sendDescUpdate(); + } + + @Override + public DimensionalCoord getLocation() + { + return new DimensionalCoord( getTile() ); + } + + @Override + public void invalidateConvertedTile() + { + cb.setHost( this ); + } + + public void convertFromTile(TileEntity blockTileEntity) + { + TileCableBus tcb = (TileCableBus) blockTileEntity; + cb = tcb.cb; + } + + @Override + public boolean occlusionTest(TMultiPart npart) + { + return NormalOcclusionTest.apply( this, npart ); + } + + @Override + public Iterable getCollisionBoxes() + { + LinkedList l = new LinkedList(); + for (AxisAlignedBB b : cb.getSelectedBoundingBoxsFromPool( false, true, null, false )) + { + l.add( new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ) ); + } + return l; + + } + + @Override + public Iterable getSubParts() + { + LinkedList l = new LinkedList(); + for (Cuboid6 c : getCollisionBoxes()) + { + l.add( new IndexedCuboid6( 0, c ) ); + } + return l; + } + + @Override + public Iterable getOcclusionBoxes() + { + LinkedList l = new LinkedList(); + for (AxisAlignedBB b : cb.getSelectedBoundingBoxsFromPool( true, disableFacadeOcclusion.get() == null, null, true )) + { + l.add( new Cuboid6( b.minX, b.minY, b.minZ, b.maxX, b.maxY, b.maxZ ) ); + } + return l; + } + + @Override + public IGridNode getGridNode(ForgeDirection dir) + { + return cb.getGridNode( dir ); + } + + @Override + public IFacadeContainer getFacadeContainer() + { + return cb.getFacadeContainer(); + } + + @Override + public void clearContainer() + { + cb = new CableBusContainer( this ); + } + + @Override + public boolean isBlocked(ForgeDirection side) + { + if ( side == null || side == ForgeDirection.UNKNOWN || tile() == null ) + return false; + + disableFacadeOcclusion.set( true ); + boolean blocked = !tile().canAddPart( new NormallyOccludedPart( sideTests[side.ordinal()] ) ); + disableFacadeOcclusion.remove(); + + return blocked; + } + + @Override + public SelectedPart selectPart(Vec3 pos) + { + return cb.selectPart( pos ); + } + + @Override + public void partChanged() + { + if ( isInWorld() ) + notifyNeighbors(); + } + + @Override + public Set getLayerFlags() + { + return cb.getLayerFlags(); + } + + @Override + public void markForSave() + { + // mark the chunk for save... + TileEntity te = getTile(); + if ( te != null && te.getWorldObj() != null ) + te.getWorldObj().getChunkFromBlockCoords( x(), z() ).isModified = true; + } + + @Override + public boolean hasRedstone(ForgeDirection side) + { + return cb.hasRedstone( side ); + } + + @Override + public void securityBreak() + { + cb.securityBreak(); + } + + @Override + public boolean isEmpty() + { + return cb.isEmpty(); + } + + @Override + public void cleanup() + { + tile().remPart( this ); + } + + @Override + public void notifyNeighbors() + { + if ( tile() instanceof TIInventoryTile ) + ((TIInventoryTile) tile()).rebuildSlotMap(); + + if ( world() != null && world().blockExists( x(), y(), z() ) && !CableBusContainer.isLoading() ) + Platform.notifyBlocksOfNeighbors(world(), x(), y(), z() ); + } + + // @Override + public int getHollowSize(int side) + { + IPartCable cable = (IPartCable) getPart( ForgeDirection.UNKNOWN ); + + ForgeDirection dir = ForgeDirection.getOrientation( side ); + if ( cable != null && cable.isConnected( dir ) ) + { + List boxes = new ArrayList(); + + BusCollisionHelper bch = new BusCollisionHelper( boxes, ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH, null, true ); + + for (ForgeDirection whichSide : ForgeDirection.values()) + { + IPart fPart = getPart( whichSide ); + + if ( fPart != null ) + fPart.getBoxes( bch ); + } + + AxisAlignedBB b = null; + AxisAlignedBB pb = Platform.getPrimaryBox( dir, 2 ); + + for (AxisAlignedBB bb : boxes) + { + if ( bb.intersectsWith( pb ) ) + { + if ( b == null ) + b = bb; + else + { + b.maxX = Math.max( b.maxX, bb.maxX ); + b.maxY = Math.max( b.maxY, bb.maxY ); + b.maxZ = Math.max( b.maxZ, bb.maxZ ); + b.minX = Math.min( b.minX, bb.minX ); + b.minY = Math.min( b.minY, bb.minY ); + b.minZ = Math.min( b.minZ, bb.minZ ); + } + } + } + + if ( b == null ) + return 0; + + switch (dir) + { + case WEST: + case EAST: + return getSize( b.minZ, b.maxZ, b.minY, b.maxY ); + case DOWN: + case NORTH: + return getSize( b.minX, b.maxX, b.minZ, b.maxZ ); + case SOUTH: + case UP: + return getSize( b.minX, b.maxX, b.minY, b.maxY ); + default: + } + } + + return 12; + } + + int getSize(double a, double b, double c, double d) + { + double r = Math.abs( a - 0.5 ); + r = Math.max( Math.abs( b - 0.5 ), r ); + r = Math.max( Math.abs( c - 0.5 ), r ); + return (8 * (int) Math.max( Math.abs( d - 0.5 ), r )); + } + + // @Override + public int getSlotMask() + { + int mask = 0; + + for (ForgeDirection side : ForgeDirection.values()) + { + if ( getPart( side ) != null ) + mask |= 1 << side.ordinal(); + else if ( side != ForgeDirection.UNKNOWN && getFacadeContainer().getFacade( side ) != null ) + mask |= 1 << side.ordinal(); + } + + return mask; + } + +} diff --git a/fmp/FMPEvent.java b/src/main/java/appeng/fmp/FMPEvent.java similarity index 96% rename from fmp/FMPEvent.java rename to src/main/java/appeng/fmp/FMPEvent.java index 40750b1c1..876827729 100644 --- a/fmp/FMPEvent.java +++ b/src/main/java/appeng/fmp/FMPEvent.java @@ -1,140 +1,140 @@ -package appeng.fmp; - -import java.io.IOException; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockFence; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.world.World; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; -import appeng.block.AEBaseItemBlock; -import appeng.core.AELog; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketMultiPart; -import appeng.integration.modules.helpers.FMPPacketEvent; -import codechicken.lib.packet.PacketCustom; -import codechicken.lib.raytracer.RayTracer; -import codechicken.lib.vec.BlockCoord; -import codechicken.lib.vec.Vector3; -import codechicken.multipart.TMultiPart; -import codechicken.multipart.TileMultipart; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; - -/** - * Basically a total rip of of the FMP version for vanilla, seemed to work well enough... - */ -public class FMPEvent -{ - - private ThreadLocal placing = new ThreadLocal(); - - @SubscribeEvent - public void ServerFMPEvent(FMPPacketEvent event) - { - FMPEvent.place( event.sender, event.sender.worldObj ); - } - - @SubscribeEvent - public void playerInteract(PlayerInteractEvent event) - { - if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote ) - { - if ( placing.get() != null ) - return; - placing.set( event ); - if ( place( event.entityPlayer, event.entityPlayer.worldObj ) ) - event.setCanceled( true ); - placing.set( null ); - } - } - - public static boolean place(EntityPlayer player, World world) - { - MovingObjectPosition hit = RayTracer.reTrace( world, player ); - if ( hit == null ) - return false; - - BlockCoord pos = new BlockCoord( hit.blockX, hit.blockY, hit.blockZ ).offset( hit.sideHit ); - ItemStack held = player.getHeldItem(); - TMultiPart part = null; - - Block blk = null; - - if ( held == null ) - return false; - - if ( held.getItem() instanceof AEBaseItemBlock ) - { - AEBaseItemBlock ib = (AEBaseItemBlock) held.getItem(); - blk = Block.getBlockFromItem( ib ); - part = PartRegistry.getPartByBlock( blk, hit.sideHit ); - } - - if ( part == null ) - return false; - - if ( world.isRemote && !player.isSneaking() )// attempt to use block activated like normal and tell the server - // the right stuff - { - Vector3 f = new Vector3( hit.hitVec ).add( -hit.blockX, -hit.blockY, -hit.blockZ ); - Block block = world.getBlock( hit.blockX, hit.blockY, hit.blockZ ); - if ( block != null && !ignoreActivate( block ) - && block.onBlockActivated( world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float) f.x, (float) f.y, (float) f.z ) ) - { - player.swingItem(); - PacketCustom.sendToServer( new C08PacketPlayerBlockPlacement( hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory - .getCurrentItem(), (float) f.x, (float) f.y, (float) f.z ) ); - return true; - } - } - - TileMultipart tile = TileMultipart.getOrConvertTile( world, pos ); - if ( tile == null || !tile.canAddPart( part ) ) - return false; - - if ( !world.isRemote ) - { - TileMultipart.addPart( world, pos, part ); - world.playSoundEffect( pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, blk.stepSound.func_150496_b(), (blk.stepSound.getVolume() + 1.0F) / 2.0F, - blk.stepSound.getPitch() * 0.8F ); - if ( !player.capabilities.isCreativeMode ) - { - held.stackSize--; - if ( held.stackSize == 0 ) - { - player.inventory.mainInventory[player.inventory.currentItem] = null; - MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) ); - } - } - } - else - { - player.swingItem(); - try - { - NetworkHandler.instance.sendToServer( new PacketMultiPart() ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - return true; - } - - /** - * Because vanilla is weird. - */ - private static boolean ignoreActivate(Block block) - { - if ( block instanceof BlockFence ) - return true; - return false; - } -} +package appeng.fmp; + +import java.io.IOException; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockFence; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; +import appeng.block.AEBaseItemBlock; +import appeng.core.AELog; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketMultiPart; +import appeng.integration.modules.helpers.FMPPacketEvent; +import codechicken.lib.packet.PacketCustom; +import codechicken.lib.raytracer.RayTracer; +import codechicken.lib.vec.BlockCoord; +import codechicken.lib.vec.Vector3; +import codechicken.multipart.TMultiPart; +import codechicken.multipart.TileMultipart; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +/** + * Basically a total rip of of the FMP version for vanilla, seemed to work well enough... + */ +public class FMPEvent +{ + + private ThreadLocal placing = new ThreadLocal(); + + @SubscribeEvent + public void ServerFMPEvent(FMPPacketEvent event) + { + FMPEvent.place( event.sender, event.sender.worldObj ); + } + + @SubscribeEvent + public void playerInteract(PlayerInteractEvent event) + { + if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote ) + { + if ( placing.get() != null ) + return; + placing.set( event ); + if ( place( event.entityPlayer, event.entityPlayer.worldObj ) ) + event.setCanceled( true ); + placing.set( null ); + } + } + + public static boolean place(EntityPlayer player, World world) + { + MovingObjectPosition hit = RayTracer.reTrace( world, player ); + if ( hit == null ) + return false; + + BlockCoord pos = new BlockCoord( hit.blockX, hit.blockY, hit.blockZ ).offset( hit.sideHit ); + ItemStack held = player.getHeldItem(); + TMultiPart part = null; + + Block blk = null; + + if ( held == null ) + return false; + + if ( held.getItem() instanceof AEBaseItemBlock ) + { + AEBaseItemBlock ib = (AEBaseItemBlock) held.getItem(); + blk = Block.getBlockFromItem( ib ); + part = PartRegistry.getPartByBlock( blk, hit.sideHit ); + } + + if ( part == null ) + return false; + + if ( world.isRemote && !player.isSneaking() )// attempt to use block activated like normal and tell the server + // the right stuff + { + Vector3 f = new Vector3( hit.hitVec ).add( -hit.blockX, -hit.blockY, -hit.blockZ ); + Block block = world.getBlock( hit.blockX, hit.blockY, hit.blockZ ); + if ( block != null && !ignoreActivate( block ) + && block.onBlockActivated( world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float) f.x, (float) f.y, (float) f.z ) ) + { + player.swingItem(); + PacketCustom.sendToServer( new C08PacketPlayerBlockPlacement( hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory + .getCurrentItem(), (float) f.x, (float) f.y, (float) f.z ) ); + return true; + } + } + + TileMultipart tile = TileMultipart.getOrConvertTile( world, pos ); + if ( tile == null || !tile.canAddPart( part ) ) + return false; + + if ( !world.isRemote ) + { + TileMultipart.addPart( world, pos, part ); + world.playSoundEffect( pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, blk.stepSound.func_150496_b(), (blk.stepSound.getVolume() + 1.0F) / 2.0F, + blk.stepSound.getPitch() * 0.8F ); + if ( !player.capabilities.isCreativeMode ) + { + held.stackSize--; + if ( held.stackSize == 0 ) + { + player.inventory.mainInventory[player.inventory.currentItem] = null; + MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) ); + } + } + } + else + { + player.swingItem(); + try + { + NetworkHandler.instance.sendToServer( new PacketMultiPart() ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + return true; + } + + /** + * Because vanilla is weird. + */ + private static boolean ignoreActivate(Block block) + { + if ( block instanceof BlockFence ) + return true; + return false; + } +} diff --git a/fmp/FMPPlacementHelper.java b/src/main/java/appeng/fmp/FMPPlacementHelper.java similarity index 100% rename from fmp/FMPPlacementHelper.java rename to src/main/java/appeng/fmp/FMPPlacementHelper.java diff --git a/fmp/PartRegistry.java b/src/main/java/appeng/fmp/PartRegistry.java similarity index 95% rename from fmp/PartRegistry.java rename to src/main/java/appeng/fmp/PartRegistry.java index 7e4f450f5..5eba67119 100644 --- a/fmp/PartRegistry.java +++ b/src/main/java/appeng/fmp/PartRegistry.java @@ -1,78 +1,78 @@ -package appeng.fmp; - -import net.minecraft.block.Block; -import appeng.block.AEBaseBlock; -import appeng.block.misc.BlockQuartzTorch; -import appeng.block.networking.BlockCableBus; -import appeng.core.Api; -import codechicken.multipart.TMultiPart; - -public enum PartRegistry -{ - QuartzTorchPart("ae2_torch", BlockQuartzTorch.class, QuartzTorchPart.class), CableBusPart("ae2_cablebus", BlockCableBus.class, CableBusPart.class); - - final private String name; - final private Class blk; - final private Class part; - - public String getName() - { - return name; - } - - private PartRegistry(String name, Class blk, Class part) { - this.name = name; - this.blk = blk; - this.part = part; - } - - public TMultiPart construct(int meta) - { - try - { - if ( this == CableBusPart ) - return (TMultiPart) Api.instance.partHelper.getCombinedInstance( part.getName() ).newInstance(); - else - return part.getConstructor( int.class ).newInstance( meta ); - } - catch (Throwable t) - { - throw new RuntimeException( t ); - } - } - - public static String getPartName(TMultiPart part) - { - Class c = part.getClass(); - for (PartRegistry pr : values()) - { - if ( pr.equals( c ) ) - return pr.getName(); - } - throw new RuntimeException( "Invalid PartName" ); - } - - public static TMultiPart getPartByBlock(Block block, int meta) - { - for (PartRegistry pr : values()) - { - if ( pr.blk.isInstance( block ) ) - { - return pr.construct( meta ); - } - } - return null; - } - - public static boolean isPart(Block block) - { - for (PartRegistry pr : values()) - { - if ( pr.blk.isInstance( block ) ) - { - return true; - } - } - return false; - } -} +package appeng.fmp; + +import net.minecraft.block.Block; +import appeng.block.AEBaseBlock; +import appeng.block.misc.BlockQuartzTorch; +import appeng.block.networking.BlockCableBus; +import appeng.core.Api; +import codechicken.multipart.TMultiPart; + +public enum PartRegistry +{ + QuartzTorchPart("ae2_torch", BlockQuartzTorch.class, QuartzTorchPart.class), CableBusPart("ae2_cablebus", BlockCableBus.class, CableBusPart.class); + + final private String name; + final private Class blk; + final private Class part; + + public String getName() + { + return name; + } + + private PartRegistry(String name, Class blk, Class part) { + this.name = name; + this.blk = blk; + this.part = part; + } + + public TMultiPart construct(int meta) + { + try + { + if ( this == CableBusPart ) + return (TMultiPart) Api.instance.partHelper.getCombinedInstance( part.getName() ).newInstance(); + else + return part.getConstructor( int.class ).newInstance( meta ); + } + catch (Throwable t) + { + throw new RuntimeException( t ); + } + } + + public static String getPartName(TMultiPart part) + { + Class c = part.getClass(); + for (PartRegistry pr : values()) + { + if ( pr.equals( c ) ) + return pr.getName(); + } + throw new RuntimeException( "Invalid PartName" ); + } + + public static TMultiPart getPartByBlock(Block block, int meta) + { + for (PartRegistry pr : values()) + { + if ( pr.blk.isInstance( block ) ) + { + return pr.construct( meta ); + } + } + return null; + } + + public static boolean isPart(Block block) + { + for (PartRegistry pr : values()) + { + if ( pr.blk.isInstance( block ) ) + { + return true; + } + } + return false; + } +} diff --git a/fmp/QuartzTorchPart.java b/src/main/java/appeng/fmp/QuartzTorchPart.java similarity index 95% rename from fmp/QuartzTorchPart.java rename to src/main/java/appeng/fmp/QuartzTorchPart.java index 9cf227567..ed75cf056 100644 --- a/fmp/QuartzTorchPart.java +++ b/src/main/java/appeng/fmp/QuartzTorchPart.java @@ -1,81 +1,81 @@ -package appeng.fmp; - -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import codechicken.lib.vec.BlockCoord; -import codechicken.lib.vec.Cuboid6; -import codechicken.multipart.IRandomDisplayTick; -import codechicken.multipart.minecraft.McBlockPart; -import codechicken.multipart.minecraft.McSidedMetaPart; - -public class QuartzTorchPart extends McSidedMetaPart implements IRandomDisplayTick -{ - - public QuartzTorchPart() { - this( ForgeDirection.DOWN.ordinal() ); - } - - public QuartzTorchPart(int meta) { - super( meta ); - } - - @Override - public boolean doesTick() - { - return false; - } - - @Override - public Block getBlock() - { - return AEApi.instance().blocks().blockQuartzTorch.block(); - } - - @Override - public String getType() - { - return PartRegistry.QuartzTorchPart.getName(); - } - - @Override - public Cuboid6 getBounds() - { - return getBounds( meta ); - } - - public Cuboid6 getBounds(int meta) - { - ForgeDirection up = ForgeDirection.getOrientation( meta ); - double xOff = -0.3 * up.offsetX; - double yOff = -0.3 * up.offsetY; - double zOff = -0.3 * up.offsetZ; - return new Cuboid6( xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7 ); - } - - @Override - public int sideForMeta(int meta) - { - return ForgeDirection.getOrientation( meta ).getOpposite().ordinal(); - } - - public static McBlockPart placement(World world, BlockCoord pos, int side) - { - pos = pos.copy().offset( side ); - if ( !world.isSideSolid( pos.x, pos.y, pos.z, ForgeDirection.getOrientation( side ) ) ) - { - return null; - } - - return new QuartzTorchPart( side ); - } - - @Override - public void randomDisplayTick(Random r) - { - getBlock().randomDisplayTick( world(), x(), y(), z(), r ); - } +package appeng.fmp; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import codechicken.lib.vec.BlockCoord; +import codechicken.lib.vec.Cuboid6; +import codechicken.multipart.IRandomDisplayTick; +import codechicken.multipart.minecraft.McBlockPart; +import codechicken.multipart.minecraft.McSidedMetaPart; + +public class QuartzTorchPart extends McSidedMetaPart implements IRandomDisplayTick +{ + + public QuartzTorchPart() { + this( ForgeDirection.DOWN.ordinal() ); + } + + public QuartzTorchPart(int meta) { + super( meta ); + } + + @Override + public boolean doesTick() + { + return false; + } + + @Override + public Block getBlock() + { + return AEApi.instance().blocks().blockQuartzTorch.block(); + } + + @Override + public String getType() + { + return PartRegistry.QuartzTorchPart.getName(); + } + + @Override + public Cuboid6 getBounds() + { + return getBounds( meta ); + } + + public Cuboid6 getBounds(int meta) + { + ForgeDirection up = ForgeDirection.getOrientation( meta ); + double xOff = -0.3 * up.offsetX; + double yOff = -0.3 * up.offsetY; + double zOff = -0.3 * up.offsetZ; + return new Cuboid6( xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7 ); + } + + @Override + public int sideForMeta(int meta) + { + return ForgeDirection.getOrientation( meta ).getOpposite().ordinal(); + } + + public static McBlockPart placement(World world, BlockCoord pos, int side) + { + pos = pos.copy().offset( side ); + if ( !world.isSideSolid( pos.x, pos.y, pos.z, ForgeDirection.getOrientation( side ) ) ) + { + return null; + } + + return new QuartzTorchPart( side ); + } + + @Override + public void randomDisplayTick(Random r) + { + getBlock().randomDisplayTick( world(), x(), y(), z(), r ); + } } \ No newline at end of file diff --git a/helpers/AEGlassMaterial.java b/src/main/java/appeng/helpers/AEGlassMaterial.java similarity index 100% rename from helpers/AEGlassMaterial.java rename to src/main/java/appeng/helpers/AEGlassMaterial.java diff --git a/helpers/AEMultiTile.java b/src/main/java/appeng/helpers/AEMultiTile.java similarity index 95% rename from helpers/AEMultiTile.java rename to src/main/java/appeng/helpers/AEMultiTile.java index 99539274f..a80fb3854 100644 --- a/helpers/AEMultiTile.java +++ b/src/main/java/appeng/helpers/AEMultiTile.java @@ -1,10 +1,10 @@ -package appeng.helpers; - -import appeng.api.implementations.tiles.IColorableTile; -import appeng.api.networking.IGridHost; -import appeng.api.parts.IPartHost; - -public interface AEMultiTile extends IGridHost, IPartHost, IColorableTile -{ - -} +package appeng.helpers; + +import appeng.api.implementations.tiles.IColorableTile; +import appeng.api.networking.IGridHost; +import appeng.api.parts.IPartHost; + +public interface AEMultiTile extends IGridHost, IPartHost, IColorableTile +{ + +} diff --git a/helpers/DualityInterface.java b/src/main/java/appeng/helpers/DualityInterface.java similarity index 96% rename from helpers/DualityInterface.java rename to src/main/java/appeng/helpers/DualityInterface.java index 4860d7c92..4c4d8e999 100644 --- a/helpers/DualityInterface.java +++ b/src/main/java/appeng/helpers/DualityInterface.java @@ -1,1117 +1,1117 @@ -package appeng.helpers; - -import java.util.EnumSet; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import net.minecraft.block.Block; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MovingObjectPosition; -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.Settings; -import appeng.api.config.Upgrades; -import appeng.api.config.YesNo; -import appeng.api.implementations.ICraftingPatternItem; -import appeng.api.implementations.IUpgradeableHost; -import appeng.api.implementations.tiles.ICraftingMachine; -import appeng.api.implementations.tiles.ISegmentedInventory; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingLink; -import appeng.api.networking.crafting.ICraftingPatternDetails; -import appeng.api.networking.crafting.ICraftingProvider; -import appeng.api.networking.crafting.ICraftingProviderHelper; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.events.MENetworkCraftingPatternChange; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.MachineSource; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.parts.IPart; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IStorageMonitorable; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalCoord; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.core.settings.TickRates; -import appeng.me.GridAccessException; -import appeng.me.helpers.AENetworkProxy; -import appeng.me.storage.MEMonitorIInventory; -import appeng.me.storage.MEMonitorPassthu; -import appeng.me.storage.NullInventory; -import appeng.parts.automation.UpgradeInventory; -import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.ConfigManager; -import appeng.util.IConfigManagerHost; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.AdaptorIInventory; -import appeng.util.inv.IInventoryDestination; -import appeng.util.inv.WrapperInvSlot; -import appeng.util.item.AEItemStack; - -import com.google.common.collect.ImmutableSet; - -public class DualityInterface implements IGridTickable, ISegmentedInventory, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, - IConfigurableObject, IConfigManagerHost, ICraftingProvider, IUpgradeableHost, IPriorityHost -{ - - final int sides[] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }; - final IAEItemStack requireWork[] = new IAEItemStack[] { null, null, null, null, null, null, null, null }; - final MultiCraftingTracker craftingTracker; - - boolean hasConfig = false; - AENetworkProxy gridProxy; - IInterfaceHost iHost; - BaseActionSource mySrc; - ConfigManager cm = new ConfigManager( this ); - int priority; - - List craftingList = null; - List waitingToSend = null; - - private UpgradeInventory upgrades; - - @Override - public int getInstalledUpgrades(Upgrades u) - { - if ( upgrades == null ) - return 0; - return upgrades.getInstalledUpgrades( u ); - } - - public boolean hasItemsToSend() - { - return waitingToSend != null && !waitingToSend.isEmpty(); - } - - public void updateCraftingList() - { - Boolean accountedFor[] = new Boolean[] { false, false, false, false, false, false, false, false, false }; // 9... - - assert (accountedFor.length == patterns.getSizeInventory()); - - if ( !gridProxy.isReady() ) - return; - - if ( craftingList != null ) - { - Iterator i = craftingList.iterator(); - while (i.hasNext()) - { - ICraftingPatternDetails details = i.next(); - boolean found = false; - - for (int x = 0; x < accountedFor.length; x++) - { - ItemStack is = patterns.getStackInSlot( x ); - if ( details.getPattern() == is ) - { - accountedFor[x] = found = true; - } - } - - if ( !found ) - i.remove(); - } - } - - for (int x = 0; x < accountedFor.length; x++) - { - if ( accountedFor[x] == false ) - addToCraftingList( patterns.getStackInSlot( x ) ); - } - - try - { - gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) ); - } - catch (GridAccessException e) - { - // :P - } - } - - public void addToCraftingList(ItemStack is) - { - if ( is == null ) - return; - - if ( is.getItem() instanceof ICraftingPatternItem ) - { - ICraftingPatternItem cpi = (ICraftingPatternItem) is.getItem(); - ICraftingPatternDetails details = cpi.getPatternForItem( is, iHost.getTileEntity().getWorldObj() ); - - if ( details != null ) - { - if ( craftingList == null ) - craftingList = new LinkedList(); - - craftingList.add( details ); - } - } - } - - public void addToSendList(ItemStack is) - { - if ( is == null ) - return; - - if ( waitingToSend == null ) - waitingToSend = new LinkedList(); - - waitingToSend.add( is ); - - try - { - gridProxy.getTick().wakeDevice( gridProxy.getNode() ); - } - catch (GridAccessException e) - { - // :P - } - } - - public DualityInterface(AENetworkProxy prox, IInterfaceHost ih) { - gridProxy = prox; - gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL ); - - upgrades = new UpgradeInventory( gridProxy.getMachineRepresentation(), this, 1 ); - cm.registerSetting( Settings.BLOCK, YesNo.NO ); - cm.registerSetting( Settings.INTERFACE_TERMINAL, YesNo.YES ); - - iHost = ih; - craftingTracker = new MultiCraftingTracker( iHost, 9 ); - mySrc = fluids.changeSource = items.changeSource = new MachineSource( iHost ); - } - - @Override - public void saveChanges() - { - iHost.saveChanges(); - } - - private void readConfig() - { - hasConfig = false; - - for (ItemStack p : config) - { - if ( p != null ) - { - hasConfig = true; - break; - } - } - - boolean had = hasWorkToDo(); - - for (int x = 0; x < 8; x++) - updatePlan( x ); - - boolean has = hasWorkToDo(); - - if ( had != has ) - { - try - { - if ( has ) - gridProxy.getTick().alertDevice( gridProxy.getNode() ); - else - gridProxy.getTick().sleepDevice( gridProxy.getNode() ); - } - catch (GridAccessException e) - { - // :P - } - } - - notifyNeightbors(); - } - - public void writeToNBT(NBTTagCompound data) - { - config.writeToNBT( data, "config" ); - patterns.writeToNBT( data, "patterns" ); - storage.writeToNBT( data, "storage" ); - upgrades.writeToNBT( data, "upgrades" ); - cm.writeToNBT( data ); - craftingTracker.writeToNBT( data ); - data.setInteger( "priority", priority ); - - NBTTagList waitingToSend = new NBTTagList(); - if ( this.waitingToSend != null ) - { - for (ItemStack is : this.waitingToSend) - { - NBTTagCompound item = new NBTTagCompound(); - is.writeToNBT( item ); - waitingToSend.appendTag( item ); - } - } - data.setTag( "waitingToSend", waitingToSend ); - } - - public void readFromNBT(NBTTagCompound data) - { - this.waitingToSend = null; - NBTTagList waitingList = data.getTagList( "waitingToSend", 10 ); - if ( waitingList != null ) - { - for (int x = 0; x < waitingList.tagCount(); x++) - { - NBTTagCompound c = waitingList.getCompoundTagAt( x ); - if ( c != null ) - { - ItemStack is = ItemStack.loadItemStackFromNBT( c ); - addToSendList( is ); - } - } - } - - craftingTracker.readFromNBT( data ); - upgrades.readFromNBT( data, "upgrades" ); - config.readFromNBT( data, "config" ); - patterns.readFromNBT( data, "patterns" ); - storage.readFromNBT( data, "storage" ); - priority = data.getInteger( "priority" ); - cm.readFromNBT( data ); - readConfig(); - updateCraftingList(); - } - - AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 8 ); - AppEngInternalInventory storage = new AppEngInternalInventory( this, 8 ); - AppEngInternalInventory patterns = new AppEngInternalInventory( this, 9 ); - - WrapperInvSlot slotInv = new WrapperInvSlot( storage ); - - private InventoryAdaptor getAdaptor(int slot) - { - return new AdaptorIInventory( slotInv.getWrapper( slot ) ); - } - - IMEInventory destination; - private boolean isWorking = false; - - @Override - public boolean canInsert(ItemStack stack) - { - IAEItemStack out = destination.injectItems( AEApi.instance().storage().createItemStack( stack ), Actionable.SIMULATE, null ); - if ( out == null ) - return true; - return out.getStackSize() != stack.stackSize; - // ItemStack after = adaptor.simulateAdd( stack ); - // if ( after == null ) - // return true; - // return after.stackSize != stack.stackSize; - } - - private void updatePlan(int slot) - { - IAEItemStack req = config.getAEStackInSlot( slot ); - if ( req != null && req.getStackSize() <= 0 ) - { - config.setInventorySlotContents( slot, null ); - req = null; - } - - ItemStack Stored = storage.getStackInSlot( slot ); - - if ( req == null && Stored != null ) - { - IAEItemStack work = AEApi.instance().storage().createItemStack( Stored ); - requireWork[slot] = work.setStackSize( -work.getStackSize() ); - return; - } - else if ( req != null ) - { - if ( Stored == null ) // need to add stuff! - { - requireWork[slot] = req.copy(); - return; - } - else if ( req.isSameType( Stored ) ) // same type ( qty different? )! - { - if ( req.getStackSize() != Stored.stackSize ) - { - requireWork[slot] = req.copy(); - requireWork[slot].setStackSize( req.getStackSize() - Stored.stackSize ); - return; - } - } - else if ( Stored != null ) // dispose! - { - IAEItemStack work = AEApi.instance().storage().createItemStack( Stored ); - requireWork[slot] = work.setStackSize( -work.getStackSize() ); - return; - } - } - - // else - - requireWork[slot] = null; - } - - static private boolean interfaceRequest = false; - - class InterfaceInventory extends MEMonitorIInventory - { - - public InterfaceInventory(DualityInterface tileInterface) { - super( new AdaptorIInventory( tileInterface.storage ) ); - mySource = new MachineSource( iHost ); - } - - @Override - public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) - { - if ( interfaceRequest ) - return input; - - return super.injectItems( input, type, src ); - } - - @Override - public IAEItemStack extractItems(IAEItemStack request, Actionable type, BaseActionSource src) - { - if ( interfaceRequest ) - return null; - - return super.extractItems( request, type, src ); - } - - }; - - private boolean usePlan(int x, IAEItemStack itemStack) - { - boolean changed = false; - InventoryAdaptor adaptor = getAdaptor( x ); - interfaceRequest = isWorking = true; - - try - { - destination = gridProxy.getStorage().getItemInventory(); - IEnergySource src = gridProxy.getEnergy(); - - if ( craftingTracker.isBusy( x ) ) - changed = handleCrafting( x, adaptor, itemStack ) || changed; - else if ( itemStack.getStackSize() > 0 ) - { - // make sure strange things didn't happen... - if ( adaptor.simulateAdd( itemStack.getItemStack() ) != null ) - { - changed = true; - throw new GridAccessException(); - } - - IAEItemStack acquired = Platform.poweredExtraction( src, destination, itemStack, mySrc ); - if ( acquired != null ) - { - changed = true; - ItemStack issue = adaptor.addItems( acquired.getItemStack() ); - if ( issue != null ) - throw new RuntimeException( "bad attempt at managing inventory. ( addItems )" ); - } - else - changed = handleCrafting( x, adaptor, itemStack ) || changed; - } - else if ( itemStack.getStackSize() < 0 ) - { - IAEItemStack toStore = itemStack.copy(); - toStore.setStackSize( -toStore.getStackSize() ); - - long diff = toStore.getStackSize(); - - // make sure strange things didn't happen... - ItemStack canExtract = adaptor.simulateRemove( (int) diff, toStore.getItemStack(), null ); - if ( canExtract == null || canExtract.stackSize != diff ) - { - changed = true; - throw new GridAccessException(); - } - - toStore = Platform.poweredInsert( src, destination, toStore, mySrc ); - - if ( toStore != null ) - diff -= toStore.getStackSize(); - - if ( diff != 0 ) - { - // extract items! - changed = true; - ItemStack removed = adaptor.removeItems( (int) diff, null, null ); - if ( removed == null ) - throw new RuntimeException( "bad attempt at managing inventory. ( removeItems )" ); - else if ( removed.stackSize != diff ) - throw new RuntimeException( "bad attempt at managing inventory. ( removeItems )" ); - } - } - // else wtf? - } - catch (GridAccessException e) - { - // :P - } - - if ( changed ) - updatePlan( x ); - - interfaceRequest = isWorking = false; - return changed; - } - - private boolean handleCrafting(int x, InventoryAdaptor d, IAEItemStack itemStack) - { - try - { - if ( getInstalledUpgrades( Upgrades.CRAFTING ) > 0 && itemStack != null ) - { - return craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, iHost.getTileEntity().getWorldObj(), gridProxy.getGrid(), - gridProxy.getCrafting(), mySrc ); - } - } - catch (GridAccessException e) - { - // :P - } - - return false; - } - - public IInventory getConfig() - { - return config; - } - - public IInventory getPatterns() - { - return patterns; - } - - MEMonitorPassthu items = new MEMonitorPassthu( new NullInventory(), StorageChannel.ITEMS ); - MEMonitorPassthu fluids = new MEMonitorPassthu( new NullInventory(), StorageChannel.FLUIDS ); - - public void gridChanged() - { - try - { - items.setInternal( gridProxy.getStorage().getItemInventory() ); - fluids.setInternal( gridProxy.getStorage().getFluidInventory() ); - } - catch (GridAccessException gae) - { - items.setInternal( new NullInventory() ); - fluids.setInternal( new NullInventory() ); - } - - notifyNeightbors(); - } - - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.SMART; - } - - public DimensionalCoord getLocation() - { - return new DimensionalCoord( iHost.getTileEntity() ); - } - - public IInventory getInternalInventory() - { - return storage; - } - - public void markDirty() - { - for (int slot = 0; slot < storage.getSizeInventory(); slot++) - onChangeInventory( storage, slot, InvOperation.markDirty, null, null ); - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) - { - if ( isWorking ) - return; - - if ( inv == config ) - readConfig(); - else if ( inv == patterns && (removed != null || added != null) ) - updateCraftingList(); - else if ( inv == storage && slot >= 0 ) - { - boolean had = hasWorkToDo(); - - updatePlan( slot ); - - boolean now = hasWorkToDo(); - - if ( had != now ) - { - try - { - if ( now ) - gridProxy.getTick().alertDevice( gridProxy.getNode() ); - else - gridProxy.getTick().sleepDevice( gridProxy.getNode() ); - } - catch (GridAccessException e) - { - // :P - } - } - } - } - - public boolean hasWorkToDo() - { - return hasItemsToSend() || requireWork[0] != null || requireWork[1] != null || requireWork[2] != null || requireWork[3] != null - || requireWork[4] != null || requireWork[5] != null || requireWork[6] != null || requireWork[7] != null; - } - - private boolean updateStorage() - { - boolean didSomething = false; - - for (int x = 0; x < 8; x++) - { - if ( requireWork[x] != null ) - { - didSomething = usePlan( x, requireWork[x] ) || didSomething; - } - } - - return didSomething; - } - - public boolean hasConfig() - { - return hasConfig; - } - - public int[] getAccessibleSlotsFromSide(int side) - { - return sides; - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) - { - return new TickingRequest( TickRates.Interface.min, TickRates.Interface.max, !hasWorkToDo(), true ); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) - { - if ( !gridProxy.isActive() ) - return TickRateModulation.SLEEP; - - if ( hasItemsToSend() ) - pushItemsOut( EnumSet.allOf( ForgeDirection.class ) ); - - boolean couldDoWork = updateStorage(); - return hasWorkToDo() ? (couldDoWork ? TickRateModulation.URGENT : TickRateModulation.SLOWER) : TickRateModulation.SLEEP; - } - - @Override - public IMEMonitor getItemInventory() - { - if ( hasConfig() ) - return new InterfaceInventory( this ); - - return items; - } - - @Override - public IMEMonitor getFluidInventory() - { - if ( hasConfig() ) - return null; - - return fluids; - } - - @Override - public IInventory getInventoryByName(String name) - { - if ( name.equals( "storage" ) ) - return storage; - - if ( name.equals( "patterns" ) ) - return patterns; - - if ( name.equals( "config" ) ) - return config; - - if ( name.equals( "upgrades" ) ) - return upgrades; - - return null; - } - - public IInventory getStorage() - { - return storage; - } - - @Override - public TileEntity getTile() - { - return (TileEntity) (iHost instanceof TileEntity ? iHost : null); - } - - public IPart getPart() - { - return (IPart) (iHost instanceof IPart ? iHost : null); - } - - public appeng.api.util.IConfigManager getConfigManager() - { - return cm; - } - - @Override - public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) - { - if ( getInstalledUpgrades( Upgrades.CRAFTING ) == 0 ) - cancelCrafting(); - - markDirty(); - } - - private void cancelCrafting() - { - craftingTracker.cancel(); - } - - public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src, IStorageMonitorable myInterface) - { - if ( Platform.canAccess( gridProxy, src ) ) - return myInterface; - - final DualityInterface di = this; - - return new IStorageMonitorable() { - - @Override - public IMEMonitor getItemInventory() - { - return new InterfaceInventory( di ); - } - - @Override - public IMEMonitor getFluidInventory() - { - return null; - } - }; - } - - @Override - public boolean isBusy() - { - if ( hasItemsToSend() ) - return true; - - boolean busy = false; - - if ( isBlocking() ) - { - EnumSet possibleDirections = iHost.getTargets(); - TileEntity tile = iHost.getTileEntity(); - World w = tile.getWorldObj(); - - boolean allAreBusy = true; - - for (ForgeDirection s : possibleDirections) - { - TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); - - InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() ); - if ( ad != null ) - { - if ( ad.simulateRemove( 1, null, null ) == null ) - { - allAreBusy = false; - break; - } - } - } - - busy = allAreBusy; - } - - return busy; - } - - private boolean isBlocking() - { - return cm.getSetting( Settings.BLOCK ) == YesNo.YES; - } - - @Override - public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) - { - if ( hasItemsToSend() || !gridProxy.isActive() ) - return false; - - TileEntity tile = iHost.getTileEntity(); - World w = tile.getWorldObj(); - - EnumSet possibleDirections = iHost.getTargets(); - for (ForgeDirection s : possibleDirections) - { - TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); - if ( te instanceof IInterfaceHost ) - { - try - { - if ( ((IInterfaceHost) te).getInterfaceDuality().sameGrid( gridProxy.getGrid() ) ) - continue; - } - catch (GridAccessException e) - { - continue; - } - } - - if ( te instanceof ICraftingMachine ) - { - ICraftingMachine cm = (ICraftingMachine) te; - if ( cm.acceptsPlans() ) - { - if ( cm.pushPattern( patternDetails, table, s.getOpposite() ) ) - return true; - continue; - } - } - - InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() ); - if ( ad != null ) - { - if ( isBlocking() ) - { - if ( ad.simulateRemove( 1, null, null ) != null ) - continue; - } - - if ( acceptsItems( ad, table ) ) - { - for (int x = 0; x < table.getSizeInventory(); x++) - { - ItemStack is = table.getStackInSlot( x ); - if ( is != null ) - { - addToSendList( ad.addItems( is ) ); - } - } - pushItemsOut( possibleDirections ); - return true; - } - } - } - - return false; - } - - private boolean sameGrid(IGrid grid) throws GridAccessException - { - return grid == gridProxy.getGrid(); - } - - private boolean acceptsItems(InventoryAdaptor ad, InventoryCrafting table) - { - for (int x = 0; x < table.getSizeInventory(); x++) - { - ItemStack is = table.getStackInSlot( x ); - if ( is == null ) - continue; - - if ( ad.simulateAdd( is.copy() ) != null ) - return false; - } - - return true; - } - - private void pushItemsOut(EnumSet possibleDirections) - { - if ( !hasItemsToSend() ) - return; - - TileEntity tile = iHost.getTileEntity(); - World w = tile.getWorldObj(); - - Iterator i = waitingToSend.iterator(); - while (i.hasNext()) - { - ItemStack whatToSend = i.next(); - - for (ForgeDirection s : possibleDirections) - { - TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); - if ( te == null ) - continue; - - InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() ); - if ( ad != null ) - { - ItemStack Result = ad.addItems( whatToSend ); - - if ( Result == null ) - whatToSend = null; - else - whatToSend.stackSize -= whatToSend.stackSize - Result.stackSize; - - if ( whatToSend == null ) - break; - } - } - - if ( whatToSend == null ) - i.remove(); - } - - if ( waitingToSend.isEmpty() ) - waitingToSend = null; - } - - @Override - public void provideCrafting(ICraftingProviderHelper craftingTracker) - { - if ( gridProxy.isActive() && craftingList != null ) - { - for (ICraftingPatternDetails details : craftingList) - { - details.setPriority( this.priority ); - craftingTracker.addCraftingOption( this, details ); - } - } - } - - public void addDrops(List drops) - { - if ( waitingToSend != null ) - { - for (ItemStack is : waitingToSend) - if ( is != null ) - drops.add( is ); - } - - for (ItemStack is : upgrades) - if ( is != null ) - drops.add( is ); - - for (ItemStack is : storage) - if ( is != null ) - drops.add( is ); - - for (ItemStack is : patterns) - if ( is != null ) - drops.add( is ); - } - - public void notifyNeightbors() - { - if ( gridProxy.isActive() ) - { - try - { - gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) ); - gridProxy.getTick().wakeDevice( gridProxy.getNode() ); - } - catch (GridAccessException e) - { - // :P - } - } - - TileEntity te = iHost.getTileEntity(); - if ( te != null && te.getWorldObj() != null ) - Platform.notifyBlocksOfNeighbors( te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord ); - } - - public IUpgradeableHost getHost() - { - if ( getPart() instanceof IUpgradeableHost ) - return (IUpgradeableHost) getPart(); - if ( getTile() instanceof IUpgradeableHost ) - return (IUpgradeableHost) getTile(); - return null; - } - - public ImmutableSet getRequestedJobs() - { - return craftingTracker.getRequestedJobs(); - } - - public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack acquired, Actionable mode) - { - int slot = craftingTracker.getSlot( link ); - - if ( acquired != null && slot >= 0 && slot <= requireWork.length ) - { - InventoryAdaptor adaptor = getAdaptor( slot ); - - if ( mode == Actionable.SIMULATE ) - return AEItemStack.create( adaptor.simulateAdd( acquired.getItemStack() ) ); - else - { - IAEItemStack is = AEItemStack.create( adaptor.addItems( acquired.getItemStack() ) ); - updatePlan( slot ); - return is; - } - } - - return acquired; - } - - public void jobStateChange(ICraftingLink link) - { - craftingTracker.jobStateChange( link ); - } - - static final Set badBlocks = new HashSet(); - - public String getTermName() - { - TileEntity tile = iHost.getTileEntity(); - World w = tile.getWorldObj(); - - if ( ((ICustomNameObject) iHost).hasCustomName() ) - return ((ICustomNameObject) iHost).getCustomName(); - - EnumSet possibleDirections = iHost.getTargets(); - for (ForgeDirection s : possibleDirections) - { - Vec3 from = Vec3.createVectorHelper( (double) tile.xCoord + 0.5, (double) tile.yCoord + 0.5, (double) tile.zCoord + 0.5 ); - from = from.addVector( s.offsetX * 0.501, s.offsetY * 0.501, s.offsetZ * 0.501 ); - Vec3 to = from.addVector( s.offsetX, s.offsetY, s.offsetZ ); - - Block blk = w.getBlock( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); - MovingObjectPosition mop = w.rayTraceBlocks( from, to, true ); - - TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); - - if ( te == null ) - continue; - - if ( te instanceof IInterfaceHost ) - { - try - { - if ( ((IInterfaceHost) te).getInterfaceDuality().sameGrid( gridProxy.getGrid() ) ) - continue; - } - catch (GridAccessException e) - { - continue; - } - } - - Item item = Item.getItemFromBlock( blk ); - - if ( item == null ) - { - return blk.getUnlocalizedName(); - } - - ItemStack what = new ItemStack( item, 1, blk.getDamageValue( w, tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ) ); - - if ( te instanceof ICraftingMachine || InventoryAdaptor.getAdaptor( te, s.getOpposite() ) != null ) - { - if ( te instanceof IInventory && ((IInventory) te).getSizeInventory() == 0 ) - continue; - - if ( te instanceof ISidedInventory ) - { - int[] sides = ((ISidedInventory) te).getAccessibleSlotsFromSide( s.getOpposite().ordinal() ); - - if ( sides == null || sides.length == 0 ) - continue; - } - - try - { - if ( mop != null && !badBlocks.contains( blk ) ) - { - if ( mop.blockX == te.xCoord && mop.blockY == te.yCoord && mop.blockZ == te.zCoord ) - { - ItemStack g = blk.getPickBlock( mop, w, te.xCoord, te.yCoord, te.zCoord ); - if ( g != null ) - what = g; - } - } - } - catch (Throwable t) - { - badBlocks.add( blk ); // nope! - } - - if ( what.getItem() != null ) - return what.getUnlocalizedName(); - } - - } - - return "Nothing"; - } - - public long getSortValue() - { - TileEntity te = iHost.getTileEntity(); - return (te.zCoord << 24) ^ (te.xCoord << 8) ^ te.yCoord; - } - - public void initialize() - { - updateCraftingList(); - } - - @Override - public int getPriority() - { - return priority; - } - - @Override - public void setPriority(int newValue) - { - priority = newValue; - markDirty(); - - try - { - gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) ); - } - catch (GridAccessException e) - { - // :P - } - } -} +package appeng.helpers; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +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.Settings; +import appeng.api.config.Upgrades; +import appeng.api.config.YesNo; +import appeng.api.implementations.ICraftingPatternItem; +import appeng.api.implementations.IUpgradeableHost; +import appeng.api.implementations.tiles.ICraftingMachine; +import appeng.api.implementations.tiles.ISegmentedInventory; +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridNode; +import appeng.api.networking.crafting.ICraftingLink; +import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.networking.crafting.ICraftingProvider; +import appeng.api.networking.crafting.ICraftingProviderHelper; +import appeng.api.networking.energy.IEnergySource; +import appeng.api.networking.events.MENetworkCraftingPatternChange; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.security.MachineSource; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; +import appeng.api.parts.IPart; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.IStorageMonitorable; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.util.AECableType; +import appeng.api.util.DimensionalCoord; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.core.settings.TickRates; +import appeng.me.GridAccessException; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.storage.MEMonitorIInventory; +import appeng.me.storage.MEMonitorPassthu; +import appeng.me.storage.NullInventory; +import appeng.parts.automation.UpgradeInventory; +import appeng.tile.inventory.AppEngInternalAEInventory; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.tile.inventory.IAEAppEngInventory; +import appeng.tile.inventory.InvOperation; +import appeng.util.ConfigManager; +import appeng.util.IConfigManagerHost; +import appeng.util.InventoryAdaptor; +import appeng.util.Platform; +import appeng.util.inv.AdaptorIInventory; +import appeng.util.inv.IInventoryDestination; +import appeng.util.inv.WrapperInvSlot; +import appeng.util.item.AEItemStack; + +import com.google.common.collect.ImmutableSet; + +public class DualityInterface implements IGridTickable, ISegmentedInventory, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, + IConfigurableObject, IConfigManagerHost, ICraftingProvider, IUpgradeableHost, IPriorityHost +{ + + final int sides[] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }; + final IAEItemStack requireWork[] = new IAEItemStack[] { null, null, null, null, null, null, null, null }; + final MultiCraftingTracker craftingTracker; + + boolean hasConfig = false; + AENetworkProxy gridProxy; + IInterfaceHost iHost; + BaseActionSource mySrc; + ConfigManager cm = new ConfigManager( this ); + int priority; + + List craftingList = null; + List waitingToSend = null; + + private UpgradeInventory upgrades; + + @Override + public int getInstalledUpgrades(Upgrades u) + { + if ( upgrades == null ) + return 0; + return upgrades.getInstalledUpgrades( u ); + } + + public boolean hasItemsToSend() + { + return waitingToSend != null && !waitingToSend.isEmpty(); + } + + public void updateCraftingList() + { + Boolean accountedFor[] = new Boolean[] { false, false, false, false, false, false, false, false, false }; // 9... + + assert (accountedFor.length == patterns.getSizeInventory()); + + if ( !gridProxy.isReady() ) + return; + + if ( craftingList != null ) + { + Iterator i = craftingList.iterator(); + while (i.hasNext()) + { + ICraftingPatternDetails details = i.next(); + boolean found = false; + + for (int x = 0; x < accountedFor.length; x++) + { + ItemStack is = patterns.getStackInSlot( x ); + if ( details.getPattern() == is ) + { + accountedFor[x] = found = true; + } + } + + if ( !found ) + i.remove(); + } + } + + for (int x = 0; x < accountedFor.length; x++) + { + if ( accountedFor[x] == false ) + addToCraftingList( patterns.getStackInSlot( x ) ); + } + + try + { + gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) ); + } + catch (GridAccessException e) + { + // :P + } + } + + public void addToCraftingList(ItemStack is) + { + if ( is == null ) + return; + + if ( is.getItem() instanceof ICraftingPatternItem ) + { + ICraftingPatternItem cpi = (ICraftingPatternItem) is.getItem(); + ICraftingPatternDetails details = cpi.getPatternForItem( is, iHost.getTileEntity().getWorldObj() ); + + if ( details != null ) + { + if ( craftingList == null ) + craftingList = new LinkedList(); + + craftingList.add( details ); + } + } + } + + public void addToSendList(ItemStack is) + { + if ( is == null ) + return; + + if ( waitingToSend == null ) + waitingToSend = new LinkedList(); + + waitingToSend.add( is ); + + try + { + gridProxy.getTick().wakeDevice( gridProxy.getNode() ); + } + catch (GridAccessException e) + { + // :P + } + } + + public DualityInterface(AENetworkProxy prox, IInterfaceHost ih) { + gridProxy = prox; + gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL ); + + upgrades = new UpgradeInventory( gridProxy.getMachineRepresentation(), this, 1 ); + cm.registerSetting( Settings.BLOCK, YesNo.NO ); + cm.registerSetting( Settings.INTERFACE_TERMINAL, YesNo.YES ); + + iHost = ih; + craftingTracker = new MultiCraftingTracker( iHost, 9 ); + mySrc = fluids.changeSource = items.changeSource = new MachineSource( iHost ); + } + + @Override + public void saveChanges() + { + iHost.saveChanges(); + } + + private void readConfig() + { + hasConfig = false; + + for (ItemStack p : config) + { + if ( p != null ) + { + hasConfig = true; + break; + } + } + + boolean had = hasWorkToDo(); + + for (int x = 0; x < 8; x++) + updatePlan( x ); + + boolean has = hasWorkToDo(); + + if ( had != has ) + { + try + { + if ( has ) + gridProxy.getTick().alertDevice( gridProxy.getNode() ); + else + gridProxy.getTick().sleepDevice( gridProxy.getNode() ); + } + catch (GridAccessException e) + { + // :P + } + } + + notifyNeightbors(); + } + + public void writeToNBT(NBTTagCompound data) + { + config.writeToNBT( data, "config" ); + patterns.writeToNBT( data, "patterns" ); + storage.writeToNBT( data, "storage" ); + upgrades.writeToNBT( data, "upgrades" ); + cm.writeToNBT( data ); + craftingTracker.writeToNBT( data ); + data.setInteger( "priority", priority ); + + NBTTagList waitingToSend = new NBTTagList(); + if ( this.waitingToSend != null ) + { + for (ItemStack is : this.waitingToSend) + { + NBTTagCompound item = new NBTTagCompound(); + is.writeToNBT( item ); + waitingToSend.appendTag( item ); + } + } + data.setTag( "waitingToSend", waitingToSend ); + } + + public void readFromNBT(NBTTagCompound data) + { + this.waitingToSend = null; + NBTTagList waitingList = data.getTagList( "waitingToSend", 10 ); + if ( waitingList != null ) + { + for (int x = 0; x < waitingList.tagCount(); x++) + { + NBTTagCompound c = waitingList.getCompoundTagAt( x ); + if ( c != null ) + { + ItemStack is = ItemStack.loadItemStackFromNBT( c ); + addToSendList( is ); + } + } + } + + craftingTracker.readFromNBT( data ); + upgrades.readFromNBT( data, "upgrades" ); + config.readFromNBT( data, "config" ); + patterns.readFromNBT( data, "patterns" ); + storage.readFromNBT( data, "storage" ); + priority = data.getInteger( "priority" ); + cm.readFromNBT( data ); + readConfig(); + updateCraftingList(); + } + + AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 8 ); + AppEngInternalInventory storage = new AppEngInternalInventory( this, 8 ); + AppEngInternalInventory patterns = new AppEngInternalInventory( this, 9 ); + + WrapperInvSlot slotInv = new WrapperInvSlot( storage ); + + private InventoryAdaptor getAdaptor(int slot) + { + return new AdaptorIInventory( slotInv.getWrapper( slot ) ); + } + + IMEInventory destination; + private boolean isWorking = false; + + @Override + public boolean canInsert(ItemStack stack) + { + IAEItemStack out = destination.injectItems( AEApi.instance().storage().createItemStack( stack ), Actionable.SIMULATE, null ); + if ( out == null ) + return true; + return out.getStackSize() != stack.stackSize; + // ItemStack after = adaptor.simulateAdd( stack ); + // if ( after == null ) + // return true; + // return after.stackSize != stack.stackSize; + } + + private void updatePlan(int slot) + { + IAEItemStack req = config.getAEStackInSlot( slot ); + if ( req != null && req.getStackSize() <= 0 ) + { + config.setInventorySlotContents( slot, null ); + req = null; + } + + ItemStack Stored = storage.getStackInSlot( slot ); + + if ( req == null && Stored != null ) + { + IAEItemStack work = AEApi.instance().storage().createItemStack( Stored ); + requireWork[slot] = work.setStackSize( -work.getStackSize() ); + return; + } + else if ( req != null ) + { + if ( Stored == null ) // need to add stuff! + { + requireWork[slot] = req.copy(); + return; + } + else if ( req.isSameType( Stored ) ) // same type ( qty different? )! + { + if ( req.getStackSize() != Stored.stackSize ) + { + requireWork[slot] = req.copy(); + requireWork[slot].setStackSize( req.getStackSize() - Stored.stackSize ); + return; + } + } + else if ( Stored != null ) // dispose! + { + IAEItemStack work = AEApi.instance().storage().createItemStack( Stored ); + requireWork[slot] = work.setStackSize( -work.getStackSize() ); + return; + } + } + + // else + + requireWork[slot] = null; + } + + static private boolean interfaceRequest = false; + + class InterfaceInventory extends MEMonitorIInventory + { + + public InterfaceInventory(DualityInterface tileInterface) { + super( new AdaptorIInventory( tileInterface.storage ) ); + mySource = new MachineSource( iHost ); + } + + @Override + public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) + { + if ( interfaceRequest ) + return input; + + return super.injectItems( input, type, src ); + } + + @Override + public IAEItemStack extractItems(IAEItemStack request, Actionable type, BaseActionSource src) + { + if ( interfaceRequest ) + return null; + + return super.extractItems( request, type, src ); + } + + }; + + private boolean usePlan(int x, IAEItemStack itemStack) + { + boolean changed = false; + InventoryAdaptor adaptor = getAdaptor( x ); + interfaceRequest = isWorking = true; + + try + { + destination = gridProxy.getStorage().getItemInventory(); + IEnergySource src = gridProxy.getEnergy(); + + if ( craftingTracker.isBusy( x ) ) + changed = handleCrafting( x, adaptor, itemStack ) || changed; + else if ( itemStack.getStackSize() > 0 ) + { + // make sure strange things didn't happen... + if ( adaptor.simulateAdd( itemStack.getItemStack() ) != null ) + { + changed = true; + throw new GridAccessException(); + } + + IAEItemStack acquired = Platform.poweredExtraction( src, destination, itemStack, mySrc ); + if ( acquired != null ) + { + changed = true; + ItemStack issue = adaptor.addItems( acquired.getItemStack() ); + if ( issue != null ) + throw new RuntimeException( "bad attempt at managing inventory. ( addItems )" ); + } + else + changed = handleCrafting( x, adaptor, itemStack ) || changed; + } + else if ( itemStack.getStackSize() < 0 ) + { + IAEItemStack toStore = itemStack.copy(); + toStore.setStackSize( -toStore.getStackSize() ); + + long diff = toStore.getStackSize(); + + // make sure strange things didn't happen... + ItemStack canExtract = adaptor.simulateRemove( (int) diff, toStore.getItemStack(), null ); + if ( canExtract == null || canExtract.stackSize != diff ) + { + changed = true; + throw new GridAccessException(); + } + + toStore = Platform.poweredInsert( src, destination, toStore, mySrc ); + + if ( toStore != null ) + diff -= toStore.getStackSize(); + + if ( diff != 0 ) + { + // extract items! + changed = true; + ItemStack removed = adaptor.removeItems( (int) diff, null, null ); + if ( removed == null ) + throw new RuntimeException( "bad attempt at managing inventory. ( removeItems )" ); + else if ( removed.stackSize != diff ) + throw new RuntimeException( "bad attempt at managing inventory. ( removeItems )" ); + } + } + // else wtf? + } + catch (GridAccessException e) + { + // :P + } + + if ( changed ) + updatePlan( x ); + + interfaceRequest = isWorking = false; + return changed; + } + + private boolean handleCrafting(int x, InventoryAdaptor d, IAEItemStack itemStack) + { + try + { + if ( getInstalledUpgrades( Upgrades.CRAFTING ) > 0 && itemStack != null ) + { + return craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, iHost.getTileEntity().getWorldObj(), gridProxy.getGrid(), + gridProxy.getCrafting(), mySrc ); + } + } + catch (GridAccessException e) + { + // :P + } + + return false; + } + + public IInventory getConfig() + { + return config; + } + + public IInventory getPatterns() + { + return patterns; + } + + MEMonitorPassthu items = new MEMonitorPassthu( new NullInventory(), StorageChannel.ITEMS ); + MEMonitorPassthu fluids = new MEMonitorPassthu( new NullInventory(), StorageChannel.FLUIDS ); + + public void gridChanged() + { + try + { + items.setInternal( gridProxy.getStorage().getItemInventory() ); + fluids.setInternal( gridProxy.getStorage().getFluidInventory() ); + } + catch (GridAccessException gae) + { + items.setInternal( new NullInventory() ); + fluids.setInternal( new NullInventory() ); + } + + notifyNeightbors(); + } + + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.SMART; + } + + public DimensionalCoord getLocation() + { + return new DimensionalCoord( iHost.getTileEntity() ); + } + + public IInventory getInternalInventory() + { + return storage; + } + + public void markDirty() + { + for (int slot = 0; slot < storage.getSizeInventory(); slot++) + onChangeInventory( storage, slot, InvOperation.markDirty, null, null ); + } + + @Override + public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) + { + if ( isWorking ) + return; + + if ( inv == config ) + readConfig(); + else if ( inv == patterns && (removed != null || added != null) ) + updateCraftingList(); + else if ( inv == storage && slot >= 0 ) + { + boolean had = hasWorkToDo(); + + updatePlan( slot ); + + boolean now = hasWorkToDo(); + + if ( had != now ) + { + try + { + if ( now ) + gridProxy.getTick().alertDevice( gridProxy.getNode() ); + else + gridProxy.getTick().sleepDevice( gridProxy.getNode() ); + } + catch (GridAccessException e) + { + // :P + } + } + } + } + + public boolean hasWorkToDo() + { + return hasItemsToSend() || requireWork[0] != null || requireWork[1] != null || requireWork[2] != null || requireWork[3] != null + || requireWork[4] != null || requireWork[5] != null || requireWork[6] != null || requireWork[7] != null; + } + + private boolean updateStorage() + { + boolean didSomething = false; + + for (int x = 0; x < 8; x++) + { + if ( requireWork[x] != null ) + { + didSomething = usePlan( x, requireWork[x] ) || didSomething; + } + } + + return didSomething; + } + + public boolean hasConfig() + { + return hasConfig; + } + + public int[] getAccessibleSlotsFromSide(int side) + { + return sides; + } + + @Override + public TickingRequest getTickingRequest(IGridNode node) + { + return new TickingRequest( TickRates.Interface.min, TickRates.Interface.max, !hasWorkToDo(), true ); + } + + @Override + public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + { + if ( !gridProxy.isActive() ) + return TickRateModulation.SLEEP; + + if ( hasItemsToSend() ) + pushItemsOut( EnumSet.allOf( ForgeDirection.class ) ); + + boolean couldDoWork = updateStorage(); + return hasWorkToDo() ? (couldDoWork ? TickRateModulation.URGENT : TickRateModulation.SLOWER) : TickRateModulation.SLEEP; + } + + @Override + public IMEMonitor getItemInventory() + { + if ( hasConfig() ) + return new InterfaceInventory( this ); + + return items; + } + + @Override + public IMEMonitor getFluidInventory() + { + if ( hasConfig() ) + return null; + + return fluids; + } + + @Override + public IInventory getInventoryByName(String name) + { + if ( name.equals( "storage" ) ) + return storage; + + if ( name.equals( "patterns" ) ) + return patterns; + + if ( name.equals( "config" ) ) + return config; + + if ( name.equals( "upgrades" ) ) + return upgrades; + + return null; + } + + public IInventory getStorage() + { + return storage; + } + + @Override + public TileEntity getTile() + { + return (TileEntity) (iHost instanceof TileEntity ? iHost : null); + } + + public IPart getPart() + { + return (IPart) (iHost instanceof IPart ? iHost : null); + } + + public appeng.api.util.IConfigManager getConfigManager() + { + return cm; + } + + @Override + public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) + { + if ( getInstalledUpgrades( Upgrades.CRAFTING ) == 0 ) + cancelCrafting(); + + markDirty(); + } + + private void cancelCrafting() + { + craftingTracker.cancel(); + } + + public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src, IStorageMonitorable myInterface) + { + if ( Platform.canAccess( gridProxy, src ) ) + return myInterface; + + final DualityInterface di = this; + + return new IStorageMonitorable() { + + @Override + public IMEMonitor getItemInventory() + { + return new InterfaceInventory( di ); + } + + @Override + public IMEMonitor getFluidInventory() + { + return null; + } + }; + } + + @Override + public boolean isBusy() + { + if ( hasItemsToSend() ) + return true; + + boolean busy = false; + + if ( isBlocking() ) + { + EnumSet possibleDirections = iHost.getTargets(); + TileEntity tile = iHost.getTileEntity(); + World w = tile.getWorldObj(); + + boolean allAreBusy = true; + + for (ForgeDirection s : possibleDirections) + { + TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); + + InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() ); + if ( ad != null ) + { + if ( ad.simulateRemove( 1, null, null ) == null ) + { + allAreBusy = false; + break; + } + } + } + + busy = allAreBusy; + } + + return busy; + } + + private boolean isBlocking() + { + return cm.getSetting( Settings.BLOCK ) == YesNo.YES; + } + + @Override + public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) + { + if ( hasItemsToSend() || !gridProxy.isActive() ) + return false; + + TileEntity tile = iHost.getTileEntity(); + World w = tile.getWorldObj(); + + EnumSet possibleDirections = iHost.getTargets(); + for (ForgeDirection s : possibleDirections) + { + TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); + if ( te instanceof IInterfaceHost ) + { + try + { + if ( ((IInterfaceHost) te).getInterfaceDuality().sameGrid( gridProxy.getGrid() ) ) + continue; + } + catch (GridAccessException e) + { + continue; + } + } + + if ( te instanceof ICraftingMachine ) + { + ICraftingMachine cm = (ICraftingMachine) te; + if ( cm.acceptsPlans() ) + { + if ( cm.pushPattern( patternDetails, table, s.getOpposite() ) ) + return true; + continue; + } + } + + InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() ); + if ( ad != null ) + { + if ( isBlocking() ) + { + if ( ad.simulateRemove( 1, null, null ) != null ) + continue; + } + + if ( acceptsItems( ad, table ) ) + { + for (int x = 0; x < table.getSizeInventory(); x++) + { + ItemStack is = table.getStackInSlot( x ); + if ( is != null ) + { + addToSendList( ad.addItems( is ) ); + } + } + pushItemsOut( possibleDirections ); + return true; + } + } + } + + return false; + } + + private boolean sameGrid(IGrid grid) throws GridAccessException + { + return grid == gridProxy.getGrid(); + } + + private boolean acceptsItems(InventoryAdaptor ad, InventoryCrafting table) + { + for (int x = 0; x < table.getSizeInventory(); x++) + { + ItemStack is = table.getStackInSlot( x ); + if ( is == null ) + continue; + + if ( ad.simulateAdd( is.copy() ) != null ) + return false; + } + + return true; + } + + private void pushItemsOut(EnumSet possibleDirections) + { + if ( !hasItemsToSend() ) + return; + + TileEntity tile = iHost.getTileEntity(); + World w = tile.getWorldObj(); + + Iterator i = waitingToSend.iterator(); + while (i.hasNext()) + { + ItemStack whatToSend = i.next(); + + for (ForgeDirection s : possibleDirections) + { + TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); + if ( te == null ) + continue; + + InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() ); + if ( ad != null ) + { + ItemStack Result = ad.addItems( whatToSend ); + + if ( Result == null ) + whatToSend = null; + else + whatToSend.stackSize -= whatToSend.stackSize - Result.stackSize; + + if ( whatToSend == null ) + break; + } + } + + if ( whatToSend == null ) + i.remove(); + } + + if ( waitingToSend.isEmpty() ) + waitingToSend = null; + } + + @Override + public void provideCrafting(ICraftingProviderHelper craftingTracker) + { + if ( gridProxy.isActive() && craftingList != null ) + { + for (ICraftingPatternDetails details : craftingList) + { + details.setPriority( this.priority ); + craftingTracker.addCraftingOption( this, details ); + } + } + } + + public void addDrops(List drops) + { + if ( waitingToSend != null ) + { + for (ItemStack is : waitingToSend) + if ( is != null ) + drops.add( is ); + } + + for (ItemStack is : upgrades) + if ( is != null ) + drops.add( is ); + + for (ItemStack is : storage) + if ( is != null ) + drops.add( is ); + + for (ItemStack is : patterns) + if ( is != null ) + drops.add( is ); + } + + public void notifyNeightbors() + { + if ( gridProxy.isActive() ) + { + try + { + gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) ); + gridProxy.getTick().wakeDevice( gridProxy.getNode() ); + } + catch (GridAccessException e) + { + // :P + } + } + + TileEntity te = iHost.getTileEntity(); + if ( te != null && te.getWorldObj() != null ) + Platform.notifyBlocksOfNeighbors( te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord ); + } + + public IUpgradeableHost getHost() + { + if ( getPart() instanceof IUpgradeableHost ) + return (IUpgradeableHost) getPart(); + if ( getTile() instanceof IUpgradeableHost ) + return (IUpgradeableHost) getTile(); + return null; + } + + public ImmutableSet getRequestedJobs() + { + return craftingTracker.getRequestedJobs(); + } + + public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack acquired, Actionable mode) + { + int slot = craftingTracker.getSlot( link ); + + if ( acquired != null && slot >= 0 && slot <= requireWork.length ) + { + InventoryAdaptor adaptor = getAdaptor( slot ); + + if ( mode == Actionable.SIMULATE ) + return AEItemStack.create( adaptor.simulateAdd( acquired.getItemStack() ) ); + else + { + IAEItemStack is = AEItemStack.create( adaptor.addItems( acquired.getItemStack() ) ); + updatePlan( slot ); + return is; + } + } + + return acquired; + } + + public void jobStateChange(ICraftingLink link) + { + craftingTracker.jobStateChange( link ); + } + + static final Set badBlocks = new HashSet(); + + public String getTermName() + { + TileEntity tile = iHost.getTileEntity(); + World w = tile.getWorldObj(); + + if ( ((ICustomNameObject) iHost).hasCustomName() ) + return ((ICustomNameObject) iHost).getCustomName(); + + EnumSet possibleDirections = iHost.getTargets(); + for (ForgeDirection s : possibleDirections) + { + Vec3 from = Vec3.createVectorHelper( (double) tile.xCoord + 0.5, (double) tile.yCoord + 0.5, (double) tile.zCoord + 0.5 ); + from = from.addVector( s.offsetX * 0.501, s.offsetY * 0.501, s.offsetZ * 0.501 ); + Vec3 to = from.addVector( s.offsetX, s.offsetY, s.offsetZ ); + + Block blk = w.getBlock( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); + MovingObjectPosition mop = w.rayTraceBlocks( from, to, true ); + + TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ); + + if ( te == null ) + continue; + + if ( te instanceof IInterfaceHost ) + { + try + { + if ( ((IInterfaceHost) te).getInterfaceDuality().sameGrid( gridProxy.getGrid() ) ) + continue; + } + catch (GridAccessException e) + { + continue; + } + } + + Item item = Item.getItemFromBlock( blk ); + + if ( item == null ) + { + return blk.getUnlocalizedName(); + } + + ItemStack what = new ItemStack( item, 1, blk.getDamageValue( w, tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ) ); + + if ( te instanceof ICraftingMachine || InventoryAdaptor.getAdaptor( te, s.getOpposite() ) != null ) + { + if ( te instanceof IInventory && ((IInventory) te).getSizeInventory() == 0 ) + continue; + + if ( te instanceof ISidedInventory ) + { + int[] sides = ((ISidedInventory) te).getAccessibleSlotsFromSide( s.getOpposite().ordinal() ); + + if ( sides == null || sides.length == 0 ) + continue; + } + + try + { + if ( mop != null && !badBlocks.contains( blk ) ) + { + if ( mop.blockX == te.xCoord && mop.blockY == te.yCoord && mop.blockZ == te.zCoord ) + { + ItemStack g = blk.getPickBlock( mop, w, te.xCoord, te.yCoord, te.zCoord ); + if ( g != null ) + what = g; + } + } + } + catch (Throwable t) + { + badBlocks.add( blk ); // nope! + } + + if ( what.getItem() != null ) + return what.getUnlocalizedName(); + } + + } + + return "Nothing"; + } + + public long getSortValue() + { + TileEntity te = iHost.getTileEntity(); + return (te.zCoord << 24) ^ (te.xCoord << 8) ^ te.yCoord; + } + + public void initialize() + { + updateCraftingList(); + } + + @Override + public int getPriority() + { + return priority; + } + + @Override + public void setPriority(int newValue) + { + priority = newValue; + markDirty(); + + try + { + gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) ); + } + catch (GridAccessException e) + { + // :P + } + } +} diff --git a/helpers/IContainerCraftingPacket.java b/src/main/java/appeng/helpers/IContainerCraftingPacket.java similarity index 100% rename from helpers/IContainerCraftingPacket.java rename to src/main/java/appeng/helpers/IContainerCraftingPacket.java diff --git a/helpers/ICustomCollision.java b/src/main/java/appeng/helpers/ICustomCollision.java similarity index 96% rename from helpers/ICustomCollision.java rename to src/main/java/appeng/helpers/ICustomCollision.java index b214fa8ec..b93df2614 100644 --- a/helpers/ICustomCollision.java +++ b/src/main/java/appeng/helpers/ICustomCollision.java @@ -1,16 +1,16 @@ -package appeng.helpers; - -import java.util.List; - -import net.minecraft.entity.Entity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.World; - -public interface ICustomCollision -{ - - Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity thePlayer, boolean b); - - void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e); - -} +package appeng.helpers; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; + +public interface ICustomCollision +{ + + Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity thePlayer, boolean b); + + void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e); + +} diff --git a/helpers/ICustomNameObject.java b/src/main/java/appeng/helpers/ICustomNameObject.java similarity index 100% rename from helpers/ICustomNameObject.java rename to src/main/java/appeng/helpers/ICustomNameObject.java diff --git a/helpers/IInterfaceHost.java b/src/main/java/appeng/helpers/IInterfaceHost.java similarity index 96% rename from helpers/IInterfaceHost.java rename to src/main/java/appeng/helpers/IInterfaceHost.java index 5ad3c4f55..ea2e23386 100644 --- a/helpers/IInterfaceHost.java +++ b/src/main/java/appeng/helpers/IInterfaceHost.java @@ -1,22 +1,22 @@ -package appeng.helpers; - -import java.util.EnumSet; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.implementations.IUpgradeableHost; -import appeng.api.networking.crafting.ICraftingProvider; -import appeng.api.networking.crafting.ICraftingRequester; -import appeng.api.networking.security.IActionHost; - -public interface IInterfaceHost extends IActionHost, ICraftingProvider, IUpgradeableHost, ICraftingRequester -{ - - DualityInterface getInterfaceDuality(); - - EnumSet getTargets(); - - TileEntity getTileEntity(); - - void saveChanges(); -} +package appeng.helpers; + +import java.util.EnumSet; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.implementations.IUpgradeableHost; +import appeng.api.networking.crafting.ICraftingProvider; +import appeng.api.networking.crafting.ICraftingRequester; +import appeng.api.networking.security.IActionHost; + +public interface IInterfaceHost extends IActionHost, ICraftingProvider, IUpgradeableHost, ICraftingRequester +{ + + DualityInterface getInterfaceDuality(); + + EnumSet getTargets(); + + TileEntity getTileEntity(); + + void saveChanges(); +} diff --git a/helpers/IMouseWheelItem.java b/src/main/java/appeng/helpers/IMouseWheelItem.java similarity index 100% rename from helpers/IMouseWheelItem.java rename to src/main/java/appeng/helpers/IMouseWheelItem.java diff --git a/helpers/IPriorityHost.java b/src/main/java/appeng/helpers/IPriorityHost.java similarity index 100% rename from helpers/IPriorityHost.java rename to src/main/java/appeng/helpers/IPriorityHost.java diff --git a/helpers/InventoryAction.java b/src/main/java/appeng/helpers/InventoryAction.java similarity index 96% rename from helpers/InventoryAction.java rename to src/main/java/appeng/helpers/InventoryAction.java index de7589318..26e689e08 100644 --- a/helpers/InventoryAction.java +++ b/src/main/java/appeng/helpers/InventoryAction.java @@ -1,13 +1,13 @@ -package appeng.helpers; - -public enum InventoryAction -{ - // standard vanilla mechanics. - PICKUP_OR_SETDOWN, SPLIT_OR_PLACESINGLE, CREATIVE_DUPLICATE, SHIFT_CLICK, - - // crafting term - CRAFT_STACK, CRAFT_ITEM, CRAFT_SHIFT, - - // extra... - MOVE_REGION, PICKUP_SINGLE, UPDATE_HAND, ROLLUP, ROLLDOWN, AUTOCRAFT, PLACE_SINGLE -} +package appeng.helpers; + +public enum InventoryAction +{ + // standard vanilla mechanics. + PICKUP_OR_SETDOWN, SPLIT_OR_PLACESINGLE, CREATIVE_DUPLICATE, SHIFT_CLICK, + + // crafting term + CRAFT_STACK, CRAFT_ITEM, CRAFT_SHIFT, + + // extra... + MOVE_REGION, PICKUP_SINGLE, UPDATE_HAND, ROLLUP, ROLLDOWN, AUTOCRAFT, PLACE_SINGLE +} diff --git a/helpers/LocationRotation.java b/src/main/java/appeng/helpers/LocationRotation.java similarity index 94% rename from helpers/LocationRotation.java rename to src/main/java/appeng/helpers/LocationRotation.java index b8f700480..cae07aa56 100644 --- a/helpers/LocationRotation.java +++ b/src/main/java/appeng/helpers/LocationRotation.java @@ -1,48 +1,48 @@ -package appeng.helpers; - -import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.util.IOrientable; - -public class LocationRotation implements IOrientable -{ - - final IBlockAccess w; - final int x; - final int y; - final int z; - - public LocationRotation(IBlockAccess world, int x, int y, int z) { - w = world; - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public void setOrientation(ForgeDirection Forward, ForgeDirection Up) - { - - } - - @Override - public ForgeDirection getUp() - { - int num = Math.abs( x + y + z ) % 6; - return ForgeDirection.getOrientation( num ); - } - - @Override - public ForgeDirection getForward() - { - if ( getUp().offsetY == 0 ) - return ForgeDirection.UP; - return ForgeDirection.SOUTH; - } - - @Override - public boolean canBeRotated() - { - return false; - } -} +package appeng.helpers; + +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.util.IOrientable; + +public class LocationRotation implements IOrientable +{ + + final IBlockAccess w; + final int x; + final int y; + final int z; + + public LocationRotation(IBlockAccess world, int x, int y, int z) { + w = world; + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public void setOrientation(ForgeDirection Forward, ForgeDirection Up) + { + + } + + @Override + public ForgeDirection getUp() + { + int num = Math.abs( x + y + z ) % 6; + return ForgeDirection.getOrientation( num ); + } + + @Override + public ForgeDirection getForward() + { + if ( getUp().offsetY == 0 ) + return ForgeDirection.UP; + return ForgeDirection.SOUTH; + } + + @Override + public boolean canBeRotated() + { + return false; + } +} diff --git a/helpers/MetaRotation.java b/src/main/java/appeng/helpers/MetaRotation.java similarity index 95% rename from helpers/MetaRotation.java rename to src/main/java/appeng/helpers/MetaRotation.java index c465ee9b8..7888e1ff5 100644 --- a/helpers/MetaRotation.java +++ b/src/main/java/appeng/helpers/MetaRotation.java @@ -1,51 +1,51 @@ -package appeng.helpers; - -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.util.IOrientable; - -public class MetaRotation implements IOrientable -{ - - final IBlockAccess w; - final int x; - final int y; - final int z; - - public MetaRotation(IBlockAccess world, int x, int y, int z) { - w = world; - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public void setOrientation(ForgeDirection Forward, ForgeDirection Up) - { - if ( w instanceof World ) - ((World) w).setBlockMetadataWithNotify( x, y, z, Up.ordinal(), 1 + 2 ); - else - throw new RuntimeException( w.getClass().getName() + " received, expected World" ); - } - - @Override - public ForgeDirection getUp() - { - return ForgeDirection.getOrientation( w.getBlockMetadata( x, y, z ) ); - } - - @Override - public ForgeDirection getForward() - { - if ( getUp().offsetY == 0 ) - return ForgeDirection.UP; - return ForgeDirection.SOUTH; - } - - @Override - public boolean canBeRotated() - { - return true; - } -} +package appeng.helpers; + +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.util.IOrientable; + +public class MetaRotation implements IOrientable +{ + + final IBlockAccess w; + final int x; + final int y; + final int z; + + public MetaRotation(IBlockAccess world, int x, int y, int z) { + w = world; + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public void setOrientation(ForgeDirection Forward, ForgeDirection Up) + { + if ( w instanceof World ) + ((World) w).setBlockMetadataWithNotify( x, y, z, Up.ordinal(), 1 + 2 ); + else + throw new RuntimeException( w.getClass().getName() + " received, expected World" ); + } + + @Override + public ForgeDirection getUp() + { + return ForgeDirection.getOrientation( w.getBlockMetadata( x, y, z ) ); + } + + @Override + public ForgeDirection getForward() + { + if ( getUp().offsetY == 0 ) + return ForgeDirection.UP; + return ForgeDirection.SOUTH; + } + + @Override + public boolean canBeRotated() + { + return true; + } +} diff --git a/helpers/MeteoritePlacer.java b/src/main/java/appeng/helpers/MeteoritePlacer.java similarity index 100% rename from helpers/MeteoritePlacer.java rename to src/main/java/appeng/helpers/MeteoritePlacer.java diff --git a/helpers/MultiCraftingTracker.java b/src/main/java/appeng/helpers/MultiCraftingTracker.java similarity index 100% rename from helpers/MultiCraftingTracker.java rename to src/main/java/appeng/helpers/MultiCraftingTracker.java diff --git a/helpers/NullRotation.java b/src/main/java/appeng/helpers/NullRotation.java similarity index 100% rename from helpers/NullRotation.java rename to src/main/java/appeng/helpers/NullRotation.java diff --git a/helpers/PatternHelper.java b/src/main/java/appeng/helpers/PatternHelper.java similarity index 100% rename from helpers/PatternHelper.java rename to src/main/java/appeng/helpers/PatternHelper.java diff --git a/helpers/PlayerSecurityWrapper.java b/src/main/java/appeng/helpers/PlayerSecurityWrapper.java similarity index 100% rename from helpers/PlayerSecurityWrapper.java rename to src/main/java/appeng/helpers/PlayerSecurityWrapper.java diff --git a/helpers/Splot.java b/src/main/java/appeng/helpers/Splot.java similarity index 100% rename from helpers/Splot.java rename to src/main/java/appeng/helpers/Splot.java diff --git a/helpers/WirelessTerminalGuiObject.java b/src/main/java/appeng/helpers/WirelessTerminalGuiObject.java similarity index 100% rename from helpers/WirelessTerminalGuiObject.java rename to src/main/java/appeng/helpers/WirelessTerminalGuiObject.java diff --git a/hooks/AETrading.java b/src/main/java/appeng/hooks/AETrading.java similarity index 100% rename from hooks/AETrading.java rename to src/main/java/appeng/hooks/AETrading.java diff --git a/hooks/CompassManager.java b/src/main/java/appeng/hooks/CompassManager.java similarity index 100% rename from hooks/CompassManager.java rename to src/main/java/appeng/hooks/CompassManager.java diff --git a/hooks/CompassResult.java b/src/main/java/appeng/hooks/CompassResult.java similarity index 100% rename from hooks/CompassResult.java rename to src/main/java/appeng/hooks/CompassResult.java diff --git a/hooks/DispenserBehaviorTinyTNT.java b/src/main/java/appeng/hooks/DispenserBehaviorTinyTNT.java similarity index 100% rename from hooks/DispenserBehaviorTinyTNT.java rename to src/main/java/appeng/hooks/DispenserBehaviorTinyTNT.java diff --git a/hooks/DispenserBlockTool.java b/src/main/java/appeng/hooks/DispenserBlockTool.java similarity index 100% rename from hooks/DispenserBlockTool.java rename to src/main/java/appeng/hooks/DispenserBlockTool.java diff --git a/hooks/DispenserMatterCannon.java b/src/main/java/appeng/hooks/DispenserMatterCannon.java similarity index 100% rename from hooks/DispenserMatterCannon.java rename to src/main/java/appeng/hooks/DispenserMatterCannon.java diff --git a/hooks/IBlockTool.java b/src/main/java/appeng/hooks/IBlockTool.java similarity index 100% rename from hooks/IBlockTool.java rename to src/main/java/appeng/hooks/IBlockTool.java diff --git a/hooks/MeteoriteWorldGen.java b/src/main/java/appeng/hooks/MeteoriteWorldGen.java similarity index 100% rename from hooks/MeteoriteWorldGen.java rename to src/main/java/appeng/hooks/MeteoriteWorldGen.java diff --git a/hooks/QuartzWorldGen.java b/src/main/java/appeng/hooks/QuartzWorldGen.java similarity index 100% rename from hooks/QuartzWorldGen.java rename to src/main/java/appeng/hooks/QuartzWorldGen.java diff --git a/hooks/TickHandler.java b/src/main/java/appeng/hooks/TickHandler.java similarity index 100% rename from hooks/TickHandler.java rename to src/main/java/appeng/hooks/TickHandler.java diff --git a/integration/BaseModule.java b/src/main/java/appeng/integration/BaseModule.java similarity index 94% rename from integration/BaseModule.java rename to src/main/java/appeng/integration/BaseModule.java index 58cd250c6..3a5248b3b 100644 --- a/integration/BaseModule.java +++ b/src/main/java/appeng/integration/BaseModule.java @@ -1,16 +1,16 @@ -package appeng.integration; - -public abstract class BaseModule implements IIntegrationModule { - - protected void TestClass( Class clz ) - { - clz.isInstance(this); - } - - @Override - public abstract void Init() throws Throwable; - - @Override - public abstract void PostInit() throws Throwable; - -} +package appeng.integration; + +public abstract class BaseModule implements IIntegrationModule { + + protected void TestClass( Class clz ) + { + clz.isInstance(this); + } + + @Override + public abstract void Init() throws Throwable; + + @Override + public abstract void PostInit() throws Throwable; + +} diff --git a/integration/IIntegrationModule.java b/src/main/java/appeng/integration/IIntegrationModule.java similarity index 93% rename from integration/IIntegrationModule.java rename to src/main/java/appeng/integration/IIntegrationModule.java index a627a947e..cd117ec2f 100644 --- a/integration/IIntegrationModule.java +++ b/src/main/java/appeng/integration/IIntegrationModule.java @@ -1,10 +1,10 @@ -package appeng.integration; - -public interface IIntegrationModule -{ - - void Init() throws Throwable; - - void PostInit() throws Throwable; - -} +package appeng.integration; + +public interface IIntegrationModule +{ + + void Init() throws Throwable; + + void PostInit() throws Throwable; + +} diff --git a/integration/IntegrationNode.java b/src/main/java/appeng/integration/IntegrationNode.java similarity index 95% rename from integration/IntegrationNode.java rename to src/main/java/appeng/integration/IntegrationNode.java index e08e1680f..5f728dd34 100644 --- a/integration/IntegrationNode.java +++ b/src/main/java/appeng/integration/IntegrationNode.java @@ -1,124 +1,124 @@ -package appeng.integration; - -import java.lang.reflect.Field; - -import appeng.api.exceptions.ModNotInstalled; -import appeng.core.AEConfig; -import appeng.core.AELog; -import cpw.mods.fml.common.Loader; - -public class IntegrationNode -{ - - IntegrationStage state = IntegrationStage.PREINIT; - IntegrationStage failedStage = IntegrationStage.PREINIT; - Throwable exception = null; - - String displayName; - String modID; - - IntegrationType shortName; - String name = null; - Class classValue = null; - Object instance; - IIntegrationModule mod = null; - - public IntegrationNode(String dspname, String _modID, IntegrationType sName, String n) { - displayName = dspname; - shortName = sName; - modID = _modID; - name = n; - } - - @Override - public String toString() - { - return shortName.name() + ":" + state.name(); - } - - void Call(IntegrationStage stage) - { - if ( state != IntegrationStage.FAILED ) - { - if ( state.ordinal() > stage.ordinal() ) - return; - - try - { - switch (stage) - { - case PREINIT: - - boolean enabled = modID == null || Loader.isModLoaded( modID ); - - AEConfig.instance - .addCustomCategoryComment( - "ModIntegration", - "Valid Values are 'AUTO', 'ON', or 'OFF' - defaults to 'AUTO' ; Suggested that you leave this alone unless your experiencing an issue, or wish to disable the integration for a reason." ); - String Mode = AEConfig.instance.get( "ModIntegration", displayName.replace( " ", "" ), "AUTO" ).getString(); - - if ( Mode.toUpperCase().equals( "ON" ) ) - enabled = true; - if ( Mode.toUpperCase().equals( "OFF" ) ) - enabled = false; - - if ( enabled ) - { - classValue = getClass().getClassLoader().loadClass( name ); - mod = (IIntegrationModule) classValue.getConstructor().newInstance(); - Field f = classValue.getField( "instance" ); - f.set( classValue, instance = mod ); - } - else - throw new ModNotInstalled( modID ); - - state = IntegrationStage.INIT; - - break; - case INIT: - mod.Init(); - state = IntegrationStage.POSTINIT; - - break; - case POSTINIT: - mod.PostInit(); - state = IntegrationStage.READY; - - break; - case FAILED: - default: - break; - } - } - catch (Throwable t) - { - failedStage = stage; - exception = t; - state = IntegrationStage.FAILED; - } - } - - if ( stage == IntegrationStage.POSTINIT ) - { - if ( state == IntegrationStage.FAILED ) - { - AELog.info( displayName + " - Integration Disabled" ); - if ( !(exception instanceof ModNotInstalled) ) - AELog.integration( exception ); - } - else - { - AELog.info( displayName + " - Integration Enable" ); - } - } - } - - public boolean isActive() - { - if ( state == IntegrationStage.PREINIT ) - Call( IntegrationStage.PREINIT ); - - return state != IntegrationStage.FAILED; - } - -} +package appeng.integration; + +import java.lang.reflect.Field; + +import appeng.api.exceptions.ModNotInstalled; +import appeng.core.AEConfig; +import appeng.core.AELog; +import cpw.mods.fml.common.Loader; + +public class IntegrationNode +{ + + IntegrationStage state = IntegrationStage.PREINIT; + IntegrationStage failedStage = IntegrationStage.PREINIT; + Throwable exception = null; + + String displayName; + String modID; + + IntegrationType shortName; + String name = null; + Class classValue = null; + Object instance; + IIntegrationModule mod = null; + + public IntegrationNode(String dspname, String _modID, IntegrationType sName, String n) { + displayName = dspname; + shortName = sName; + modID = _modID; + name = n; + } + + @Override + public String toString() + { + return shortName.name() + ":" + state.name(); + } + + void Call(IntegrationStage stage) + { + if ( state != IntegrationStage.FAILED ) + { + if ( state.ordinal() > stage.ordinal() ) + return; + + try + { + switch (stage) + { + case PREINIT: + + boolean enabled = modID == null || Loader.isModLoaded( modID ); + + AEConfig.instance + .addCustomCategoryComment( + "ModIntegration", + "Valid Values are 'AUTO', 'ON', or 'OFF' - defaults to 'AUTO' ; Suggested that you leave this alone unless your experiencing an issue, or wish to disable the integration for a reason." ); + String Mode = AEConfig.instance.get( "ModIntegration", displayName.replace( " ", "" ), "AUTO" ).getString(); + + if ( Mode.toUpperCase().equals( "ON" ) ) + enabled = true; + if ( Mode.toUpperCase().equals( "OFF" ) ) + enabled = false; + + if ( enabled ) + { + classValue = getClass().getClassLoader().loadClass( name ); + mod = (IIntegrationModule) classValue.getConstructor().newInstance(); + Field f = classValue.getField( "instance" ); + f.set( classValue, instance = mod ); + } + else + throw new ModNotInstalled( modID ); + + state = IntegrationStage.INIT; + + break; + case INIT: + mod.Init(); + state = IntegrationStage.POSTINIT; + + break; + case POSTINIT: + mod.PostInit(); + state = IntegrationStage.READY; + + break; + case FAILED: + default: + break; + } + } + catch (Throwable t) + { + failedStage = stage; + exception = t; + state = IntegrationStage.FAILED; + } + } + + if ( stage == IntegrationStage.POSTINIT ) + { + if ( state == IntegrationStage.FAILED ) + { + AELog.info( displayName + " - Integration Disabled" ); + if ( !(exception instanceof ModNotInstalled) ) + AELog.integration( exception ); + } + else + { + AELog.info( displayName + " - Integration Enable" ); + } + } + } + + public boolean isActive() + { + if ( state == IntegrationStage.PREINIT ) + Call( IntegrationStage.PREINIT ); + + return state != IntegrationStage.FAILED; + } + +} diff --git a/integration/IntegrationRegistry.java b/src/main/java/appeng/integration/IntegrationRegistry.java similarity index 95% rename from integration/IntegrationRegistry.java rename to src/main/java/appeng/integration/IntegrationRegistry.java index 1f6d2ec07..9d4593178 100644 --- a/integration/IntegrationRegistry.java +++ b/src/main/java/appeng/integration/IntegrationRegistry.java @@ -1,83 +1,83 @@ -package appeng.integration; - -import java.util.LinkedList; - -import cpw.mods.fml.relauncher.FMLLaunchHandler; -import cpw.mods.fml.relauncher.Side; - -public class IntegrationRegistry -{ - - public static IntegrationRegistry instance = null; - private LinkedList modules = new LinkedList(); - - public void add( IntegrationType type) - { - if ( type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER ) - return; - - if ( type.side == IntegrationSide.SERVER && FMLLaunchHandler.side() == Side.CLIENT ) - return; - - modules.add( new IntegrationNode( type.dspName, type.modID, type, "appeng.integration.modules." + type.name() ) ); - } - - public IntegrationRegistry() { - instance = this; - } - - public void init() - { - for (IntegrationNode node : modules) - node.Call( IntegrationStage.PREINIT ); - - for (IntegrationNode node : modules) - node.Call( IntegrationStage.INIT ); - } - - public void postinit() - { - for (IntegrationNode node : modules) - node.Call( IntegrationStage.POSTINIT ); - } - - public String getStatus() - { - String out = null; - - for (IntegrationNode node : modules) - { - String str = node.shortName + ":" + (node.state == IntegrationStage.FAILED ? "OFF" : "ON"); - - if ( out == null ) - out = str; - else - out += ", " + str; - } - - return out; - } - - public boolean isEnabled(IntegrationType name) - { - for (IntegrationNode node : modules) - { - if ( node.shortName == name ) - return node.isActive(); - } - return false; - } - - public Object getInstance(IntegrationType name) - { - for (IntegrationNode node : modules) - { - if ( node.shortName.equals( name ) && node.isActive() ) - { - return node.instance; - } - } - throw new RuntimeException( "integration with "+name.name()+" is disabled." ); - } - -} +package appeng.integration; + +import java.util.LinkedList; + +import cpw.mods.fml.relauncher.FMLLaunchHandler; +import cpw.mods.fml.relauncher.Side; + +public class IntegrationRegistry +{ + + public static IntegrationRegistry instance = null; + private LinkedList modules = new LinkedList(); + + public void add( IntegrationType type) + { + if ( type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER ) + return; + + if ( type.side == IntegrationSide.SERVER && FMLLaunchHandler.side() == Side.CLIENT ) + return; + + modules.add( new IntegrationNode( type.dspName, type.modID, type, "appeng.integration.modules." + type.name() ) ); + } + + public IntegrationRegistry() { + instance = this; + } + + public void init() + { + for (IntegrationNode node : modules) + node.Call( IntegrationStage.PREINIT ); + + for (IntegrationNode node : modules) + node.Call( IntegrationStage.INIT ); + } + + public void postinit() + { + for (IntegrationNode node : modules) + node.Call( IntegrationStage.POSTINIT ); + } + + public String getStatus() + { + String out = null; + + for (IntegrationNode node : modules) + { + String str = node.shortName + ":" + (node.state == IntegrationStage.FAILED ? "OFF" : "ON"); + + if ( out == null ) + out = str; + else + out += ", " + str; + } + + return out; + } + + public boolean isEnabled(IntegrationType name) + { + for (IntegrationNode node : modules) + { + if ( node.shortName == name ) + return node.isActive(); + } + return false; + } + + public Object getInstance(IntegrationType name) + { + for (IntegrationNode node : modules) + { + if ( node.shortName.equals( name ) && node.isActive() ) + { + return node.instance; + } + } + throw new RuntimeException( "integration with "+name.name()+" is disabled." ); + } + +} diff --git a/integration/IntegrationSide.java b/src/main/java/appeng/integration/IntegrationSide.java similarity index 93% rename from integration/IntegrationSide.java rename to src/main/java/appeng/integration/IntegrationSide.java index e691ec201..c27776cdd 100644 --- a/integration/IntegrationSide.java +++ b/src/main/java/appeng/integration/IntegrationSide.java @@ -1,6 +1,6 @@ -package appeng.integration; - -public enum IntegrationSide -{ - CLIENT, SERVER, BOTH -} +package appeng.integration; + +public enum IntegrationSide +{ + CLIENT, SERVER, BOTH +} diff --git a/integration/IntegrationStage.java b/src/main/java/appeng/integration/IntegrationStage.java similarity index 91% rename from integration/IntegrationStage.java rename to src/main/java/appeng/integration/IntegrationStage.java index e42cd1773..24b0ece0e 100644 --- a/integration/IntegrationStage.java +++ b/src/main/java/appeng/integration/IntegrationStage.java @@ -1,10 +1,10 @@ -package appeng.integration; - -public enum IntegrationStage -{ - - PREINIT, INIT, POSTINIT, - - FAILED, READY - -} +package appeng.integration; + +public enum IntegrationStage +{ + + PREINIT, INIT, POSTINIT, + + FAILED, READY + +} diff --git a/integration/IntegrationType.java b/src/main/java/appeng/integration/IntegrationType.java similarity index 96% rename from integration/IntegrationType.java rename to src/main/java/appeng/integration/IntegrationType.java index 02d1ec9ce..7cd0c44b0 100644 --- a/integration/IntegrationType.java +++ b/src/main/java/appeng/integration/IntegrationType.java @@ -1,57 +1,57 @@ -package appeng.integration; - -public enum IntegrationType -{ - IC2(IntegrationSide.BOTH, "Industrial Craft 2", "IC2"), - - RotaryCraft(IntegrationSide.BOTH, "Rotary Craft", "RotaryCraft"), - - RC(IntegrationSide.BOTH, "Railcraft", "Railcraft"), - - BC(IntegrationSide.BOTH, "BuildCraft", "BuildCraft|Silicon"), - - MJ6(IntegrationSide.BOTH, "BuildCraft6 Power", null), - - MJ5(IntegrationSide.BOTH, "BuildCraft5 Power", null), - - RF(IntegrationSide.BOTH, "RedstoneFlux Power - Tiles", null), - - RFItem(IntegrationSide.BOTH, "RedstoneFlux Power - Items", null), - - MFR(IntegrationSide.BOTH, "Mine Factory Reloaded", "MineFactoryReloaded"), - - DSU(IntegrationSide.BOTH, "Deep Storage Unit", null), - - FZ(IntegrationSide.BOTH, "Factorization", "factorization"), - - FMP(IntegrationSide.BOTH, "Forge MultiPart", "McMultipart"), - - RB(IntegrationSide.BOTH, "Rotatable Blocks", "RotatableBlocks"), - - CLApi(IntegrationSide.BOTH, "Colored Lights Core", "coloredlightscore"), - - Waila(IntegrationSide.CLIENT, "Waila", "Waila"), - - InvTweaks(IntegrationSide.CLIENT, "Inventory Tweaks", "inventorytweaks"), - - NEI(IntegrationSide.CLIENT, "Not Enough Items", "NotEnoughItems"), - - CraftGuide(IntegrationSide.CLIENT, "Craft Guide", "craftguide"), - - Mekanism(IntegrationSide.BOTH, "Mekanism", "Mekanism"), - - ImmibisMicroblocks(IntegrationSide.BOTH, "ImmibisMicroblocks", "ImmibisMicroblocks"), - - BetterStorage(IntegrationSide.BOTH, "BetterStorage", "betterstorage" ); - - public final IntegrationSide side; - public final String dspName; - public final String modID; - - private IntegrationType(IntegrationSide side, String Name, String modid) { - this.side = side; - this.dspName = Name; - this.modID = modid; - } - -} +package appeng.integration; + +public enum IntegrationType +{ + IC2(IntegrationSide.BOTH, "Industrial Craft 2", "IC2"), + + RotaryCraft(IntegrationSide.BOTH, "Rotary Craft", "RotaryCraft"), + + RC(IntegrationSide.BOTH, "Railcraft", "Railcraft"), + + BC(IntegrationSide.BOTH, "BuildCraft", "BuildCraft|Silicon"), + + MJ6(IntegrationSide.BOTH, "BuildCraft6 Power", null), + + MJ5(IntegrationSide.BOTH, "BuildCraft5 Power", null), + + RF(IntegrationSide.BOTH, "RedstoneFlux Power - Tiles", null), + + RFItem(IntegrationSide.BOTH, "RedstoneFlux Power - Items", null), + + MFR(IntegrationSide.BOTH, "Mine Factory Reloaded", "MineFactoryReloaded"), + + DSU(IntegrationSide.BOTH, "Deep Storage Unit", null), + + FZ(IntegrationSide.BOTH, "Factorization", "factorization"), + + FMP(IntegrationSide.BOTH, "Forge MultiPart", "McMultipart"), + + RB(IntegrationSide.BOTH, "Rotatable Blocks", "RotatableBlocks"), + + CLApi(IntegrationSide.BOTH, "Colored Lights Core", "coloredlightscore"), + + Waila(IntegrationSide.CLIENT, "Waila", "Waila"), + + InvTweaks(IntegrationSide.CLIENT, "Inventory Tweaks", "inventorytweaks"), + + NEI(IntegrationSide.CLIENT, "Not Enough Items", "NotEnoughItems"), + + CraftGuide(IntegrationSide.CLIENT, "Craft Guide", "craftguide"), + + Mekanism(IntegrationSide.BOTH, "Mekanism", "Mekanism"), + + ImmibisMicroblocks(IntegrationSide.BOTH, "ImmibisMicroblocks", "ImmibisMicroblocks"), + + BetterStorage(IntegrationSide.BOTH, "BetterStorage", "betterstorage" ); + + public final IntegrationSide side; + public final String dspName; + public final String modID; + + private IntegrationType(IntegrationSide side, String Name, String modid) { + this.side = side; + this.dspName = Name; + this.modID = modid; + } + +} diff --git a/integration/abstraction/IBC.java b/src/main/java/appeng/integration/abstraction/IBC.java similarity index 96% rename from integration/abstraction/IBC.java rename to src/main/java/appeng/integration/abstraction/IBC.java index 1397ccbf6..f30ec6d96 100644 --- a/integration/abstraction/IBC.java +++ b/src/main/java/appeng/integration/abstraction/IBC.java @@ -1,45 +1,45 @@ -package appeng.integration.abstraction; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.parts.IFacadePart; - -public interface IBC -{ - - boolean isWrench(Item eq); - - boolean canWrench(Item i, EntityPlayer p, int x, int y, int z); - - void wrenchUsed(Item i, EntityPlayer p, int x, int y, int z); - - boolean canAddItemsToPipe(TileEntity te, ItemStack is, ForgeDirection dir); - - boolean addItemsToPipe(TileEntity te, ItemStack is, ForgeDirection dir); - - boolean isFacade(ItemStack is); - - boolean isPipe(TileEntity te, ForgeDirection dir); - - void addFacade(ItemStack item); - - void registerPowerP2P(); - - void registerItemP2P(); - - void registerLiquidsP2P(); - - IFacadePart createFacadePart(Block blk, int meta, ForgeDirection side); - - IFacadePart createFacadePart(ItemStack held, ForgeDirection side); - - ItemStack getTextureForFacade(ItemStack facade); - - IIcon getFacadeTexture(); - -} +package appeng.integration.abstraction; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.parts.IFacadePart; + +public interface IBC +{ + + boolean isWrench(Item eq); + + boolean canWrench(Item i, EntityPlayer p, int x, int y, int z); + + void wrenchUsed(Item i, EntityPlayer p, int x, int y, int z); + + boolean canAddItemsToPipe(TileEntity te, ItemStack is, ForgeDirection dir); + + boolean addItemsToPipe(TileEntity te, ItemStack is, ForgeDirection dir); + + boolean isFacade(ItemStack is); + + boolean isPipe(TileEntity te, ForgeDirection dir); + + void addFacade(ItemStack item); + + void registerPowerP2P(); + + void registerItemP2P(); + + void registerLiquidsP2P(); + + IFacadePart createFacadePart(Block blk, int meta, ForgeDirection side); + + IFacadePart createFacadePart(ItemStack held, ForgeDirection side); + + ItemStack getTextureForFacade(ItemStack facade); + + IIcon getFacadeTexture(); + +} diff --git a/integration/abstraction/IBetterStorage.java b/src/main/java/appeng/integration/abstraction/IBetterStorage.java similarity index 95% rename from integration/abstraction/IBetterStorage.java rename to src/main/java/appeng/integration/abstraction/IBetterStorage.java index 7acd679d8..a966e0d98 100644 --- a/integration/abstraction/IBetterStorage.java +++ b/src/main/java/appeng/integration/abstraction/IBetterStorage.java @@ -1,13 +1,13 @@ -package appeng.integration.abstraction; - -import net.minecraftforge.common.util.ForgeDirection; -import appeng.util.InventoryAdaptor; - -public interface IBetterStorage -{ - - boolean isStorageCrate(Object te); - - InventoryAdaptor getAdaptor(Object te, ForgeDirection d); - -} +package appeng.integration.abstraction; + +import net.minecraftforge.common.util.ForgeDirection; +import appeng.util.InventoryAdaptor; + +public interface IBetterStorage +{ + + boolean isStorageCrate(Object te); + + InventoryAdaptor getAdaptor(Object te, ForgeDirection d); + +} diff --git a/integration/abstraction/ICLApi.java b/src/main/java/appeng/integration/abstraction/ICLApi.java similarity index 100% rename from integration/abstraction/ICLApi.java rename to src/main/java/appeng/integration/abstraction/ICLApi.java diff --git a/integration/abstraction/IDSU.java b/src/main/java/appeng/integration/abstraction/IDSU.java similarity index 100% rename from integration/abstraction/IDSU.java rename to src/main/java/appeng/integration/abstraction/IDSU.java diff --git a/integration/abstraction/IFMP.java b/src/main/java/appeng/integration/abstraction/IFMP.java similarity index 96% rename from integration/abstraction/IFMP.java rename to src/main/java/appeng/integration/abstraction/IFMP.java index 6cad36078..920b5dddf 100644 --- a/integration/abstraction/IFMP.java +++ b/src/main/java/appeng/integration/abstraction/IFMP.java @@ -1,20 +1,20 @@ -package appeng.integration.abstraction; - -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.tileentity.TileEntity; -import appeng.api.parts.IPartHost; -import appeng.parts.CableBusContainer; -import cpw.mods.fml.common.eventhandler.Event; - -public interface IFMP -{ - - IPartHost getOrCreateHost(TileEntity tile); - - CableBusContainer getCableContainer(TileEntity te); - - void registerPassThrough(Class layerInterface); - - Event newFMPPacketEvent(EntityPlayerMP sender); - -} +package appeng.integration.abstraction; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import appeng.api.parts.IPartHost; +import appeng.parts.CableBusContainer; +import cpw.mods.fml.common.eventhandler.Event; + +public interface IFMP +{ + + IPartHost getOrCreateHost(TileEntity tile); + + CableBusContainer getCableContainer(TileEntity te); + + void registerPassThrough(Class layerInterface); + + Event newFMPPacketEvent(EntityPlayerMP sender); + +} diff --git a/integration/abstraction/IFZ.java b/src/main/java/appeng/integration/abstraction/IFZ.java similarity index 95% rename from integration/abstraction/IFZ.java rename to src/main/java/appeng/integration/abstraction/IFZ.java index 275310481..a80017d8d 100644 --- a/integration/abstraction/IFZ.java +++ b/src/main/java/appeng/integration/abstraction/IFZ.java @@ -1,26 +1,26 @@ -package appeng.integration.abstraction; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import appeng.api.storage.IMEInventory; - -public interface IFZ -{ - - ItemStack barrelGetItem(TileEntity te); - - int barrelGetMaxItemCount(TileEntity te); - - int barrelGetItemCount(TileEntity te); - - void setItemType(TileEntity te, ItemStack input); - - void barrelSetCount(TileEntity te, int max); - - IMEInventory getFactorizationBarrel(TileEntity te); - - boolean isBarrel(TileEntity te); - - void grinderRecipe(ItemStack is, ItemStack itemStack); - -} +package appeng.integration.abstraction; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import appeng.api.storage.IMEInventory; + +public interface IFZ +{ + + ItemStack barrelGetItem(TileEntity te); + + int barrelGetMaxItemCount(TileEntity te); + + int barrelGetItemCount(TileEntity te); + + void setItemType(TileEntity te, ItemStack input); + + void barrelSetCount(TileEntity te, int max); + + IMEInventory getFactorizationBarrel(TileEntity te); + + boolean isBarrel(TileEntity te); + + void grinderRecipe(ItemStack is, ItemStack itemStack); + +} diff --git a/integration/abstraction/IForestry.java b/src/main/java/appeng/integration/abstraction/IForestry.java similarity index 95% rename from integration/abstraction/IForestry.java rename to src/main/java/appeng/integration/abstraction/IForestry.java index 50b6ab64d..3dbfbd4b5 100644 --- a/integration/abstraction/IForestry.java +++ b/src/main/java/appeng/integration/abstraction/IForestry.java @@ -1,10 +1,10 @@ -package appeng.integration.abstraction; - -import appeng.api.features.IItemComparisonProvider; - -public interface IForestry -{ - - IItemComparisonProvider getGeneticsComparisonProvider(); - +package appeng.integration.abstraction; + +import appeng.api.features.IItemComparisonProvider; + +public interface IForestry +{ + + IItemComparisonProvider getGeneticsComparisonProvider(); + } \ No newline at end of file diff --git a/integration/abstraction/IGT.java b/src/main/java/appeng/integration/abstraction/IGT.java similarity index 94% rename from integration/abstraction/IGT.java rename to src/main/java/appeng/integration/abstraction/IGT.java index 764673694..452b79163 100644 --- a/integration/abstraction/IGT.java +++ b/src/main/java/appeng/integration/abstraction/IGT.java @@ -1,13 +1,13 @@ -package appeng.integration.abstraction; - -import net.minecraft.tileentity.TileEntity; -import appeng.api.storage.IMEInventory; - -public interface IGT -{ - - boolean isQuantumChest(TileEntity te); - - IMEInventory getQuantumChest(TileEntity te); - -} +package appeng.integration.abstraction; + +import net.minecraft.tileentity.TileEntity; +import appeng.api.storage.IMEInventory; + +public interface IGT +{ + + boolean isQuantumChest(TileEntity te); + + IMEInventory getQuantumChest(TileEntity te); + +} diff --git a/integration/abstraction/IIC2.java b/src/main/java/appeng/integration/abstraction/IIC2.java similarity index 95% rename from integration/abstraction/IIC2.java rename to src/main/java/appeng/integration/abstraction/IIC2.java index cead3e1fb..f2c451f1d 100644 --- a/integration/abstraction/IIC2.java +++ b/src/main/java/appeng/integration/abstraction/IIC2.java @@ -1,17 +1,17 @@ -package appeng.integration.abstraction; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -public interface IIC2 -{ - - void addToEnergyNet(TileEntity appEngTile); - - void removeFromEnergyNet(TileEntity appEngTile); - - ItemStack getItem(String string); - - void maceratorRecipe(ItemStack in, ItemStack out); - -} +package appeng.integration.abstraction; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +public interface IIC2 +{ + + void addToEnergyNet(TileEntity appEngTile); + + void removeFromEnergyNet(TileEntity appEngTile); + + ItemStack getItem(String string); + + void maceratorRecipe(ItemStack in, ItemStack out); + +} diff --git a/integration/abstraction/IImmibisMicroblocks.java b/src/main/java/appeng/integration/abstraction/IImmibisMicroblocks.java similarity index 100% rename from integration/abstraction/IImmibisMicroblocks.java rename to src/main/java/appeng/integration/abstraction/IImmibisMicroblocks.java diff --git a/integration/abstraction/IInvTweaks.java b/src/main/java/appeng/integration/abstraction/IInvTweaks.java similarity index 94% rename from integration/abstraction/IInvTweaks.java rename to src/main/java/appeng/integration/abstraction/IInvTweaks.java index 6d83eea34..ce60eee8e 100644 --- a/integration/abstraction/IInvTweaks.java +++ b/src/main/java/appeng/integration/abstraction/IInvTweaks.java @@ -1,10 +1,10 @@ -package appeng.integration.abstraction; - -import net.minecraft.item.ItemStack; - -public interface IInvTweaks -{ - - int compareItems(ItemStack i, ItemStack j); - -} +package appeng.integration.abstraction; + +import net.minecraft.item.ItemStack; + +public interface IInvTweaks +{ + + int compareItems(ItemStack i, ItemStack j); + +} diff --git a/integration/abstraction/ILP.java b/src/main/java/appeng/integration/abstraction/ILP.java similarity index 95% rename from integration/abstraction/ILP.java rename to src/main/java/appeng/integration/abstraction/ILP.java index 45369504c..3b5beab08 100644 --- a/integration/abstraction/ILP.java +++ b/src/main/java/appeng/integration/abstraction/ILP.java @@ -1,30 +1,30 @@ -package appeng.integration.abstraction; - -import java.util.List; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import appeng.api.storage.IMEInventory; - -public interface ILP -{ - - List getCraftedItems(TileEntity te); - - List getProvidedItems(TileEntity te); - - boolean isRequestPipe(TileEntity te); - - List performRequest(TileEntity te, ItemStack wanted); - - IMEInventory getInv(TileEntity te); - - Object getGetPowerPipe(TileEntity te); - - boolean isPowerSource(TileEntity tt); - - boolean canUseEnergy(Object pp, int ceil, List providersToIgnore); - - boolean useEnergy(Object pp, int ceil, List providersToIgnore); - -} +package appeng.integration.abstraction; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import appeng.api.storage.IMEInventory; + +public interface ILP +{ + + List getCraftedItems(TileEntity te); + + List getProvidedItems(TileEntity te); + + boolean isRequestPipe(TileEntity te); + + List performRequest(TileEntity te, ItemStack wanted); + + IMEInventory getInv(TileEntity te); + + Object getGetPowerPipe(TileEntity te); + + boolean isPowerSource(TileEntity tt); + + boolean canUseEnergy(Object pp, int ceil, List providersToIgnore); + + boolean useEnergy(Object pp, int ceil, List providersToIgnore); + +} diff --git a/integration/abstraction/IMJ5.java b/src/main/java/appeng/integration/abstraction/IMJ5.java similarity index 100% rename from integration/abstraction/IMJ5.java rename to src/main/java/appeng/integration/abstraction/IMJ5.java diff --git a/integration/abstraction/IMJ6.java b/src/main/java/appeng/integration/abstraction/IMJ6.java similarity index 100% rename from integration/abstraction/IMJ6.java rename to src/main/java/appeng/integration/abstraction/IMJ6.java diff --git a/integration/abstraction/IMekanism.java b/src/main/java/appeng/integration/abstraction/IMekanism.java similarity index 95% rename from integration/abstraction/IMekanism.java rename to src/main/java/appeng/integration/abstraction/IMekanism.java index 518f8d5b7..8be4c7075 100644 --- a/integration/abstraction/IMekanism.java +++ b/src/main/java/appeng/integration/abstraction/IMekanism.java @@ -1,12 +1,12 @@ -package appeng.integration.abstraction; - -import net.minecraft.item.ItemStack; - -public interface IMekanism -{ - - void addCrusherRecipe(ItemStack in, ItemStack out); - - void addEnrichmentChamberRecipe(ItemStack in, ItemStack out); - -} +package appeng.integration.abstraction; + +import net.minecraft.item.ItemStack; + +public interface IMekanism +{ + + void addCrusherRecipe(ItemStack in, ItemStack out); + + void addEnrichmentChamberRecipe(ItemStack in, ItemStack out); + +} diff --git a/integration/abstraction/INEI.java b/src/main/java/appeng/integration/abstraction/INEI.java similarity index 100% rename from integration/abstraction/INEI.java rename to src/main/java/appeng/integration/abstraction/INEI.java diff --git a/integration/abstraction/IRB.java b/src/main/java/appeng/integration/abstraction/IRB.java similarity index 100% rename from integration/abstraction/IRB.java rename to src/main/java/appeng/integration/abstraction/IRB.java diff --git a/integration/abstraction/IRC.java b/src/main/java/appeng/integration/abstraction/IRC.java similarity index 100% rename from integration/abstraction/IRC.java rename to src/main/java/appeng/integration/abstraction/IRC.java diff --git a/integration/abstraction/ITE.java b/src/main/java/appeng/integration/abstraction/ITE.java similarity index 96% rename from integration/abstraction/ITE.java rename to src/main/java/appeng/integration/abstraction/ITE.java index adb1c485c..56e70230a 100644 --- a/integration/abstraction/ITE.java +++ b/src/main/java/appeng/integration/abstraction/ITE.java @@ -1,18 +1,18 @@ -package appeng.integration.abstraction; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; - -public interface ITE -{ - - void addPulverizerRecipe(int i, ItemStack blkQuartz, ItemStack blockDust); - - void addPulverizerRecipe(int i, ItemStack blkQuartzOre, ItemStack matQuartz, ItemStack matQuartzDust); - - boolean isPipe(TileEntity te, ForgeDirection opposite); - - ItemStack addItemsToPipe(TileEntity ad, ItemStack itemstack, ForgeDirection dir); - -} +package appeng.integration.abstraction; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public interface ITE +{ + + void addPulverizerRecipe(int i, ItemStack blkQuartz, ItemStack blockDust); + + void addPulverizerRecipe(int i, ItemStack blkQuartzOre, ItemStack matQuartz, ItemStack matQuartzDust); + + boolean isPipe(TileEntity te, ForgeDirection opposite); + + ItemStack addItemsToPipe(TileEntity ad, ItemStack itemstack, ForgeDirection dir); + +} diff --git a/integration/abstraction/helpers/BaseMJperdition.java b/src/main/java/appeng/integration/abstraction/helpers/BaseMJperdition.java similarity index 100% rename from integration/abstraction/helpers/BaseMJperdition.java rename to src/main/java/appeng/integration/abstraction/helpers/BaseMJperdition.java diff --git a/integration/modules/BC.java b/src/main/java/appeng/integration/modules/BC.java similarity index 100% rename from integration/modules/BC.java rename to src/main/java/appeng/integration/modules/BC.java diff --git a/integration/modules/BCHelpers/AECableSchematicTile.java b/src/main/java/appeng/integration/modules/BCHelpers/AECableSchematicTile.java similarity index 100% rename from integration/modules/BCHelpers/AECableSchematicTile.java rename to src/main/java/appeng/integration/modules/BCHelpers/AECableSchematicTile.java diff --git a/integration/modules/BCHelpers/AEGenericSchematicTile.java b/src/main/java/appeng/integration/modules/BCHelpers/AEGenericSchematicTile.java similarity index 100% rename from integration/modules/BCHelpers/AEGenericSchematicTile.java rename to src/main/java/appeng/integration/modules/BCHelpers/AEGenericSchematicTile.java diff --git a/integration/modules/BCHelpers/AERotatableBlockSchematic.java b/src/main/java/appeng/integration/modules/BCHelpers/AERotatableBlockSchematic.java similarity index 100% rename from integration/modules/BCHelpers/AERotatableBlockSchematic.java rename to src/main/java/appeng/integration/modules/BCHelpers/AERotatableBlockSchematic.java diff --git a/integration/modules/BCHelpers/BCPipeHandler.java b/src/main/java/appeng/integration/modules/BCHelpers/BCPipeHandler.java similarity index 100% rename from integration/modules/BCHelpers/BCPipeHandler.java rename to src/main/java/appeng/integration/modules/BCHelpers/BCPipeHandler.java diff --git a/integration/modules/BCHelpers/BCPipeInventory.java b/src/main/java/appeng/integration/modules/BCHelpers/BCPipeInventory.java similarity index 100% rename from integration/modules/BCHelpers/BCPipeInventory.java rename to src/main/java/appeng/integration/modules/BCHelpers/BCPipeInventory.java diff --git a/integration/modules/BetterStorage.java b/src/main/java/appeng/integration/modules/BetterStorage.java similarity index 100% rename from integration/modules/BetterStorage.java rename to src/main/java/appeng/integration/modules/BetterStorage.java diff --git a/integration/modules/CLApi.java b/src/main/java/appeng/integration/modules/CLApi.java similarity index 100% rename from integration/modules/CLApi.java rename to src/main/java/appeng/integration/modules/CLApi.java diff --git a/integration/modules/CraftGuide.java b/src/main/java/appeng/integration/modules/CraftGuide.java similarity index 100% rename from integration/modules/CraftGuide.java rename to src/main/java/appeng/integration/modules/CraftGuide.java diff --git a/integration/modules/DSU.java b/src/main/java/appeng/integration/modules/DSU.java similarity index 100% rename from integration/modules/DSU.java rename to src/main/java/appeng/integration/modules/DSU.java diff --git a/integration/modules/FMP.java b/src/main/java/appeng/integration/modules/FMP.java similarity index 100% rename from integration/modules/FMP.java rename to src/main/java/appeng/integration/modules/FMP.java diff --git a/integration/modules/FZ.java b/src/main/java/appeng/integration/modules/FZ.java similarity index 100% rename from integration/modules/FZ.java rename to src/main/java/appeng/integration/modules/FZ.java diff --git a/integration/modules/IC2.java b/src/main/java/appeng/integration/modules/IC2.java similarity index 100% rename from integration/modules/IC2.java rename to src/main/java/appeng/integration/modules/IC2.java diff --git a/integration/modules/ImmibisMicroblocks.java b/src/main/java/appeng/integration/modules/ImmibisMicroblocks.java similarity index 100% rename from integration/modules/ImmibisMicroblocks.java rename to src/main/java/appeng/integration/modules/ImmibisMicroblocks.java diff --git a/integration/modules/InvTweaks.java b/src/main/java/appeng/integration/modules/InvTweaks.java similarity index 100% rename from integration/modules/InvTweaks.java rename to src/main/java/appeng/integration/modules/InvTweaks.java diff --git a/integration/modules/MFR.java b/src/main/java/appeng/integration/modules/MFR.java similarity index 100% rename from integration/modules/MFR.java rename to src/main/java/appeng/integration/modules/MFR.java diff --git a/integration/modules/MJ5.java b/src/main/java/appeng/integration/modules/MJ5.java similarity index 100% rename from integration/modules/MJ5.java rename to src/main/java/appeng/integration/modules/MJ5.java diff --git a/integration/modules/MJ6.java b/src/main/java/appeng/integration/modules/MJ6.java similarity index 100% rename from integration/modules/MJ6.java rename to src/main/java/appeng/integration/modules/MJ6.java diff --git a/integration/modules/Mekanism.java b/src/main/java/appeng/integration/modules/Mekanism.java similarity index 100% rename from integration/modules/Mekanism.java rename to src/main/java/appeng/integration/modules/Mekanism.java diff --git a/integration/modules/NEI.java b/src/main/java/appeng/integration/modules/NEI.java similarity index 100% rename from integration/modules/NEI.java rename to src/main/java/appeng/integration/modules/NEI.java diff --git a/integration/modules/NEIHelpers/NEIAEShapedRecipeHandler.java b/src/main/java/appeng/integration/modules/NEIHelpers/NEIAEShapedRecipeHandler.java similarity index 100% rename from integration/modules/NEIHelpers/NEIAEShapedRecipeHandler.java rename to src/main/java/appeng/integration/modules/NEIHelpers/NEIAEShapedRecipeHandler.java diff --git a/integration/modules/NEIHelpers/NEIAEShapelessRecipeHandler.java b/src/main/java/appeng/integration/modules/NEIHelpers/NEIAEShapelessRecipeHandler.java similarity index 100% rename from integration/modules/NEIHelpers/NEIAEShapelessRecipeHandler.java rename to src/main/java/appeng/integration/modules/NEIHelpers/NEIAEShapelessRecipeHandler.java diff --git a/integration/modules/NEIHelpers/NEICraftingHandler.java b/src/main/java/appeng/integration/modules/NEIHelpers/NEICraftingHandler.java similarity index 100% rename from integration/modules/NEIHelpers/NEICraftingHandler.java rename to src/main/java/appeng/integration/modules/NEIHelpers/NEICraftingHandler.java diff --git a/integration/modules/NEIHelpers/NEIFacadeRecipeHandler.java b/src/main/java/appeng/integration/modules/NEIHelpers/NEIFacadeRecipeHandler.java similarity index 100% rename from integration/modules/NEIHelpers/NEIFacadeRecipeHandler.java rename to src/main/java/appeng/integration/modules/NEIHelpers/NEIFacadeRecipeHandler.java diff --git a/integration/modules/NEIHelpers/NEIGrinderRecipeHandler.java b/src/main/java/appeng/integration/modules/NEIHelpers/NEIGrinderRecipeHandler.java similarity index 100% rename from integration/modules/NEIHelpers/NEIGrinderRecipeHandler.java rename to src/main/java/appeng/integration/modules/NEIHelpers/NEIGrinderRecipeHandler.java diff --git a/integration/modules/NEIHelpers/NEIInscriberRecipeHandler.java b/src/main/java/appeng/integration/modules/NEIHelpers/NEIInscriberRecipeHandler.java similarity index 100% rename from integration/modules/NEIHelpers/NEIInscriberRecipeHandler.java rename to src/main/java/appeng/integration/modules/NEIHelpers/NEIInscriberRecipeHandler.java diff --git a/integration/modules/NEIHelpers/NEIWorldCraftingHandler.java b/src/main/java/appeng/integration/modules/NEIHelpers/NEIWorldCraftingHandler.java similarity index 100% rename from integration/modules/NEIHelpers/NEIWorldCraftingHandler.java rename to src/main/java/appeng/integration/modules/NEIHelpers/NEIWorldCraftingHandler.java diff --git a/integration/modules/NEIHelpers/TerminalCraftingSlotFinder.java b/src/main/java/appeng/integration/modules/NEIHelpers/TerminalCraftingSlotFinder.java similarity index 100% rename from integration/modules/NEIHelpers/TerminalCraftingSlotFinder.java rename to src/main/java/appeng/integration/modules/NEIHelpers/TerminalCraftingSlotFinder.java diff --git a/integration/modules/RB.java b/src/main/java/appeng/integration/modules/RB.java similarity index 100% rename from integration/modules/RB.java rename to src/main/java/appeng/integration/modules/RB.java diff --git a/integration/modules/RC.java b/src/main/java/appeng/integration/modules/RC.java similarity index 100% rename from integration/modules/RC.java rename to src/main/java/appeng/integration/modules/RC.java diff --git a/integration/modules/RF.java b/src/main/java/appeng/integration/modules/RF.java similarity index 100% rename from integration/modules/RF.java rename to src/main/java/appeng/integration/modules/RF.java diff --git a/integration/modules/RFItem.java b/src/main/java/appeng/integration/modules/RFItem.java similarity index 100% rename from integration/modules/RFItem.java rename to src/main/java/appeng/integration/modules/RFItem.java diff --git a/integration/modules/RotaryCraft.java b/src/main/java/appeng/integration/modules/RotaryCraft.java similarity index 100% rename from integration/modules/RotaryCraft.java rename to src/main/java/appeng/integration/modules/RotaryCraft.java diff --git a/integration/modules/Waila.java b/src/main/java/appeng/integration/modules/Waila.java similarity index 96% rename from integration/modules/Waila.java rename to src/main/java/appeng/integration/modules/Waila.java index 20d131c48..440495b05 100644 --- a/integration/modules/Waila.java +++ b/src/main/java/appeng/integration/modules/Waila.java @@ -1,245 +1,245 @@ -package appeng.integration.modules; - -import java.util.List; - -import mcp.mobius.waila.api.IWailaConfigHandler; -import mcp.mobius.waila.api.IWailaDataAccessor; -import mcp.mobius.waila.api.IWailaDataProvider; -import mcp.mobius.waila.api.IWailaFMPAccessor; -import mcp.mobius.waila.api.IWailaFMPProvider; -import mcp.mobius.waila.api.IWailaRegistrar; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; -import appeng.api.implementations.IPowerChannelState; -import appeng.api.implementations.parts.IPartStorageMonitor; -import appeng.api.parts.IFacadePart; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartHost; -import appeng.api.parts.SelectedPart; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IAEStack; -import appeng.block.AEBaseBlock; -import appeng.core.AppEng; -import appeng.core.localization.GuiText; -import appeng.core.localization.WailaText; -import appeng.integration.BaseModule; -import appeng.integration.IntegrationType; -import appeng.parts.networking.PartCableSmart; -import appeng.parts.networking.PartDenseCable; -import appeng.tile.misc.TileCharger; -import appeng.tile.networking.TileCableBus; -import appeng.tile.networking.TileEnergyCell; -import appeng.util.Platform; -import cpw.mods.fml.common.event.FMLInterModComms; - -public class Waila extends BaseModule implements IWailaDataProvider, IWailaFMPProvider -{ - - public static Waila instance; - - public static void register(IWailaRegistrar registrar) - { - Waila w = (Waila) AppEng.instance.getIntegration( IntegrationType.Waila ); - - registrar.registerBodyProvider( w, AEBaseBlock.class ); - registrar.registerBodyProvider( w, "ae2_cablebus" ); - - registrar.registerSyncedNBTKey( "internalCurrentPower", TileEnergyCell.class ); - registrar.registerSyncedNBTKey( "extra:6.usedChannels", TileCableBus.class ); - } - - @Override - public void Init() throws Throwable - { - TestClass( IWailaDataProvider.class ); - TestClass( IWailaRegistrar.class ); - FMLInterModComms.sendMessage( "Waila", "register", this.getClass().getName() + ".register" ); - } - - @Override - public void PostInit() throws Throwable - { - // :P - } - - @Override - public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) - { - return null; - } - - @Override - public List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) - { - TileEntity te = accessor.getTileEntity(); - MovingObjectPosition mop = accessor.getPosition(); - - NBTTagCompound nbt = null; - - try - { - nbt = accessor.getNBTData(); - } - catch (NullPointerException npe) - { - } - - return getBody( itemStack, currenttip, accessor.getPlayer(), nbt, te, mop ); - } - - @Override - public List getWailaBody(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) - { - TileEntity te = accessor.getTileEntity(); - MovingObjectPosition mop = accessor.getPosition(); - - NBTTagCompound nbt = null; - - try - { - nbt = accessor.getNBTData(); - } - catch (NullPointerException npe) - { - } - - return getBody( itemStack, currenttip, accessor.getPlayer(), nbt, te, mop ); - } - - public List getBody(ItemStack itemStack, List currenttip, EntityPlayer player, NBTTagCompound nbt, TileEntity te, MovingObjectPosition mop) - { - - Object ThingOfInterest = te; - if ( te instanceof IPartHost ) - { - Vec3 Pos = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ); - SelectedPart sp = ((IPartHost) te).selectPart( Pos ); - if ( sp.facade != null ) - { - IFacadePart fp = sp.facade; - ThingOfInterest = fp; - } - else if ( sp.part != null ) - { - IPart part = sp.part; - ThingOfInterest = part; - } - } - - try - { - if ( ThingOfInterest instanceof PartCableSmart || ThingOfInterest instanceof PartDenseCable ) - { - NBTTagCompound c = nbt; - if ( c != null && c.hasKey( "extra:6" ) ) - { - NBTTagCompound ic = c.getCompoundTag( "extra:6" ); - if ( ic != null && ic.hasKey( "usedChannels" ) ) - { - int channels = ic.getByte( "usedChannels" ); - currenttip.add( channels + " " + GuiText.Of.getLocal() + " " + (ThingOfInterest instanceof PartDenseCable ? 32 : 8) + " " - + WailaText.Channels.getLocal() ); - } - } - } - - if ( ThingOfInterest instanceof TileEnergyCell ) - { - NBTTagCompound c = nbt; - if ( c != null && c.hasKey( "internalCurrentPower" ) ) - { - TileEnergyCell tec = (TileEnergyCell) ThingOfInterest; - long power = (long) (100 * c.getDouble( "internalCurrentPower" )); - currenttip.add( WailaText.Contains + ": " + Platform.formatPowerLong( power, false ) + " / " - + Platform.formatPowerLong( (long) (100 * tec.getAEMaxPower()), false ) ); - } - } - } - catch (NullPointerException ex) - { - // :P - } - - if ( ThingOfInterest instanceof IPartStorageMonitor ) - { - IPartStorageMonitor psm = (IPartStorageMonitor) ThingOfInterest; - IAEStack stack = psm.getDisplayed(); - boolean isLocked = psm.isLocked(); - - if ( stack instanceof IAEItemStack ) - { - IAEItemStack ais = (IAEItemStack) stack; - currenttip.add( WailaText.Showing.getLocal() + ": " + ais.getItemStack().getDisplayName() ); - } - - if ( stack instanceof IAEFluidStack ) - { - IAEFluidStack ais = (IAEFluidStack) stack; - currenttip.add( WailaText.Showing.getLocal() + ": " + ais.getFluid().getLocalizedName( ais.getFluidStack() ) ); - } - - if ( isLocked ) - currenttip.add( WailaText.Locked.getLocal() ); - else - currenttip.add( WailaText.Unlocked.getLocal() ); - } - - if ( ThingOfInterest instanceof TileCharger ) - { - TileCharger tc = (TileCharger) ThingOfInterest; - IInventory inv = tc.getInternalInventory(); - ItemStack is = inv.getStackInSlot( 0 ); - if ( is != null ) - { - currenttip.add( WailaText.Contains + ": " + is.getDisplayName() ); - is.getItem().addInformation( is, player, currenttip, true ); - } - } - - if ( ThingOfInterest instanceof IPowerChannelState ) - { - IPowerChannelState pbs = (IPowerChannelState) ThingOfInterest; - if ( pbs.isActive() && pbs.isPowered() ) - currenttip.add( WailaText.DeviceOnline.getLocal() ); - else if ( pbs.isPowered() ) - currenttip.add( WailaText.DeviceMissingChannel.getLocal() ); - else - currenttip.add( WailaText.DeviceOffline.getLocal() ); - } - - return currenttip; - } - - @Override - public List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) - { - - return currenttip; - } - - @Override - public List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) - { - - return currenttip; - } - - @Override - public List getWailaHead(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) - { - return currenttip; - } - - @Override - public List getWailaTail(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) - { - return currenttip; - } - -} +package appeng.integration.modules; + +import java.util.List; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import mcp.mobius.waila.api.IWailaDataProvider; +import mcp.mobius.waila.api.IWailaFMPAccessor; +import mcp.mobius.waila.api.IWailaFMPProvider; +import mcp.mobius.waila.api.IWailaRegistrar; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import appeng.api.implementations.IPowerChannelState; +import appeng.api.implementations.parts.IPartStorageMonitor; +import appeng.api.parts.IFacadePart; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartHost; +import appeng.api.parts.SelectedPart; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IAEStack; +import appeng.block.AEBaseBlock; +import appeng.core.AppEng; +import appeng.core.localization.GuiText; +import appeng.core.localization.WailaText; +import appeng.integration.BaseModule; +import appeng.integration.IntegrationType; +import appeng.parts.networking.PartCableSmart; +import appeng.parts.networking.PartDenseCable; +import appeng.tile.misc.TileCharger; +import appeng.tile.networking.TileCableBus; +import appeng.tile.networking.TileEnergyCell; +import appeng.util.Platform; +import cpw.mods.fml.common.event.FMLInterModComms; + +public class Waila extends BaseModule implements IWailaDataProvider, IWailaFMPProvider +{ + + public static Waila instance; + + public static void register(IWailaRegistrar registrar) + { + Waila w = (Waila) AppEng.instance.getIntegration( IntegrationType.Waila ); + + registrar.registerBodyProvider( w, AEBaseBlock.class ); + registrar.registerBodyProvider( w, "ae2_cablebus" ); + + registrar.registerSyncedNBTKey( "internalCurrentPower", TileEnergyCell.class ); + registrar.registerSyncedNBTKey( "extra:6.usedChannels", TileCableBus.class ); + } + + @Override + public void Init() throws Throwable + { + TestClass( IWailaDataProvider.class ); + TestClass( IWailaRegistrar.class ); + FMLInterModComms.sendMessage( "Waila", "register", this.getClass().getName() + ".register" ); + } + + @Override + public void PostInit() throws Throwable + { + // :P + } + + @Override + public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) + { + return null; + } + + @Override + public List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) + { + TileEntity te = accessor.getTileEntity(); + MovingObjectPosition mop = accessor.getPosition(); + + NBTTagCompound nbt = null; + + try + { + nbt = accessor.getNBTData(); + } + catch (NullPointerException npe) + { + } + + return getBody( itemStack, currenttip, accessor.getPlayer(), nbt, te, mop ); + } + + @Override + public List getWailaBody(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) + { + TileEntity te = accessor.getTileEntity(); + MovingObjectPosition mop = accessor.getPosition(); + + NBTTagCompound nbt = null; + + try + { + nbt = accessor.getNBTData(); + } + catch (NullPointerException npe) + { + } + + return getBody( itemStack, currenttip, accessor.getPlayer(), nbt, te, mop ); + } + + public List getBody(ItemStack itemStack, List currenttip, EntityPlayer player, NBTTagCompound nbt, TileEntity te, MovingObjectPosition mop) + { + + Object ThingOfInterest = te; + if ( te instanceof IPartHost ) + { + Vec3 Pos = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ); + SelectedPart sp = ((IPartHost) te).selectPart( Pos ); + if ( sp.facade != null ) + { + IFacadePart fp = sp.facade; + ThingOfInterest = fp; + } + else if ( sp.part != null ) + { + IPart part = sp.part; + ThingOfInterest = part; + } + } + + try + { + if ( ThingOfInterest instanceof PartCableSmart || ThingOfInterest instanceof PartDenseCable ) + { + NBTTagCompound c = nbt; + if ( c != null && c.hasKey( "extra:6" ) ) + { + NBTTagCompound ic = c.getCompoundTag( "extra:6" ); + if ( ic != null && ic.hasKey( "usedChannels" ) ) + { + int channels = ic.getByte( "usedChannels" ); + currenttip.add( channels + " " + GuiText.Of.getLocal() + " " + (ThingOfInterest instanceof PartDenseCable ? 32 : 8) + " " + + WailaText.Channels.getLocal() ); + } + } + } + + if ( ThingOfInterest instanceof TileEnergyCell ) + { + NBTTagCompound c = nbt; + if ( c != null && c.hasKey( "internalCurrentPower" ) ) + { + TileEnergyCell tec = (TileEnergyCell) ThingOfInterest; + long power = (long) (100 * c.getDouble( "internalCurrentPower" )); + currenttip.add( WailaText.Contains + ": " + Platform.formatPowerLong( power, false ) + " / " + + Platform.formatPowerLong( (long) (100 * tec.getAEMaxPower()), false ) ); + } + } + } + catch (NullPointerException ex) + { + // :P + } + + if ( ThingOfInterest instanceof IPartStorageMonitor ) + { + IPartStorageMonitor psm = (IPartStorageMonitor) ThingOfInterest; + IAEStack stack = psm.getDisplayed(); + boolean isLocked = psm.isLocked(); + + if ( stack instanceof IAEItemStack ) + { + IAEItemStack ais = (IAEItemStack) stack; + currenttip.add( WailaText.Showing.getLocal() + ": " + ais.getItemStack().getDisplayName() ); + } + + if ( stack instanceof IAEFluidStack ) + { + IAEFluidStack ais = (IAEFluidStack) stack; + currenttip.add( WailaText.Showing.getLocal() + ": " + ais.getFluid().getLocalizedName( ais.getFluidStack() ) ); + } + + if ( isLocked ) + currenttip.add( WailaText.Locked.getLocal() ); + else + currenttip.add( WailaText.Unlocked.getLocal() ); + } + + if ( ThingOfInterest instanceof TileCharger ) + { + TileCharger tc = (TileCharger) ThingOfInterest; + IInventory inv = tc.getInternalInventory(); + ItemStack is = inv.getStackInSlot( 0 ); + if ( is != null ) + { + currenttip.add( WailaText.Contains + ": " + is.getDisplayName() ); + is.getItem().addInformation( is, player, currenttip, true ); + } + } + + if ( ThingOfInterest instanceof IPowerChannelState ) + { + IPowerChannelState pbs = (IPowerChannelState) ThingOfInterest; + if ( pbs.isActive() && pbs.isPowered() ) + currenttip.add( WailaText.DeviceOnline.getLocal() ); + else if ( pbs.isPowered() ) + currenttip.add( WailaText.DeviceMissingChannel.getLocal() ); + else + currenttip.add( WailaText.DeviceOffline.getLocal() ); + } + + return currenttip; + } + + @Override + public List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) + { + + return currenttip; + } + + @Override + public List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) + { + + return currenttip; + } + + @Override + public List getWailaHead(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) + { + return currenttip; + } + + @Override + public List getWailaTail(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config) + { + return currenttip; + } + +} diff --git a/integration/modules/helpers/BSCrate.java b/src/main/java/appeng/integration/modules/helpers/BSCrate.java similarity index 100% rename from integration/modules/helpers/BSCrate.java rename to src/main/java/appeng/integration/modules/helpers/BSCrate.java diff --git a/integration/modules/helpers/BSCrateHandler.java b/src/main/java/appeng/integration/modules/helpers/BSCrateHandler.java similarity index 100% rename from integration/modules/helpers/BSCrateHandler.java rename to src/main/java/appeng/integration/modules/helpers/BSCrateHandler.java diff --git a/integration/modules/helpers/BSCrateStorageAdaptor.java b/src/main/java/appeng/integration/modules/helpers/BSCrateStorageAdaptor.java similarity index 100% rename from integration/modules/helpers/BSCrateStorageAdaptor.java rename to src/main/java/appeng/integration/modules/helpers/BSCrateStorageAdaptor.java diff --git a/integration/modules/helpers/FMPPacketEvent.java b/src/main/java/appeng/integration/modules/helpers/FMPPacketEvent.java similarity index 100% rename from integration/modules/helpers/FMPPacketEvent.java rename to src/main/java/appeng/integration/modules/helpers/FMPPacketEvent.java diff --git a/integration/modules/helpers/FactorizationBarrel.java b/src/main/java/appeng/integration/modules/helpers/FactorizationBarrel.java similarity index 100% rename from integration/modules/helpers/FactorizationBarrel.java rename to src/main/java/appeng/integration/modules/helpers/FactorizationBarrel.java diff --git a/integration/modules/helpers/FactorizationHandler.java b/src/main/java/appeng/integration/modules/helpers/FactorizationHandler.java similarity index 100% rename from integration/modules/helpers/FactorizationHandler.java rename to src/main/java/appeng/integration/modules/helpers/FactorizationHandler.java diff --git a/integration/modules/helpers/MFRDSU.java b/src/main/java/appeng/integration/modules/helpers/MFRDSU.java similarity index 96% rename from integration/modules/helpers/MFRDSU.java rename to src/main/java/appeng/integration/modules/helpers/MFRDSU.java index 0601c67a3..e019edd7d 100644 --- a/integration/modules/helpers/MFRDSU.java +++ b/src/main/java/appeng/integration/modules/helpers/MFRDSU.java @@ -1,106 +1,106 @@ -package appeng.integration.modules.helpers; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import powercrystals.minefactoryreloaded.api.IDeepStorageUnit; -import appeng.api.config.Actionable; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.util.item.AEItemStack; - -public class MFRDSU implements IMEInventory -{ - - IDeepStorageUnit dsu; - TileEntity te; - - public MFRDSU(TileEntity ta) { - te = ta; - dsu = (IDeepStorageUnit) ta; - } - - @Override - public StorageChannel getChannel() - { - return StorageChannel.ITEMS; - } - - @Override - public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src) - { - ItemStack is = dsu.getStoredItemType(); - if ( is != null ) - { - if ( input.equals( is ) ) - { - long max = dsu.getMaxStoredCount(); - long storedItems = is.stackSize; - if ( max == storedItems ) - return input; - - storedItems += input.getStackSize(); - if ( storedItems > max ) - { - IAEItemStack overflow = AEItemStack.create( is ); - overflow.setStackSize( (int) (storedItems - max) ); - if ( mode == Actionable.MODULATE ) - dsu.setStoredItemCount( (int) max ); - return overflow; - } - else - { - if ( mode == Actionable.MODULATE ) - dsu.setStoredItemCount( is.stackSize + (int) input.getStackSize() ); - return null; - } - } - } - else - { - if ( input.getTagCompound() != null ) - return input; - if ( mode == Actionable.MODULATE ) - dsu.setStoredItemType( input.getItemStack(), (int) input.getStackSize() ); - return null; - } - return input; - } - - @Override - public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src) - { - ItemStack is = dsu.getStoredItemType(); - if ( request.equals( is ) ) - { - if ( request.getStackSize() >= is.stackSize ) - { - is = is.copy(); - if ( mode == Actionable.MODULATE ) - dsu.setStoredItemCount( 0 ); - return AEItemStack.create( is ); - } - else - { - if ( mode == Actionable.MODULATE ) - dsu.setStoredItemCount( is.stackSize - (int) request.getStackSize() ); - return request.copy(); - } - } - return null; - } - - @Override - public IItemList getAvailableItems(IItemList out) - { - ItemStack is = dsu.getStoredItemType(); - if ( is != null ) - { - out.add( AEItemStack.create( is ) ); - } - return out; - } - -} +package appeng.integration.modules.helpers; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import powercrystals.minefactoryreloaded.api.IDeepStorageUnit; +import appeng.api.config.Actionable; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.util.item.AEItemStack; + +public class MFRDSU implements IMEInventory +{ + + IDeepStorageUnit dsu; + TileEntity te; + + public MFRDSU(TileEntity ta) { + te = ta; + dsu = (IDeepStorageUnit) ta; + } + + @Override + public StorageChannel getChannel() + { + return StorageChannel.ITEMS; + } + + @Override + public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src) + { + ItemStack is = dsu.getStoredItemType(); + if ( is != null ) + { + if ( input.equals( is ) ) + { + long max = dsu.getMaxStoredCount(); + long storedItems = is.stackSize; + if ( max == storedItems ) + return input; + + storedItems += input.getStackSize(); + if ( storedItems > max ) + { + IAEItemStack overflow = AEItemStack.create( is ); + overflow.setStackSize( (int) (storedItems - max) ); + if ( mode == Actionable.MODULATE ) + dsu.setStoredItemCount( (int) max ); + return overflow; + } + else + { + if ( mode == Actionable.MODULATE ) + dsu.setStoredItemCount( is.stackSize + (int) input.getStackSize() ); + return null; + } + } + } + else + { + if ( input.getTagCompound() != null ) + return input; + if ( mode == Actionable.MODULATE ) + dsu.setStoredItemType( input.getItemStack(), (int) input.getStackSize() ); + return null; + } + return input; + } + + @Override + public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src) + { + ItemStack is = dsu.getStoredItemType(); + if ( request.equals( is ) ) + { + if ( request.getStackSize() >= is.stackSize ) + { + is = is.copy(); + if ( mode == Actionable.MODULATE ) + dsu.setStoredItemCount( 0 ); + return AEItemStack.create( is ); + } + else + { + if ( mode == Actionable.MODULATE ) + dsu.setStoredItemCount( is.stackSize - (int) request.getStackSize() ); + return request.copy(); + } + } + return null; + } + + @Override + public IItemList getAvailableItems(IItemList out) + { + ItemStack is = dsu.getStoredItemType(); + if ( is != null ) + { + out.add( AEItemStack.create( is ) ); + } + return out; + } + +} diff --git a/integration/modules/helpers/MFRDSUHandler.java b/src/main/java/appeng/integration/modules/helpers/MFRDSUHandler.java similarity index 97% rename from integration/modules/helpers/MFRDSUHandler.java rename to src/main/java/appeng/integration/modules/helpers/MFRDSUHandler.java index 1a059355c..f8e912757 100644 --- a/integration/modules/helpers/MFRDSUHandler.java +++ b/src/main/java/appeng/integration/modules/helpers/MFRDSUHandler.java @@ -1,30 +1,30 @@ -package appeng.integration.modules.helpers; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IExternalStorageHandler; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.StorageChannel; -import appeng.integration.modules.DSU; -import appeng.me.storage.MEMonitorIInventory; -import appeng.util.inv.IMEAdaptor; - -public class MFRDSUHandler implements IExternalStorageHandler -{ - - @Override - public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource mySrc) - { - return chan == StorageChannel.ITEMS && DSU.instance.isDSU( te ); - } - - @Override - public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource src) - { - if ( chan == StorageChannel.ITEMS ) - return new MEMonitorIInventory( new IMEAdaptor( DSU.instance.getDSU( te ), src ) ); - - return null; - } -} +package appeng.integration.modules.helpers; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IExternalStorageHandler; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.StorageChannel; +import appeng.integration.modules.DSU; +import appeng.me.storage.MEMonitorIInventory; +import appeng.util.inv.IMEAdaptor; + +public class MFRDSUHandler implements IExternalStorageHandler +{ + + @Override + public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource mySrc) + { + return chan == StorageChannel.ITEMS && DSU.instance.isDSU( te ); + } + + @Override + public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel chan, BaseActionSource src) + { + if ( chan == StorageChannel.ITEMS ) + return new MEMonitorIInventory( new IMEAdaptor( DSU.instance.getDSU( te ), src ) ); + + return null; + } +} diff --git a/integration/modules/helpers/MJBattery.java b/src/main/java/appeng/integration/modules/helpers/MJBattery.java similarity index 100% rename from integration/modules/helpers/MJBattery.java rename to src/main/java/appeng/integration/modules/helpers/MJBattery.java diff --git a/integration/modules/helpers/MJPerdition.java b/src/main/java/appeng/integration/modules/helpers/MJPerdition.java similarity index 100% rename from integration/modules/helpers/MJPerdition.java rename to src/main/java/appeng/integration/modules/helpers/MJPerdition.java diff --git a/integration/modules/helpers/NullRFHandler.java b/src/main/java/appeng/integration/modules/helpers/NullRFHandler.java similarity index 100% rename from integration/modules/helpers/NullRFHandler.java rename to src/main/java/appeng/integration/modules/helpers/NullRFHandler.java diff --git a/items/AEBaseItem.java b/src/main/java/appeng/items/AEBaseItem.java similarity index 94% rename from items/AEBaseItem.java rename to src/main/java/appeng/items/AEBaseItem.java index 47c1539d7..b018b8396 100644 --- a/items/AEBaseItem.java +++ b/src/main/java/appeng/items/AEBaseItem.java @@ -1,56 +1,56 @@ -package appeng.items; - -import java.util.EnumSet; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import appeng.core.features.AEFeature; -import appeng.core.features.AEFeatureHandler; -import appeng.core.features.IAEFeature; - -public class AEBaseItem extends Item implements IAEFeature -{ - - String FeatureFullname; - String FeatureSubname; - AEFeatureHandler feature; - - @Override - public String toString() - { - return FeatureFullname; - } - - @Override - public AEFeatureHandler feature() - { - 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; - } - - @Override - public void postInit() - { - // override! - } -} +package appeng.items; + +import java.util.EnumSet; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import appeng.core.features.AEFeature; +import appeng.core.features.AEFeatureHandler; +import appeng.core.features.IAEFeature; + +public class AEBaseItem extends Item implements IAEFeature +{ + + String FeatureFullname; + String FeatureSubname; + AEFeatureHandler feature; + + @Override + public String toString() + { + return FeatureFullname; + } + + @Override + public AEFeatureHandler feature() + { + 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; + } + + @Override + public void postInit() + { + // override! + } +} diff --git a/items/contents/CellConfig.java b/src/main/java/appeng/items/contents/CellConfig.java similarity index 100% rename from items/contents/CellConfig.java rename to src/main/java/appeng/items/contents/CellConfig.java diff --git a/items/contents/CellUpgrades.java b/src/main/java/appeng/items/contents/CellUpgrades.java similarity index 100% rename from items/contents/CellUpgrades.java rename to src/main/java/appeng/items/contents/CellUpgrades.java diff --git a/items/contents/NetworkToolViewer.java b/src/main/java/appeng/items/contents/NetworkToolViewer.java similarity index 100% rename from items/contents/NetworkToolViewer.java rename to src/main/java/appeng/items/contents/NetworkToolViewer.java diff --git a/items/contents/PortableCellViewer.java b/src/main/java/appeng/items/contents/PortableCellViewer.java similarity index 100% rename from items/contents/PortableCellViewer.java rename to src/main/java/appeng/items/contents/PortableCellViewer.java diff --git a/items/contents/QuartzKnifeObj.java b/src/main/java/appeng/items/contents/QuartzKnifeObj.java similarity index 100% rename from items/contents/QuartzKnifeObj.java rename to src/main/java/appeng/items/contents/QuartzKnifeObj.java diff --git a/items/materials/ItemMultiMaterial.java b/src/main/java/appeng/items/materials/ItemMultiMaterial.java similarity index 100% rename from items/materials/ItemMultiMaterial.java rename to src/main/java/appeng/items/materials/ItemMultiMaterial.java diff --git a/items/materials/MaterialType.java b/src/main/java/appeng/items/materials/MaterialType.java similarity index 96% rename from items/materials/MaterialType.java rename to src/main/java/appeng/items/materials/MaterialType.java index 2b38ae6c7..e7ca1330d 100644 --- a/items/materials/MaterialType.java +++ b/src/main/java/appeng/items/materials/MaterialType.java @@ -1,151 +1,151 @@ -package appeng.items.materials; - -import java.util.EnumSet; - -import net.minecraft.entity.Entity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import appeng.core.AppEng; -import appeng.core.features.AEFeature; -import appeng.core.features.MaterialStackSrc; -import appeng.entity.EntityChargedQuartz; -import appeng.entity.EntityIds; -import appeng.entity.EntitySingularity; -import cpw.mods.fml.common.registry.EntityRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public enum MaterialType -{ - InvalidType(-1, AEFeature.Core), - - CertusQuartzCrystal(0, AEFeature.Core, "crystalCertusQuartz"), CertusQuartzCrystalCharged(1, AEFeature.Core, EntityChargedQuartz.class), - - CertusQuartzDust(2, AEFeature.Core, "dustCertusQuartz"), NetherQuartzDust(3, AEFeature.Core, "dustNetherQuartz"), Flour(4, AEFeature.Flour, "dustWheat"), GoldDust( - 51, AEFeature.Core, "dustGold"), IronDust(49, AEFeature.Core, "dustIron"), IronNugget(50, AEFeature.Core, "nuggetIron"), - - Silicon(5, AEFeature.Core, "itemSilicon"), MatterBall(6), - - FluixCrystal(7, AEFeature.Core, "crystalFluix"), FluixDust(8, AEFeature.Core, "dustFluix"), FluixPearl(9, AEFeature.Core, "pearlFluix"), - - PurifiedCertusQuartzCrystal(10), PurifiedNetherQuartzCrystal(11), PurifiedFluixCrystal(12), - - CalcProcessorPress(13), EngProcessorPress(14), LogicProcessorPress(15), - - CalcProcessorPrint(16), EngProcessorPrint(17), LogicProcessorPrint(18), - - SiliconPress(19), SiliconPrint(20), - - NamePress(21), - - LogicProcessor(22), CalcProcessor(23), EngProcessor(24), - - // Basic Cards - BasicCard(25), CardRedstone(26), CardCapacity(27), - - // Adv Cards - AdvCard(28), CardFuzzy(29), CardSpeed(30), CardInverter(31), - - Cell2SpatialPart(32, AEFeature.SpatialIO), Cell16SpatialPart(33, AEFeature.SpatialIO), Cell128SpatialPart(34, AEFeature.SpatialIO), - - Cell1kPart(35, AEFeature.StorageCells), Cell4kPart(36, AEFeature.StorageCells), Cell16kPart(37, AEFeature.StorageCells), Cell64kPart(38, - AEFeature.StorageCells), EmptyStorageCell(39, AEFeature.StorageCells), - - WoodenGear(40, AEFeature.GrindStone, "gearWood"), - - Wireless(41, AEFeature.WirelessAccessTerminal), WirelessBooster(42, AEFeature.WirelessAccessTerminal), - - FormationCore(43), AnnihilationCore(44), - - SkyDust(45, AEFeature.Core), - - EnderDust(46, AEFeature.QuantumNetworkBridge, "dustEnder,dustEnderPearl", EntitySingularity.class), Singularity(47, AEFeature.QuantumNetworkBridge, - EntitySingularity.class), QESingularity(48, AEFeature.QuantumNetworkBridge, EntitySingularity.class), - - BlankPattern(52), CardCrafting(53); - - private String oreName; - private EnumSet features; - private Class droppedEntity; - - // IIcon for the material. - @SideOnly(Side.CLIENT) - public IIcon IIcon; - - public Item itemInstance; - public int damageValue; - - private boolean isRegistered = false; - - // stack! - public MaterialStackSrc stackSrc; - - MaterialType(int metaValue) { - damageValue = metaValue; - features = EnumSet.of( AEFeature.Core ); - } - - MaterialType(int metaValue, AEFeature part) { - damageValue = metaValue; - features = EnumSet.of( part ); - } - - MaterialType(int metaValue, AEFeature part, Class c) { - features = EnumSet.of( part ); - damageValue = metaValue; - droppedEntity = c; - - EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true ); - } - - MaterialType(int metaValue, AEFeature part, String oreDictionary, Class c) { - features = EnumSet.of( part ); - damageValue = metaValue; - oreName = oreDictionary; - droppedEntity = c; - EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true ); - } - - MaterialType(int metaValue, AEFeature part, String oreDictionary) { - features = EnumSet.of( part ); - damageValue = metaValue; - oreName = oreDictionary; - } - - public ItemStack stack(int size) - { - return new ItemStack( itemInstance, size, damageValue ); - } - - public EnumSet getFeature() - { - return features; - } - - public String getOreName() - { - return oreName; - } - - public boolean hasCustomEntity() - { - return droppedEntity != null; - } - - public Class getCustomEntityClass() - { - return droppedEntity; - } - - public boolean isRegistered() - { - return isRegistered; - } - - public void markReady() - { - isRegistered = true; - } - -} +package appeng.items.materials; + +import java.util.EnumSet; + +import net.minecraft.entity.Entity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import appeng.core.AppEng; +import appeng.core.features.AEFeature; +import appeng.core.features.MaterialStackSrc; +import appeng.entity.EntityChargedQuartz; +import appeng.entity.EntityIds; +import appeng.entity.EntitySingularity; +import cpw.mods.fml.common.registry.EntityRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public enum MaterialType +{ + InvalidType(-1, AEFeature.Core), + + CertusQuartzCrystal(0, AEFeature.Core, "crystalCertusQuartz"), CertusQuartzCrystalCharged(1, AEFeature.Core, EntityChargedQuartz.class), + + CertusQuartzDust(2, AEFeature.Core, "dustCertusQuartz"), NetherQuartzDust(3, AEFeature.Core, "dustNetherQuartz"), Flour(4, AEFeature.Flour, "dustWheat"), GoldDust( + 51, AEFeature.Core, "dustGold"), IronDust(49, AEFeature.Core, "dustIron"), IronNugget(50, AEFeature.Core, "nuggetIron"), + + Silicon(5, AEFeature.Core, "itemSilicon"), MatterBall(6), + + FluixCrystal(7, AEFeature.Core, "crystalFluix"), FluixDust(8, AEFeature.Core, "dustFluix"), FluixPearl(9, AEFeature.Core, "pearlFluix"), + + PurifiedCertusQuartzCrystal(10), PurifiedNetherQuartzCrystal(11), PurifiedFluixCrystal(12), + + CalcProcessorPress(13), EngProcessorPress(14), LogicProcessorPress(15), + + CalcProcessorPrint(16), EngProcessorPrint(17), LogicProcessorPrint(18), + + SiliconPress(19), SiliconPrint(20), + + NamePress(21), + + LogicProcessor(22), CalcProcessor(23), EngProcessor(24), + + // Basic Cards + BasicCard(25), CardRedstone(26), CardCapacity(27), + + // Adv Cards + AdvCard(28), CardFuzzy(29), CardSpeed(30), CardInverter(31), + + Cell2SpatialPart(32, AEFeature.SpatialIO), Cell16SpatialPart(33, AEFeature.SpatialIO), Cell128SpatialPart(34, AEFeature.SpatialIO), + + Cell1kPart(35, AEFeature.StorageCells), Cell4kPart(36, AEFeature.StorageCells), Cell16kPart(37, AEFeature.StorageCells), Cell64kPart(38, + AEFeature.StorageCells), EmptyStorageCell(39, AEFeature.StorageCells), + + WoodenGear(40, AEFeature.GrindStone, "gearWood"), + + Wireless(41, AEFeature.WirelessAccessTerminal), WirelessBooster(42, AEFeature.WirelessAccessTerminal), + + FormationCore(43), AnnihilationCore(44), + + SkyDust(45, AEFeature.Core), + + EnderDust(46, AEFeature.QuantumNetworkBridge, "dustEnder,dustEnderPearl", EntitySingularity.class), Singularity(47, AEFeature.QuantumNetworkBridge, + EntitySingularity.class), QESingularity(48, AEFeature.QuantumNetworkBridge, EntitySingularity.class), + + BlankPattern(52), CardCrafting(53); + + private String oreName; + private EnumSet features; + private Class droppedEntity; + + // IIcon for the material. + @SideOnly(Side.CLIENT) + public IIcon IIcon; + + public Item itemInstance; + public int damageValue; + + private boolean isRegistered = false; + + // stack! + public MaterialStackSrc stackSrc; + + MaterialType(int metaValue) { + damageValue = metaValue; + features = EnumSet.of( AEFeature.Core ); + } + + MaterialType(int metaValue, AEFeature part) { + damageValue = metaValue; + features = EnumSet.of( part ); + } + + MaterialType(int metaValue, AEFeature part, Class c) { + features = EnumSet.of( part ); + damageValue = metaValue; + droppedEntity = c; + + EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true ); + } + + MaterialType(int metaValue, AEFeature part, String oreDictionary, Class c) { + features = EnumSet.of( part ); + damageValue = metaValue; + oreName = oreDictionary; + droppedEntity = c; + EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true ); + } + + MaterialType(int metaValue, AEFeature part, String oreDictionary) { + features = EnumSet.of( part ); + damageValue = metaValue; + oreName = oreDictionary; + } + + public ItemStack stack(int size) + { + return new ItemStack( itemInstance, size, damageValue ); + } + + public EnumSet getFeature() + { + return features; + } + + public String getOreName() + { + return oreName; + } + + public boolean hasCustomEntity() + { + return droppedEntity != null; + } + + public Class getCustomEntityClass() + { + return droppedEntity; + } + + public boolean isRegistered() + { + return isRegistered; + } + + public void markReady() + { + isRegistered = true; + } + +} diff --git a/items/misc/ItemCrystalSeed.java b/src/main/java/appeng/items/misc/ItemCrystalSeed.java similarity index 100% rename from items/misc/ItemCrystalSeed.java rename to src/main/java/appeng/items/misc/ItemCrystalSeed.java diff --git a/items/misc/ItemEncodedPattern.java b/src/main/java/appeng/items/misc/ItemEncodedPattern.java similarity index 100% rename from items/misc/ItemEncodedPattern.java rename to src/main/java/appeng/items/misc/ItemEncodedPattern.java diff --git a/items/misc/ItemPaintBall.java b/src/main/java/appeng/items/misc/ItemPaintBall.java similarity index 100% rename from items/misc/ItemPaintBall.java rename to src/main/java/appeng/items/misc/ItemPaintBall.java diff --git a/items/parts/ItemFacade.java b/src/main/java/appeng/items/parts/ItemFacade.java similarity index 96% rename from items/parts/ItemFacade.java rename to src/main/java/appeng/items/parts/ItemFacade.java index 1161b4696..f1e5de6c9 100644 --- a/items/parts/ItemFacade.java +++ b/src/main/java/appeng/items/parts/ItemFacade.java @@ -1,245 +1,245 @@ -package appeng.items.parts; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockGlass; -import net.minecraft.block.BlockStainedGlass; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; -import net.minecraftforge.client.MinecraftForgeClient; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.parts.IAlphaPassItem; -import appeng.block.solids.OreQuartz; -import appeng.client.render.BusRenderer; -import appeng.core.FacadeConfig; -import appeng.core.features.AEFeature; -import appeng.facade.FacadePart; -import appeng.facade.IFacadeItem; -import appeng.items.AEBaseItem; -import appeng.util.Platform; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem -{ - - public ItemFacade() { - super( ItemFacade.class ); - setFeature( EnumSet.of( AEFeature.Facades ) ); - setHasSubtypes( true ); - if ( Platform.isClient() ) - MinecraftForgeClient.registerItemRenderer( this, BusRenderer.instance ); - } - - @Override - @SideOnly(Side.CLIENT) - public int getSpriteNumber() - { - return 0; - } - - @Override - public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ) - { - return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w ); - } - - @Override - public FacadePart createPartFromItemStack(ItemStack is, ForgeDirection side) - { - ItemStack in = getTextureItem( is ); - if ( in != null ) - return new FacadePart( is, side ); - return null; - } - - List subTypes = null; - - public List getFacades() - { - calculateSubTypes(); - return subTypes; - } - - public ItemStack getCreativeTabIcon() - { - calculateSubTypes(); - if ( subTypes.isEmpty() ) - return new ItemStack( Items.cake ); - return subTypes.get( 0 ); - } - - @Override - public void getSubItems(Item number, CreativeTabs tab, List list) - { - calculateSubTypes(); - list.addAll( subTypes ); - } - - public ItemStack createFromInts(int[] ids) - { - ItemStack is = new ItemStack( AEApi.instance().items().itemFacade.item() ); - NBTTagCompound data = new NBTTagCompound(); - data.setIntArray( "x", ids.clone() ); - is.setTagCompound( data ); - return is; - } - - @Override - public ItemStack getTextureItem(ItemStack is) - { - Block blk = getBlock( is ); - if ( blk != null ) - return new ItemStack( blk, 1, getMeta( is ) ); - return null; - } - - private void calculateSubTypes() - { - if ( subTypes == null ) - { - subTypes = new ArrayList(); - for (Object blk : Block.blockRegistry) - { - Block b = (Block) blk; - try - { - Item item = Item.getItemFromBlock( b ); - - List tmpList = new ArrayList(); - b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList ); - for (ItemStack l : tmpList) - { - ItemStack facade = createFacadeForItem( l, false ); - if ( facade != null ) - subTypes.add( facade ); - } - } - catch (Throwable t) - { - // just absorb.. - } - } - - if ( FacadeConfig.instance.hasChanged() ) - FacadeConfig.instance.save(); - } - - } - - public ItemStack createFacadeForItem(ItemStack l, boolean returnItem) - { - if ( l == null ) - return null; - - Block b = Block.getBlockFromItem( l.getItem() ); - if ( b == null || l.hasTagCompound() ) - return null; - - int metadata = l.getItem().getMetadata( l.getItemDamage() ); - - boolean hasTile = b.hasTileEntity( metadata ); - boolean enableGlass = b instanceof BlockGlass || b instanceof BlockStainedGlass; - boolean disableOre = b instanceof OreQuartz; - - boolean defaultValue = (b.isOpaqueCube() && !b.getTickRandomly() && !hasTile && !disableOre) || enableGlass; - if ( FacadeConfig.instance.checkEnabled( b, metadata, defaultValue ) ) - { - if ( returnItem ) - return l; - - ItemStack is = new ItemStack( this ); - NBTTagCompound data = new NBTTagCompound(); - int[] ds = new int[2]; - ds[0] = Item.getIdFromItem( l.getItem() ); - ds[1] = metadata; - data.setIntArray( "x", ds ); - UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor( l.getItem() ); - data.setString( "modid", ui.modId ); - data.setString( "itemname", ui.name ); - is.setTagCompound( data ); - return is; - } - return null; - } - - @Override - public Block getBlock(ItemStack is) - { - NBTTagCompound data = is.getTagCompound(); - if ( data != null ) - { - if ( data.hasKey( "modid" ) && data.hasKey( "itemname" ) ) - { - return GameRegistry.findBlock( data.getString( "modid" ), data.getString( "itemname" ) ); - } - else - { - int[] blk = data.getIntArray( "x" ); - if ( blk != null && blk.length == 2 ) - return Block.getBlockById( blk[0] ); - } - } - return Blocks.glass; - } - - @Override - public int getMeta(ItemStack is) - { - NBTTagCompound data = is.getTagCompound(); - if ( data != null ) - { - int[] blk = data.getIntArray( "x" ); - if ( blk != null && blk.length == 2 ) - return blk[1]; - } - return 0; - } - - @Override - public String getItemStackDisplayName(ItemStack is) - { - try - { - ItemStack in = getTextureItem( is ); - if ( in != null ) - { - return super.getItemStackDisplayName( is ) + " - " + in.getDisplayName(); - } - } - catch (Throwable t) - { - - } - - return super.getItemStackDisplayName( is ); - } - - @Override - public boolean useAlphaPass(ItemStack is) - { - ItemStack out = getTextureItem( is ); - - if ( out == null || out.getItem() == null ) - return false; - - Block blk = Block.getBlockFromItem( out.getItem() ); - if ( blk != null && blk.canRenderInPass( 1 ) ) - return true; - - return false; - } - -} +package appeng.items.parts; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockGlass; +import net.minecraft.block.BlockStainedGlass; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.parts.IAlphaPassItem; +import appeng.block.solids.OreQuartz; +import appeng.client.render.BusRenderer; +import appeng.core.FacadeConfig; +import appeng.core.features.AEFeature; +import appeng.facade.FacadePart; +import appeng.facade.IFacadeItem; +import appeng.items.AEBaseItem; +import appeng.util.Platform; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem +{ + + public ItemFacade() { + super( ItemFacade.class ); + setFeature( EnumSet.of( AEFeature.Facades ) ); + setHasSubtypes( true ); + if ( Platform.isClient() ) + MinecraftForgeClient.registerItemRenderer( this, BusRenderer.instance ); + } + + @Override + @SideOnly(Side.CLIENT) + public int getSpriteNumber() + { + return 0; + } + + @Override + public boolean onItemUse(ItemStack is, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + { + return AEApi.instance().partHelper().placeBus( is, x, y, z, side, player, w ); + } + + @Override + public FacadePart createPartFromItemStack(ItemStack is, ForgeDirection side) + { + ItemStack in = getTextureItem( is ); + if ( in != null ) + return new FacadePart( is, side ); + return null; + } + + List subTypes = null; + + public List getFacades() + { + calculateSubTypes(); + return subTypes; + } + + public ItemStack getCreativeTabIcon() + { + calculateSubTypes(); + if ( subTypes.isEmpty() ) + return new ItemStack( Items.cake ); + return subTypes.get( 0 ); + } + + @Override + public void getSubItems(Item number, CreativeTabs tab, List list) + { + calculateSubTypes(); + list.addAll( subTypes ); + } + + public ItemStack createFromInts(int[] ids) + { + ItemStack is = new ItemStack( AEApi.instance().items().itemFacade.item() ); + NBTTagCompound data = new NBTTagCompound(); + data.setIntArray( "x", ids.clone() ); + is.setTagCompound( data ); + return is; + } + + @Override + public ItemStack getTextureItem(ItemStack is) + { + Block blk = getBlock( is ); + if ( blk != null ) + return new ItemStack( blk, 1, getMeta( is ) ); + return null; + } + + private void calculateSubTypes() + { + if ( subTypes == null ) + { + subTypes = new ArrayList(); + for (Object blk : Block.blockRegistry) + { + Block b = (Block) blk; + try + { + Item item = Item.getItemFromBlock( b ); + + List tmpList = new ArrayList(); + b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList ); + for (ItemStack l : tmpList) + { + ItemStack facade = createFacadeForItem( l, false ); + if ( facade != null ) + subTypes.add( facade ); + } + } + catch (Throwable t) + { + // just absorb.. + } + } + + if ( FacadeConfig.instance.hasChanged() ) + FacadeConfig.instance.save(); + } + + } + + public ItemStack createFacadeForItem(ItemStack l, boolean returnItem) + { + if ( l == null ) + return null; + + Block b = Block.getBlockFromItem( l.getItem() ); + if ( b == null || l.hasTagCompound() ) + return null; + + int metadata = l.getItem().getMetadata( l.getItemDamage() ); + + boolean hasTile = b.hasTileEntity( metadata ); + boolean enableGlass = b instanceof BlockGlass || b instanceof BlockStainedGlass; + boolean disableOre = b instanceof OreQuartz; + + boolean defaultValue = (b.isOpaqueCube() && !b.getTickRandomly() && !hasTile && !disableOre) || enableGlass; + if ( FacadeConfig.instance.checkEnabled( b, metadata, defaultValue ) ) + { + if ( returnItem ) + return l; + + ItemStack is = new ItemStack( this ); + NBTTagCompound data = new NBTTagCompound(); + int[] ds = new int[2]; + ds[0] = Item.getIdFromItem( l.getItem() ); + ds[1] = metadata; + data.setIntArray( "x", ds ); + UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor( l.getItem() ); + data.setString( "modid", ui.modId ); + data.setString( "itemname", ui.name ); + is.setTagCompound( data ); + return is; + } + return null; + } + + @Override + public Block getBlock(ItemStack is) + { + NBTTagCompound data = is.getTagCompound(); + if ( data != null ) + { + if ( data.hasKey( "modid" ) && data.hasKey( "itemname" ) ) + { + return GameRegistry.findBlock( data.getString( "modid" ), data.getString( "itemname" ) ); + } + else + { + int[] blk = data.getIntArray( "x" ); + if ( blk != null && blk.length == 2 ) + return Block.getBlockById( blk[0] ); + } + } + return Blocks.glass; + } + + @Override + public int getMeta(ItemStack is) + { + NBTTagCompound data = is.getTagCompound(); + if ( data != null ) + { + int[] blk = data.getIntArray( "x" ); + if ( blk != null && blk.length == 2 ) + return blk[1]; + } + return 0; + } + + @Override + public String getItemStackDisplayName(ItemStack is) + { + try + { + ItemStack in = getTextureItem( is ); + if ( in != null ) + { + return super.getItemStackDisplayName( is ) + " - " + in.getDisplayName(); + } + } + catch (Throwable t) + { + + } + + return super.getItemStackDisplayName( is ); + } + + @Override + public boolean useAlphaPass(ItemStack is) + { + ItemStack out = getTextureItem( is ); + + if ( out == null || out.getItem() == null ) + return false; + + Block blk = Block.getBlockFromItem( out.getItem() ); + if ( blk != null && blk.canRenderInPass( 1 ) ) + return true; + + return false; + } + +} diff --git a/items/parts/ItemMultiPart.java b/src/main/java/appeng/items/parts/ItemMultiPart.java similarity index 100% rename from items/parts/ItemMultiPart.java rename to src/main/java/appeng/items/parts/ItemMultiPart.java diff --git a/items/parts/PartType.java b/src/main/java/appeng/items/parts/PartType.java similarity index 97% rename from items/parts/PartType.java rename to src/main/java/appeng/items/parts/PartType.java index 69f66a390..23fb39af9 100644 --- a/items/parts/PartType.java +++ b/src/main/java/appeng/items/parts/PartType.java @@ -1,152 +1,152 @@ -package appeng.items.parts; - -import java.lang.reflect.Constructor; -import java.util.EnumSet; - -import appeng.api.parts.IPart; -import appeng.api.util.AEColor; -import appeng.core.features.AEFeature; -import appeng.core.localization.GuiText; -import appeng.parts.automation.PartAnnihilationPlane; -import appeng.parts.automation.PartExportBus; -import appeng.parts.automation.PartFormationPlane; -import appeng.parts.automation.PartImportBus; -import appeng.parts.automation.PartLevelEmitter; -import appeng.parts.misc.PartCableAnchor; -import appeng.parts.misc.PartInterface; -import appeng.parts.misc.PartInvertedToggleBus; -import appeng.parts.misc.PartStorageBus; -import appeng.parts.misc.PartToggleBus; -import appeng.parts.networking.PartCableCovered; -import appeng.parts.networking.PartCableGlass; -import appeng.parts.networking.PartCableSmart; -import appeng.parts.networking.PartDenseCable; -import appeng.parts.networking.PartQuartzFiber; -import appeng.parts.p2p.PartP2PBCPower; -import appeng.parts.p2p.PartP2PIC2Power; -import appeng.parts.p2p.PartP2PItems; -import appeng.parts.p2p.PartP2PLight; -import appeng.parts.p2p.PartP2PLiquids; -import appeng.parts.p2p.PartP2PRFPower; -import appeng.parts.p2p.PartP2PRedstone; -import appeng.parts.p2p.PartP2PTunnelME; -import appeng.parts.reporting.PartConversionMonitor; -import appeng.parts.reporting.PartCraftingTerminal; -import appeng.parts.reporting.PartDarkMonitor; -import appeng.parts.reporting.PartInterfaceTerminal; -import appeng.parts.reporting.PartMonitor; -import appeng.parts.reporting.PartPatternTerminal; -import appeng.parts.reporting.PartSemiDarkMonitor; -import appeng.parts.reporting.PartStorageMonitor; -import appeng.parts.reporting.PartTerminal; - -public enum PartType -{ - InvalidType(-1, AEFeature.Core, null), - - CableGlass(0, AEFeature.Core, PartCableGlass.class), - - CableCovered(20, AEFeature.Core, PartCableCovered.class), - - CableSmart(40, AEFeature.Channels, PartCableSmart.class), - - CableDense(60, AEFeature.Channels, PartDenseCable.class), - - ToggleBus(80, AEFeature.Core, PartToggleBus.class), - - InvertedToggleBus(100, AEFeature.Core, PartInvertedToggleBus.class), - - CableAnchor(120, AEFeature.Core, PartCableAnchor.class), - - QuartzFiber(140, AEFeature.Core, PartQuartzFiber.class), - - Monitor(160, AEFeature.Core, PartMonitor.class), - - SemiDarkMonitor(180, AEFeature.Core, PartSemiDarkMonitor.class), - - DarkMonitor(200, AEFeature.Core, PartDarkMonitor.class), - - StorageBus(220, AEFeature.StorageBus, PartStorageBus.class), - - ImportBus(240, AEFeature.ImportBus, PartImportBus.class), - - ExportBus(260, AEFeature.ExportBus, PartExportBus.class), - - LevelEmitter(280, AEFeature.LevelEmitter, PartLevelEmitter.class), - - AnnihilationPlane(300, AEFeature.AnnihilationPlane, PartAnnihilationPlane.class), - - FormationPlane(320, AEFeature.FormationPlane, PartFormationPlane.class), - - PatternTerminal(340, AEFeature.Patterns, PartPatternTerminal.class), - - CraftingTerminal(360, AEFeature.CraftingTerminal, PartCraftingTerminal.class), - - Terminal(380, AEFeature.Core, PartTerminal.class), - - StorageMonitor(400, AEFeature.StorageMonitor, PartStorageMonitor.class), - - ConversionMonitor(420, AEFeature.PartConversionMonitor, PartConversionMonitor.class), - - Interface(440, AEFeature.Core, PartInterface.class), - - P2PTunnelME(460, AEFeature.P2PTunnelME, PartP2PTunnelME.class, GuiText.METunnel), - - P2PTunnelRedstone(461, AEFeature.P2PTunnelRedstone, PartP2PRedstone.class, GuiText.RedstoneTunnel), - - P2PTunnelItems(462, AEFeature.P2PTunnelItems, PartP2PItems.class, GuiText.ItemTunnel), - - P2PTunnelLiquids(463, AEFeature.P2PTunnelLiquids, PartP2PLiquids.class, GuiText.FluidTunnel), - - P2PTunnelMJ(464, AEFeature.P2PTunnelMJ, PartP2PBCPower.class, GuiText.MJTunnel), - - P2PTunnelEU(465, AEFeature.P2PTunnelEU, PartP2PIC2Power.class, GuiText.EUTunnel), - - P2PTunnelRF(466, AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel), - - P2PTunnelLight(467, AEFeature.P2PTunnelLight, PartP2PLight.class, GuiText.LightTunnel), - - InterfaceTerminal(480, AEFeature.InterfaceTerminal, PartInterfaceTerminal.class); - - private final EnumSet features; - private final Class myPart; - private final GuiText extraName; - public final int baseDamage; - - public Constructor constructor; - - PartType(int baseMetaValue, AEFeature part, Class c) { - this( baseMetaValue, part, c, null ); - } - - PartType(int baseMetaValue, AEFeature part, Class c, GuiText en) { - features = EnumSet.of( part ); - myPart = c; - extraName = en; - baseDamage = baseMetaValue; - } - - public Enum[] getVariants() - { - if ( this == CableSmart || this == CableCovered || this == CableGlass || this == CableDense ) - return AEColor.values(); - - return null; - } - - public EnumSet getFeature() - { - return features; - } - - public Class getPart() - { - return myPart; - } - - public GuiText getExtraName() - { - return extraName; - } - -} +package appeng.items.parts; + +import java.lang.reflect.Constructor; +import java.util.EnumSet; + +import appeng.api.parts.IPart; +import appeng.api.util.AEColor; +import appeng.core.features.AEFeature; +import appeng.core.localization.GuiText; +import appeng.parts.automation.PartAnnihilationPlane; +import appeng.parts.automation.PartExportBus; +import appeng.parts.automation.PartFormationPlane; +import appeng.parts.automation.PartImportBus; +import appeng.parts.automation.PartLevelEmitter; +import appeng.parts.misc.PartCableAnchor; +import appeng.parts.misc.PartInterface; +import appeng.parts.misc.PartInvertedToggleBus; +import appeng.parts.misc.PartStorageBus; +import appeng.parts.misc.PartToggleBus; +import appeng.parts.networking.PartCableCovered; +import appeng.parts.networking.PartCableGlass; +import appeng.parts.networking.PartCableSmart; +import appeng.parts.networking.PartDenseCable; +import appeng.parts.networking.PartQuartzFiber; +import appeng.parts.p2p.PartP2PBCPower; +import appeng.parts.p2p.PartP2PIC2Power; +import appeng.parts.p2p.PartP2PItems; +import appeng.parts.p2p.PartP2PLight; +import appeng.parts.p2p.PartP2PLiquids; +import appeng.parts.p2p.PartP2PRFPower; +import appeng.parts.p2p.PartP2PRedstone; +import appeng.parts.p2p.PartP2PTunnelME; +import appeng.parts.reporting.PartConversionMonitor; +import appeng.parts.reporting.PartCraftingTerminal; +import appeng.parts.reporting.PartDarkMonitor; +import appeng.parts.reporting.PartInterfaceTerminal; +import appeng.parts.reporting.PartMonitor; +import appeng.parts.reporting.PartPatternTerminal; +import appeng.parts.reporting.PartSemiDarkMonitor; +import appeng.parts.reporting.PartStorageMonitor; +import appeng.parts.reporting.PartTerminal; + +public enum PartType +{ + InvalidType(-1, AEFeature.Core, null), + + CableGlass(0, AEFeature.Core, PartCableGlass.class), + + CableCovered(20, AEFeature.Core, PartCableCovered.class), + + CableSmart(40, AEFeature.Channels, PartCableSmart.class), + + CableDense(60, AEFeature.Channels, PartDenseCable.class), + + ToggleBus(80, AEFeature.Core, PartToggleBus.class), + + InvertedToggleBus(100, AEFeature.Core, PartInvertedToggleBus.class), + + CableAnchor(120, AEFeature.Core, PartCableAnchor.class), + + QuartzFiber(140, AEFeature.Core, PartQuartzFiber.class), + + Monitor(160, AEFeature.Core, PartMonitor.class), + + SemiDarkMonitor(180, AEFeature.Core, PartSemiDarkMonitor.class), + + DarkMonitor(200, AEFeature.Core, PartDarkMonitor.class), + + StorageBus(220, AEFeature.StorageBus, PartStorageBus.class), + + ImportBus(240, AEFeature.ImportBus, PartImportBus.class), + + ExportBus(260, AEFeature.ExportBus, PartExportBus.class), + + LevelEmitter(280, AEFeature.LevelEmitter, PartLevelEmitter.class), + + AnnihilationPlane(300, AEFeature.AnnihilationPlane, PartAnnihilationPlane.class), + + FormationPlane(320, AEFeature.FormationPlane, PartFormationPlane.class), + + PatternTerminal(340, AEFeature.Patterns, PartPatternTerminal.class), + + CraftingTerminal(360, AEFeature.CraftingTerminal, PartCraftingTerminal.class), + + Terminal(380, AEFeature.Core, PartTerminal.class), + + StorageMonitor(400, AEFeature.StorageMonitor, PartStorageMonitor.class), + + ConversionMonitor(420, AEFeature.PartConversionMonitor, PartConversionMonitor.class), + + Interface(440, AEFeature.Core, PartInterface.class), + + P2PTunnelME(460, AEFeature.P2PTunnelME, PartP2PTunnelME.class, GuiText.METunnel), + + P2PTunnelRedstone(461, AEFeature.P2PTunnelRedstone, PartP2PRedstone.class, GuiText.RedstoneTunnel), + + P2PTunnelItems(462, AEFeature.P2PTunnelItems, PartP2PItems.class, GuiText.ItemTunnel), + + P2PTunnelLiquids(463, AEFeature.P2PTunnelLiquids, PartP2PLiquids.class, GuiText.FluidTunnel), + + P2PTunnelMJ(464, AEFeature.P2PTunnelMJ, PartP2PBCPower.class, GuiText.MJTunnel), + + P2PTunnelEU(465, AEFeature.P2PTunnelEU, PartP2PIC2Power.class, GuiText.EUTunnel), + + P2PTunnelRF(466, AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel), + + P2PTunnelLight(467, AEFeature.P2PTunnelLight, PartP2PLight.class, GuiText.LightTunnel), + + InterfaceTerminal(480, AEFeature.InterfaceTerminal, PartInterfaceTerminal.class); + + private final EnumSet features; + private final Class myPart; + private final GuiText extraName; + public final int baseDamage; + + public Constructor constructor; + + PartType(int baseMetaValue, AEFeature part, Class c) { + this( baseMetaValue, part, c, null ); + } + + PartType(int baseMetaValue, AEFeature part, Class c, GuiText en) { + features = EnumSet.of( part ); + myPart = c; + extraName = en; + baseDamage = baseMetaValue; + } + + public Enum[] getVariants() + { + if ( this == CableSmart || this == CableCovered || this == CableGlass || this == CableDense ) + return AEColor.values(); + + return null; + } + + public EnumSet getFeature() + { + return features; + } + + public Class getPart() + { + return myPart; + } + + public GuiText getExtraName() + { + return extraName; + } + +} diff --git a/items/storage/ItemBasicStorageCell.java b/src/main/java/appeng/items/storage/ItemBasicStorageCell.java similarity index 100% rename from items/storage/ItemBasicStorageCell.java rename to src/main/java/appeng/items/storage/ItemBasicStorageCell.java diff --git a/items/storage/ItemCreativeStorageCell.java b/src/main/java/appeng/items/storage/ItemCreativeStorageCell.java similarity index 100% rename from items/storage/ItemCreativeStorageCell.java rename to src/main/java/appeng/items/storage/ItemCreativeStorageCell.java diff --git a/items/storage/ItemSpatialStorageCell.java b/src/main/java/appeng/items/storage/ItemSpatialStorageCell.java similarity index 100% rename from items/storage/ItemSpatialStorageCell.java rename to src/main/java/appeng/items/storage/ItemSpatialStorageCell.java diff --git a/items/storage/ItemViewCell.java b/src/main/java/appeng/items/storage/ItemViewCell.java similarity index 100% rename from items/storage/ItemViewCell.java rename to src/main/java/appeng/items/storage/ItemViewCell.java diff --git a/items/tools/ToolBiometricCard.java b/src/main/java/appeng/items/tools/ToolBiometricCard.java similarity index 100% rename from items/tools/ToolBiometricCard.java rename to src/main/java/appeng/items/tools/ToolBiometricCard.java diff --git a/items/tools/ToolMemoryCard.java b/src/main/java/appeng/items/tools/ToolMemoryCard.java similarity index 100% rename from items/tools/ToolMemoryCard.java rename to src/main/java/appeng/items/tools/ToolMemoryCard.java diff --git a/items/tools/ToolNetworkTool.java b/src/main/java/appeng/items/tools/ToolNetworkTool.java similarity index 100% rename from items/tools/ToolNetworkTool.java rename to src/main/java/appeng/items/tools/ToolNetworkTool.java diff --git a/items/tools/powered/ToolChargedStaff.java b/src/main/java/appeng/items/tools/powered/ToolChargedStaff.java similarity index 100% rename from items/tools/powered/ToolChargedStaff.java rename to src/main/java/appeng/items/tools/powered/ToolChargedStaff.java diff --git a/items/tools/powered/ToolColorApplicator.java b/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java similarity index 100% rename from items/tools/powered/ToolColorApplicator.java rename to src/main/java/appeng/items/tools/powered/ToolColorApplicator.java diff --git a/items/tools/powered/ToolEntropyManipulator.java b/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java similarity index 100% rename from items/tools/powered/ToolEntropyManipulator.java rename to src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java diff --git a/items/tools/powered/ToolMassCannon.java b/src/main/java/appeng/items/tools/powered/ToolMassCannon.java similarity index 100% rename from items/tools/powered/ToolMassCannon.java rename to src/main/java/appeng/items/tools/powered/ToolMassCannon.java diff --git a/items/tools/powered/ToolPortableCell.java b/src/main/java/appeng/items/tools/powered/ToolPortableCell.java similarity index 100% rename from items/tools/powered/ToolPortableCell.java rename to src/main/java/appeng/items/tools/powered/ToolPortableCell.java diff --git a/items/tools/powered/ToolWirelessTerminal.java b/src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java similarity index 100% rename from items/tools/powered/ToolWirelessTerminal.java rename to src/main/java/appeng/items/tools/powered/ToolWirelessTerminal.java diff --git a/items/tools/powered/powersink/AEBasePoweredItem.java b/src/main/java/appeng/items/tools/powered/powersink/AEBasePoweredItem.java similarity index 95% rename from items/tools/powered/powersink/AEBasePoweredItem.java rename to src/main/java/appeng/items/tools/powered/powersink/AEBasePoweredItem.java index 7e46b5017..b2ed3b6cf 100644 --- a/items/tools/powered/powersink/AEBasePoweredItem.java +++ b/src/main/java/appeng/items/tools/powered/powersink/AEBasePoweredItem.java @@ -1,10 +1,10 @@ -package appeng.items.tools.powered.powersink; - -public class AEBasePoweredItem extends RedstoneFlux -{ - - public AEBasePoweredItem(Class c, String subname) { - super( c, subname ); - setMaxStackSize( 1 ); - } -} +package appeng.items.tools.powered.powersink; + +public class AEBasePoweredItem extends RedstoneFlux +{ + + public AEBasePoweredItem(Class c, String subname) { + super( c, subname ); + setMaxStackSize( 1 ); + } +} diff --git a/items/tools/powered/powersink/AERootPoweredItem.java b/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java similarity index 95% rename from items/tools/powered/powersink/AERootPoweredItem.java rename to src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java index 9014ab627..0cbd17810 100644 --- a/items/tools/powered/powersink/AERootPoweredItem.java +++ b/src/main/java/appeng/items/tools/powered/powersink/AERootPoweredItem.java @@ -1,181 +1,181 @@ -package appeng.items.tools.powered.powersink; - -import java.text.MessageFormat; -import java.util.List; - -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; -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 - }; - - public double maxStoredPower = 200000; - - public AERootPoweredItem(Class c, String subname) { - super( c, subname ); - setMaxDamage( 32 ); - hasSubtypes = false; - } - - @Override - public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips) - { - NBTTagCompound tag = is.getTagCompound(); - double internalCurrentPower = 0; - double internalMaxPower = getAEMaxPower( is ); - - if ( tag != null ) - { - internalCurrentPower = tag.getDouble( "internalCurrentPower" ); - } - - double percent = internalCurrentPower / internalMaxPower; - - lines.add( GuiText.StoredEnergy.getLocal() + ":" + MessageFormat.format( " {0,number,#} ", internalCurrentPower ) - + Platform.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) ); - - } - - @Override - public boolean isDamageable() - { - return true; - } - - @Override - public boolean isDamaged(ItemStack stack) - { - return true; - } - - @Override - public boolean isRepairable() - { - return false; - } - - @Override - public void setDamage(ItemStack stack, int damage) - { - - } - - final String EnergyVar = "internalCurrentPower"; - - 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; - } - - /** - * inject external - */ - double injectExternalPower(PowerUnits input, ItemStack is, double amount, boolean simulate) - { - if ( simulate ) - { - int requiredEU = (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( is ) - getAECurrentPower( is ) ); - if ( amount < requiredEU ) - return 0; - return amount - requiredEU; - } - else - { - double powerRemainder = injectAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) ); - return PowerUnits.AE.convertTo( PowerUnits.EU, powerRemainder ); - } - } - - @Override - public double injectAEPower(ItemStack is, double amt) - { - return getInternalBattery( is, batteryOperation.INJECT, amt ); - } - - @Override - public double extractAEPower(ItemStack is, double amt) - { - return getInternalBattery( is, batteryOperation.EXTRACT, amt ); - } - - @Override - public double getAEMaxPower(ItemStack is) - { - return maxStoredPower; - } - - @Override - public double getAECurrentPower(ItemStack is) - { - return getInternalBattery( is, batteryOperation.STORAGE, 0 ); - } - - @Override - public AccessRestriction getPowerFlow(ItemStack is) - { - return AccessRestriction.WRITE; - } - - @Override - public int getDisplayDamage(ItemStack is) - { - return 32 - (int) (32 * (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 ); - } - -} +package appeng.items.tools.powered.powersink; + +import java.text.MessageFormat; +import java.util.List; + +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; +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 + }; + + public double maxStoredPower = 200000; + + public AERootPoweredItem(Class c, String subname) { + super( c, subname ); + setMaxDamage( 32 ); + hasSubtypes = false; + } + + @Override + public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips) + { + NBTTagCompound tag = is.getTagCompound(); + double internalCurrentPower = 0; + double internalMaxPower = getAEMaxPower( is ); + + if ( tag != null ) + { + internalCurrentPower = tag.getDouble( "internalCurrentPower" ); + } + + double percent = internalCurrentPower / internalMaxPower; + + lines.add( GuiText.StoredEnergy.getLocal() + ":" + MessageFormat.format( " {0,number,#} ", internalCurrentPower ) + + Platform.gui_localize( PowerUnits.AE.unlocalizedName ) + " - " + MessageFormat.format( " {0,number,#.##%} ", percent ) ); + + } + + @Override + public boolean isDamageable() + { + return true; + } + + @Override + public boolean isDamaged(ItemStack stack) + { + return true; + } + + @Override + public boolean isRepairable() + { + return false; + } + + @Override + public void setDamage(ItemStack stack, int damage) + { + + } + + final String EnergyVar = "internalCurrentPower"; + + 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; + } + + /** + * inject external + */ + double injectExternalPower(PowerUnits input, ItemStack is, double amount, boolean simulate) + { + if ( simulate ) + { + int requiredEU = (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( is ) - getAECurrentPower( is ) ); + if ( amount < requiredEU ) + return 0; + return amount - requiredEU; + } + else + { + double powerRemainder = injectAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) ); + return PowerUnits.AE.convertTo( PowerUnits.EU, powerRemainder ); + } + } + + @Override + public double injectAEPower(ItemStack is, double amt) + { + return getInternalBattery( is, batteryOperation.INJECT, amt ); + } + + @Override + public double extractAEPower(ItemStack is, double amt) + { + return getInternalBattery( is, batteryOperation.EXTRACT, amt ); + } + + @Override + public double getAEMaxPower(ItemStack is) + { + return maxStoredPower; + } + + @Override + public double getAECurrentPower(ItemStack is) + { + return getInternalBattery( is, batteryOperation.STORAGE, 0 ); + } + + @Override + public AccessRestriction getPowerFlow(ItemStack is) + { + return AccessRestriction.WRITE; + } + + @Override + public int getDisplayDamage(ItemStack is) + { + return 32 - (int) (32 * (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 ); + } + +} diff --git a/items/tools/powered/powersink/IC2.java b/src/main/java/appeng/items/tools/powered/powersink/IC2.java similarity index 95% rename from items/tools/powered/powersink/IC2.java rename to src/main/java/appeng/items/tools/powered/powersink/IC2.java index 078c3b0f7..f43760f1a 100644 --- a/items/tools/powered/powersink/IC2.java +++ b/src/main/java/appeng/items/tools/powered/powersink/IC2.java @@ -1,119 +1,119 @@ -package appeng.items.tools.powered.powersink; - -import ic2.api.item.IElectricItemManager; -import ic2.api.item.ISpecialElectricItem; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -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") }) -public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpecialElectricItem -{ - - public IC2(Class c, String subname) { - super( c, subname ); - } - - @Override - public double charge(ItemStack is, double amount, int tier, boolean ignoreTransferLimit, boolean simulate) - { - double addedAmt = amount; - double limit = getTransferLimit( is ); - - if ( !ignoreTransferLimit && amount > limit ) - addedAmt = limit; - - 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) - { - return 0; - } - - @Override - public double getCharge(ItemStack is) - { - return (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAECurrentPower( is ) ); - } - - @Override - public boolean canUse(ItemStack is, double amount) - { - return getCharge( is ) > amount; - } - - @Override - public boolean use(ItemStack is, double amount, EntityLivingBase entity) - { - if ( canUse( is, amount ) ) - { - // use the power.. - extractAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) ); - return true; - } - return false; - } - - @Override - public void chargeFromArmor(ItemStack itemStack, EntityLivingBase entity) - { - // wtf? - } - - @Override - public String getToolTip(ItemStack itemStack) - { - return null; - } - - @Override - public boolean canProvideEnergy(ItemStack itemStack) - { - return false; - } - - @Override - public Item getChargedItem(ItemStack itemStack) - { - return itemStack.getItem(); - } - - @Override - public Item getEmptyItem(ItemStack itemStack) - { - return itemStack.getItem(); - } - - @Override - public double getMaxCharge(ItemStack itemStack) - { - return PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( itemStack ) ); - } - - @Override - public int getTier(ItemStack itemStack) - { - return 1; - } - - @Override - public double getTransferLimit(ItemStack itemStack) - { - return Math.max( 32, getMaxCharge( itemStack ) / 200 ); - } - - @Override - @Method(iname = "IC2") - public IElectricItemManager getManager(ItemStack itemStack) - { - return this; - } - -} +package appeng.items.tools.powered.powersink; + +import ic2.api.item.IElectricItemManager; +import ic2.api.item.ISpecialElectricItem; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +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") }) +public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpecialElectricItem +{ + + public IC2(Class c, String subname) { + super( c, subname ); + } + + @Override + public double charge(ItemStack is, double amount, int tier, boolean ignoreTransferLimit, boolean simulate) + { + double addedAmt = amount; + double limit = getTransferLimit( is ); + + if ( !ignoreTransferLimit && amount > limit ) + addedAmt = limit; + + 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) + { + return 0; + } + + @Override + public double getCharge(ItemStack is) + { + return (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAECurrentPower( is ) ); + } + + @Override + public boolean canUse(ItemStack is, double amount) + { + return getCharge( is ) > amount; + } + + @Override + public boolean use(ItemStack is, double amount, EntityLivingBase entity) + { + if ( canUse( is, amount ) ) + { + // use the power.. + extractAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) ); + return true; + } + return false; + } + + @Override + public void chargeFromArmor(ItemStack itemStack, EntityLivingBase entity) + { + // wtf? + } + + @Override + public String getToolTip(ItemStack itemStack) + { + return null; + } + + @Override + public boolean canProvideEnergy(ItemStack itemStack) + { + return false; + } + + @Override + public Item getChargedItem(ItemStack itemStack) + { + return itemStack.getItem(); + } + + @Override + public Item getEmptyItem(ItemStack itemStack) + { + return itemStack.getItem(); + } + + @Override + public double getMaxCharge(ItemStack itemStack) + { + return PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( itemStack ) ); + } + + @Override + public int getTier(ItemStack itemStack) + { + return 1; + } + + @Override + public double getTransferLimit(ItemStack itemStack) + { + return Math.max( 32, getMaxCharge( itemStack ) / 200 ); + } + + @Override + @Method(iname = "IC2") + public IElectricItemManager getManager(ItemStack itemStack) + { + return this; + } + +} diff --git a/items/tools/powered/powersink/RedstoneFlux.java b/src/main/java/appeng/items/tools/powered/powersink/RedstoneFlux.java similarity index 100% rename from items/tools/powered/powersink/RedstoneFlux.java rename to src/main/java/appeng/items/tools/powered/powersink/RedstoneFlux.java diff --git a/items/tools/powered/powersink/UniversalElectricity.java b/src/main/java/appeng/items/tools/powered/powersink/UniversalElectricity.java similarity index 97% rename from items/tools/powered/powersink/UniversalElectricity.java rename to src/main/java/appeng/items/tools/powered/powersink/UniversalElectricity.java index c9b3f4f0c..ff2ce9d19 100644 --- a/items/tools/powered/powersink/UniversalElectricity.java +++ b/src/main/java/appeng/items/tools/powered/powersink/UniversalElectricity.java @@ -1,37 +1,37 @@ -package appeng.items.tools.powered.powersink; - -/* - @Interface(iface = "universalelectricity.core.item.IItemElectric", modid = "IC2") - public class UniversalElectricity extends ThermalExpansion implements IItemElectric - { - * - * public UniversalElectricity(Class c, String subname) { super( c, subname ); } - * - * @Override public float recharge(ItemStack is, float energy, boolean - * doRecharge) { return (float) (energy - injectExternalPower( PowerUnits.KJ, - * is, energy, !doRecharge )); } - * - * @Override public float discharge(ItemStack is, float energy, boolean - * doDischarge) { return 0; } - * - * @Override public float getElectricityStored(ItemStack is) { return (int) - * PowerUnits.AE.convertTo( PowerUnits.KJ, getAECurrentPower( is ) ); } - * - * @Override public float getMaxElectricityStored(ItemStack is) { return (int) - * PowerUnits.AE.convertTo( PowerUnits.KJ, getAEMaxPower( is ) ); } - * - * @Override public void setElectricity(ItemStack is, float joules) { double - * currentPower = getAECurrentPower( is ); double targetPower = - * PowerUnits.KJ.convertTo( PowerUnits.AE, joules ); if ( targetPower > - * currentPower ) injectAEPower( is, targetPower - currentPower ); else - * extractAEPower( is, currentPower - targetPower ); } - * - * @Override public float getTransfer(ItemStack is) { return (float) - * PowerUnits.AE.convertTo( PowerUnits.KJ, getAEMaxPower( is ) - - * getAECurrentPower( is ) ); } - * - * @Override public float getVoltage(ItemStack itemStack) { return 120; } - - } - */ - +package appeng.items.tools.powered.powersink; + +/* + @Interface(iface = "universalelectricity.core.item.IItemElectric", modid = "IC2") + public class UniversalElectricity extends ThermalExpansion implements IItemElectric + { + * + * public UniversalElectricity(Class c, String subname) { super( c, subname ); } + * + * @Override public float recharge(ItemStack is, float energy, boolean + * doRecharge) { return (float) (energy - injectExternalPower( PowerUnits.KJ, + * is, energy, !doRecharge )); } + * + * @Override public float discharge(ItemStack is, float energy, boolean + * doDischarge) { return 0; } + * + * @Override public float getElectricityStored(ItemStack is) { return (int) + * PowerUnits.AE.convertTo( PowerUnits.KJ, getAECurrentPower( is ) ); } + * + * @Override public float getMaxElectricityStored(ItemStack is) { return (int) + * PowerUnits.AE.convertTo( PowerUnits.KJ, getAEMaxPower( is ) ); } + * + * @Override public void setElectricity(ItemStack is, float joules) { double + * currentPower = getAECurrentPower( is ); double targetPower = + * PowerUnits.KJ.convertTo( PowerUnits.AE, joules ); if ( targetPower > + * currentPower ) injectAEPower( is, targetPower - currentPower ); else + * extractAEPower( is, currentPower - targetPower ); } + * + * @Override public float getTransfer(ItemStack is) { return (float) + * PowerUnits.AE.convertTo( PowerUnits.KJ, getAEMaxPower( is ) - + * getAECurrentPower( is ) ); } + * + * @Override public float getVoltage(ItemStack itemStack) { return 120; } + + } + */ + diff --git a/items/tools/quartz/ToolQuartzAxe.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzAxe.java similarity index 100% rename from items/tools/quartz/ToolQuartzAxe.java rename to src/main/java/appeng/items/tools/quartz/ToolQuartzAxe.java diff --git a/items/tools/quartz/ToolQuartzCuttingKnife.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java similarity index 100% rename from items/tools/quartz/ToolQuartzCuttingKnife.java rename to src/main/java/appeng/items/tools/quartz/ToolQuartzCuttingKnife.java diff --git a/items/tools/quartz/ToolQuartzHoe.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzHoe.java similarity index 100% rename from items/tools/quartz/ToolQuartzHoe.java rename to src/main/java/appeng/items/tools/quartz/ToolQuartzHoe.java diff --git a/items/tools/quartz/ToolQuartzPickaxe.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzPickaxe.java similarity index 100% rename from items/tools/quartz/ToolQuartzPickaxe.java rename to src/main/java/appeng/items/tools/quartz/ToolQuartzPickaxe.java diff --git a/items/tools/quartz/ToolQuartzSpade.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzSpade.java similarity index 100% rename from items/tools/quartz/ToolQuartzSpade.java rename to src/main/java/appeng/items/tools/quartz/ToolQuartzSpade.java diff --git a/items/tools/quartz/ToolQuartzSword.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzSword.java similarity index 100% rename from items/tools/quartz/ToolQuartzSword.java rename to src/main/java/appeng/items/tools/quartz/ToolQuartzSword.java diff --git a/items/tools/quartz/ToolQuartzWrench.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java similarity index 100% rename from items/tools/quartz/ToolQuartzWrench.java rename to src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java diff --git a/me/Grid.java b/src/main/java/appeng/me/Grid.java similarity index 100% rename from me/Grid.java rename to src/main/java/appeng/me/Grid.java diff --git a/me/GridAccessException.java b/src/main/java/appeng/me/GridAccessException.java similarity index 94% rename from me/GridAccessException.java rename to src/main/java/appeng/me/GridAccessException.java index a9fa486ae..23627567b 100644 --- a/me/GridAccessException.java +++ b/src/main/java/appeng/me/GridAccessException.java @@ -1,8 +1,8 @@ -package appeng.me; - -public class GridAccessException extends Exception -{ - - private static final long serialVersionUID = 3914554394866375300L; - -} +package appeng.me; + +public class GridAccessException extends Exception +{ + + private static final long serialVersionUID = 3914554394866375300L; + +} diff --git a/me/GridCacheWrapper.java b/src/main/java/appeng/me/GridCacheWrapper.java similarity index 94% rename from me/GridCacheWrapper.java rename to src/main/java/appeng/me/GridCacheWrapper.java index 8a068b30e..2100ef1f0 100644 --- a/me/GridCacheWrapper.java +++ b/src/main/java/appeng/me/GridCacheWrapper.java @@ -1,60 +1,60 @@ -package appeng.me; - -import appeng.api.networking.IGridCache; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridStorage; - -public class GridCacheWrapper implements IGridCache -{ - - final IGridCache myCache; - final String name; - - public GridCacheWrapper(final IGridCache gc) { - myCache = gc; - name = myCache.getClass().getName(); - } - - @Override - public void onUpdateTick() - { - myCache.onUpdateTick(); - } - - @Override - public void removeNode(final IGridNode gridNode, final IGridHost machine) - { - myCache.removeNode( gridNode, machine ); - } - - @Override - public void addNode(final IGridNode gridNode, final IGridHost machine) - { - myCache.addNode( gridNode, machine ); - } - - public String getName() - { - return name; - } - - @Override - public void onSplit(final IGridStorage storageB) - { - myCache.onSplit( storageB ); - } - - @Override - public void onJoin(final IGridStorage storageB) - { - myCache.onJoin( storageB ); - } - - @Override - public void populateGridStorage(final IGridStorage storage) - { - myCache.populateGridStorage( storage ); - } - -} +package appeng.me; + +import appeng.api.networking.IGridCache; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridStorage; + +public class GridCacheWrapper implements IGridCache +{ + + final IGridCache myCache; + final String name; + + public GridCacheWrapper(final IGridCache gc) { + myCache = gc; + name = myCache.getClass().getName(); + } + + @Override + public void onUpdateTick() + { + myCache.onUpdateTick(); + } + + @Override + public void removeNode(final IGridNode gridNode, final IGridHost machine) + { + myCache.removeNode( gridNode, machine ); + } + + @Override + public void addNode(final IGridNode gridNode, final IGridHost machine) + { + myCache.addNode( gridNode, machine ); + } + + public String getName() + { + return name; + } + + @Override + public void onSplit(final IGridStorage storageB) + { + myCache.onSplit( storageB ); + } + + @Override + public void onJoin(final IGridStorage storageB) + { + myCache.onJoin( storageB ); + } + + @Override + public void populateGridStorage(final IGridStorage storage) + { + myCache.populateGridStorage( storage ); + } + +} diff --git a/me/GridConnection.java b/src/main/java/appeng/me/GridConnection.java similarity index 95% rename from me/GridConnection.java rename to src/main/java/appeng/me/GridConnection.java index ade8c5095..796df1a99 100644 --- a/me/GridConnection.java +++ b/src/main/java/appeng/me/GridConnection.java @@ -1,230 +1,230 @@ -package appeng.me; - -import java.util.Arrays; -import java.util.EnumSet; - -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.exceptions.FailedConnection; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridConnection; -import appeng.api.networking.IGridNode; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.pathing.IPathingGrid; -import appeng.api.util.IReadOnlyCollection; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.features.AEFeature; -import appeng.me.pathfinding.IPathItem; -import appeng.util.Platform; -import appeng.util.ReadOnlyCollection; - -public class GridConnection implements IGridConnection, IPathItem -{ - - final static private MENetworkChannelsChanged event = new MENetworkChannelsChanged(); - - private GridNode sideA; - private ForgeDirection fromAtoB; - private GridNode sideB; - - Object visitorIterationNumber = null; - - public int channelData = 0; - - public GridConnection(IGridNode aNode, IGridNode bNode, ForgeDirection fromAtoB) throws FailedConnection { - - GridNode a = (GridNode) aNode; - GridNode b = (GridNode) bNode; - - if ( Platform.securityCheck( a, b ) ) - { - if ( AEConfig.instance.isFeatureEnabled( AEFeature.LogSecurityAudits ) ) - { - AELog.info( "Audit Failed 1: " + a.getGridBlock().getLocation() ); - AELog.info( "Audit Failed 2: " + b.getGridBlock().getLocation() ); - } - - throw new FailedConnection(); - } - - if ( a == null || b == null ) - throw new GridException( "Connection Forged Between null entities." ); - - if ( a.hasConnection( b ) || b.hasConnection( a ) ) - throw new GridException( "Connection already exists." ); - - sideA = a; - this.fromAtoB = fromAtoB; - sideB = b; - - if ( b.myGrid == null ) - { - b.setGrid( a.getInternalGrid() ); - } - else - { - if ( a.myGrid == null ) - { - GridPropagator gp = new GridPropagator( b.getInternalGrid() ); - a.beginVisit( gp ); - } - else if ( b.myGrid == null ) - { - GridPropagator gp = new GridPropagator( a.getInternalGrid() ); - b.beginVisit( gp ); - } - else if ( isNetworkABetter( a, b ) ) - { - GridPropagator gp = new GridPropagator( a.getInternalGrid() ); - b.beginVisit( gp ); - } - else - { - GridPropagator gp = new GridPropagator( b.getInternalGrid() ); - a.beginVisit( gp ); - } - } - - // a connection was destroyed RE-PATH!! - IPathingGrid p = sideA.getInternalGrid().getCache( IPathingGrid.class ); - p.repath(); - - sideA.addConnection( this ); - sideB.addConnection( this ); - } - - private boolean isNetworkABetter(GridNode a, GridNode b) - { - return ((Grid) a.myGrid).isImportant > ((Grid) b.myGrid).isImportant || a.myGrid.size() > b.myGrid.size(); - } - - @Override - public void destroy() - { - // a connection was destroyed RE-PATH!! - IPathingGrid p = sideA.getInternalGrid().getCache( IPathingGrid.class ); - p.repath(); - - sideA.removeConnection( this ); - sideB.removeConnection( this ); - - sideA.validateGrid(); - sideB.validateGrid(); - } - - @Override - public IGridNode a() - { - return sideA; - } - - @Override - public ForgeDirection getDirection(IGridNode side) - { - if ( fromAtoB == ForgeDirection.UNKNOWN ) - return fromAtoB; - - if ( sideA == side ) - return fromAtoB; - else - return fromAtoB.getOpposite(); - } - - @Override - public IGridNode b() - { - return sideB; - } - - @Override - public IGridNode getOtherSide(IGridNode gridNode) - { - if ( gridNode == sideA ) - return sideB; - if ( gridNode == sideB ) - return sideA; - - throw new GridException( "Invalid Side of Connection" ); - } - - @Override - public boolean hasDirection() - { - return fromAtoB != ForgeDirection.UNKNOWN; - } - - @Override - public IReadOnlyCollection getPossibleOptions() - { - return new ReadOnlyCollection( Arrays.asList( new IPathItem[] { (IPathItem) a(), (IPathItem) b() } ) ); - } - - @Override - public void incrementChannelCount(int usedChannels) - { - channelData += usedChannels; - } - - @Override - public boolean canSupportMoreChannels() - { - return getLastUsedChannels() < 32; // max, PERIOD. - } - - @Override - public int getUsedChannels() - { - return (channelData >> 8) & 0xff; - } - - public int getLastUsedChannels() - { - return channelData & 0xff; - } - - @Override - public IPathItem getControllerRoute() - { - if ( sideA.getFlags().contains( GridFlags.CANNOT_CARRY ) ) - return null; - return sideA; - } - - @Override - public void setControllerRoute(IPathItem fast, boolean zeroOut) - { - if ( zeroOut ) - channelData &= ~0xff; - - if ( sideB == fast ) - { - GridNode tmp = sideA; - sideA = sideB; - sideB = tmp; - fromAtoB = fromAtoB.getOpposite(); - } - } - - @Override - public void finalizeChannels() - { - if ( getUsedChannels() != getLastUsedChannels() ) - { - channelData = (channelData & 0xff); - channelData |= channelData << 8; - - if ( sideA.getInternalGrid() != null ) - sideA.getInternalGrid().postEventTo( sideA, event ); - - if ( sideB.getInternalGrid() != null ) - sideB.getInternalGrid().postEventTo( sideB, event ); - } - } - - @Override - public EnumSet getFlags() - { - return EnumSet.noneOf( GridFlags.class ); - } - -} +package appeng.me; + +import java.util.Arrays; +import java.util.EnumSet; + +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.exceptions.FailedConnection; +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGridConnection; +import appeng.api.networking.IGridNode; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.pathing.IPathingGrid; +import appeng.api.util.IReadOnlyCollection; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.features.AEFeature; +import appeng.me.pathfinding.IPathItem; +import appeng.util.Platform; +import appeng.util.ReadOnlyCollection; + +public class GridConnection implements IGridConnection, IPathItem +{ + + final static private MENetworkChannelsChanged event = new MENetworkChannelsChanged(); + + private GridNode sideA; + private ForgeDirection fromAtoB; + private GridNode sideB; + + Object visitorIterationNumber = null; + + public int channelData = 0; + + public GridConnection(IGridNode aNode, IGridNode bNode, ForgeDirection fromAtoB) throws FailedConnection { + + GridNode a = (GridNode) aNode; + GridNode b = (GridNode) bNode; + + if ( Platform.securityCheck( a, b ) ) + { + if ( AEConfig.instance.isFeatureEnabled( AEFeature.LogSecurityAudits ) ) + { + AELog.info( "Audit Failed 1: " + a.getGridBlock().getLocation() ); + AELog.info( "Audit Failed 2: " + b.getGridBlock().getLocation() ); + } + + throw new FailedConnection(); + } + + if ( a == null || b == null ) + throw new GridException( "Connection Forged Between null entities." ); + + if ( a.hasConnection( b ) || b.hasConnection( a ) ) + throw new GridException( "Connection already exists." ); + + sideA = a; + this.fromAtoB = fromAtoB; + sideB = b; + + if ( b.myGrid == null ) + { + b.setGrid( a.getInternalGrid() ); + } + else + { + if ( a.myGrid == null ) + { + GridPropagator gp = new GridPropagator( b.getInternalGrid() ); + a.beginVisit( gp ); + } + else if ( b.myGrid == null ) + { + GridPropagator gp = new GridPropagator( a.getInternalGrid() ); + b.beginVisit( gp ); + } + else if ( isNetworkABetter( a, b ) ) + { + GridPropagator gp = new GridPropagator( a.getInternalGrid() ); + b.beginVisit( gp ); + } + else + { + GridPropagator gp = new GridPropagator( b.getInternalGrid() ); + a.beginVisit( gp ); + } + } + + // a connection was destroyed RE-PATH!! + IPathingGrid p = sideA.getInternalGrid().getCache( IPathingGrid.class ); + p.repath(); + + sideA.addConnection( this ); + sideB.addConnection( this ); + } + + private boolean isNetworkABetter(GridNode a, GridNode b) + { + return ((Grid) a.myGrid).isImportant > ((Grid) b.myGrid).isImportant || a.myGrid.size() > b.myGrid.size(); + } + + @Override + public void destroy() + { + // a connection was destroyed RE-PATH!! + IPathingGrid p = sideA.getInternalGrid().getCache( IPathingGrid.class ); + p.repath(); + + sideA.removeConnection( this ); + sideB.removeConnection( this ); + + sideA.validateGrid(); + sideB.validateGrid(); + } + + @Override + public IGridNode a() + { + return sideA; + } + + @Override + public ForgeDirection getDirection(IGridNode side) + { + if ( fromAtoB == ForgeDirection.UNKNOWN ) + return fromAtoB; + + if ( sideA == side ) + return fromAtoB; + else + return fromAtoB.getOpposite(); + } + + @Override + public IGridNode b() + { + return sideB; + } + + @Override + public IGridNode getOtherSide(IGridNode gridNode) + { + if ( gridNode == sideA ) + return sideB; + if ( gridNode == sideB ) + return sideA; + + throw new GridException( "Invalid Side of Connection" ); + } + + @Override + public boolean hasDirection() + { + return fromAtoB != ForgeDirection.UNKNOWN; + } + + @Override + public IReadOnlyCollection getPossibleOptions() + { + return new ReadOnlyCollection( Arrays.asList( new IPathItem[] { (IPathItem) a(), (IPathItem) b() } ) ); + } + + @Override + public void incrementChannelCount(int usedChannels) + { + channelData += usedChannels; + } + + @Override + public boolean canSupportMoreChannels() + { + return getLastUsedChannels() < 32; // max, PERIOD. + } + + @Override + public int getUsedChannels() + { + return (channelData >> 8) & 0xff; + } + + public int getLastUsedChannels() + { + return channelData & 0xff; + } + + @Override + public IPathItem getControllerRoute() + { + if ( sideA.getFlags().contains( GridFlags.CANNOT_CARRY ) ) + return null; + return sideA; + } + + @Override + public void setControllerRoute(IPathItem fast, boolean zeroOut) + { + if ( zeroOut ) + channelData &= ~0xff; + + if ( sideB == fast ) + { + GridNode tmp = sideA; + sideA = sideB; + sideB = tmp; + fromAtoB = fromAtoB.getOpposite(); + } + } + + @Override + public void finalizeChannels() + { + if ( getUsedChannels() != getLastUsedChannels() ) + { + channelData = (channelData & 0xff); + channelData |= channelData << 8; + + if ( sideA.getInternalGrid() != null ) + sideA.getInternalGrid().postEventTo( sideA, event ); + + if ( sideB.getInternalGrid() != null ) + sideB.getInternalGrid().postEventTo( sideB, event ); + } + } + + @Override + public EnumSet getFlags() + { + return EnumSet.noneOf( GridFlags.class ); + } + +} diff --git a/me/GridException.java b/src/main/java/appeng/me/GridException.java similarity index 94% rename from me/GridException.java rename to src/main/java/appeng/me/GridException.java index ce0ee338d..db5cf7a39 100644 --- a/me/GridException.java +++ b/src/main/java/appeng/me/GridException.java @@ -1,12 +1,12 @@ -package appeng.me; - -public class GridException extends RuntimeException -{ - - private static final long serialVersionUID = -8110077032108243076L; - - public GridException(String s) { - - super( s ); - } -} +package appeng.me; + +public class GridException extends RuntimeException +{ + + private static final long serialVersionUID = -8110077032108243076L; + + public GridException(String s) { + + super( s ); + } +} diff --git a/me/GridNode.java b/src/main/java/appeng/me/GridNode.java similarity index 95% rename from me/GridNode.java rename to src/main/java/appeng/me/GridNode.java index cc223b8c5..816f6278a 100644 --- a/me/GridNode.java +++ b/src/main/java/appeng/me/GridNode.java @@ -1,612 +1,612 @@ -package appeng.me; - -import java.util.Collections; -import java.util.Comparator; -import java.util.EnumSet; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.Callable; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.exceptions.FailedConnection; -import appeng.api.networking.GridFlags; -import appeng.api.networking.GridNotification; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridBlock; -import appeng.api.networking.IGridCache; -import appeng.api.networking.IGridConnectionVisitor; -import appeng.api.networking.IGridConnection; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridVisitor; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.pathing.IPathingGrid; -import appeng.api.util.AEColor; -import appeng.api.util.DimensionalCoord; -import appeng.api.util.IReadOnlyCollection; -import appeng.core.WorldSettings; -import appeng.hooks.TickHandler; -import appeng.me.pathfinding.IPathItem; -import appeng.util.ReadOnlyCollection; - -public class GridNode implements IGridNode, IPathItem -{ - - final static private MENetworkChannelsChanged event = new MENetworkChannelsChanged(); - final static private int channelCount[] = new int[] { 0, 8, 32 }; - - final List Connections = new LinkedList(); - GridStorage myStorage = null; - - IGridBlock gridProxy; - Grid myGrid; - - Object visitorIterationNumber = null; - - // connection criteria - private int compressedData = 0; - - @Override - public void updateState() - { - EnumSet set = gridProxy.getFlags(); - - compressedData = set.contains( GridFlags.CANNOT_CARRY ) ? 0 : (set.contains( GridFlags.DENSE_CAPACITY ) ? 2 : 1); - - compressedData = compressedData | (gridProxy.getGridColor().ordinal() << 3); - - for (ForgeDirection dir : gridProxy.getConnectableSides()) - compressedData = compressedData | (1 << (dir.ordinal() + 8)); - - FindConnections(); - getInternalGrid(); - } - - public int getMaxChannels() - { - return channelCount[compressedData & 0x03]; - } - - public AEColor getColor() - { - return AEColor.values()[(compressedData >> 3) & 0x1F]; - } - - private boolean isValidDirection(ForgeDirection dir) - { - return (compressedData & (1 << (8 + dir.ordinal()))) > 0; - } - - // old power draw, used to diff - public double previousDraw = 0.0; - - private int channelData = 0; - - public long lastSecurityKey = -1; - public int playerID = -1; - - @Override - public void setPlayerID(int playerID) - { - if ( playerID >= 0 ) - this.playerID = playerID; - } - - public int usedChannels() - { - return channelData >> 8; - } - - public GridNode(IGridBlock what) { - gridProxy = what; - } - - @Override - public void loadFromNBT(String name, NBTTagCompound nodeData) - { - if ( myGrid == null ) - { - NBTTagCompound node = nodeData.getCompoundTag( name ); - playerID = node.getInteger( "p" ); - lastSecurityKey = node.getLong( "k" ); - setGridStorage( WorldSettings.getInstance().getGridStorage( node.getLong( "g" ) ) ); - } - else - throw new RuntimeException( "Loading data after part of a grid, this is invalid." ); - } - - @Override - public void saveToNBT(String name, NBTTagCompound nodeData) - { - if ( myStorage != null ) - { - NBTTagCompound node = new NBTTagCompound(); - - node.setInteger( "p", playerID ); - node.setLong( "k", lastSecurityKey ); - node.setLong( "g", myStorage.getID() ); - - nodeData.setTag( name, node ); - } - else - nodeData.removeTag( name ); - } - - @Override - public IGridBlock getGridBlock() - { - return gridProxy; - } - - @Override - public EnumSet getConnectedSides() - { - EnumSet set = EnumSet.noneOf( ForgeDirection.class ); - for (IGridConnection gc : Connections) - set.add( gc.getDirection( this ) ); - return set; - } - - public Class getMachineClass() - { - return getMachine().getClass(); - } - - @Override - public IGridHost getMachine() - { - return gridProxy.getMachine(); - } - - @Override - public void beginVisit(IGridVisitor g) - { - Object tracker = new Object(); - - LinkedList nextRun = new LinkedList(); - nextRun.add( this ); - - visitorIterationNumber = tracker; - - if ( g instanceof IGridConnectionVisitor ) - { - LinkedList nextConn = new LinkedList(); - IGridConnectionVisitor gcv = (IGridConnectionVisitor) g; - - while (!nextRun.isEmpty()) - { - while (!nextConn.isEmpty()) - gcv.visitConnection( nextConn.poll() ); - - LinkedList thisRun = nextRun; - nextRun = new LinkedList(); - - for (GridNode n : thisRun) - n.visitorConnection( tracker, g, nextRun, nextConn ); - } - } - else - { - while (!nextRun.isEmpty()) - { - LinkedList thisRun = nextRun; - nextRun = new LinkedList(); - - for (GridNode n : thisRun) - n.visitorNode( tracker, g, nextRun ); - } - } - } - - private void visitorConnection(Object tracker, IGridVisitor g, LinkedList nextRun, LinkedList nextConnections) - { - if ( g.visitNode( this ) ) - { - for (IGridConnection gc : getConnections()) - { - GridNode gn = (GridNode) gc.getOtherSide( this ); - GridConnection gcc = (GridConnection) gc; - - if ( gcc.visitorIterationNumber != tracker ) - { - gcc.visitorIterationNumber = tracker; - nextConnections.add( gc ); - } - - if ( tracker == gn.visitorIterationNumber ) - continue; - - gn.visitorIterationNumber = tracker; - - nextRun.add( gn ); - } - } - } - - private void visitorNode(Object tracker, IGridVisitor g, LinkedList nextRun) - { - if ( g.visitNode( this ) ) - { - for (IGridConnection gc : getConnections()) - { - GridNode gn = (GridNode) gc.getOtherSide( this ); - - if ( tracker == gn.visitorIterationNumber ) - continue; - - gn.visitorIterationNumber = tracker; - - nextRun.add( gn ); - } - } - } - - public void FindConnections() - { - if ( !gridProxy.isWorldAccessible() ) - return; - - EnumSet newSecurityConnections = EnumSet.noneOf( ForgeDirection.class ); - - DimensionalCoord dc = gridProxy.getLocation(); - for (ForgeDirection f : ForgeDirection.VALID_DIRECTIONS) - { - IGridHost te = findGridHost( dc.getWorld(), dc.x + f.offsetX, dc.y + f.offsetY, dc.z + f.offsetZ ); - if ( te != null ) - { - GridNode node = (GridNode) te.getGridNode( f.getOpposite() ); - if ( node == null ) - continue; - - boolean isValidConnection = this.canConnect( node, f ) && node.canConnect( this, f.getOpposite() ); - - IGridConnection con = null; // find the connection for this - // direction.. - for (IGridConnection c : getConnections()) - { - if ( c.getDirection( this ) == f ) - { - con = c; - break; - } - } - - if ( con != null ) - { - IGridNode os = (IGridNode) con.getOtherSide( this ); - if ( os == node ) - { - // if this connection is no longer valid, destroy it. - if ( !isValidConnection ) - con.destroy(); - } - else - { - con.destroy(); - // throw new GridException( "invalid state found, encountered connection to phantom block." ); - } - } - else if ( isValidConnection ) - { - if ( node.lastSecurityKey != -1 ) - newSecurityConnections.add( f ); - else - { - // construct a new connection between these two nodes. - try - { - new GridConnection( node, this, f.getOpposite() ); - } - catch (FailedConnection e) - { - TickHandler.instance.addCallable( node.getWorld(), new Callable() { - - @Override - public Object call() throws Exception - { - getMachine().securityBreak(); - return null; - } - - } ); - - return; - } - } - } - - } - } - - for (ForgeDirection f : newSecurityConnections) - { - IGridHost te = findGridHost( dc.getWorld(), dc.x + f.offsetX, dc.y + f.offsetY, dc.z + f.offsetZ ); - if ( te != null ) - { - GridNode node = (GridNode) te.getGridNode( f.getOpposite() ); - if ( node == null ) - continue; - - // construct a new connection between these two nodes. - try - { - new GridConnection( node, this, f.getOpposite() ); - } - catch (FailedConnection e) - { - TickHandler.instance.addCallable( node.getWorld(), new Callable() { - - @Override - public Object call() throws Exception - { - getMachine().securityBreak(); - return null; - } - - } ); - - return; - } - } - } - } - - private IGridHost findGridHost(World world, int x, int y, int z) - { - if ( world.blockExists( x, y, z ) ) - { - TileEntity te = world.getTileEntity( x, y, z ); - if ( te instanceof IGridHost ) - return (IGridHost) te; - } - return null; - } - - public void addConnection(IGridConnection gridConnection) - { - Connections.add( gridConnection ); - if ( gridConnection.hasDirection() ) - gridProxy.onGridNotification( GridNotification.ConnectionsChanged ); - - final IGridNode gn = this; - - Collections.sort( Connections, new Comparator() { - - @Override - public int compare(IGridConnection o1, IGridConnection o2) - { - boolean preferredA = o1.getOtherSide( gn ).hasFlag( GridFlags.PREFERRED ); - boolean preferredB = o2.getOtherSide( gn ).hasFlag( GridFlags.PREFERRED ); - - return preferredA == preferredB ? 0 : (preferredA ? -1 : 1); - } - - } ); - } - - public void removeConnection(IGridConnection gridConnection) - { - Connections.remove( gridConnection ); - if ( gridConnection.hasDirection() ) - gridProxy.onGridNotification( GridNotification.ConnectionsChanged ); - } - - @Override - public IReadOnlyCollection getConnections() - { - return new ReadOnlyCollection( Connections ); - } - - public boolean hasConnection(IGridNode otherside) - { - for (IGridConnection gc : Connections) - { - if ( gc.a() == otherside || gc.b() == otherside ) - return true; - } - return false; - } - - public boolean canConnect(GridNode from, ForgeDirection dir) - { - if ( !isValidDirection( dir ) ) - return false; - - if ( !from.getColor().matches( getColor() ) ) - return false; - - return true; - } - - @Override - public IGrid getGrid() - { - return myGrid; - } - - public Grid getInternalGrid() - { - if ( myGrid == null ) - myGrid = new Grid( this ); - - return myGrid; - } - - public void setGrid(Grid grid) - { - if ( myGrid == grid ) - return; - - if ( myGrid != null ) - { - myGrid.remove( this ); - - if ( myGrid.isEmpty() ) - { - myGrid.saveState(); - - for (IGridCache c : grid.caches.values()) - c.onJoin( myGrid.myStorage ); - } - } - - myGrid = grid; - myGrid.add( this ); - } - - public void validateGrid() - { - GridSplitDetector gsd = new GridSplitDetector( getInternalGrid().getPivot() ); - beginVisit( gsd ); - if ( !gsd.pivotFound ) - { - GridPropagator gp = new GridPropagator( new Grid( this ) ); - beginVisit( gp ); - } - } - - @Override - public void destroy() - { - while (!Connections.isEmpty()) - { - // not part of this network for real anymore. - if ( Connections.size() == 1 ) - setGridStorage( null ); - - IGridConnection c = Connections.listIterator().next(); - GridNode otherSide = (GridNode) c.getOtherSide( this ); - otherSide.getInternalGrid().pivot = otherSide; - c.destroy(); - } - - if ( myGrid != null ) - myGrid.remove( this ); - } - - @Override - public World getWorld() - { - return gridProxy.getLocation().getWorld(); - } - - @Override - public boolean meetsChannelRequirements() - { - return (!getGridBlock().getFlags().contains( GridFlags.REQUIRE_CHANNEL ) || getUsedChannels() > 0); - } - - @Override - public boolean isActive() - { - IGrid g = getGrid(); - if ( g != null ) - { - IPathingGrid pg = g.getCache( IPathingGrid.class ); - IEnergyGrid eg = g.getCache( IEnergyGrid.class ); - return meetsChannelRequirements() && eg.isNetworkPowered() && !pg.isNetworkBooting(); - } - return false; - } - - @Override - public boolean canSupportMoreChannels() - { - return getUsedChannels() < getMaxChannels(); - } - - @Override - public IReadOnlyCollection getPossibleOptions() - { - return (ReadOnlyCollection) getConnections(); - } - - public int getLastUsedChannels() - { - return (channelData >> 8) & 0xff; - } - - public int getUsedChannels() - { - return channelData & 0xff; - } - - @Override - public void incrementChannelCount(int usedChannels) - { - channelData += usedChannels; - } - - public void setGridStorage(GridStorage s) - { - myStorage = s; - channelData = 0; - } - - public GridStorage getGridStorage() - { - return myStorage; - } - - @Override - public EnumSet getFlags() - { - return getGridBlock().getFlags(); - } - - @Override - public void finalizeChannels() - { - if ( getFlags().contains( GridFlags.CANNOT_CARRY ) ) - return; - - if ( getLastUsedChannels() != getUsedChannels() ) - { - channelData = (channelData & 0xff); - channelData |= channelData << 8; - - if ( getInternalGrid() != null ) - getInternalGrid().postEventTo( this, event ); - } - } - - @Override - public IPathItem getControllerRoute() - { - if ( Connections.isEmpty() || getFlags().contains( GridFlags.CANNOT_CARRY ) ) - return null; - - return (IPathItem) Connections.get( 0 ); - } - - @Override - public void setControllerRoute(IPathItem fast, boolean zeroOut) - { - if ( zeroOut ) - channelData &= ~0xff; - - int idx = Connections.indexOf( fast ); - if ( idx > 0 ) - { - Connections.remove( fast ); - Connections.add( 0, (IGridConnection) fast ); - } - } - - @Override - public boolean hasFlag(GridFlags flag) - { - return getGridBlock().getFlags().contains( flag ); - } - - @Override - public int getPlayerID() - { - return playerID; - } - -} +package appeng.me; + +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.Callable; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.exceptions.FailedConnection; +import appeng.api.networking.GridFlags; +import appeng.api.networking.GridNotification; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridBlock; +import appeng.api.networking.IGridCache; +import appeng.api.networking.IGridConnectionVisitor; +import appeng.api.networking.IGridConnection; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridVisitor; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.pathing.IPathingGrid; +import appeng.api.util.AEColor; +import appeng.api.util.DimensionalCoord; +import appeng.api.util.IReadOnlyCollection; +import appeng.core.WorldSettings; +import appeng.hooks.TickHandler; +import appeng.me.pathfinding.IPathItem; +import appeng.util.ReadOnlyCollection; + +public class GridNode implements IGridNode, IPathItem +{ + + final static private MENetworkChannelsChanged event = new MENetworkChannelsChanged(); + final static private int channelCount[] = new int[] { 0, 8, 32 }; + + final List Connections = new LinkedList(); + GridStorage myStorage = null; + + IGridBlock gridProxy; + Grid myGrid; + + Object visitorIterationNumber = null; + + // connection criteria + private int compressedData = 0; + + @Override + public void updateState() + { + EnumSet set = gridProxy.getFlags(); + + compressedData = set.contains( GridFlags.CANNOT_CARRY ) ? 0 : (set.contains( GridFlags.DENSE_CAPACITY ) ? 2 : 1); + + compressedData = compressedData | (gridProxy.getGridColor().ordinal() << 3); + + for (ForgeDirection dir : gridProxy.getConnectableSides()) + compressedData = compressedData | (1 << (dir.ordinal() + 8)); + + FindConnections(); + getInternalGrid(); + } + + public int getMaxChannels() + { + return channelCount[compressedData & 0x03]; + } + + public AEColor getColor() + { + return AEColor.values()[(compressedData >> 3) & 0x1F]; + } + + private boolean isValidDirection(ForgeDirection dir) + { + return (compressedData & (1 << (8 + dir.ordinal()))) > 0; + } + + // old power draw, used to diff + public double previousDraw = 0.0; + + private int channelData = 0; + + public long lastSecurityKey = -1; + public int playerID = -1; + + @Override + public void setPlayerID(int playerID) + { + if ( playerID >= 0 ) + this.playerID = playerID; + } + + public int usedChannels() + { + return channelData >> 8; + } + + public GridNode(IGridBlock what) { + gridProxy = what; + } + + @Override + public void loadFromNBT(String name, NBTTagCompound nodeData) + { + if ( myGrid == null ) + { + NBTTagCompound node = nodeData.getCompoundTag( name ); + playerID = node.getInteger( "p" ); + lastSecurityKey = node.getLong( "k" ); + setGridStorage( WorldSettings.getInstance().getGridStorage( node.getLong( "g" ) ) ); + } + else + throw new RuntimeException( "Loading data after part of a grid, this is invalid." ); + } + + @Override + public void saveToNBT(String name, NBTTagCompound nodeData) + { + if ( myStorage != null ) + { + NBTTagCompound node = new NBTTagCompound(); + + node.setInteger( "p", playerID ); + node.setLong( "k", lastSecurityKey ); + node.setLong( "g", myStorage.getID() ); + + nodeData.setTag( name, node ); + } + else + nodeData.removeTag( name ); + } + + @Override + public IGridBlock getGridBlock() + { + return gridProxy; + } + + @Override + public EnumSet getConnectedSides() + { + EnumSet set = EnumSet.noneOf( ForgeDirection.class ); + for (IGridConnection gc : Connections) + set.add( gc.getDirection( this ) ); + return set; + } + + public Class getMachineClass() + { + return getMachine().getClass(); + } + + @Override + public IGridHost getMachine() + { + return gridProxy.getMachine(); + } + + @Override + public void beginVisit(IGridVisitor g) + { + Object tracker = new Object(); + + LinkedList nextRun = new LinkedList(); + nextRun.add( this ); + + visitorIterationNumber = tracker; + + if ( g instanceof IGridConnectionVisitor ) + { + LinkedList nextConn = new LinkedList(); + IGridConnectionVisitor gcv = (IGridConnectionVisitor) g; + + while (!nextRun.isEmpty()) + { + while (!nextConn.isEmpty()) + gcv.visitConnection( nextConn.poll() ); + + LinkedList thisRun = nextRun; + nextRun = new LinkedList(); + + for (GridNode n : thisRun) + n.visitorConnection( tracker, g, nextRun, nextConn ); + } + } + else + { + while (!nextRun.isEmpty()) + { + LinkedList thisRun = nextRun; + nextRun = new LinkedList(); + + for (GridNode n : thisRun) + n.visitorNode( tracker, g, nextRun ); + } + } + } + + private void visitorConnection(Object tracker, IGridVisitor g, LinkedList nextRun, LinkedList nextConnections) + { + if ( g.visitNode( this ) ) + { + for (IGridConnection gc : getConnections()) + { + GridNode gn = (GridNode) gc.getOtherSide( this ); + GridConnection gcc = (GridConnection) gc; + + if ( gcc.visitorIterationNumber != tracker ) + { + gcc.visitorIterationNumber = tracker; + nextConnections.add( gc ); + } + + if ( tracker == gn.visitorIterationNumber ) + continue; + + gn.visitorIterationNumber = tracker; + + nextRun.add( gn ); + } + } + } + + private void visitorNode(Object tracker, IGridVisitor g, LinkedList nextRun) + { + if ( g.visitNode( this ) ) + { + for (IGridConnection gc : getConnections()) + { + GridNode gn = (GridNode) gc.getOtherSide( this ); + + if ( tracker == gn.visitorIterationNumber ) + continue; + + gn.visitorIterationNumber = tracker; + + nextRun.add( gn ); + } + } + } + + public void FindConnections() + { + if ( !gridProxy.isWorldAccessible() ) + return; + + EnumSet newSecurityConnections = EnumSet.noneOf( ForgeDirection.class ); + + DimensionalCoord dc = gridProxy.getLocation(); + for (ForgeDirection f : ForgeDirection.VALID_DIRECTIONS) + { + IGridHost te = findGridHost( dc.getWorld(), dc.x + f.offsetX, dc.y + f.offsetY, dc.z + f.offsetZ ); + if ( te != null ) + { + GridNode node = (GridNode) te.getGridNode( f.getOpposite() ); + if ( node == null ) + continue; + + boolean isValidConnection = this.canConnect( node, f ) && node.canConnect( this, f.getOpposite() ); + + IGridConnection con = null; // find the connection for this + // direction.. + for (IGridConnection c : getConnections()) + { + if ( c.getDirection( this ) == f ) + { + con = c; + break; + } + } + + if ( con != null ) + { + IGridNode os = (IGridNode) con.getOtherSide( this ); + if ( os == node ) + { + // if this connection is no longer valid, destroy it. + if ( !isValidConnection ) + con.destroy(); + } + else + { + con.destroy(); + // throw new GridException( "invalid state found, encountered connection to phantom block." ); + } + } + else if ( isValidConnection ) + { + if ( node.lastSecurityKey != -1 ) + newSecurityConnections.add( f ); + else + { + // construct a new connection between these two nodes. + try + { + new GridConnection( node, this, f.getOpposite() ); + } + catch (FailedConnection e) + { + TickHandler.instance.addCallable( node.getWorld(), new Callable() { + + @Override + public Object call() throws Exception + { + getMachine().securityBreak(); + return null; + } + + } ); + + return; + } + } + } + + } + } + + for (ForgeDirection f : newSecurityConnections) + { + IGridHost te = findGridHost( dc.getWorld(), dc.x + f.offsetX, dc.y + f.offsetY, dc.z + f.offsetZ ); + if ( te != null ) + { + GridNode node = (GridNode) te.getGridNode( f.getOpposite() ); + if ( node == null ) + continue; + + // construct a new connection between these two nodes. + try + { + new GridConnection( node, this, f.getOpposite() ); + } + catch (FailedConnection e) + { + TickHandler.instance.addCallable( node.getWorld(), new Callable() { + + @Override + public Object call() throws Exception + { + getMachine().securityBreak(); + return null; + } + + } ); + + return; + } + } + } + } + + private IGridHost findGridHost(World world, int x, int y, int z) + { + if ( world.blockExists( x, y, z ) ) + { + TileEntity te = world.getTileEntity( x, y, z ); + if ( te instanceof IGridHost ) + return (IGridHost) te; + } + return null; + } + + public void addConnection(IGridConnection gridConnection) + { + Connections.add( gridConnection ); + if ( gridConnection.hasDirection() ) + gridProxy.onGridNotification( GridNotification.ConnectionsChanged ); + + final IGridNode gn = this; + + Collections.sort( Connections, new Comparator() { + + @Override + public int compare(IGridConnection o1, IGridConnection o2) + { + boolean preferredA = o1.getOtherSide( gn ).hasFlag( GridFlags.PREFERRED ); + boolean preferredB = o2.getOtherSide( gn ).hasFlag( GridFlags.PREFERRED ); + + return preferredA == preferredB ? 0 : (preferredA ? -1 : 1); + } + + } ); + } + + public void removeConnection(IGridConnection gridConnection) + { + Connections.remove( gridConnection ); + if ( gridConnection.hasDirection() ) + gridProxy.onGridNotification( GridNotification.ConnectionsChanged ); + } + + @Override + public IReadOnlyCollection getConnections() + { + return new ReadOnlyCollection( Connections ); + } + + public boolean hasConnection(IGridNode otherside) + { + for (IGridConnection gc : Connections) + { + if ( gc.a() == otherside || gc.b() == otherside ) + return true; + } + return false; + } + + public boolean canConnect(GridNode from, ForgeDirection dir) + { + if ( !isValidDirection( dir ) ) + return false; + + if ( !from.getColor().matches( getColor() ) ) + return false; + + return true; + } + + @Override + public IGrid getGrid() + { + return myGrid; + } + + public Grid getInternalGrid() + { + if ( myGrid == null ) + myGrid = new Grid( this ); + + return myGrid; + } + + public void setGrid(Grid grid) + { + if ( myGrid == grid ) + return; + + if ( myGrid != null ) + { + myGrid.remove( this ); + + if ( myGrid.isEmpty() ) + { + myGrid.saveState(); + + for (IGridCache c : grid.caches.values()) + c.onJoin( myGrid.myStorage ); + } + } + + myGrid = grid; + myGrid.add( this ); + } + + public void validateGrid() + { + GridSplitDetector gsd = new GridSplitDetector( getInternalGrid().getPivot() ); + beginVisit( gsd ); + if ( !gsd.pivotFound ) + { + GridPropagator gp = new GridPropagator( new Grid( this ) ); + beginVisit( gp ); + } + } + + @Override + public void destroy() + { + while (!Connections.isEmpty()) + { + // not part of this network for real anymore. + if ( Connections.size() == 1 ) + setGridStorage( null ); + + IGridConnection c = Connections.listIterator().next(); + GridNode otherSide = (GridNode) c.getOtherSide( this ); + otherSide.getInternalGrid().pivot = otherSide; + c.destroy(); + } + + if ( myGrid != null ) + myGrid.remove( this ); + } + + @Override + public World getWorld() + { + return gridProxy.getLocation().getWorld(); + } + + @Override + public boolean meetsChannelRequirements() + { + return (!getGridBlock().getFlags().contains( GridFlags.REQUIRE_CHANNEL ) || getUsedChannels() > 0); + } + + @Override + public boolean isActive() + { + IGrid g = getGrid(); + if ( g != null ) + { + IPathingGrid pg = g.getCache( IPathingGrid.class ); + IEnergyGrid eg = g.getCache( IEnergyGrid.class ); + return meetsChannelRequirements() && eg.isNetworkPowered() && !pg.isNetworkBooting(); + } + return false; + } + + @Override + public boolean canSupportMoreChannels() + { + return getUsedChannels() < getMaxChannels(); + } + + @Override + public IReadOnlyCollection getPossibleOptions() + { + return (ReadOnlyCollection) getConnections(); + } + + public int getLastUsedChannels() + { + return (channelData >> 8) & 0xff; + } + + public int getUsedChannels() + { + return channelData & 0xff; + } + + @Override + public void incrementChannelCount(int usedChannels) + { + channelData += usedChannels; + } + + public void setGridStorage(GridStorage s) + { + myStorage = s; + channelData = 0; + } + + public GridStorage getGridStorage() + { + return myStorage; + } + + @Override + public EnumSet getFlags() + { + return getGridBlock().getFlags(); + } + + @Override + public void finalizeChannels() + { + if ( getFlags().contains( GridFlags.CANNOT_CARRY ) ) + return; + + if ( getLastUsedChannels() != getUsedChannels() ) + { + channelData = (channelData & 0xff); + channelData |= channelData << 8; + + if ( getInternalGrid() != null ) + getInternalGrid().postEventTo( this, event ); + } + } + + @Override + public IPathItem getControllerRoute() + { + if ( Connections.isEmpty() || getFlags().contains( GridFlags.CANNOT_CARRY ) ) + return null; + + return (IPathItem) Connections.get( 0 ); + } + + @Override + public void setControllerRoute(IPathItem fast, boolean zeroOut) + { + if ( zeroOut ) + channelData &= ~0xff; + + int idx = Connections.indexOf( fast ); + if ( idx > 0 ) + { + Connections.remove( fast ); + Connections.add( 0, (IGridConnection) fast ); + } + } + + @Override + public boolean hasFlag(GridFlags flag) + { + return getGridBlock().getFlags().contains( flag ); + } + + @Override + public int getPlayerID() + { + return playerID; + } + +} diff --git a/me/GridPropagator.java b/src/main/java/appeng/me/GridPropagator.java similarity index 94% rename from me/GridPropagator.java rename to src/main/java/appeng/me/GridPropagator.java index 366a721ec..47dc5d967 100644 --- a/me/GridPropagator.java +++ b/src/main/java/appeng/me/GridPropagator.java @@ -1,27 +1,27 @@ -package appeng.me; - -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridVisitor; - -public class GridPropagator implements IGridVisitor -{ - - final private Grid g; - - public GridPropagator(Grid g) { - this.g = g; - } - - @Override - public boolean visitNode(IGridNode n) - { - GridNode gn = (GridNode) n; - if ( gn.myGrid != g || g.pivot == n ) - { - gn.setGrid( g ); - return true; - } - return false; - } - -} +package appeng.me; + +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridVisitor; + +public class GridPropagator implements IGridVisitor +{ + + final private Grid g; + + public GridPropagator(Grid g) { + this.g = g; + } + + @Override + public boolean visitNode(IGridNode n) + { + GridNode gn = (GridNode) n; + if ( gn.myGrid != g || g.pivot == n ) + { + gn.setGrid( g ); + return true; + } + return false; + } + +} diff --git a/me/GridSplitDetector.java b/src/main/java/appeng/me/GridSplitDetector.java similarity index 94% rename from me/GridSplitDetector.java rename to src/main/java/appeng/me/GridSplitDetector.java index f478f93e5..523d464f6 100644 --- a/me/GridSplitDetector.java +++ b/src/main/java/appeng/me/GridSplitDetector.java @@ -1,24 +1,24 @@ -package appeng.me; - -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridVisitor; - -class GridSplitDetector implements IGridVisitor -{ - - final IGridNode pivot; - boolean pivotFound; - - public GridSplitDetector(IGridNode pivot) { - this.pivot = pivot; - } - - @Override - public boolean visitNode(IGridNode n) - { - if ( n == pivot ) - pivotFound = true; - - return !pivotFound; - } -}; +package appeng.me; + +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridVisitor; + +class GridSplitDetector implements IGridVisitor +{ + + final IGridNode pivot; + boolean pivotFound; + + public GridSplitDetector(IGridNode pivot) { + this.pivot = pivot; + } + + @Override + public boolean visitNode(IGridNode n) + { + if ( n == pivot ) + pivotFound = true; + + return !pivotFound; + } +}; diff --git a/me/GridStorage.java b/src/main/java/appeng/me/GridStorage.java similarity index 94% rename from me/GridStorage.java rename to src/main/java/appeng/me/GridStorage.java index 3a8802682..52cc2f6e6 100644 --- a/me/GridStorage.java +++ b/src/main/java/appeng/me/GridStorage.java @@ -1,140 +1,140 @@ -package appeng.me; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridStorage; -import appeng.core.AELog; -import appeng.core.WorldSettings; - -public class GridStorage implements IGridStorage -{ - - IGrid myGrid = null; - - final long myID; - final NBTTagCompound data; - - public boolean isDirty = false; - private Set divlist = new HashSet(); - final GridStorageSearch mySearchEntry; // keep myself in the list until I'm - // lost... - - /** - * for use with world settings - * - * @param id - * @param gss - */ - public GridStorage(long id, GridStorageSearch gss) { - myID = id; - mySearchEntry = gss; - data = new NBTTagCompound(); - } - - /** - * for use with world settings - * - * @param input - * @param id - * @param gss - */ - public GridStorage(String input, long id, GridStorageSearch gss) { - myID = id; - mySearchEntry = gss; - NBTTagCompound myTag = null; - - try - { - byte[] dbata = javax.xml.bind.DatatypeConverter.parseBase64Binary( input ); - myTag = CompressedStreamTools.readCompressed( new ByteArrayInputStream( dbata ) ); - } - catch (Throwable t) - { - myTag = new NBTTagCompound(); - } - - data = myTag; - } - - /** - * fake storage. - */ - public GridStorage() { - myID = 0; - mySearchEntry = null; - data = new NBTTagCompound(); - } - - public String getValue() - { - isDirty = false; - - if ( myGrid != null ) - { - ((Grid) myGrid).saveState(); - } - - try - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - CompressedStreamTools.writeCompressed( data, out ); - return javax.xml.bind.DatatypeConverter.printBase64Binary( out.toByteArray() ); - } - catch (IOException e) - { - AELog.error( e ); - } - - return ""; - } - - @Override - public NBTTagCompound dataObject() - { - return data; - } - - @Override - public long getID() - { - return myID; - } - - public void markDirty() - { - isDirty = true; - } - - public IGrid getGrid() - { - return myGrid; - } - - public void setGrid(Grid grid) - { - myGrid = grid; - } - - public void addDivided(GridStorage gs) - { - divlist.add( gs ); - } - - public boolean hasDivided(GridStorage myStorage) - { - return divlist.contains( myStorage ); - } - - public void remove() - { - WorldSettings.getInstance().destroyGridStorage( getID() ); - } - -} +package appeng.me; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridStorage; +import appeng.core.AELog; +import appeng.core.WorldSettings; + +public class GridStorage implements IGridStorage +{ + + IGrid myGrid = null; + + final long myID; + final NBTTagCompound data; + + public boolean isDirty = false; + private Set divlist = new HashSet(); + final GridStorageSearch mySearchEntry; // keep myself in the list until I'm + // lost... + + /** + * for use with world settings + * + * @param id + * @param gss + */ + public GridStorage(long id, GridStorageSearch gss) { + myID = id; + mySearchEntry = gss; + data = new NBTTagCompound(); + } + + /** + * for use with world settings + * + * @param input + * @param id + * @param gss + */ + public GridStorage(String input, long id, GridStorageSearch gss) { + myID = id; + mySearchEntry = gss; + NBTTagCompound myTag = null; + + try + { + byte[] dbata = javax.xml.bind.DatatypeConverter.parseBase64Binary( input ); + myTag = CompressedStreamTools.readCompressed( new ByteArrayInputStream( dbata ) ); + } + catch (Throwable t) + { + myTag = new NBTTagCompound(); + } + + data = myTag; + } + + /** + * fake storage. + */ + public GridStorage() { + myID = 0; + mySearchEntry = null; + data = new NBTTagCompound(); + } + + public String getValue() + { + isDirty = false; + + if ( myGrid != null ) + { + ((Grid) myGrid).saveState(); + } + + try + { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + CompressedStreamTools.writeCompressed( data, out ); + return javax.xml.bind.DatatypeConverter.printBase64Binary( out.toByteArray() ); + } + catch (IOException e) + { + AELog.error( e ); + } + + return ""; + } + + @Override + public NBTTagCompound dataObject() + { + return data; + } + + @Override + public long getID() + { + return myID; + } + + public void markDirty() + { + isDirty = true; + } + + public IGrid getGrid() + { + return myGrid; + } + + public void setGrid(Grid grid) + { + myGrid = grid; + } + + public void addDivided(GridStorage gs) + { + divlist.add( gs ); + } + + public boolean hasDivided(GridStorage myStorage) + { + return divlist.contains( myStorage ); + } + + public void remove() + { + WorldSettings.getInstance().destroyGridStorage( getID() ); + } + +} diff --git a/me/GridStorageSearch.java b/src/main/java/appeng/me/GridStorageSearch.java similarity index 93% rename from me/GridStorageSearch.java rename to src/main/java/appeng/me/GridStorageSearch.java index ca5afd5b9..56167a991 100644 --- a/me/GridStorageSearch.java +++ b/src/main/java/appeng/me/GridStorageSearch.java @@ -1,40 +1,40 @@ -package appeng.me; - -import java.lang.ref.WeakReference; - -public class GridStorageSearch -{ - - final long id; - public WeakReference gridStorage; - - /** - * for use with the world settings - * - * @param id - */ - public GridStorageSearch(long id) { - this.id = id; - } - - @Override - public boolean equals(Object obj) - { - if ( obj == null ) - return false; - - GridStorageSearch b = (GridStorageSearch) obj; - - if ( id == b.id ) - return true; - - return false; - } - - @Override - public int hashCode() - { - return ((Long) id).hashCode(); - } - -} +package appeng.me; + +import java.lang.ref.WeakReference; + +public class GridStorageSearch +{ + + final long id; + public WeakReference gridStorage; + + /** + * for use with the world settings + * + * @param id + */ + public GridStorageSearch(long id) { + this.id = id; + } + + @Override + public boolean equals(Object obj) + { + if ( obj == null ) + return false; + + GridStorageSearch b = (GridStorageSearch) obj; + + if ( id == b.id ) + return true; + + return false; + } + + @Override + public int hashCode() + { + return ((Long) id).hashCode(); + } + +} diff --git a/me/MachineSet.java b/src/main/java/appeng/me/MachineSet.java similarity index 95% rename from me/MachineSet.java rename to src/main/java/appeng/me/MachineSet.java index 018c187be..ad27ee955 100644 --- a/me/MachineSet.java +++ b/src/main/java/appeng/me/MachineSet.java @@ -1,26 +1,26 @@ -package appeng.me; - -import java.util.HashSet; - -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IMachineSet; - -public class MachineSet extends HashSet implements IMachineSet -{ - - private static final long serialVersionUID = 3224660708327386933L; - - private final Class machine; - - MachineSet(Class m) { - machine = m; - } - - @Override - public Class getMachineClass() - { - return machine; - } - -} +package appeng.me; + +import java.util.HashSet; + +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IMachineSet; + +public class MachineSet extends HashSet implements IMachineSet +{ + + private static final long serialVersionUID = 3224660708327386933L; + + private final Class machine; + + MachineSet(Class m) { + machine = m; + } + + @Override + public Class getMachineClass() + { + return machine; + } + +} diff --git a/me/NetworkEventBus.java b/src/main/java/appeng/me/NetworkEventBus.java similarity index 100% rename from me/NetworkEventBus.java rename to src/main/java/appeng/me/NetworkEventBus.java diff --git a/me/NetworkList.java b/src/main/java/appeng/me/NetworkList.java similarity index 100% rename from me/NetworkList.java rename to src/main/java/appeng/me/NetworkList.java diff --git a/me/NodeIterable.java b/src/main/java/appeng/me/NodeIterable.java similarity index 100% rename from me/NodeIterable.java rename to src/main/java/appeng/me/NodeIterable.java diff --git a/me/NodeIterator.java b/src/main/java/appeng/me/NodeIterator.java similarity index 93% rename from me/NodeIterator.java rename to src/main/java/appeng/me/NodeIterator.java index c00c52f9a..37ab6557b 100644 --- a/me/NodeIterator.java +++ b/src/main/java/appeng/me/NodeIterator.java @@ -1,53 +1,53 @@ -package appeng.me; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Set; - -public class NodeIterator implements Iterator -{ - - boolean hasMore; - Iterator lvl1; - Iterator lvl2; - - boolean pull() - { - hasMore = lvl1.hasNext(); - if ( hasMore ) - { - lvl2 = ((Collection) lvl1.next()).iterator(); - return true; - } - return false; - } - - public NodeIterator(HashMap> machines) { - lvl1 = machines.values().iterator(); - pull(); - } - - @Override - public boolean hasNext() - { - if ( lvl2.hasNext() ) - return true; - if ( pull() ) - return hasNext(); - return hasMore; - } - - @Override - public IGridNode next() - { - return (IGridNode) lvl2.next(); - } - - @Override - public void remove() - { - lvl2.remove(); - } - -} +package appeng.me; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; + +public class NodeIterator implements Iterator +{ + + boolean hasMore; + Iterator lvl1; + Iterator lvl2; + + boolean pull() + { + hasMore = lvl1.hasNext(); + if ( hasMore ) + { + lvl2 = ((Collection) lvl1.next()).iterator(); + return true; + } + return false; + } + + public NodeIterator(HashMap> machines) { + lvl1 = machines.values().iterator(); + pull(); + } + + @Override + public boolean hasNext() + { + if ( lvl2.hasNext() ) + return true; + if ( pull() ) + return hasNext(); + return hasMore; + } + + @Override + public IGridNode next() + { + return (IGridNode) lvl2.next(); + } + + @Override + public void remove() + { + lvl2.remove(); + } + +} diff --git a/me/cache/CraftingGridCache.java b/src/main/java/appeng/me/cache/CraftingGridCache.java similarity index 100% rename from me/cache/CraftingGridCache.java rename to src/main/java/appeng/me/cache/CraftingGridCache.java diff --git a/me/cache/EnergyGridCache.java b/src/main/java/appeng/me/cache/EnergyGridCache.java similarity index 96% rename from me/cache/EnergyGridCache.java rename to src/main/java/appeng/me/cache/EnergyGridCache.java index 15125a760..69839567e 100644 --- a/me/cache/EnergyGridCache.java +++ b/src/main/java/appeng/me/cache/EnergyGridCache.java @@ -1,583 +1,583 @@ -package appeng.me.cache; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.TreeSet; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridBlock; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridStorage; -import appeng.api.networking.energy.IAEPowerStorage; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.energy.IEnergyGridProvider; -import appeng.api.networking.energy.IEnergyWatcher; -import appeng.api.networking.energy.IEnergyWatcherHost; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPostCacheConstruction; -import appeng.api.networking.events.MENetworkPowerIdleChange; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.networking.events.MENetworkPowerStorage; -import appeng.api.networking.pathing.IPathingGrid; -import appeng.api.networking.storage.IStackWatcherHost; -import appeng.me.Grid; -import appeng.me.GridNode; -import appeng.me.energy.EnergyThreshold; -import appeng.me.energy.EnergyWatcher; - -import com.google.common.collect.HashMultiset; -import com.google.common.collect.Multiset; - -public class EnergyGridCache implements IEnergyGrid -{ - - /** - * estimated power available. - */ - int availableTicksSinceUpdate = 0; - double globalAvailablePower = 0; - double globalMaxPower = 0; - - /** - * idle draw. - */ - double drainPerTick = 0; - - final double AvgLength = 40.0; - - double avgDrainPerTick = 0; - double avgInjectionPerTick = 0; - - double tickDrainPerTick = 0; - double tickInjectionPerTick = 0; - - /** - * power status - */ - boolean publicHasPower = false; - boolean hasPower = true; - long ticksSinceHasPowerChange = 900; - - /** - * excess power in the system. - */ - double extra = 0; - - IAEPowerStorage lastProvider; - final Set providers = new LinkedHashSet(); - - IAEPowerStorage lastRequestor; - final Set requesters = new LinkedHashSet(); - - final public TreeSet interests = new TreeSet(); - final private HashMap watchers = new HashMap(); - - final private Set localSeen = new HashSet(); - - private double buffer() - { - return providers.isEmpty() ? 1000.0 : 0.0; - } - - private IAEPowerStorage getFirstRequestor() - { - if ( lastRequestor == null ) - { - Iterator i = requesters.iterator(); - lastRequestor = i.hasNext() ? i.next() : null; - } - - return lastRequestor; - } - - private IAEPowerStorage getFirstProvider() - { - if ( lastProvider == null ) - { - Iterator i = providers.iterator(); - lastProvider = i.hasNext() ? i.next() : null; - } - - return lastProvider; - } - - final Multiset gproviders = HashMultiset.create(); - - final IGrid myGrid; - PathGridCache pgc; - - public EnergyGridCache(IGrid g) { - myGrid = g; - } - - @MENetworkEventSubscribe - public void postInit(MENetworkPostCacheConstruction pcc) - { - pgc = myGrid.getCache( IPathingGrid.class ); - } - - @MENetworkEventSubscribe - public void EnergyNodeChanges(MENetworkPowerIdleChange ev) - { - // update power usage based on event. - GridNode node = (GridNode) ev.node; - IGridBlock gb = node.getGridBlock(); - - double newDraw = gb.getIdlePowerUsage(); - double diffDraw = newDraw - node.previousDraw; - node.previousDraw = newDraw; - - drainPerTick += diffDraw; - } - - @MENetworkEventSubscribe - public void EnergyNodeChanges(MENetworkPowerStorage ev) - { - if ( ev.storage.isAEPublicPowerStorage() ) - { - switch (ev.type) - { - case PROVIDE_POWER: - if ( ev.storage.getPowerFlow() != AccessRestriction.WRITE ) - providers.add( ev.storage ); - break; - case REQUEST_POWER: - if ( ev.storage.getPowerFlow() != AccessRestriction.READ ) - requesters.add( ev.storage ); - break; - } - } - else - { - (new RuntimeException( "Attempt to ask the IEnergyGrid to charge a non public energy store." )).printStackTrace(); - } - } - - @Override - public double getEnergyDemand(double maxRequired) - { - localSeen.clear(); - return getEnergyDemand( maxRequired, localSeen ); - } - - public double getEnergyDemand(double maxRequired, Set seen) - { - if ( !seen.add( this ) ) - return 0; - - double required = buffer() - extra; - - Iterator it = requesters.iterator(); - while (required < maxRequired && it.hasNext()) - { - IAEPowerStorage node = it.next(); - if ( node.getPowerFlow() != AccessRestriction.READ ) - required += Math.max( 0.0, node.getAEMaxPower() - node.getAECurrentPower() ); - } - - Iterator ix = gproviders.iterator(); - while (required < maxRequired && ix.hasNext()) - { - IEnergyGridProvider node = ix.next(); - required += node.getEnergyDemand( maxRequired - required, seen ); - } - - return required; - } - - @Override - public double injectPower(double amt, Actionable mode) - { - localSeen.clear(); - return injectAEPower( amt, mode, localSeen ); - } - - public double injectAEPower(double amt, Actionable mode, Set seen) - { - if ( !seen.add( this ) ) - return 0; - - double ignore = extra; - amt += extra; - - if ( mode == Actionable.SIMULATE ) - { - Iterator it = requesters.iterator(); - while (amt > 0 && it.hasNext()) - { - IAEPowerStorage node = it.next(); - amt = node.injectAEPower( amt, Actionable.SIMULATE ); - } - - Iterator i = gproviders.iterator(); - while (amt > 0 && i.hasNext()) - amt = i.next().injectAEPower( amt, mode, seen ); - } - else - { - tickInjectionPerTick += amt - ignore; - // totalInjectionPastTicks[0] += i; - - while (amt > 0 && !requesters.isEmpty()) - { - IAEPowerStorage node = getFirstRequestor(); - - amt = node.injectAEPower( amt, Actionable.MODULATE ); - if ( amt > 0 ) - { - requesters.remove( node ); - lastRequestor = null; - } - } - - Iterator i = gproviders.iterator(); - while (amt > 0 && i.hasNext()) - { - IEnergyGridProvider what = i.next(); - Set listCopy = new HashSet(); - listCopy.addAll( seen ); - - double cannotHold = what.injectAEPower( amt, Actionable.SIMULATE, listCopy ); - what.injectAEPower( amt - cannotHold, mode, seen ); - - amt = cannotHold; - } - - extra = amt; - } - - return Math.max( 0.0, amt - buffer() ); - } - - @Override - public double extractAEPower(double amt, Actionable mode, PowerMultiplier pm) - { - localSeen.clear(); - return pm.divide( extractAEPower( pm.multiply( amt ), mode, localSeen ) ); - } - - @Override - public void addNode(IGridNode node, IGridHost machine) - { - if ( machine instanceof IEnergyGridProvider ) - gproviders.add( (IEnergyGridProvider) machine ); - - // idle draw... - GridNode gnode = (GridNode) node; - IGridBlock gb = gnode.getGridBlock(); - gnode.previousDraw = gb.getIdlePowerUsage(); - drainPerTick += gnode.previousDraw; - - // power storage - if ( machine instanceof IAEPowerStorage ) - { - IAEPowerStorage ps = (IAEPowerStorage) machine; - if ( ps.isAEPublicPowerStorage() ) - { - double max = ps.getAEMaxPower(); - double current = ps.getAECurrentPower(); - - if ( ps.getPowerFlow() != AccessRestriction.WRITE ) - { - globalMaxPower += ps.getAEMaxPower(); - } - - if ( current > 0 && ps.getPowerFlow() != AccessRestriction.WRITE ) - { - globalAvailablePower += current; - providers.add( ps ); - } - - if ( current < max && ps.getPowerFlow() != AccessRestriction.READ ) - requesters.add( ps ); - } - } - - if ( machine instanceof IEnergyWatcherHost ) - { - IEnergyWatcherHost swh = (IEnergyWatcherHost) machine; - EnergyWatcher iw = new EnergyWatcher( this, (IEnergyWatcherHost) swh ); - watchers.put( node, iw ); - swh.updateWatcher( iw ); - } - - myGrid.postEventTo( node, new MENetworkPowerStatusChange() ); - } - - @Override - public void removeNode(IGridNode node, IGridHost machine) - { - if ( machine instanceof IEnergyGridProvider ) - gproviders.remove( machine ); - - // idle draw. - GridNode gnode = (GridNode) node; - drainPerTick -= gnode.previousDraw; - - // power storage. - if ( machine instanceof IAEPowerStorage ) - { - IAEPowerStorage ps = (IAEPowerStorage) machine; - if ( ps.isAEPublicPowerStorage() ) - { - if ( ps.getPowerFlow() != AccessRestriction.WRITE ) - { - globalMaxPower -= ps.getAEMaxPower(); - globalAvailablePower -= ps.getAECurrentPower(); - } - - if ( lastProvider == machine ) - lastProvider = null; - - if ( lastRequestor == machine ) - lastRequestor = null; - - providers.remove( machine ); - requesters.remove( machine ); - } - } - - if ( machine instanceof IStackWatcherHost ) - { - IEnergyWatcher myWatcher = watchers.get( machine ); - if ( myWatcher != null ) - { - myWatcher.clear(); - watchers.remove( machine ); - } - } - - } - - double lastStoredPower = -1; - - @Override - public void onUpdateTick() - { - if ( !interests.isEmpty() ) - { - double oldPower = lastStoredPower; - lastStoredPower = getStoredPower(); - - EnergyThreshold low = new EnergyThreshold( Math.min( oldPower, lastStoredPower ), null ); - EnergyThreshold high = new EnergyThreshold( Math.max( oldPower, lastStoredPower ), null ); - for (EnergyThreshold th : interests.subSet( low, true, high, true )) - { - ((EnergyWatcher) th.watcher).post( this ); - } - } - - avgDrainPerTick *= (AvgLength - 1) / AvgLength; - avgInjectionPerTick *= (AvgLength - 1) / AvgLength; - - avgDrainPerTick += tickDrainPerTick / AvgLength; - avgInjectionPerTick += tickInjectionPerTick / AvgLength; - - tickDrainPerTick = 0; - tickInjectionPerTick = 0; - - // power information. - boolean currentlyHasPower = false; - - if ( drainPerTick > 0.0001 ) - { - double drained = extractAEPower( getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG ); - currentlyHasPower = drained >= drainPerTick - 0.001; - } - else - { - currentlyHasPower = extractAEPower( 0.1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0; - } - - // ticks since change.. - if ( currentlyHasPower == hasPower ) - ticksSinceHasPowerChange++; - else - ticksSinceHasPowerChange = 0; - - // update status.. - hasPower = currentlyHasPower; - - // update public status, this buffers power ups for 30 ticks. - if ( hasPower && ticksSinceHasPowerChange > 30 ) - publicPowerState( true, myGrid ); - else if ( !hasPower ) - publicPowerState( false, myGrid ); - - availableTicksSinceUpdate++; - } - - private void publicPowerState(boolean newState, IGrid grid) - { - if ( publicHasPower == newState ) - return; - - publicHasPower = newState; - ((Grid) myGrid).setImportantFlag( 0, publicHasPower ); - grid.postEvent( new MENetworkPowerStatusChange() ); - } - - /** - * refresh current stored power. - */ - public void refreshPower() - { - availableTicksSinceUpdate = 0; - globalAvailablePower = 0; - for (IAEPowerStorage p : providers) - globalAvailablePower += p.getAECurrentPower(); - } - - @Override - public double getStoredPower() - { - if ( availableTicksSinceUpdate > 90 ) - refreshPower(); - - return Math.max( 0.0, globalAvailablePower ); - } - - @Override - public double getMaxStoredPower() - { - return globalMaxPower; - } - - @Override - public double extractAEPower(double amt, Actionable mode, Set seen) - { - if ( !seen.add( this ) ) - return 0; - - double extractedPower = extra; - - if ( mode == Actionable.SIMULATE ) - { - extractedPower += simulateExtract( extractedPower, amt ); - - if ( extractedPower < amt ) - { - Iterator i = gproviders.iterator(); - while (extractedPower < amt && i.hasNext()) - extractedPower += i.next().extractAEPower( amt - extractedPower, mode, seen ); - } - - return extractedPower; - } - else - { - extra = 0; - extractedPower = doExtract( extractedPower, amt ); - } - - // got more then we wanted? - if ( extractedPower > amt ) - { - extra = extractedPower - amt; - globalAvailablePower -= amt; - - tickDrainPerTick += amt; - return amt; - } - - if ( extractedPower < amt ) - { - Iterator i = gproviders.iterator(); - while (extractedPower < amt && i.hasNext()) - extractedPower += i.next().extractAEPower( amt - extractedPower, mode, seen ); - } - - // go less or the correct amount? - globalAvailablePower -= extractedPower; - tickDrainPerTick += extractedPower; - return extractedPower; - } - - private double doExtract(double extractedPower, double amt) - { - while (extractedPower < amt && !providers.isEmpty()) - { - IAEPowerStorage node = getFirstProvider(); - - double req = amt - extractedPower; - double newPower = node.extractAEPower( req, Actionable.MODULATE, PowerMultiplier.ONE ); - extractedPower += newPower; - - if ( newPower < req ) - { - providers.remove( node ); - lastProvider = null; - } - } - - // totalDrainPastTicks[0] += extractedPower; - return extractedPower; - } - - private double simulateExtract(double extractedPower, double amt) - { - Iterator it = providers.iterator(); - - while (extractedPower < amt && it.hasNext()) - { - IAEPowerStorage node = it.next(); - - double req = amt - extractedPower; - double newPower = node.extractAEPower( req, Actionable.SIMULATE, PowerMultiplier.ONE ); - extractedPower += newPower; - } - - return extractedPower; - } - - @Override - public boolean isNetworkPowered() - { - return publicHasPower; - } - - @Override - public double getIdlePowerUsage() - { - return drainPerTick + pgc.channelPowerUsage; - } - - @Override - public double getAvgPowerUsage() - { - return avgDrainPerTick; - } - - @Override - public double getAvgPowerInjection() - { - return avgInjectionPerTick; - } - - @Override - public void onSplit(IGridStorage storageB) - { - extra /= 2; - storageB.dataObject().setDouble( "extraEnergy", extra ); - } - - @Override - public void onJoin(IGridStorage storageB) - { - extra += storageB.dataObject().getDouble( "extraEnergy" ); - } - - @Override - public void populateGridStorage(IGridStorage storage) - { - storage.dataObject().setDouble( "extraEnergy", this.extra ); - } - -} +package appeng.me.cache; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.TreeSet; + +import appeng.api.config.AccessRestriction; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridBlock; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridStorage; +import appeng.api.networking.energy.IAEPowerStorage; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.energy.IEnergyGridProvider; +import appeng.api.networking.energy.IEnergyWatcher; +import appeng.api.networking.energy.IEnergyWatcherHost; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPostCacheConstruction; +import appeng.api.networking.events.MENetworkPowerIdleChange; +import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.api.networking.events.MENetworkPowerStorage; +import appeng.api.networking.pathing.IPathingGrid; +import appeng.api.networking.storage.IStackWatcherHost; +import appeng.me.Grid; +import appeng.me.GridNode; +import appeng.me.energy.EnergyThreshold; +import appeng.me.energy.EnergyWatcher; + +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; + +public class EnergyGridCache implements IEnergyGrid +{ + + /** + * estimated power available. + */ + int availableTicksSinceUpdate = 0; + double globalAvailablePower = 0; + double globalMaxPower = 0; + + /** + * idle draw. + */ + double drainPerTick = 0; + + final double AvgLength = 40.0; + + double avgDrainPerTick = 0; + double avgInjectionPerTick = 0; + + double tickDrainPerTick = 0; + double tickInjectionPerTick = 0; + + /** + * power status + */ + boolean publicHasPower = false; + boolean hasPower = true; + long ticksSinceHasPowerChange = 900; + + /** + * excess power in the system. + */ + double extra = 0; + + IAEPowerStorage lastProvider; + final Set providers = new LinkedHashSet(); + + IAEPowerStorage lastRequestor; + final Set requesters = new LinkedHashSet(); + + final public TreeSet interests = new TreeSet(); + final private HashMap watchers = new HashMap(); + + final private Set localSeen = new HashSet(); + + private double buffer() + { + return providers.isEmpty() ? 1000.0 : 0.0; + } + + private IAEPowerStorage getFirstRequestor() + { + if ( lastRequestor == null ) + { + Iterator i = requesters.iterator(); + lastRequestor = i.hasNext() ? i.next() : null; + } + + return lastRequestor; + } + + private IAEPowerStorage getFirstProvider() + { + if ( lastProvider == null ) + { + Iterator i = providers.iterator(); + lastProvider = i.hasNext() ? i.next() : null; + } + + return lastProvider; + } + + final Multiset gproviders = HashMultiset.create(); + + final IGrid myGrid; + PathGridCache pgc; + + public EnergyGridCache(IGrid g) { + myGrid = g; + } + + @MENetworkEventSubscribe + public void postInit(MENetworkPostCacheConstruction pcc) + { + pgc = myGrid.getCache( IPathingGrid.class ); + } + + @MENetworkEventSubscribe + public void EnergyNodeChanges(MENetworkPowerIdleChange ev) + { + // update power usage based on event. + GridNode node = (GridNode) ev.node; + IGridBlock gb = node.getGridBlock(); + + double newDraw = gb.getIdlePowerUsage(); + double diffDraw = newDraw - node.previousDraw; + node.previousDraw = newDraw; + + drainPerTick += diffDraw; + } + + @MENetworkEventSubscribe + public void EnergyNodeChanges(MENetworkPowerStorage ev) + { + if ( ev.storage.isAEPublicPowerStorage() ) + { + switch (ev.type) + { + case PROVIDE_POWER: + if ( ev.storage.getPowerFlow() != AccessRestriction.WRITE ) + providers.add( ev.storage ); + break; + case REQUEST_POWER: + if ( ev.storage.getPowerFlow() != AccessRestriction.READ ) + requesters.add( ev.storage ); + break; + } + } + else + { + (new RuntimeException( "Attempt to ask the IEnergyGrid to charge a non public energy store." )).printStackTrace(); + } + } + + @Override + public double getEnergyDemand(double maxRequired) + { + localSeen.clear(); + return getEnergyDemand( maxRequired, localSeen ); + } + + public double getEnergyDemand(double maxRequired, Set seen) + { + if ( !seen.add( this ) ) + return 0; + + double required = buffer() - extra; + + Iterator it = requesters.iterator(); + while (required < maxRequired && it.hasNext()) + { + IAEPowerStorage node = it.next(); + if ( node.getPowerFlow() != AccessRestriction.READ ) + required += Math.max( 0.0, node.getAEMaxPower() - node.getAECurrentPower() ); + } + + Iterator ix = gproviders.iterator(); + while (required < maxRequired && ix.hasNext()) + { + IEnergyGridProvider node = ix.next(); + required += node.getEnergyDemand( maxRequired - required, seen ); + } + + return required; + } + + @Override + public double injectPower(double amt, Actionable mode) + { + localSeen.clear(); + return injectAEPower( amt, mode, localSeen ); + } + + public double injectAEPower(double amt, Actionable mode, Set seen) + { + if ( !seen.add( this ) ) + return 0; + + double ignore = extra; + amt += extra; + + if ( mode == Actionable.SIMULATE ) + { + Iterator it = requesters.iterator(); + while (amt > 0 && it.hasNext()) + { + IAEPowerStorage node = it.next(); + amt = node.injectAEPower( amt, Actionable.SIMULATE ); + } + + Iterator i = gproviders.iterator(); + while (amt > 0 && i.hasNext()) + amt = i.next().injectAEPower( amt, mode, seen ); + } + else + { + tickInjectionPerTick += amt - ignore; + // totalInjectionPastTicks[0] += i; + + while (amt > 0 && !requesters.isEmpty()) + { + IAEPowerStorage node = getFirstRequestor(); + + amt = node.injectAEPower( amt, Actionable.MODULATE ); + if ( amt > 0 ) + { + requesters.remove( node ); + lastRequestor = null; + } + } + + Iterator i = gproviders.iterator(); + while (amt > 0 && i.hasNext()) + { + IEnergyGridProvider what = i.next(); + Set listCopy = new HashSet(); + listCopy.addAll( seen ); + + double cannotHold = what.injectAEPower( amt, Actionable.SIMULATE, listCopy ); + what.injectAEPower( amt - cannotHold, mode, seen ); + + amt = cannotHold; + } + + extra = amt; + } + + return Math.max( 0.0, amt - buffer() ); + } + + @Override + public double extractAEPower(double amt, Actionable mode, PowerMultiplier pm) + { + localSeen.clear(); + return pm.divide( extractAEPower( pm.multiply( amt ), mode, localSeen ) ); + } + + @Override + public void addNode(IGridNode node, IGridHost machine) + { + if ( machine instanceof IEnergyGridProvider ) + gproviders.add( (IEnergyGridProvider) machine ); + + // idle draw... + GridNode gnode = (GridNode) node; + IGridBlock gb = gnode.getGridBlock(); + gnode.previousDraw = gb.getIdlePowerUsage(); + drainPerTick += gnode.previousDraw; + + // power storage + if ( machine instanceof IAEPowerStorage ) + { + IAEPowerStorage ps = (IAEPowerStorage) machine; + if ( ps.isAEPublicPowerStorage() ) + { + double max = ps.getAEMaxPower(); + double current = ps.getAECurrentPower(); + + if ( ps.getPowerFlow() != AccessRestriction.WRITE ) + { + globalMaxPower += ps.getAEMaxPower(); + } + + if ( current > 0 && ps.getPowerFlow() != AccessRestriction.WRITE ) + { + globalAvailablePower += current; + providers.add( ps ); + } + + if ( current < max && ps.getPowerFlow() != AccessRestriction.READ ) + requesters.add( ps ); + } + } + + if ( machine instanceof IEnergyWatcherHost ) + { + IEnergyWatcherHost swh = (IEnergyWatcherHost) machine; + EnergyWatcher iw = new EnergyWatcher( this, (IEnergyWatcherHost) swh ); + watchers.put( node, iw ); + swh.updateWatcher( iw ); + } + + myGrid.postEventTo( node, new MENetworkPowerStatusChange() ); + } + + @Override + public void removeNode(IGridNode node, IGridHost machine) + { + if ( machine instanceof IEnergyGridProvider ) + gproviders.remove( machine ); + + // idle draw. + GridNode gnode = (GridNode) node; + drainPerTick -= gnode.previousDraw; + + // power storage. + if ( machine instanceof IAEPowerStorage ) + { + IAEPowerStorage ps = (IAEPowerStorage) machine; + if ( ps.isAEPublicPowerStorage() ) + { + if ( ps.getPowerFlow() != AccessRestriction.WRITE ) + { + globalMaxPower -= ps.getAEMaxPower(); + globalAvailablePower -= ps.getAECurrentPower(); + } + + if ( lastProvider == machine ) + lastProvider = null; + + if ( lastRequestor == machine ) + lastRequestor = null; + + providers.remove( machine ); + requesters.remove( machine ); + } + } + + if ( machine instanceof IStackWatcherHost ) + { + IEnergyWatcher myWatcher = watchers.get( machine ); + if ( myWatcher != null ) + { + myWatcher.clear(); + watchers.remove( machine ); + } + } + + } + + double lastStoredPower = -1; + + @Override + public void onUpdateTick() + { + if ( !interests.isEmpty() ) + { + double oldPower = lastStoredPower; + lastStoredPower = getStoredPower(); + + EnergyThreshold low = new EnergyThreshold( Math.min( oldPower, lastStoredPower ), null ); + EnergyThreshold high = new EnergyThreshold( Math.max( oldPower, lastStoredPower ), null ); + for (EnergyThreshold th : interests.subSet( low, true, high, true )) + { + ((EnergyWatcher) th.watcher).post( this ); + } + } + + avgDrainPerTick *= (AvgLength - 1) / AvgLength; + avgInjectionPerTick *= (AvgLength - 1) / AvgLength; + + avgDrainPerTick += tickDrainPerTick / AvgLength; + avgInjectionPerTick += tickInjectionPerTick / AvgLength; + + tickDrainPerTick = 0; + tickInjectionPerTick = 0; + + // power information. + boolean currentlyHasPower = false; + + if ( drainPerTick > 0.0001 ) + { + double drained = extractAEPower( getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG ); + currentlyHasPower = drained >= drainPerTick - 0.001; + } + else + { + currentlyHasPower = extractAEPower( 0.1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0; + } + + // ticks since change.. + if ( currentlyHasPower == hasPower ) + ticksSinceHasPowerChange++; + else + ticksSinceHasPowerChange = 0; + + // update status.. + hasPower = currentlyHasPower; + + // update public status, this buffers power ups for 30 ticks. + if ( hasPower && ticksSinceHasPowerChange > 30 ) + publicPowerState( true, myGrid ); + else if ( !hasPower ) + publicPowerState( false, myGrid ); + + availableTicksSinceUpdate++; + } + + private void publicPowerState(boolean newState, IGrid grid) + { + if ( publicHasPower == newState ) + return; + + publicHasPower = newState; + ((Grid) myGrid).setImportantFlag( 0, publicHasPower ); + grid.postEvent( new MENetworkPowerStatusChange() ); + } + + /** + * refresh current stored power. + */ + public void refreshPower() + { + availableTicksSinceUpdate = 0; + globalAvailablePower = 0; + for (IAEPowerStorage p : providers) + globalAvailablePower += p.getAECurrentPower(); + } + + @Override + public double getStoredPower() + { + if ( availableTicksSinceUpdate > 90 ) + refreshPower(); + + return Math.max( 0.0, globalAvailablePower ); + } + + @Override + public double getMaxStoredPower() + { + return globalMaxPower; + } + + @Override + public double extractAEPower(double amt, Actionable mode, Set seen) + { + if ( !seen.add( this ) ) + return 0; + + double extractedPower = extra; + + if ( mode == Actionable.SIMULATE ) + { + extractedPower += simulateExtract( extractedPower, amt ); + + if ( extractedPower < amt ) + { + Iterator i = gproviders.iterator(); + while (extractedPower < amt && i.hasNext()) + extractedPower += i.next().extractAEPower( amt - extractedPower, mode, seen ); + } + + return extractedPower; + } + else + { + extra = 0; + extractedPower = doExtract( extractedPower, amt ); + } + + // got more then we wanted? + if ( extractedPower > amt ) + { + extra = extractedPower - amt; + globalAvailablePower -= amt; + + tickDrainPerTick += amt; + return amt; + } + + if ( extractedPower < amt ) + { + Iterator i = gproviders.iterator(); + while (extractedPower < amt && i.hasNext()) + extractedPower += i.next().extractAEPower( amt - extractedPower, mode, seen ); + } + + // go less or the correct amount? + globalAvailablePower -= extractedPower; + tickDrainPerTick += extractedPower; + return extractedPower; + } + + private double doExtract(double extractedPower, double amt) + { + while (extractedPower < amt && !providers.isEmpty()) + { + IAEPowerStorage node = getFirstProvider(); + + double req = amt - extractedPower; + double newPower = node.extractAEPower( req, Actionable.MODULATE, PowerMultiplier.ONE ); + extractedPower += newPower; + + if ( newPower < req ) + { + providers.remove( node ); + lastProvider = null; + } + } + + // totalDrainPastTicks[0] += extractedPower; + return extractedPower; + } + + private double simulateExtract(double extractedPower, double amt) + { + Iterator it = providers.iterator(); + + while (extractedPower < amt && it.hasNext()) + { + IAEPowerStorage node = it.next(); + + double req = amt - extractedPower; + double newPower = node.extractAEPower( req, Actionable.SIMULATE, PowerMultiplier.ONE ); + extractedPower += newPower; + } + + return extractedPower; + } + + @Override + public boolean isNetworkPowered() + { + return publicHasPower; + } + + @Override + public double getIdlePowerUsage() + { + return drainPerTick + pgc.channelPowerUsage; + } + + @Override + public double getAvgPowerUsage() + { + return avgDrainPerTick; + } + + @Override + public double getAvgPowerInjection() + { + return avgInjectionPerTick; + } + + @Override + public void onSplit(IGridStorage storageB) + { + extra /= 2; + storageB.dataObject().setDouble( "extraEnergy", extra ); + } + + @Override + public void onJoin(IGridStorage storageB) + { + extra += storageB.dataObject().getDouble( "extraEnergy" ); + } + + @Override + public void populateGridStorage(IGridStorage storage) + { + storage.dataObject().setDouble( "extraEnergy", this.extra ); + } + +} diff --git a/me/cache/GridStorageCache.java b/src/main/java/appeng/me/cache/GridStorageCache.java similarity index 96% rename from me/cache/GridStorageCache.java rename to src/main/java/appeng/me/cache/GridStorageCache.java index 8024b4f8e..1c03e47e1 100644 --- a/me/cache/GridStorageCache.java +++ b/src/main/java/appeng/me/cache/GridStorageCache.java @@ -1,351 +1,351 @@ -package appeng.me.cache; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; - -import appeng.api.AEApi; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridStorage; -import appeng.api.networking.events.MENetworkCellArrayUpdate; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.IActionHost; -import appeng.api.networking.security.ISecurityGrid; -import appeng.api.networking.security.MachineSource; -import appeng.api.networking.storage.IStackWatcher; -import appeng.api.networking.storage.IStackWatcherHost; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.storage.ICellContainer; -import appeng.api.storage.ICellProvider; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; -import appeng.me.helpers.GenericInterestManager; -import appeng.me.storage.ItemWatcher; -import appeng.me.storage.NetworkInventoryHandler; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.SetMultimap; - -public class GridStorageCache implements IStorageGrid -{ - - final private SetMultimap interests = HashMultimap.create(); - final public GenericInterestManager interestManager = new GenericInterestManager( interests ); - - final HashSet activeCellProviders = new HashSet(); - final HashSet inactiveCellProviders = new HashSet(); - final public IGrid myGrid; - - private NetworkInventoryHandler myItemNetwork; - private NetworkMonitor itemMonitor = new NetworkMonitor( this, StorageChannel.ITEMS ); - - private NetworkInventoryHandler myFluidNetwork; - private NetworkMonitor fluidMonitor = new NetworkMonitor( this, StorageChannel.FLUIDS ); - - private HashMap watchers = new HashMap(); - - public GridStorageCache(IGrid g) { - myGrid = g; - } - - @Override - public void onUpdateTick() - { - itemMonitor.onTick(); - fluidMonitor.onTick(); - } - - private class CellChangeTrackerRecord - { - - final StorageChannel channel; - final int up_or_down; - final IItemList list; - final BaseActionSource src; - - public CellChangeTrackerRecord(StorageChannel channel, int i, IMEInventoryHandler h, BaseActionSource actionSrc) { - this.channel = channel; - this.up_or_down = i; - this.src = actionSrc; - - if ( channel == StorageChannel.ITEMS ) - this.list = ((IMEInventoryHandler) h).getAvailableItems( AEApi.instance().storage().createItemList() ); - else if ( channel == StorageChannel.FLUIDS ) - this.list = ((IMEInventoryHandler) h).getAvailableItems( AEApi.instance().storage().createFluidList() ); - else - this.list = null; - } - - public void applyChanges() - { - postChangesToNetwork( channel, up_or_down, list, src ); - } - - }; - - private class CellChangeTracker - { - - List data = new LinkedList(); - - public void postChanges(StorageChannel channel, int i, IMEInventoryHandler h, BaseActionSource actionSrc) - { - data.add( new CellChangeTrackerRecord( channel, i, h, actionSrc ) ); - } - - public void applyChanges() - { - for (CellChangeTrackerRecord rec : data) - rec.applyChanges(); - } - }; - - @Override - public void registerCellProvider(ICellProvider provider) - { - inactiveCellProviders.add( provider ); - addCellProvider( provider, new CellChangeTracker() ).applyChanges(); - } - - @Override - public void unregisterCellProvider(ICellProvider provider) - { - removeCellProvider( provider, new CellChangeTracker() ).applyChanges(); - inactiveCellProviders.remove( provider ); - } - - public CellChangeTracker addCellProvider(ICellProvider cc, CellChangeTracker tracker) - { - if ( inactiveCellProviders.contains( cc ) ) - { - inactiveCellProviders.remove( cc ); - activeCellProviders.add( cc ); - - BaseActionSource actionSrc = new BaseActionSource(); - if ( cc instanceof IActionHost ) - actionSrc = new MachineSource( (IActionHost) cc ); - - for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) - { - tracker.postChanges( StorageChannel.ITEMS, 1, h, actionSrc ); - } - - for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.FLUIDS )) - { - tracker.postChanges( StorageChannel.FLUIDS, 1, h, actionSrc ); - } - } - - return tracker; - } - - public CellChangeTracker removeCellProvider(ICellProvider cc, CellChangeTracker tracker) - { - if ( activeCellProviders.contains( cc ) ) - { - inactiveCellProviders.add( cc ); - activeCellProviders.remove( cc ); - - BaseActionSource actionSrc = new BaseActionSource(); - if ( cc instanceof IActionHost ) - actionSrc = new MachineSource( (IActionHost) cc ); - - for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) - { - tracker.postChanges( StorageChannel.ITEMS, -1, h, actionSrc ); - } - - for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.FLUIDS )) - { - tracker.postChanges( StorageChannel.FLUIDS, -1, h, actionSrc ); - } - } - - return tracker; - } - - @MENetworkEventSubscribe - public void cellUpdate(MENetworkCellArrayUpdate ev) - { - myItemNetwork = null; - myFluidNetwork = null; - - LinkedList ll = new LinkedList(); - ll.addAll( inactiveCellProviders ); - ll.addAll( activeCellProviders ); - - CellChangeTracker tracker = new CellChangeTracker(); - - for (ICellProvider cc : ll) - { - boolean Active = true; - - if ( cc instanceof IActionHost ) - { - IGridNode node = ((IActionHost) cc).getActionableNode(); - if ( node != null && node.isActive() ) - Active = true; - else - Active = false; - } - - if ( Active ) - addCellProvider( cc, tracker ); - else - removeCellProvider( cc, tracker ); - } - - itemMonitor.forceUpdate(); - fluidMonitor.forceUpdate(); - - tracker.applyChanges(); - } - - @Override - public void removeNode(IGridNode node, IGridHost machine) - { - if ( machine instanceof ICellContainer ) - { - ICellContainer cc = (ICellContainer) machine; - - myGrid.postEvent( new MENetworkCellArrayUpdate() ); - removeCellProvider( cc, new CellChangeTracker() ).applyChanges(); - inactiveCellProviders.remove( cc ); - } - - if ( machine instanceof IStackWatcherHost ) - { - IStackWatcher myWatcher = watchers.get( machine ); - if ( myWatcher != null ) - { - myWatcher.clear(); - watchers.remove( machine ); - } - } - } - - @Override - public void addNode(IGridNode node, IGridHost machine) - { - if ( machine instanceof ICellContainer ) - { - ICellContainer cc = (ICellContainer) machine; - inactiveCellProviders.add( cc ); - - myGrid.postEvent( new MENetworkCellArrayUpdate() ); - if ( node.isActive() ) - addCellProvider( cc, new CellChangeTracker() ).applyChanges(); - } - - if ( machine instanceof IStackWatcherHost ) - { - IStackWatcherHost swh = (IStackWatcherHost) machine; - ItemWatcher iw = new ItemWatcher( this, (IStackWatcherHost) swh ); - watchers.put( node, iw ); - swh.updateWatcher( iw ); - } - } - - private void buildNetworkStorage(StorageChannel chan) - { - SecurityCache security = myGrid.getCache( ISecurityGrid.class ); - - switch (chan) - { - case FLUIDS: - myFluidNetwork = new NetworkInventoryHandler( StorageChannel.FLUIDS, security ); - for (ICellProvider cc : activeCellProviders) - { - for (IMEInventoryHandler h : cc.getCellArray( chan )) - myFluidNetwork.addNewStorage( h ); - } - break; - case ITEMS: - myItemNetwork = new NetworkInventoryHandler( StorageChannel.ITEMS, security ); - for (ICellProvider cc : activeCellProviders) - { - for (IMEInventoryHandler h : cc.getCellArray( chan )) - myItemNetwork.addNewStorage( h ); - } - break; - default: - } - } - - private void postChangesToNetwork(StorageChannel chan, int up_or_down, IItemList availableItems, BaseActionSource src) - { - switch (chan) - { - case FLUIDS: - fluidMonitor.postChange( up_or_down > 0, (IItemList) availableItems, src ); - break; - case ITEMS: - itemMonitor.postChange( up_or_down > 0, (IItemList) availableItems, src ); - break; - default: - } - } - - public IMEInventoryHandler getItemInventoryHandler() - { - if ( myItemNetwork == null ) - buildNetworkStorage( StorageChannel.ITEMS ); - return myItemNetwork; - } - - public IMEInventoryHandler getFluidInventoryHandler() - { - if ( myFluidNetwork == null ) - buildNetworkStorage( StorageChannel.FLUIDS ); - return myFluidNetwork; - } - - @Override - public void postAlterationOfStoredItems(StorageChannel chan, Iterable input, BaseActionSource src) - { - if ( chan == StorageChannel.ITEMS ) - itemMonitor.postChange( true, (Iterable) input, src ); - else if ( chan == StorageChannel.FLUIDS ) - fluidMonitor.postChange( true, (Iterable) input, src ); - } - - @Override - public IMEMonitor getFluidInventory() - { - return fluidMonitor; - } - - @Override - public IMEMonitor getItemInventory() - { - return itemMonitor; - } - - @Override - public void onSplit(IGridStorage storageB) - { - - } - - @Override - public void onJoin(IGridStorage storageB) - { - - } - - @Override - public void populateGridStorage(IGridStorage storage) - { - - } - -} +package appeng.me.cache; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; + +import appeng.api.AEApi; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridStorage; +import appeng.api.networking.events.MENetworkCellArrayUpdate; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.security.IActionHost; +import appeng.api.networking.security.ISecurityGrid; +import appeng.api.networking.security.MachineSource; +import appeng.api.networking.storage.IStackWatcher; +import appeng.api.networking.storage.IStackWatcherHost; +import appeng.api.networking.storage.IStorageGrid; +import appeng.api.storage.ICellContainer; +import appeng.api.storage.ICellProvider; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; +import appeng.me.helpers.GenericInterestManager; +import appeng.me.storage.ItemWatcher; +import appeng.me.storage.NetworkInventoryHandler; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.SetMultimap; + +public class GridStorageCache implements IStorageGrid +{ + + final private SetMultimap interests = HashMultimap.create(); + final public GenericInterestManager interestManager = new GenericInterestManager( interests ); + + final HashSet activeCellProviders = new HashSet(); + final HashSet inactiveCellProviders = new HashSet(); + final public IGrid myGrid; + + private NetworkInventoryHandler myItemNetwork; + private NetworkMonitor itemMonitor = new NetworkMonitor( this, StorageChannel.ITEMS ); + + private NetworkInventoryHandler myFluidNetwork; + private NetworkMonitor fluidMonitor = new NetworkMonitor( this, StorageChannel.FLUIDS ); + + private HashMap watchers = new HashMap(); + + public GridStorageCache(IGrid g) { + myGrid = g; + } + + @Override + public void onUpdateTick() + { + itemMonitor.onTick(); + fluidMonitor.onTick(); + } + + private class CellChangeTrackerRecord + { + + final StorageChannel channel; + final int up_or_down; + final IItemList list; + final BaseActionSource src; + + public CellChangeTrackerRecord(StorageChannel channel, int i, IMEInventoryHandler h, BaseActionSource actionSrc) { + this.channel = channel; + this.up_or_down = i; + this.src = actionSrc; + + if ( channel == StorageChannel.ITEMS ) + this.list = ((IMEInventoryHandler) h).getAvailableItems( AEApi.instance().storage().createItemList() ); + else if ( channel == StorageChannel.FLUIDS ) + this.list = ((IMEInventoryHandler) h).getAvailableItems( AEApi.instance().storage().createFluidList() ); + else + this.list = null; + } + + public void applyChanges() + { + postChangesToNetwork( channel, up_or_down, list, src ); + } + + }; + + private class CellChangeTracker + { + + List data = new LinkedList(); + + public void postChanges(StorageChannel channel, int i, IMEInventoryHandler h, BaseActionSource actionSrc) + { + data.add( new CellChangeTrackerRecord( channel, i, h, actionSrc ) ); + } + + public void applyChanges() + { + for (CellChangeTrackerRecord rec : data) + rec.applyChanges(); + } + }; + + @Override + public void registerCellProvider(ICellProvider provider) + { + inactiveCellProviders.add( provider ); + addCellProvider( provider, new CellChangeTracker() ).applyChanges(); + } + + @Override + public void unregisterCellProvider(ICellProvider provider) + { + removeCellProvider( provider, new CellChangeTracker() ).applyChanges(); + inactiveCellProviders.remove( provider ); + } + + public CellChangeTracker addCellProvider(ICellProvider cc, CellChangeTracker tracker) + { + if ( inactiveCellProviders.contains( cc ) ) + { + inactiveCellProviders.remove( cc ); + activeCellProviders.add( cc ); + + BaseActionSource actionSrc = new BaseActionSource(); + if ( cc instanceof IActionHost ) + actionSrc = new MachineSource( (IActionHost) cc ); + + for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) + { + tracker.postChanges( StorageChannel.ITEMS, 1, h, actionSrc ); + } + + for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.FLUIDS )) + { + tracker.postChanges( StorageChannel.FLUIDS, 1, h, actionSrc ); + } + } + + return tracker; + } + + public CellChangeTracker removeCellProvider(ICellProvider cc, CellChangeTracker tracker) + { + if ( activeCellProviders.contains( cc ) ) + { + inactiveCellProviders.add( cc ); + activeCellProviders.remove( cc ); + + BaseActionSource actionSrc = new BaseActionSource(); + if ( cc instanceof IActionHost ) + actionSrc = new MachineSource( (IActionHost) cc ); + + for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) + { + tracker.postChanges( StorageChannel.ITEMS, -1, h, actionSrc ); + } + + for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.FLUIDS )) + { + tracker.postChanges( StorageChannel.FLUIDS, -1, h, actionSrc ); + } + } + + return tracker; + } + + @MENetworkEventSubscribe + public void cellUpdate(MENetworkCellArrayUpdate ev) + { + myItemNetwork = null; + myFluidNetwork = null; + + LinkedList ll = new LinkedList(); + ll.addAll( inactiveCellProviders ); + ll.addAll( activeCellProviders ); + + CellChangeTracker tracker = new CellChangeTracker(); + + for (ICellProvider cc : ll) + { + boolean Active = true; + + if ( cc instanceof IActionHost ) + { + IGridNode node = ((IActionHost) cc).getActionableNode(); + if ( node != null && node.isActive() ) + Active = true; + else + Active = false; + } + + if ( Active ) + addCellProvider( cc, tracker ); + else + removeCellProvider( cc, tracker ); + } + + itemMonitor.forceUpdate(); + fluidMonitor.forceUpdate(); + + tracker.applyChanges(); + } + + @Override + public void removeNode(IGridNode node, IGridHost machine) + { + if ( machine instanceof ICellContainer ) + { + ICellContainer cc = (ICellContainer) machine; + + myGrid.postEvent( new MENetworkCellArrayUpdate() ); + removeCellProvider( cc, new CellChangeTracker() ).applyChanges(); + inactiveCellProviders.remove( cc ); + } + + if ( machine instanceof IStackWatcherHost ) + { + IStackWatcher myWatcher = watchers.get( machine ); + if ( myWatcher != null ) + { + myWatcher.clear(); + watchers.remove( machine ); + } + } + } + + @Override + public void addNode(IGridNode node, IGridHost machine) + { + if ( machine instanceof ICellContainer ) + { + ICellContainer cc = (ICellContainer) machine; + inactiveCellProviders.add( cc ); + + myGrid.postEvent( new MENetworkCellArrayUpdate() ); + if ( node.isActive() ) + addCellProvider( cc, new CellChangeTracker() ).applyChanges(); + } + + if ( machine instanceof IStackWatcherHost ) + { + IStackWatcherHost swh = (IStackWatcherHost) machine; + ItemWatcher iw = new ItemWatcher( this, (IStackWatcherHost) swh ); + watchers.put( node, iw ); + swh.updateWatcher( iw ); + } + } + + private void buildNetworkStorage(StorageChannel chan) + { + SecurityCache security = myGrid.getCache( ISecurityGrid.class ); + + switch (chan) + { + case FLUIDS: + myFluidNetwork = new NetworkInventoryHandler( StorageChannel.FLUIDS, security ); + for (ICellProvider cc : activeCellProviders) + { + for (IMEInventoryHandler h : cc.getCellArray( chan )) + myFluidNetwork.addNewStorage( h ); + } + break; + case ITEMS: + myItemNetwork = new NetworkInventoryHandler( StorageChannel.ITEMS, security ); + for (ICellProvider cc : activeCellProviders) + { + for (IMEInventoryHandler h : cc.getCellArray( chan )) + myItemNetwork.addNewStorage( h ); + } + break; + default: + } + } + + private void postChangesToNetwork(StorageChannel chan, int up_or_down, IItemList availableItems, BaseActionSource src) + { + switch (chan) + { + case FLUIDS: + fluidMonitor.postChange( up_or_down > 0, (IItemList) availableItems, src ); + break; + case ITEMS: + itemMonitor.postChange( up_or_down > 0, (IItemList) availableItems, src ); + break; + default: + } + } + + public IMEInventoryHandler getItemInventoryHandler() + { + if ( myItemNetwork == null ) + buildNetworkStorage( StorageChannel.ITEMS ); + return myItemNetwork; + } + + public IMEInventoryHandler getFluidInventoryHandler() + { + if ( myFluidNetwork == null ) + buildNetworkStorage( StorageChannel.FLUIDS ); + return myFluidNetwork; + } + + @Override + public void postAlterationOfStoredItems(StorageChannel chan, Iterable input, BaseActionSource src) + { + if ( chan == StorageChannel.ITEMS ) + itemMonitor.postChange( true, (Iterable) input, src ); + else if ( chan == StorageChannel.FLUIDS ) + fluidMonitor.postChange( true, (Iterable) input, src ); + } + + @Override + public IMEMonitor getFluidInventory() + { + return fluidMonitor; + } + + @Override + public IMEMonitor getItemInventory() + { + return itemMonitor; + } + + @Override + public void onSplit(IGridStorage storageB) + { + + } + + @Override + public void onJoin(IGridStorage storageB) + { + + } + + @Override + public void populateGridStorage(IGridStorage storage) + { + + } + +} diff --git a/me/cache/NetworkMonitor.java b/src/main/java/appeng/me/cache/NetworkMonitor.java similarity index 96% rename from me/cache/NetworkMonitor.java rename to src/main/java/appeng/me/cache/NetworkMonitor.java index e68a86c4f..522714d2d 100644 --- a/me/cache/NetworkMonitor.java +++ b/src/main/java/appeng/me/cache/NetworkMonitor.java @@ -1,126 +1,126 @@ -package appeng.me.cache; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map.Entry; -import java.util.Set; - -import appeng.api.networking.events.MENetworkStorageEvent; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.IMEMonitorHandlerReceiver; -import appeng.api.storage.MEMonitorHandler; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; -import appeng.me.storage.ItemWatcher; - -public class NetworkMonitor> extends MEMonitorHandler -{ - - final private GridStorageCache myGridCache; - final private StorageChannel myChannel; - - boolean sendEvent = false; - - public void forceUpdate() - { - hasChanged = true; - - Iterator, Object>> i = getListeners(); - while (i.hasNext()) - { - Entry, Object> o = i.next(); - IMEMonitorHandlerReceiver recv = o.getKey(); - - if ( recv.isValid( o.getValue() ) ) - recv.onListUpdate(); - else - i.remove(); - } - } - - public NetworkMonitor(GridStorageCache cache, StorageChannel chan) { - super( null, chan ); - myGridCache = cache; - myChannel = chan; - } - - final static public LinkedList depth = new LinkedList(); - - @Override - protected void postChangesToListeners(Iterable changes, BaseActionSource src) - { - postChange( true, changes, src ); - } - - protected void postChange(boolean Add, Iterable changes, BaseActionSource src) - { - if ( depth.contains( this ) ) - return; - - depth.push( this ); - - sendEvent = true; - notifyListenersOfChange( changes, src ); - - IItemList myStorageList = getStorageList(); - - for (T changedItem : changes) - { - T difference = changedItem; - - if ( !Add && changedItem != null ) - (difference = changedItem.copy()).setStackSize( -changedItem.getStackSize() ); - - if ( myGridCache.interestManager.containsKey( changedItem ) ) - { - Set list = myGridCache.interestManager.get( changedItem ); - if ( !list.isEmpty() ) - { - IAEStack fullStack = myStorageList.findPrecise( changedItem ); - if ( fullStack == null ) - { - fullStack = changedItem.copy(); - fullStack.setStackSize( 0 ); - } - - myGridCache.interestManager.enableTransactions(); - - for (ItemWatcher iw : list) - iw.getHost().onStackChange( myStorageList, fullStack, difference, src, getChannel() ); - - myGridCache.interestManager.disableTransactions(); - } - } - } - - Object last = depth.pop(); - if ( last != this ) - throw new RuntimeException( "Invalid Access to Networked Storage API detected." ); - } - - public void onTick() - { - if ( sendEvent ) - { - sendEvent = false; - myGridCache.myGrid.postEvent( new MENetworkStorageEvent( this, myChannel ) ); - } - } - - @Override - protected IMEInventoryHandler getHandler() - { - switch (myChannel) - { - case ITEMS: - return myGridCache.getItemInventoryHandler(); - case FLUIDS: - return myGridCache.getFluidInventoryHandler(); - default: - } - return null; - } - -} +package appeng.me.cache; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map.Entry; +import java.util.Set; + +import appeng.api.networking.events.MENetworkStorageEvent; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.IMEMonitorHandlerReceiver; +import appeng.api.storage.MEMonitorHandler; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; +import appeng.me.storage.ItemWatcher; + +public class NetworkMonitor> extends MEMonitorHandler +{ + + final private GridStorageCache myGridCache; + final private StorageChannel myChannel; + + boolean sendEvent = false; + + public void forceUpdate() + { + hasChanged = true; + + Iterator, Object>> i = getListeners(); + while (i.hasNext()) + { + Entry, Object> o = i.next(); + IMEMonitorHandlerReceiver recv = o.getKey(); + + if ( recv.isValid( o.getValue() ) ) + recv.onListUpdate(); + else + i.remove(); + } + } + + public NetworkMonitor(GridStorageCache cache, StorageChannel chan) { + super( null, chan ); + myGridCache = cache; + myChannel = chan; + } + + final static public LinkedList depth = new LinkedList(); + + @Override + protected void postChangesToListeners(Iterable changes, BaseActionSource src) + { + postChange( true, changes, src ); + } + + protected void postChange(boolean Add, Iterable changes, BaseActionSource src) + { + if ( depth.contains( this ) ) + return; + + depth.push( this ); + + sendEvent = true; + notifyListenersOfChange( changes, src ); + + IItemList myStorageList = getStorageList(); + + for (T changedItem : changes) + { + T difference = changedItem; + + if ( !Add && changedItem != null ) + (difference = changedItem.copy()).setStackSize( -changedItem.getStackSize() ); + + if ( myGridCache.interestManager.containsKey( changedItem ) ) + { + Set list = myGridCache.interestManager.get( changedItem ); + if ( !list.isEmpty() ) + { + IAEStack fullStack = myStorageList.findPrecise( changedItem ); + if ( fullStack == null ) + { + fullStack = changedItem.copy(); + fullStack.setStackSize( 0 ); + } + + myGridCache.interestManager.enableTransactions(); + + for (ItemWatcher iw : list) + iw.getHost().onStackChange( myStorageList, fullStack, difference, src, getChannel() ); + + myGridCache.interestManager.disableTransactions(); + } + } + } + + Object last = depth.pop(); + if ( last != this ) + throw new RuntimeException( "Invalid Access to Networked Storage API detected." ); + } + + public void onTick() + { + if ( sendEvent ) + { + sendEvent = false; + myGridCache.myGrid.postEvent( new MENetworkStorageEvent( this, myChannel ) ); + } + } + + @Override + protected IMEInventoryHandler getHandler() + { + switch (myChannel) + { + case ITEMS: + return myGridCache.getItemInventoryHandler(); + case FLUIDS: + return myGridCache.getFluidInventoryHandler(); + default: + } + return null; + } + +} diff --git a/me/cache/P2PCache.java b/src/main/java/appeng/me/cache/P2PCache.java similarity index 100% rename from me/cache/P2PCache.java rename to src/main/java/appeng/me/cache/P2PCache.java diff --git a/me/cache/PathGridCache.java b/src/main/java/appeng/me/cache/PathGridCache.java similarity index 96% rename from me/cache/PathGridCache.java rename to src/main/java/appeng/me/cache/PathGridCache.java index 494d1b00b..c5501babb 100644 --- a/me/cache/PathGridCache.java +++ b/src/main/java/appeng/me/cache/PathGridCache.java @@ -1,379 +1,379 @@ -package appeng.me.cache; - -import java.util.EnumSet; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridBlock; -import appeng.api.networking.IGridConnection; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridMultiblock; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridStorage; -import appeng.api.networking.events.MENetworkBootingStatusChange; -import appeng.api.networking.events.MENetworkChannelChanged; -import appeng.api.networking.events.MENetworkControllerChange; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.pathing.ControllerState; -import appeng.api.networking.pathing.IPathingGrid; -import appeng.api.util.DimensionalCoord; -import appeng.core.AEConfig; -import appeng.core.features.AEFeature; -import appeng.core.stats.Achievements; -import appeng.me.GridConnection; -import appeng.me.GridNode; -import appeng.me.pathfinding.AdHocChannelUpdater; -import appeng.me.pathfinding.ControllerChannelUpdater; -import appeng.me.pathfinding.ControllerValidator; -import appeng.me.pathfinding.IPathItem; -import appeng.me.pathfinding.PathSegment; -import appeng.tile.networking.TileController; -import appeng.util.Platform; - -public class PathGridCache implements IPathingGrid -{ - - boolean recalculateControllerNextTick = true; - boolean updateNetwork = true; - boolean booting = false; - - final LinkedList active = new LinkedList(); - - ControllerState controllerState = ControllerState.NO_CONTROLLER; - - int instance = Integer.MIN_VALUE; - - int ticksUntilReady = 20; - public int channelsInUse = 0; - int lastChannels = 0; - - final Set controllers = new HashSet(); - final Set requireChannels = new HashSet(); - final Set blockDense = new HashSet(); - - final IGrid myGrid; - private HashSet semiOpen = new HashSet(); - private HashSet closedList = new HashSet(); - - public int channelsByBlocks = 0; - public double channelPowerUsage = 0.0; - - public PathGridCache(IGrid g) - { - myGrid = g; - } - - @Override - public void onUpdateTick() - { - if ( recalculateControllerNextTick ) - { - recalcController(); - } - - if ( updateNetwork ) - { - if ( !booting ) - myGrid.postEvent( new MENetworkBootingStatusChange() ); - - booting = true; - updateNetwork = false; - instance++; - channelsInUse = 0; - - if ( !AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) ) - { - int used = calculateRequiredChannels(); - - int nodes = myGrid.getNodes().size(); - ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 ); - channelsByBlocks = nodes * used; - channelPowerUsage = (double) channelsByBlocks / 128.0; - - myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) ); - } - else if ( controllerState == ControllerState.NO_CONTROLLER ) - { - int requiredChannels = calculateRequiredChannels(); - int used = requiredChannels; - if ( requiredChannels > 8 ) - used = 0; - - int nodes = myGrid.getNodes().size(); - channelsInUse = used; - - ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 ); - channelsByBlocks = nodes * used; - channelPowerUsage = (double) channelsByBlocks / 128.0; - - myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) ); - } - else if ( controllerState == ControllerState.CONTROLLER_CONFLICT ) - { - ticksUntilReady = 20; - myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 ) ); - } - else - { - int nodes = myGrid.getNodes().size(); - ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 ); - closedList = new HashSet(); - semiOpen = new HashSet(); - - // myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 ) - // ); - for (IGridNode node : myGrid.getMachines( TileController.class )) - { - closedList.add( (IPathItem) node ); - for (IGridConnection gcc : node.getConnections()) - { - GridConnection gc = (GridConnection) gcc; - if ( !(gc.getOtherSide( node ).getMachine() instanceof TileController) ) - { - List open = new LinkedList(); - closedList.add( gc ); - open.add( gc ); - gc.setControllerRoute( (GridNode) node, true ); - active.add( new PathSegment( this, open, semiOpen, closedList ) ); - } - } - } - } - } - - if ( !active.isEmpty() || ticksUntilReady > 0 ) - { - Iterator i = active.iterator(); - while (i.hasNext()) - { - PathSegment pat = i.next(); - if ( pat.step() ) - { - pat.isDead = true; - i.remove(); - } - } - - ticksUntilReady--; - - if ( active.isEmpty() && ticksUntilReady <= 0 ) - { - if ( controllerState == ControllerState.CONTROLLER_ONLINE ) - { - for (TileController tc : controllers) - { - tc.getGridNode( ForgeDirection.UNKNOWN ).beginVisit( new ControllerChannelUpdater() ); - break; - } - } - - // check for achievements - achievementPost(); - - booting = false; - channelPowerUsage = (double) channelsByBlocks / 128.0; - myGrid.postEvent( new MENetworkBootingStatusChange() ); - } - } - } - - private void achievementPost() - { - if ( lastChannels != channelsInUse && AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) ) - { - Achievements currentBracket = getAchievementBracket( channelsInUse ); - Achievements lastBracket = getAchievementBracket( lastChannels ); - if ( currentBracket != lastBracket && currentBracket != null ) - { - Set players = new HashSet(); - for (IGridNode n : requireChannels) - players.add( n.getPlayerID() ); - - for (int id : players) - { - Platform.addStat( id, currentBracket.getAchievement() ); - } - } - } - lastChannels = channelsInUse; - } - - private Achievements getAchievementBracket(int ch) - { - if ( ch < 8 ) - return null; - - if ( ch < 128 ) - return Achievements.Networking1; - - if ( ch < 2048 ) - return Achievements.Networking2; - - return Achievements.Networking3; - } - - private int calculateRequiredChannels() - { - int depth = 0; - semiOpen.clear(); - - for (IGridNode nodes : requireChannels) - { - if ( !semiOpen.contains( nodes ) ) - { - IGridBlock gb = nodes.getGridBlock(); - EnumSet flags = gb.getFlags(); - - if ( flags.contains( GridFlags.COMPRESSED_CHANNEL ) && !blockDense.isEmpty() ) - return 9; - - depth++; - - if ( flags.contains( GridFlags.MULTIBLOCK ) ) - { - IGridMultiblock gmb = (IGridMultiblock) gb; - Iterator i = gmb.getMultiblockNodes(); - while (i.hasNext()) - semiOpen.add( (IPathItem) i.next() ); - } - } - } - - return depth; - } - - @Override - public void repath() - { - // clean up... - active.clear(); - - channelsByBlocks = 0; - updateNetwork = true; - } - - @Override - public void removeNode(IGridNode gridNode, IGridHost machine) - { - if ( machine instanceof TileController ) - { - controllers.remove( machine ); - recalculateControllerNextTick = true; - } - - EnumSet flags = gridNode.getGridBlock().getFlags(); - - if ( flags.contains( GridFlags.REQUIRE_CHANNEL ) ) - requireChannels.remove( gridNode ); - - if ( flags.contains( GridFlags.CANNOT_CARRY_COMPRESSED ) ) - blockDense.remove( gridNode ); - - repath(); - } - - @Override - public void addNode(IGridNode gridNode, IGridHost machine) - { - if ( machine instanceof TileController ) - { - controllers.add( (TileController) machine ); - recalculateControllerNextTick = true; - } - - EnumSet flags = gridNode.getGridBlock().getFlags(); - - if ( flags.contains( GridFlags.REQUIRE_CHANNEL ) ) - requireChannels.add( gridNode ); - - if ( flags.contains( GridFlags.CANNOT_CARRY_COMPRESSED ) ) - blockDense.add( gridNode ); - - repath(); - } - - @MENetworkEventSubscribe - void updateNodReq(MENetworkChannelChanged ev) - { - IGridNode gridNode = ev.node; - - if ( gridNode.getGridBlock().getFlags().contains( GridFlags.REQUIRE_CHANNEL ) ) - requireChannels.add( gridNode ); - else - requireChannels.remove( gridNode ); - - repath(); - } - - private void recalcController() - { - recalculateControllerNextTick = false; - ControllerState old = controllerState; - - if ( controllers.isEmpty() ) - { - controllerState = ControllerState.NO_CONTROLLER; - } - else - { - IGridNode startingNode = controllers.iterator().next().getGridNode( ForgeDirection.UNKNOWN ); - if ( startingNode == null ) - { - controllerState = ControllerState.CONTROLLER_CONFLICT; - return; - } - - DimensionalCoord dc = startingNode.getGridBlock().getLocation(); - ControllerValidator cv = new ControllerValidator( dc.x, dc.y, dc.z ); - - startingNode.beginVisit( cv ); - - if ( cv.isValid && cv.found == controllers.size() ) - controllerState = ControllerState.CONTROLLER_ONLINE; - else - controllerState = ControllerState.CONTROLLER_CONFLICT; - } - - if ( old != controllerState ) - { - myGrid.postEvent( new MENetworkControllerChange() ); - } - } - - @Override - public ControllerState getControllerState() - { - return controllerState; - } - - @Override - public boolean isNetworkBooting() - { - return !active.isEmpty() && booting == false; - } - - @Override - public void onSplit(IGridStorage storageB) - { - - } - - @Override - public void onJoin(IGridStorage storageB) - { - - } - - @Override - public void populateGridStorage(IGridStorage storage) - { - - } - -} +package appeng.me.cache; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridBlock; +import appeng.api.networking.IGridConnection; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridMultiblock; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridStorage; +import appeng.api.networking.events.MENetworkBootingStatusChange; +import appeng.api.networking.events.MENetworkChannelChanged; +import appeng.api.networking.events.MENetworkControllerChange; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.pathing.ControllerState; +import appeng.api.networking.pathing.IPathingGrid; +import appeng.api.util.DimensionalCoord; +import appeng.core.AEConfig; +import appeng.core.features.AEFeature; +import appeng.core.stats.Achievements; +import appeng.me.GridConnection; +import appeng.me.GridNode; +import appeng.me.pathfinding.AdHocChannelUpdater; +import appeng.me.pathfinding.ControllerChannelUpdater; +import appeng.me.pathfinding.ControllerValidator; +import appeng.me.pathfinding.IPathItem; +import appeng.me.pathfinding.PathSegment; +import appeng.tile.networking.TileController; +import appeng.util.Platform; + +public class PathGridCache implements IPathingGrid +{ + + boolean recalculateControllerNextTick = true; + boolean updateNetwork = true; + boolean booting = false; + + final LinkedList active = new LinkedList(); + + ControllerState controllerState = ControllerState.NO_CONTROLLER; + + int instance = Integer.MIN_VALUE; + + int ticksUntilReady = 20; + public int channelsInUse = 0; + int lastChannels = 0; + + final Set controllers = new HashSet(); + final Set requireChannels = new HashSet(); + final Set blockDense = new HashSet(); + + final IGrid myGrid; + private HashSet semiOpen = new HashSet(); + private HashSet closedList = new HashSet(); + + public int channelsByBlocks = 0; + public double channelPowerUsage = 0.0; + + public PathGridCache(IGrid g) + { + myGrid = g; + } + + @Override + public void onUpdateTick() + { + if ( recalculateControllerNextTick ) + { + recalcController(); + } + + if ( updateNetwork ) + { + if ( !booting ) + myGrid.postEvent( new MENetworkBootingStatusChange() ); + + booting = true; + updateNetwork = false; + instance++; + channelsInUse = 0; + + if ( !AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) ) + { + int used = calculateRequiredChannels(); + + int nodes = myGrid.getNodes().size(); + ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 ); + channelsByBlocks = nodes * used; + channelPowerUsage = (double) channelsByBlocks / 128.0; + + myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) ); + } + else if ( controllerState == ControllerState.NO_CONTROLLER ) + { + int requiredChannels = calculateRequiredChannels(); + int used = requiredChannels; + if ( requiredChannels > 8 ) + used = 0; + + int nodes = myGrid.getNodes().size(); + channelsInUse = used; + + ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 ); + channelsByBlocks = nodes * used; + channelPowerUsage = (double) channelsByBlocks / 128.0; + + myGrid.getPivot().beginVisit( new AdHocChannelUpdater( used ) ); + } + else if ( controllerState == ControllerState.CONTROLLER_CONFLICT ) + { + ticksUntilReady = 20; + myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 ) ); + } + else + { + int nodes = myGrid.getNodes().size(); + ticksUntilReady = 20 + Math.max( 0, nodes / 100 - 20 ); + closedList = new HashSet(); + semiOpen = new HashSet(); + + // myGrid.getPivot().beginVisit( new AdHocChannelUpdater( 0 ) + // ); + for (IGridNode node : myGrid.getMachines( TileController.class )) + { + closedList.add( (IPathItem) node ); + for (IGridConnection gcc : node.getConnections()) + { + GridConnection gc = (GridConnection) gcc; + if ( !(gc.getOtherSide( node ).getMachine() instanceof TileController) ) + { + List open = new LinkedList(); + closedList.add( gc ); + open.add( gc ); + gc.setControllerRoute( (GridNode) node, true ); + active.add( new PathSegment( this, open, semiOpen, closedList ) ); + } + } + } + } + } + + if ( !active.isEmpty() || ticksUntilReady > 0 ) + { + Iterator i = active.iterator(); + while (i.hasNext()) + { + PathSegment pat = i.next(); + if ( pat.step() ) + { + pat.isDead = true; + i.remove(); + } + } + + ticksUntilReady--; + + if ( active.isEmpty() && ticksUntilReady <= 0 ) + { + if ( controllerState == ControllerState.CONTROLLER_ONLINE ) + { + for (TileController tc : controllers) + { + tc.getGridNode( ForgeDirection.UNKNOWN ).beginVisit( new ControllerChannelUpdater() ); + break; + } + } + + // check for achievements + achievementPost(); + + booting = false; + channelPowerUsage = (double) channelsByBlocks / 128.0; + myGrid.postEvent( new MENetworkBootingStatusChange() ); + } + } + } + + private void achievementPost() + { + if ( lastChannels != channelsInUse && AEConfig.instance.isFeatureEnabled( AEFeature.Channels ) ) + { + Achievements currentBracket = getAchievementBracket( channelsInUse ); + Achievements lastBracket = getAchievementBracket( lastChannels ); + if ( currentBracket != lastBracket && currentBracket != null ) + { + Set players = new HashSet(); + for (IGridNode n : requireChannels) + players.add( n.getPlayerID() ); + + for (int id : players) + { + Platform.addStat( id, currentBracket.getAchievement() ); + } + } + } + lastChannels = channelsInUse; + } + + private Achievements getAchievementBracket(int ch) + { + if ( ch < 8 ) + return null; + + if ( ch < 128 ) + return Achievements.Networking1; + + if ( ch < 2048 ) + return Achievements.Networking2; + + return Achievements.Networking3; + } + + private int calculateRequiredChannels() + { + int depth = 0; + semiOpen.clear(); + + for (IGridNode nodes : requireChannels) + { + if ( !semiOpen.contains( nodes ) ) + { + IGridBlock gb = nodes.getGridBlock(); + EnumSet flags = gb.getFlags(); + + if ( flags.contains( GridFlags.COMPRESSED_CHANNEL ) && !blockDense.isEmpty() ) + return 9; + + depth++; + + if ( flags.contains( GridFlags.MULTIBLOCK ) ) + { + IGridMultiblock gmb = (IGridMultiblock) gb; + Iterator i = gmb.getMultiblockNodes(); + while (i.hasNext()) + semiOpen.add( (IPathItem) i.next() ); + } + } + } + + return depth; + } + + @Override + public void repath() + { + // clean up... + active.clear(); + + channelsByBlocks = 0; + updateNetwork = true; + } + + @Override + public void removeNode(IGridNode gridNode, IGridHost machine) + { + if ( machine instanceof TileController ) + { + controllers.remove( machine ); + recalculateControllerNextTick = true; + } + + EnumSet flags = gridNode.getGridBlock().getFlags(); + + if ( flags.contains( GridFlags.REQUIRE_CHANNEL ) ) + requireChannels.remove( gridNode ); + + if ( flags.contains( GridFlags.CANNOT_CARRY_COMPRESSED ) ) + blockDense.remove( gridNode ); + + repath(); + } + + @Override + public void addNode(IGridNode gridNode, IGridHost machine) + { + if ( machine instanceof TileController ) + { + controllers.add( (TileController) machine ); + recalculateControllerNextTick = true; + } + + EnumSet flags = gridNode.getGridBlock().getFlags(); + + if ( flags.contains( GridFlags.REQUIRE_CHANNEL ) ) + requireChannels.add( gridNode ); + + if ( flags.contains( GridFlags.CANNOT_CARRY_COMPRESSED ) ) + blockDense.add( gridNode ); + + repath(); + } + + @MENetworkEventSubscribe + void updateNodReq(MENetworkChannelChanged ev) + { + IGridNode gridNode = ev.node; + + if ( gridNode.getGridBlock().getFlags().contains( GridFlags.REQUIRE_CHANNEL ) ) + requireChannels.add( gridNode ); + else + requireChannels.remove( gridNode ); + + repath(); + } + + private void recalcController() + { + recalculateControllerNextTick = false; + ControllerState old = controllerState; + + if ( controllers.isEmpty() ) + { + controllerState = ControllerState.NO_CONTROLLER; + } + else + { + IGridNode startingNode = controllers.iterator().next().getGridNode( ForgeDirection.UNKNOWN ); + if ( startingNode == null ) + { + controllerState = ControllerState.CONTROLLER_CONFLICT; + return; + } + + DimensionalCoord dc = startingNode.getGridBlock().getLocation(); + ControllerValidator cv = new ControllerValidator( dc.x, dc.y, dc.z ); + + startingNode.beginVisit( cv ); + + if ( cv.isValid && cv.found == controllers.size() ) + controllerState = ControllerState.CONTROLLER_ONLINE; + else + controllerState = ControllerState.CONTROLLER_CONFLICT; + } + + if ( old != controllerState ) + { + myGrid.postEvent( new MENetworkControllerChange() ); + } + } + + @Override + public ControllerState getControllerState() + { + return controllerState; + } + + @Override + public boolean isNetworkBooting() + { + return !active.isEmpty() && booting == false; + } + + @Override + public void onSplit(IGridStorage storageB) + { + + } + + @Override + public void onJoin(IGridStorage storageB) + { + + } + + @Override + public void populateGridStorage(IGridStorage storage) + { + + } + +} diff --git a/me/cache/SecurityCache.java b/src/main/java/appeng/me/cache/SecurityCache.java similarity index 100% rename from me/cache/SecurityCache.java rename to src/main/java/appeng/me/cache/SecurityCache.java diff --git a/me/cache/SpatialPylonCache.java b/src/main/java/appeng/me/cache/SpatialPylonCache.java similarity index 100% rename from me/cache/SpatialPylonCache.java rename to src/main/java/appeng/me/cache/SpatialPylonCache.java diff --git a/me/cache/TickManagerCache.java b/src/main/java/appeng/me/cache/TickManagerCache.java similarity index 95% rename from me/cache/TickManagerCache.java rename to src/main/java/appeng/me/cache/TickManagerCache.java index 6f7f1d065..3ef73c418 100644 --- a/me/cache/TickManagerCache.java +++ b/src/main/java/appeng/me/cache/TickManagerCache.java @@ -1,225 +1,225 @@ -package appeng.me.cache; - -import java.util.HashMap; -import java.util.PriorityQueue; - -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.util.ReportedException; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridStorage; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.ITickManager; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.me.cache.helpers.TickTracker; - -public class TickManagerCache implements ITickManager -{ - - private long currentTick = 0; - - final IGrid myGrid; - - public TickManagerCache(IGrid g) { - myGrid = g; - } - - final HashMap alertable = new HashMap(); - - final HashMap sleeping = new HashMap(); - final HashMap awake = new HashMap(); - - final PriorityQueue upcomingTicks = new PriorityQueue(); - - public long getCurrentTick() - { - return currentTick; - } - - public long getAvgNanoTime(IGridNode node) - { - TickTracker tt = awake.get( node ); - - if ( tt == null ) - tt = sleeping.get( node ); - - if ( tt == null ) - return -1; - - return tt.getAvgNanos(); - } - - @Override - public void onUpdateTick() - { - TickTracker tt = null; - try - { - currentTick++; - while (!upcomingTicks.isEmpty()) - { - tt = upcomingTicks.peek(); - int diff = (int) (currentTick - tt.lastTick); - if ( diff >= tt.current_rate ) - { - // remove tt.. - upcomingTicks.poll(); - TickRateModulation mod = tt.gt.tickingRequest( tt.node, diff ); - - switch (mod) - { - case FASTER: - tt.setRate( tt.current_rate - 2 ); - break; - case IDLE: - tt.setRate( tt.request.maxTickRate ); - break; - case SAME: - break; - case SLEEP: - sleepDevice( tt.node ); - break; - case SLOWER: - tt.setRate( tt.current_rate + 1 ); - break; - case URGENT: - tt.setRate( 0 ); - break; - default: - break; - } - - if ( awake.containsKey( tt.node ) ) - addToQueue( tt ); - } - else - return; // done! - } - } - catch( Throwable t ) - { - CrashReport crashreport = CrashReport.makeCrashReport(t, "Ticking GridNode"); - CrashReportCategory crashreportcategory = crashreport.makeCategory( tt.gt.getClass().getSimpleName() + " being ticked." ); - tt.addEntityCrashInfo(crashreportcategory); - throw new ReportedException(crashreport); - } - } - - private void addToQueue(TickTracker tt) - { - tt.lastTick = currentTick; - upcomingTicks.add( tt ); - } - - @Override - public boolean alertDevice(IGridNode node) - { - TickTracker tt = alertable.get( node ); - if ( tt == null ) - return false; - // throw new RuntimeException( - // "Invalid alerted device, this node is not marked as alertable, or part of this grid." ); - - // set to awake, this is for sanity. - sleeping.remove( node ); - awake.put( node, tt ); - - // configure sort. - tt.lastTick = tt.lastTick - tt.request.maxTickRate; - tt.current_rate = tt.request.minTickRate; - - // prevent dupes and tick build up. - upcomingTicks.remove( tt ); - upcomingTicks.add( tt ); - - return true; - } - - @Override - public boolean sleepDevice(IGridNode node) - { - if ( awake.containsKey( node ) ) - { - TickTracker gt = awake.get( node ); - awake.remove( node ); - sleeping.put( node, gt ); - - return true; - } - - return false; - } - - @Override - public boolean wakeDevice(IGridNode node) - { - if ( sleeping.containsKey( node ) ) - { - TickTracker gt = sleeping.get( node ); - sleeping.remove( node ); - awake.put( node, gt ); - addToQueue( gt ); - - return true; - } - - return false; - } - - @Override - public void removeNode(IGridNode gridNode, IGridHost machine) - { - if ( machine instanceof IGridTickable ) - { - alertable.remove( gridNode ); - sleeping.remove( gridNode ); - awake.remove( gridNode ); - } - } - - @Override - public void addNode(IGridNode gridNode, IGridHost machine) - { - if ( machine instanceof IGridTickable ) - { - TickingRequest tr = ((IGridTickable) machine).getTickingRequest( gridNode ); - if ( tr != null ) - { - TickTracker tt = new TickTracker( tr, gridNode, (IGridTickable) machine, currentTick, this ); - - if ( tr.canBeAlerted ) - alertable.put( gridNode, tt ); - - if ( tr.isSleeping ) - sleeping.put( gridNode, tt ); - else - { - awake.put( gridNode, tt ); - addToQueue( tt ); - } - - } - } - } - - @Override - public void onSplit(IGridStorage storageB) - { - - } - - @Override - public void onJoin(IGridStorage storageB) - { - - } - - @Override - public void populateGridStorage(IGridStorage storage) - { - - } -} +package appeng.me.cache; + +import java.util.HashMap; +import java.util.PriorityQueue; + +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.util.ReportedException; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridStorage; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.ITickManager; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; +import appeng.me.cache.helpers.TickTracker; + +public class TickManagerCache implements ITickManager +{ + + private long currentTick = 0; + + final IGrid myGrid; + + public TickManagerCache(IGrid g) { + myGrid = g; + } + + final HashMap alertable = new HashMap(); + + final HashMap sleeping = new HashMap(); + final HashMap awake = new HashMap(); + + final PriorityQueue upcomingTicks = new PriorityQueue(); + + public long getCurrentTick() + { + return currentTick; + } + + public long getAvgNanoTime(IGridNode node) + { + TickTracker tt = awake.get( node ); + + if ( tt == null ) + tt = sleeping.get( node ); + + if ( tt == null ) + return -1; + + return tt.getAvgNanos(); + } + + @Override + public void onUpdateTick() + { + TickTracker tt = null; + try + { + currentTick++; + while (!upcomingTicks.isEmpty()) + { + tt = upcomingTicks.peek(); + int diff = (int) (currentTick - tt.lastTick); + if ( diff >= tt.current_rate ) + { + // remove tt.. + upcomingTicks.poll(); + TickRateModulation mod = tt.gt.tickingRequest( tt.node, diff ); + + switch (mod) + { + case FASTER: + tt.setRate( tt.current_rate - 2 ); + break; + case IDLE: + tt.setRate( tt.request.maxTickRate ); + break; + case SAME: + break; + case SLEEP: + sleepDevice( tt.node ); + break; + case SLOWER: + tt.setRate( tt.current_rate + 1 ); + break; + case URGENT: + tt.setRate( 0 ); + break; + default: + break; + } + + if ( awake.containsKey( tt.node ) ) + addToQueue( tt ); + } + else + return; // done! + } + } + catch( Throwable t ) + { + CrashReport crashreport = CrashReport.makeCrashReport(t, "Ticking GridNode"); + CrashReportCategory crashreportcategory = crashreport.makeCategory( tt.gt.getClass().getSimpleName() + " being ticked." ); + tt.addEntityCrashInfo(crashreportcategory); + throw new ReportedException(crashreport); + } + } + + private void addToQueue(TickTracker tt) + { + tt.lastTick = currentTick; + upcomingTicks.add( tt ); + } + + @Override + public boolean alertDevice(IGridNode node) + { + TickTracker tt = alertable.get( node ); + if ( tt == null ) + return false; + // throw new RuntimeException( + // "Invalid alerted device, this node is not marked as alertable, or part of this grid." ); + + // set to awake, this is for sanity. + sleeping.remove( node ); + awake.put( node, tt ); + + // configure sort. + tt.lastTick = tt.lastTick - tt.request.maxTickRate; + tt.current_rate = tt.request.minTickRate; + + // prevent dupes and tick build up. + upcomingTicks.remove( tt ); + upcomingTicks.add( tt ); + + return true; + } + + @Override + public boolean sleepDevice(IGridNode node) + { + if ( awake.containsKey( node ) ) + { + TickTracker gt = awake.get( node ); + awake.remove( node ); + sleeping.put( node, gt ); + + return true; + } + + return false; + } + + @Override + public boolean wakeDevice(IGridNode node) + { + if ( sleeping.containsKey( node ) ) + { + TickTracker gt = sleeping.get( node ); + sleeping.remove( node ); + awake.put( node, gt ); + addToQueue( gt ); + + return true; + } + + return false; + } + + @Override + public void removeNode(IGridNode gridNode, IGridHost machine) + { + if ( machine instanceof IGridTickable ) + { + alertable.remove( gridNode ); + sleeping.remove( gridNode ); + awake.remove( gridNode ); + } + } + + @Override + public void addNode(IGridNode gridNode, IGridHost machine) + { + if ( machine instanceof IGridTickable ) + { + TickingRequest tr = ((IGridTickable) machine).getTickingRequest( gridNode ); + if ( tr != null ) + { + TickTracker tt = new TickTracker( tr, gridNode, (IGridTickable) machine, currentTick, this ); + + if ( tr.canBeAlerted ) + alertable.put( gridNode, tt ); + + if ( tr.isSleeping ) + sleeping.put( gridNode, tt ); + else + { + awake.put( gridNode, tt ); + addToQueue( tt ); + } + + } + } + } + + @Override + public void onSplit(IGridStorage storageB) + { + + } + + @Override + public void onJoin(IGridStorage storageB) + { + + } + + @Override + public void populateGridStorage(IGridStorage storage) + { + + } +} diff --git a/me/cache/helpers/ConnectionWrapper.java b/src/main/java/appeng/me/cache/helpers/ConnectionWrapper.java similarity index 94% rename from me/cache/helpers/ConnectionWrapper.java rename to src/main/java/appeng/me/cache/helpers/ConnectionWrapper.java index 56e9eb61e..c408aa646 100644 --- a/me/cache/helpers/ConnectionWrapper.java +++ b/src/main/java/appeng/me/cache/helpers/ConnectionWrapper.java @@ -1,14 +1,14 @@ -package appeng.me.cache.helpers; - -import appeng.api.networking.IGridConnection; - -public class ConnectionWrapper -{ - - public IGridConnection connection; - - public ConnectionWrapper(IGridConnection gc) { - connection = gc; - } - +package appeng.me.cache.helpers; + +import appeng.api.networking.IGridConnection; + +public class ConnectionWrapper +{ + + public IGridConnection connection; + + public ConnectionWrapper(IGridConnection gc) { + connection = gc; + } + } \ No newline at end of file diff --git a/me/cache/helpers/Connections.java b/src/main/java/appeng/me/cache/helpers/Connections.java similarity index 94% rename from me/cache/helpers/Connections.java rename to src/main/java/appeng/me/cache/helpers/Connections.java index 8c9e4b9b1..62baa52ef 100644 --- a/me/cache/helpers/Connections.java +++ b/src/main/java/appeng/me/cache/helpers/Connections.java @@ -1,42 +1,42 @@ -package appeng.me.cache.helpers; - -import java.util.HashMap; -import java.util.concurrent.Callable; - -import appeng.api.networking.IGridNode; -import appeng.parts.p2p.PartP2PTunnelME; - -public class Connections implements Callable -{ - - final private PartP2PTunnelME me; - final public HashMap connections = new HashMap(); - - public boolean create = false; - public boolean destroy = false; - - public Connections(PartP2PTunnelME o) { - me = o; - } - - @Override - public Object call() throws Exception - { - me.updateConnections( this ); - - return null; - } - - public void markDestroy() - { - create = false; - destroy = true; - } - - public void markCreate() - { - create = true; - destroy = false; - } - -}; +package appeng.me.cache.helpers; + +import java.util.HashMap; +import java.util.concurrent.Callable; + +import appeng.api.networking.IGridNode; +import appeng.parts.p2p.PartP2PTunnelME; + +public class Connections implements Callable +{ + + final private PartP2PTunnelME me; + final public HashMap connections = new HashMap(); + + public boolean create = false; + public boolean destroy = false; + + public Connections(PartP2PTunnelME o) { + me = o; + } + + @Override + public Object call() throws Exception + { + me.updateConnections( this ); + + return null; + } + + public void markDestroy() + { + create = false; + destroy = true; + } + + public void markCreate() + { + create = true; + destroy = false; + } + +}; diff --git a/me/cache/helpers/TickTracker.java b/src/main/java/appeng/me/cache/helpers/TickTracker.java similarity index 96% rename from me/cache/helpers/TickTracker.java rename to src/main/java/appeng/me/cache/helpers/TickTracker.java index d726e4357..1fb377935 100644 --- a/me/cache/helpers/TickTracker.java +++ b/src/main/java/appeng/me/cache/helpers/TickTracker.java @@ -1,76 +1,76 @@ -package appeng.me.cache.helpers; - -import net.minecraft.crash.CrashReportCategory; -import appeng.api.networking.IGridNode; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.util.DimensionalCoord; -import appeng.me.cache.TickManagerCache; -import appeng.parts.AEBasePart; - -public class TickTracker implements Comparable -{ - - public final TickingRequest request; - public final IGridTickable gt; - public final IGridNode node; - public final TickManagerCache host; - - public long LastFiveTicksTime = 0; - - public long lastTick; - public int current_rate; - - public TickTracker(TickingRequest req, IGridNode node, IGridTickable gt, long currentTick, TickManagerCache tickManagerCache) { - request = req; - this.gt = gt; - this.node = node; - current_rate = (req.minTickRate + req.maxTickRate) / 2; - lastTick = currentTick; - host = tickManagerCache; - } - - public long getAvgNanos() - { - return (LastFiveTicksTime / 5); - } - - public void setRate(int rate) - { - current_rate = rate; - - if ( current_rate < request.minTickRate ) - current_rate = request.minTickRate; - - if ( current_rate > request.maxTickRate ) - current_rate = request.maxTickRate; - } - - @Override - public int compareTo(TickTracker t) - { - int nextTick = (int) ((lastTick - host.getCurrentTick()) + current_rate); - int ts_nextTick = (int) ((t.lastTick - host.getCurrentTick()) + t.current_rate); - return nextTick - ts_nextTick; - } - - public void addEntityCrashInfo(CrashReportCategory crashreportcategory) - { - if ( gt instanceof AEBasePart ) - { - AEBasePart part = (AEBasePart)gt; - part.addEntityCrashInfo( crashreportcategory ); - } - - crashreportcategory.addCrashSection( "CurrentTickRate", current_rate ); - crashreportcategory.addCrashSection( "MinTickRate", request.minTickRate ); - crashreportcategory.addCrashSection( "MaxTickRate", request.maxTickRate ); - crashreportcategory.addCrashSection( "MachineType", gt.getClass().getName() ); - crashreportcategory.addCrashSection( "GridBlockType", node.getGridBlock().getClass().getName() ); - crashreportcategory.addCrashSection( "ConnectedSides", node.getConnectedSides() ); - - DimensionalCoord dc = node.getGridBlock().getLocation(); - if ( dc != null ) - crashreportcategory.addCrashSection( "Location", dc ); - } -}; +package appeng.me.cache.helpers; + +import net.minecraft.crash.CrashReportCategory; +import appeng.api.networking.IGridNode; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickingRequest; +import appeng.api.util.DimensionalCoord; +import appeng.me.cache.TickManagerCache; +import appeng.parts.AEBasePart; + +public class TickTracker implements Comparable +{ + + public final TickingRequest request; + public final IGridTickable gt; + public final IGridNode node; + public final TickManagerCache host; + + public long LastFiveTicksTime = 0; + + public long lastTick; + public int current_rate; + + public TickTracker(TickingRequest req, IGridNode node, IGridTickable gt, long currentTick, TickManagerCache tickManagerCache) { + request = req; + this.gt = gt; + this.node = node; + current_rate = (req.minTickRate + req.maxTickRate) / 2; + lastTick = currentTick; + host = tickManagerCache; + } + + public long getAvgNanos() + { + return (LastFiveTicksTime / 5); + } + + public void setRate(int rate) + { + current_rate = rate; + + if ( current_rate < request.minTickRate ) + current_rate = request.minTickRate; + + if ( current_rate > request.maxTickRate ) + current_rate = request.maxTickRate; + } + + @Override + public int compareTo(TickTracker t) + { + int nextTick = (int) ((lastTick - host.getCurrentTick()) + current_rate); + int ts_nextTick = (int) ((t.lastTick - host.getCurrentTick()) + t.current_rate); + return nextTick - ts_nextTick; + } + + public void addEntityCrashInfo(CrashReportCategory crashreportcategory) + { + if ( gt instanceof AEBasePart ) + { + AEBasePart part = (AEBasePart)gt; + part.addEntityCrashInfo( crashreportcategory ); + } + + crashreportcategory.addCrashSection( "CurrentTickRate", current_rate ); + crashreportcategory.addCrashSection( "MinTickRate", request.minTickRate ); + crashreportcategory.addCrashSection( "MaxTickRate", request.maxTickRate ); + crashreportcategory.addCrashSection( "MachineType", gt.getClass().getName() ); + crashreportcategory.addCrashSection( "GridBlockType", node.getGridBlock().getClass().getName() ); + crashreportcategory.addCrashSection( "ConnectedSides", node.getConnectedSides() ); + + DimensionalCoord dc = node.getGridBlock().getLocation(); + if ( dc != null ) + crashreportcategory.addCrashSection( "Location", dc ); + } +}; diff --git a/me/cache/helpers/TunnelCollection.java b/src/main/java/appeng/me/cache/helpers/TunnelCollection.java similarity index 94% rename from me/cache/helpers/TunnelCollection.java rename to src/main/java/appeng/me/cache/helpers/TunnelCollection.java index 356e94563..05921caaa 100644 --- a/me/cache/helpers/TunnelCollection.java +++ b/src/main/java/appeng/me/cache/helpers/TunnelCollection.java @@ -1,47 +1,47 @@ -package appeng.me.cache.helpers; - -import java.util.Collection; -import java.util.Iterator; - -import appeng.parts.p2p.PartP2PTunnel; -import appeng.util.iterators.NullIterator; - -public class TunnelCollection implements Iterable -{ - - final Class clz; - Collection tunnelsource; - - public TunnelCollection(Collection src, Class c) { - tunnelsource = src; - clz = c; - } - - @Override - public Iterator iterator() - { - if ( tunnelsource == null ) - return new NullIterator(); - return new TunnelIterator( tunnelsource, clz ); - } - - public void setSource(Collection c) - { - tunnelsource = c; - } - - public boolean isEmpty() - { - return !iterator().hasNext(); - } - - public boolean matches(Class c) - { - return clz == c; - } - - public Class getClz() - { - return clz; - } -} +package appeng.me.cache.helpers; + +import java.util.Collection; +import java.util.Iterator; + +import appeng.parts.p2p.PartP2PTunnel; +import appeng.util.iterators.NullIterator; + +public class TunnelCollection implements Iterable +{ + + final Class clz; + Collection tunnelsource; + + public TunnelCollection(Collection src, Class c) { + tunnelsource = src; + clz = c; + } + + @Override + public Iterator iterator() + { + if ( tunnelsource == null ) + return new NullIterator(); + return new TunnelIterator( tunnelsource, clz ); + } + + public void setSource(Collection c) + { + tunnelsource = c; + } + + public boolean isEmpty() + { + return !iterator().hasNext(); + } + + public boolean matches(Class c) + { + return clz == c; + } + + public Class getClz() + { + return clz; + } +} diff --git a/me/cache/helpers/TunnelConnection.java b/src/main/java/appeng/me/cache/helpers/TunnelConnection.java similarity index 95% rename from me/cache/helpers/TunnelConnection.java rename to src/main/java/appeng/me/cache/helpers/TunnelConnection.java index f64f0bfd7..b152b83bb 100644 --- a/me/cache/helpers/TunnelConnection.java +++ b/src/main/java/appeng/me/cache/helpers/TunnelConnection.java @@ -1,16 +1,16 @@ -package appeng.me.cache.helpers; - -import appeng.api.networking.IGridConnection; -import appeng.parts.p2p.PartP2PTunnelME; - -public class TunnelConnection -{ - - final public PartP2PTunnelME tunnel; - final public IGridConnection c; - - public TunnelConnection(PartP2PTunnelME t, IGridConnection con) { - tunnel = t; - c = con; - } +package appeng.me.cache.helpers; + +import appeng.api.networking.IGridConnection; +import appeng.parts.p2p.PartP2PTunnelME; + +public class TunnelConnection +{ + + final public PartP2PTunnelME tunnel; + final public IGridConnection c; + + public TunnelConnection(PartP2PTunnelME t, IGridConnection con) { + tunnel = t; + c = con; + } } \ No newline at end of file diff --git a/me/cache/helpers/TunnelIterator.java b/src/main/java/appeng/me/cache/helpers/TunnelIterator.java similarity index 93% rename from me/cache/helpers/TunnelIterator.java rename to src/main/java/appeng/me/cache/helpers/TunnelIterator.java index 5375f6070..a4ec4676d 100644 --- a/me/cache/helpers/TunnelIterator.java +++ b/src/main/java/appeng/me/cache/helpers/TunnelIterator.java @@ -1,52 +1,52 @@ -package appeng.me.cache.helpers; - -import java.util.Collection; -import java.util.Iterator; - -import appeng.parts.p2p.PartP2PTunnel; - -public class TunnelIterator implements Iterator -{ - - Iterator wrapped; - Class targetType; - T Next; - - private void findNext() - { - while (Next == null && wrapped.hasNext()) - { - Next = wrapped.next(); - if ( !targetType.isInstance( Next ) ) - Next = null; - } - } - - public TunnelIterator(Collection tunnelsource, Class clz) { - wrapped = tunnelsource.iterator(); - targetType = clz; - findNext(); - } - - @Override - public boolean hasNext() - { - findNext(); - return Next != null; - } - - @Override - public T next() - { - T tmp = Next; - Next = null; - return tmp; - } - - @Override - public void remove() - { - // no. - } - -} +package appeng.me.cache.helpers; + +import java.util.Collection; +import java.util.Iterator; + +import appeng.parts.p2p.PartP2PTunnel; + +public class TunnelIterator implements Iterator +{ + + Iterator wrapped; + Class targetType; + T Next; + + private void findNext() + { + while (Next == null && wrapped.hasNext()) + { + Next = wrapped.next(); + if ( !targetType.isInstance( Next ) ) + Next = null; + } + } + + public TunnelIterator(Collection tunnelsource, Class clz) { + wrapped = tunnelsource.iterator(); + targetType = clz; + findNext(); + } + + @Override + public boolean hasNext() + { + findNext(); + return Next != null; + } + + @Override + public T next() + { + T tmp = Next; + Next = null; + return tmp; + } + + @Override + public void remove() + { + // no. + } + +} diff --git a/me/cluster/IAECluster.java b/src/main/java/appeng/me/cluster/IAECluster.java similarity index 100% rename from me/cluster/IAECluster.java rename to src/main/java/appeng/me/cluster/IAECluster.java diff --git a/me/cluster/IAEMultiBlock.java b/src/main/java/appeng/me/cluster/IAEMultiBlock.java similarity index 100% rename from me/cluster/IAEMultiBlock.java rename to src/main/java/appeng/me/cluster/IAEMultiBlock.java diff --git a/me/cluster/MBCalculator.java b/src/main/java/appeng/me/cluster/MBCalculator.java similarity index 100% rename from me/cluster/MBCalculator.java rename to src/main/java/appeng/me/cluster/MBCalculator.java diff --git a/me/cluster/implementations/CraftingCPUCalculator.java b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCalculator.java similarity index 100% rename from me/cluster/implementations/CraftingCPUCalculator.java rename to src/main/java/appeng/me/cluster/implementations/CraftingCPUCalculator.java diff --git a/me/cluster/implementations/CraftingCPUCluster.java b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java similarity index 100% rename from me/cluster/implementations/CraftingCPUCluster.java rename to src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java diff --git a/me/cluster/implementations/QuantumCalculator.java b/src/main/java/appeng/me/cluster/implementations/QuantumCalculator.java similarity index 100% rename from me/cluster/implementations/QuantumCalculator.java rename to src/main/java/appeng/me/cluster/implementations/QuantumCalculator.java diff --git a/me/cluster/implementations/QuantumCluster.java b/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java similarity index 100% rename from me/cluster/implementations/QuantumCluster.java rename to src/main/java/appeng/me/cluster/implementations/QuantumCluster.java diff --git a/me/cluster/implementations/SpatialPylonCalculator.java b/src/main/java/appeng/me/cluster/implementations/SpatialPylonCalculator.java similarity index 100% rename from me/cluster/implementations/SpatialPylonCalculator.java rename to src/main/java/appeng/me/cluster/implementations/SpatialPylonCalculator.java diff --git a/me/cluster/implementations/SpatialPylonCluster.java b/src/main/java/appeng/me/cluster/implementations/SpatialPylonCluster.java similarity index 100% rename from me/cluster/implementations/SpatialPylonCluster.java rename to src/main/java/appeng/me/cluster/implementations/SpatialPylonCluster.java diff --git a/me/energy/EnergyThreshold.java b/src/main/java/appeng/me/energy/EnergyThreshold.java similarity index 100% rename from me/energy/EnergyThreshold.java rename to src/main/java/appeng/me/energy/EnergyThreshold.java diff --git a/me/energy/EnergyWatcher.java b/src/main/java/appeng/me/energy/EnergyWatcher.java similarity index 100% rename from me/energy/EnergyWatcher.java rename to src/main/java/appeng/me/energy/EnergyWatcher.java diff --git a/me/helpers/AENetworkProxy.java b/src/main/java/appeng/me/helpers/AENetworkProxy.java similarity index 95% rename from me/helpers/AENetworkProxy.java rename to src/main/java/appeng/me/helpers/AENetworkProxy.java index 976043b32..238240806 100644 --- a/me/helpers/AENetworkProxy.java +++ b/src/main/java/appeng/me/helpers/AENetworkProxy.java @@ -1,376 +1,376 @@ -package appeng.me.helpers; - -import java.util.EnumSet; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.networking.GridFlags; -import appeng.api.networking.GridNotification; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridBlock; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.crafting.ICraftingGrid; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.events.MENetworkPowerIdleChange; -import appeng.api.networking.pathing.IPathingGrid; -import appeng.api.networking.security.ISecurityGrid; -import appeng.api.networking.storage.IStorageGrid; -import appeng.api.networking.ticking.ITickManager; -import appeng.api.util.AEColor; -import appeng.api.util.DimensionalCoord; -import appeng.api.util.IOrientable; -import appeng.core.WorldSettings; -import appeng.hooks.TickHandler; -import appeng.me.GridAccessException; -import appeng.me.cache.P2PCache; -import appeng.parts.networking.PartCable; -import appeng.tile.AEBaseTile; -import appeng.util.Platform; - -public class AENetworkProxy implements IGridBlock -{ - - final private IGridProxyable gp; - final private boolean worldNode; - - private ItemStack myRepInstance; - - private boolean isReady = false; - private IGridNode node = null; - - private EnumSet validSides; - public AEColor myColor = AEColor.Transparent; - - private EnumSet flags = EnumSet.noneOf( GridFlags.class ); - private double idleDraw = 1.0; - - final private String nbtName; // name - NBTTagCompound data = null; // input - - private EntityPlayer owner; - - @Override - public ItemStack getMachineRepresentation() - { - return myRepInstance; - } - - public void setVisualRepresentation(ItemStack is) - { - myRepInstance = is; - } - - public AENetworkProxy(IGridProxyable te, String nbtName, ItemStack visual, boolean inWorld) { - this.gp = te; - this.nbtName = nbtName; - worldNode = inWorld; - myRepInstance = visual; - validSides = EnumSet.allOf( ForgeDirection.class ); - } - - public void writeToNBT(NBTTagCompound tag) - { - if ( node != null ) - node.saveToNBT( nbtName, tag ); - } - - public void readFromNBT(NBTTagCompound tag) - { - data = tag; - if ( node != null && data != null ) - { - node.loadFromNBT( nbtName, data ); - data = null; - } - else if ( node != null && owner != null ) - { - node.setPlayerID( WorldSettings.getInstance().getPlayerID( owner.getGameProfile() ) ); - owner = null; - } - } - - @Override - public DimensionalCoord getLocation() - { - return gp.getLocation(); - } - - @Override - public AEColor getGridColor() - { - return myColor; - } - - @Override - public void onGridNotification(GridNotification notification) - { - if ( gp instanceof PartCable ) - ((PartCable) gp).markForUpdate(); - } - - @Override - public void setNetworkStatus(IGrid grid, int channelsInUse) - { - - } - - @Override - public EnumSet getConnectableSides() - { - return validSides; - } - - public void setValidSides(EnumSet validSides) - { - this.validSides = validSides; - if ( node != null ) - node.updateState(); - } - - public IGridNode getNode() - { - if ( node == null && Platform.isServer() && isReady ) - { - node = AEApi.instance().createGridNode( this ); - readFromNBT( data ); - node.updateState(); - } - - return node; - } - - public void validate() - { - if ( gp instanceof AEBaseTile ) - TickHandler.instance.addInit( (AEBaseTile) gp ); - } - - public void onChunkUnload() - { - isReady = false; - invalidate(); - } - - public void invalidate() - { - isReady = false; - if ( node != null ) - { - node.destroy(); - node = null; - } - } - - public void onReady() - { - isReady = true; - - // send orientation based directionality to the node. - if ( gp instanceof IOrientable ) - { - IOrientable ori = (IOrientable) gp; - if ( ori.canBeRotated() ) - ori.setOrientation( ori.getForward(), ori.getUp() ); - } - - getNode(); - } - - @Override - public IGridHost getMachine() - { - return gp; - } - - /** - * short cut! - * - * @return - * @throws GridAccessException - */ - public IGrid getGrid() throws GridAccessException - { - if ( node == null ) - throw new GridAccessException(); - IGrid grid = node.getGrid(); - if ( grid == null ) - throw new GridAccessException(); - return grid; - } - - public IEnergyGrid getEnergy() throws GridAccessException - { - IGrid grid = getGrid(); - if ( grid == null ) - throw new GridAccessException(); - IEnergyGrid eg = grid.getCache( IEnergyGrid.class ); - if ( eg == null ) - throw new GridAccessException(); - return eg; - } - - public IPathingGrid getPath() throws GridAccessException - { - IGrid grid = getGrid(); - if ( grid == null ) - throw new GridAccessException(); - IPathingGrid pg = grid.getCache( IPathingGrid.class ); - if ( pg == null ) - throw new GridAccessException(); - return pg; - } - - public ITickManager getTick() throws GridAccessException - { - IGrid grid = getGrid(); - if ( grid == null ) - throw new GridAccessException(); - ITickManager pg = grid.getCache( ITickManager.class ); - if ( pg == null ) - throw new GridAccessException(); - return pg; - } - - public IStorageGrid getStorage() throws GridAccessException - { - IGrid grid = getGrid(); - if ( grid == null ) - throw new GridAccessException(); - - IStorageGrid pg = grid.getCache( IStorageGrid.class ); - - if ( pg == null ) - throw new GridAccessException(); - - return pg; - } - - public P2PCache getP2P() throws GridAccessException - { - IGrid grid = getGrid(); - if ( grid == null ) - throw new GridAccessException(); - - P2PCache pg = grid.getCache( P2PCache.class ); - - if ( pg == null ) - throw new GridAccessException(); - - return pg; - } - - public ISecurityGrid getSecurity() throws GridAccessException - { - IGrid grid = getGrid(); - if ( grid == null ) - throw new GridAccessException(); - - ISecurityGrid sg = grid.getCache( ISecurityGrid.class ); - - if ( sg == null ) - throw new GridAccessException(); - - return sg; - } - - public ICraftingGrid getCrafting() throws GridAccessException - { - IGrid grid = getGrid(); - if ( grid == null ) - throw new GridAccessException(); - - ICraftingGrid sg = grid.getCache( ICraftingGrid.class ); - - if ( sg == null ) - throw new GridAccessException(); - - return sg; - } - - @Override - public boolean isWorldAccessible() - { - return worldNode; - } - - @Override - public EnumSet getFlags() - { - return flags; - } - - public void setFlags(GridFlags... requireChannel) - { - EnumSet flags = EnumSet.noneOf( GridFlags.class ); - - for (GridFlags gf : requireChannel) - flags.add( gf ); - - this.flags = flags; - } - - @Override - public double getIdlePowerUsage() - { - return idleDraw; - } - - public void setIdlePowerUsage(double idle) - { - idleDraw = idle; - - if ( node != null ) - { - try - { - IGrid g = getGrid(); - g.postEvent( new MENetworkPowerIdleChange( node ) ); - } - catch (GridAccessException e) - { - // not ready for this yet.. - } - } - } - - public boolean isReady() - { - return isReady; - } - - public boolean isActive() - { - if ( node == null ) - return false; - - return node.isActive(); - } - - public boolean isPowered() - { - try - { - return getEnergy().isNetworkPowered(); - } - catch (GridAccessException e) - { - return false; - } - } - - @Override - public void gridChanged() - { - gp.gridChanged(); - } - - public void setOwner(EntityPlayer player) - { - owner = player; - } - -} +package appeng.me.helpers; + +import java.util.EnumSet; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.networking.GridFlags; +import appeng.api.networking.GridNotification; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridBlock; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.crafting.ICraftingGrid; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.events.MENetworkPowerIdleChange; +import appeng.api.networking.pathing.IPathingGrid; +import appeng.api.networking.security.ISecurityGrid; +import appeng.api.networking.storage.IStorageGrid; +import appeng.api.networking.ticking.ITickManager; +import appeng.api.util.AEColor; +import appeng.api.util.DimensionalCoord; +import appeng.api.util.IOrientable; +import appeng.core.WorldSettings; +import appeng.hooks.TickHandler; +import appeng.me.GridAccessException; +import appeng.me.cache.P2PCache; +import appeng.parts.networking.PartCable; +import appeng.tile.AEBaseTile; +import appeng.util.Platform; + +public class AENetworkProxy implements IGridBlock +{ + + final private IGridProxyable gp; + final private boolean worldNode; + + private ItemStack myRepInstance; + + private boolean isReady = false; + private IGridNode node = null; + + private EnumSet validSides; + public AEColor myColor = AEColor.Transparent; + + private EnumSet flags = EnumSet.noneOf( GridFlags.class ); + private double idleDraw = 1.0; + + final private String nbtName; // name + NBTTagCompound data = null; // input + + private EntityPlayer owner; + + @Override + public ItemStack getMachineRepresentation() + { + return myRepInstance; + } + + public void setVisualRepresentation(ItemStack is) + { + myRepInstance = is; + } + + public AENetworkProxy(IGridProxyable te, String nbtName, ItemStack visual, boolean inWorld) { + this.gp = te; + this.nbtName = nbtName; + worldNode = inWorld; + myRepInstance = visual; + validSides = EnumSet.allOf( ForgeDirection.class ); + } + + public void writeToNBT(NBTTagCompound tag) + { + if ( node != null ) + node.saveToNBT( nbtName, tag ); + } + + public void readFromNBT(NBTTagCompound tag) + { + data = tag; + if ( node != null && data != null ) + { + node.loadFromNBT( nbtName, data ); + data = null; + } + else if ( node != null && owner != null ) + { + node.setPlayerID( WorldSettings.getInstance().getPlayerID( owner.getGameProfile() ) ); + owner = null; + } + } + + @Override + public DimensionalCoord getLocation() + { + return gp.getLocation(); + } + + @Override + public AEColor getGridColor() + { + return myColor; + } + + @Override + public void onGridNotification(GridNotification notification) + { + if ( gp instanceof PartCable ) + ((PartCable) gp).markForUpdate(); + } + + @Override + public void setNetworkStatus(IGrid grid, int channelsInUse) + { + + } + + @Override + public EnumSet getConnectableSides() + { + return validSides; + } + + public void setValidSides(EnumSet validSides) + { + this.validSides = validSides; + if ( node != null ) + node.updateState(); + } + + public IGridNode getNode() + { + if ( node == null && Platform.isServer() && isReady ) + { + node = AEApi.instance().createGridNode( this ); + readFromNBT( data ); + node.updateState(); + } + + return node; + } + + public void validate() + { + if ( gp instanceof AEBaseTile ) + TickHandler.instance.addInit( (AEBaseTile) gp ); + } + + public void onChunkUnload() + { + isReady = false; + invalidate(); + } + + public void invalidate() + { + isReady = false; + if ( node != null ) + { + node.destroy(); + node = null; + } + } + + public void onReady() + { + isReady = true; + + // send orientation based directionality to the node. + if ( gp instanceof IOrientable ) + { + IOrientable ori = (IOrientable) gp; + if ( ori.canBeRotated() ) + ori.setOrientation( ori.getForward(), ori.getUp() ); + } + + getNode(); + } + + @Override + public IGridHost getMachine() + { + return gp; + } + + /** + * short cut! + * + * @return + * @throws GridAccessException + */ + public IGrid getGrid() throws GridAccessException + { + if ( node == null ) + throw new GridAccessException(); + IGrid grid = node.getGrid(); + if ( grid == null ) + throw new GridAccessException(); + return grid; + } + + public IEnergyGrid getEnergy() throws GridAccessException + { + IGrid grid = getGrid(); + if ( grid == null ) + throw new GridAccessException(); + IEnergyGrid eg = grid.getCache( IEnergyGrid.class ); + if ( eg == null ) + throw new GridAccessException(); + return eg; + } + + public IPathingGrid getPath() throws GridAccessException + { + IGrid grid = getGrid(); + if ( grid == null ) + throw new GridAccessException(); + IPathingGrid pg = grid.getCache( IPathingGrid.class ); + if ( pg == null ) + throw new GridAccessException(); + return pg; + } + + public ITickManager getTick() throws GridAccessException + { + IGrid grid = getGrid(); + if ( grid == null ) + throw new GridAccessException(); + ITickManager pg = grid.getCache( ITickManager.class ); + if ( pg == null ) + throw new GridAccessException(); + return pg; + } + + public IStorageGrid getStorage() throws GridAccessException + { + IGrid grid = getGrid(); + if ( grid == null ) + throw new GridAccessException(); + + IStorageGrid pg = grid.getCache( IStorageGrid.class ); + + if ( pg == null ) + throw new GridAccessException(); + + return pg; + } + + public P2PCache getP2P() throws GridAccessException + { + IGrid grid = getGrid(); + if ( grid == null ) + throw new GridAccessException(); + + P2PCache pg = grid.getCache( P2PCache.class ); + + if ( pg == null ) + throw new GridAccessException(); + + return pg; + } + + public ISecurityGrid getSecurity() throws GridAccessException + { + IGrid grid = getGrid(); + if ( grid == null ) + throw new GridAccessException(); + + ISecurityGrid sg = grid.getCache( ISecurityGrid.class ); + + if ( sg == null ) + throw new GridAccessException(); + + return sg; + } + + public ICraftingGrid getCrafting() throws GridAccessException + { + IGrid grid = getGrid(); + if ( grid == null ) + throw new GridAccessException(); + + ICraftingGrid sg = grid.getCache( ICraftingGrid.class ); + + if ( sg == null ) + throw new GridAccessException(); + + return sg; + } + + @Override + public boolean isWorldAccessible() + { + return worldNode; + } + + @Override + public EnumSet getFlags() + { + return flags; + } + + public void setFlags(GridFlags... requireChannel) + { + EnumSet flags = EnumSet.noneOf( GridFlags.class ); + + for (GridFlags gf : requireChannel) + flags.add( gf ); + + this.flags = flags; + } + + @Override + public double getIdlePowerUsage() + { + return idleDraw; + } + + public void setIdlePowerUsage(double idle) + { + idleDraw = idle; + + if ( node != null ) + { + try + { + IGrid g = getGrid(); + g.postEvent( new MENetworkPowerIdleChange( node ) ); + } + catch (GridAccessException e) + { + // not ready for this yet.. + } + } + } + + public boolean isReady() + { + return isReady; + } + + public boolean isActive() + { + if ( node == null ) + return false; + + return node.isActive(); + } + + public boolean isPowered() + { + try + { + return getEnergy().isNetworkPowered(); + } + catch (GridAccessException e) + { + return false; + } + } + + @Override + public void gridChanged() + { + gp.gridChanged(); + } + + public void setOwner(EntityPlayer player) + { + owner = player; + } + +} diff --git a/me/helpers/AENetworkProxyMultiblock.java b/src/main/java/appeng/me/helpers/AENetworkProxyMultiblock.java similarity index 96% rename from me/helpers/AENetworkProxyMultiblock.java rename to src/main/java/appeng/me/helpers/AENetworkProxyMultiblock.java index 183427990..a7da1a1c9 100644 --- a/me/helpers/AENetworkProxyMultiblock.java +++ b/src/main/java/appeng/me/helpers/AENetworkProxyMultiblock.java @@ -1,33 +1,33 @@ -package appeng.me.helpers; - -import java.util.Iterator; - -import net.minecraft.item.ItemStack; -import appeng.api.networking.IGridMultiblock; -import appeng.api.networking.IGridNode; -import appeng.me.cluster.IAECluster; -import appeng.me.cluster.IAEMultiBlock; -import appeng.util.iterators.ChainedIterator; -import appeng.util.iterators.ProxyNodeIterator; - -public class AENetworkProxyMultiblock extends AENetworkProxy implements IGridMultiblock -{ - - IAECluster getCluster() - { - return ((IAEMultiBlock) getMachine()).getCluster(); - } - - public AENetworkProxyMultiblock(IGridProxyable te, String nbtName, ItemStack itemStack, boolean inWorld) { - super( te, nbtName, itemStack, inWorld ); - } - - @Override - public Iterator getMultiblockNodes() - { - if ( getCluster() == null ) - return new ChainedIterator(); - - return new ProxyNodeIterator( getCluster().getTiles() ); - } -} +package appeng.me.helpers; + +import java.util.Iterator; + +import net.minecraft.item.ItemStack; +import appeng.api.networking.IGridMultiblock; +import appeng.api.networking.IGridNode; +import appeng.me.cluster.IAECluster; +import appeng.me.cluster.IAEMultiBlock; +import appeng.util.iterators.ChainedIterator; +import appeng.util.iterators.ProxyNodeIterator; + +public class AENetworkProxyMultiblock extends AENetworkProxy implements IGridMultiblock +{ + + IAECluster getCluster() + { + return ((IAEMultiBlock) getMachine()).getCluster(); + } + + public AENetworkProxyMultiblock(IGridProxyable te, String nbtName, ItemStack itemStack, boolean inWorld) { + super( te, nbtName, itemStack, inWorld ); + } + + @Override + public Iterator getMultiblockNodes() + { + if ( getCluster() == null ) + return new ChainedIterator(); + + return new ProxyNodeIterator( getCluster().getTiles() ); + } +} diff --git a/me/helpers/ChannelPowerSrc.java b/src/main/java/appeng/me/helpers/ChannelPowerSrc.java similarity index 100% rename from me/helpers/ChannelPowerSrc.java rename to src/main/java/appeng/me/helpers/ChannelPowerSrc.java diff --git a/me/helpers/GenericInterestManager.java b/src/main/java/appeng/me/helpers/GenericInterestManager.java similarity index 100% rename from me/helpers/GenericInterestManager.java rename to src/main/java/appeng/me/helpers/GenericInterestManager.java diff --git a/me/helpers/IGridProxyable.java b/src/main/java/appeng/me/helpers/IGridProxyable.java similarity index 94% rename from me/helpers/IGridProxyable.java rename to src/main/java/appeng/me/helpers/IGridProxyable.java index d3bc415a5..67d88c776 100644 --- a/me/helpers/IGridProxyable.java +++ b/src/main/java/appeng/me/helpers/IGridProxyable.java @@ -1,14 +1,14 @@ -package appeng.me.helpers; - -import appeng.api.networking.IGridHost; -import appeng.api.util.DimensionalCoord; - -public interface IGridProxyable extends IGridHost -{ - - AENetworkProxy getProxy(); - - DimensionalCoord getLocation(); - - void gridChanged(); -} +package appeng.me.helpers; + +import appeng.api.networking.IGridHost; +import appeng.api.util.DimensionalCoord; + +public interface IGridProxyable extends IGridHost +{ + + AENetworkProxy getProxy(); + + DimensionalCoord getLocation(); + + void gridChanged(); +} diff --git a/me/pathfinding/AdHocChannelUpdater.java b/src/main/java/appeng/me/pathfinding/AdHocChannelUpdater.java similarity index 95% rename from me/pathfinding/AdHocChannelUpdater.java rename to src/main/java/appeng/me/pathfinding/AdHocChannelUpdater.java index 4ed91a39a..71bfdd5a9 100644 --- a/me/pathfinding/AdHocChannelUpdater.java +++ b/src/main/java/appeng/me/pathfinding/AdHocChannelUpdater.java @@ -1,36 +1,36 @@ -package appeng.me.pathfinding; - -import appeng.api.networking.IGridConnectionVisitor; -import appeng.api.networking.IGridConnection; -import appeng.api.networking.IGridNode; -import appeng.me.GridConnection; -import appeng.me.GridNode; - -public class AdHocChannelUpdater implements IGridConnectionVisitor -{ - - final private int usedChannels; - - public AdHocChannelUpdater(int used) { - usedChannels = used; - } - - @Override - public boolean visitNode(IGridNode n) - { - GridNode gn = (GridNode) n; - gn.setControllerRoute( null, true ); - gn.incrementChannelCount( usedChannels ); - gn.finalizeChannels(); - return true; - } - - @Override - public void visitConnection(IGridConnection gcc) - { - GridConnection gc = (GridConnection) gcc; - gc.setControllerRoute( null, true ); - gc.incrementChannelCount( usedChannels ); - gc.finalizeChannels(); - } -} +package appeng.me.pathfinding; + +import appeng.api.networking.IGridConnectionVisitor; +import appeng.api.networking.IGridConnection; +import appeng.api.networking.IGridNode; +import appeng.me.GridConnection; +import appeng.me.GridNode; + +public class AdHocChannelUpdater implements IGridConnectionVisitor +{ + + final private int usedChannels; + + public AdHocChannelUpdater(int used) { + usedChannels = used; + } + + @Override + public boolean visitNode(IGridNode n) + { + GridNode gn = (GridNode) n; + gn.setControllerRoute( null, true ); + gn.incrementChannelCount( usedChannels ); + gn.finalizeChannels(); + return true; + } + + @Override + public void visitConnection(IGridConnection gcc) + { + GridConnection gc = (GridConnection) gcc; + gc.setControllerRoute( null, true ); + gc.incrementChannelCount( usedChannels ); + gc.finalizeChannels(); + } +} diff --git a/me/pathfinding/ControllerChannelUpdater.java b/src/main/java/appeng/me/pathfinding/ControllerChannelUpdater.java similarity index 95% rename from me/pathfinding/ControllerChannelUpdater.java rename to src/main/java/appeng/me/pathfinding/ControllerChannelUpdater.java index a9d0b5a34..c9eca4023 100644 --- a/me/pathfinding/ControllerChannelUpdater.java +++ b/src/main/java/appeng/me/pathfinding/ControllerChannelUpdater.java @@ -1,26 +1,26 @@ -package appeng.me.pathfinding; - -import appeng.api.networking.IGridConnectionVisitor; -import appeng.api.networking.IGridConnection; -import appeng.api.networking.IGridNode; -import appeng.me.GridConnection; -import appeng.me.GridNode; - -public class ControllerChannelUpdater implements IGridConnectionVisitor -{ - - @Override - public boolean visitNode(IGridNode n) - { - GridNode gn = (GridNode) n; - gn.finalizeChannels(); - return true; - } - - @Override - public void visitConnection(IGridConnection gcc) - { - GridConnection gc = (GridConnection) gcc; - gc.finalizeChannels(); - } -} +package appeng.me.pathfinding; + +import appeng.api.networking.IGridConnectionVisitor; +import appeng.api.networking.IGridConnection; +import appeng.api.networking.IGridNode; +import appeng.me.GridConnection; +import appeng.me.GridNode; + +public class ControllerChannelUpdater implements IGridConnectionVisitor +{ + + @Override + public boolean visitNode(IGridNode n) + { + GridNode gn = (GridNode) n; + gn.finalizeChannels(); + return true; + } + + @Override + public void visitConnection(IGridConnection gcc) + { + GridConnection gc = (GridConnection) gcc; + gc.finalizeChannels(); + } +} diff --git a/me/pathfinding/ControllerValidator.java b/src/main/java/appeng/me/pathfinding/ControllerValidator.java similarity index 94% rename from me/pathfinding/ControllerValidator.java rename to src/main/java/appeng/me/pathfinding/ControllerValidator.java index 30551656b..30fc18604 100644 --- a/me/pathfinding/ControllerValidator.java +++ b/src/main/java/appeng/me/pathfinding/ControllerValidator.java @@ -1,59 +1,59 @@ -package appeng.me.pathfinding; - -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.IGridVisitor; -import appeng.tile.networking.TileController; - -public class ControllerValidator implements IGridVisitor -{ - - int minX; - int minY; - int minZ; - - int maxX; - int maxY; - int maxZ; - - public boolean isValid = true; - public int found = 0; - - public ControllerValidator(int x, int y, int z) { - minX = x; - minY = y; - minZ = z; - maxX = x; - maxY = y; - maxZ = z; - } - - @Override - public boolean visitNode(IGridNode n) - { - IGridHost host = n.getMachine(); - if ( isValid && host instanceof TileController ) - { - TileController c = (TileController) host; - - minX = Math.min( c.xCoord, minX ); - maxX = Math.max( c.xCoord, maxX ); - minY = Math.min( c.yCoord, minY ); - maxY = Math.max( c.yCoord, maxY ); - minZ = Math.min( c.zCoord, minZ ); - maxZ = Math.max( c.zCoord, maxZ ); - - if ( maxX - minX < 7 && maxY - minY < 7 && maxZ - minZ < 7 ) - { - found++; - return true; - } - - isValid = false; - } - else - return false; - - return isValid; - } -} +package appeng.me.pathfinding; + +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.IGridVisitor; +import appeng.tile.networking.TileController; + +public class ControllerValidator implements IGridVisitor +{ + + int minX; + int minY; + int minZ; + + int maxX; + int maxY; + int maxZ; + + public boolean isValid = true; + public int found = 0; + + public ControllerValidator(int x, int y, int z) { + minX = x; + minY = y; + minZ = z; + maxX = x; + maxY = y; + maxZ = z; + } + + @Override + public boolean visitNode(IGridNode n) + { + IGridHost host = n.getMachine(); + if ( isValid && host instanceof TileController ) + { + TileController c = (TileController) host; + + minX = Math.min( c.xCoord, minX ); + maxX = Math.max( c.xCoord, maxX ); + minY = Math.min( c.yCoord, minY ); + maxY = Math.max( c.yCoord, maxY ); + minZ = Math.min( c.zCoord, minZ ); + maxZ = Math.max( c.zCoord, maxZ ); + + if ( maxX - minX < 7 && maxY - minY < 7 && maxZ - minZ < 7 ) + { + found++; + return true; + } + + isValid = false; + } + else + return false; + + return isValid; + } +} diff --git a/me/pathfinding/IPathItem.java b/src/main/java/appeng/me/pathfinding/IPathItem.java similarity index 94% rename from me/pathfinding/IPathItem.java rename to src/main/java/appeng/me/pathfinding/IPathItem.java index 6b46941ee..eb3afaaa5 100644 --- a/me/pathfinding/IPathItem.java +++ b/src/main/java/appeng/me/pathfinding/IPathItem.java @@ -1,44 +1,44 @@ -package appeng.me.pathfinding; - -import java.util.EnumSet; - -import appeng.api.networking.GridFlags; -import appeng.api.util.IReadOnlyCollection; - -public interface IPathItem -{ - - IPathItem getControllerRoute(); - - void setControllerRoute(IPathItem fast, boolean zeroOut); - - /** - * used to determine if the finder can continue. - */ - boolean canSupportMoreChannels(); - - /** - * find possible choices for other pathing. - */ - IReadOnlyCollection getPossibleOptions(); - - /** - * add one to the channel count, this is mostly for cables. - */ - void incrementChannelCount(int usedChannels); - - /** - * get the grid flags for this IPathItem. - * - * @return the flag set. - */ - public EnumSet getFlags(); - - /** - * channels are done, wrap it up. - * - * @return - */ - void finalizeChannels(); - -} +package appeng.me.pathfinding; + +import java.util.EnumSet; + +import appeng.api.networking.GridFlags; +import appeng.api.util.IReadOnlyCollection; + +public interface IPathItem +{ + + IPathItem getControllerRoute(); + + void setControllerRoute(IPathItem fast, boolean zeroOut); + + /** + * used to determine if the finder can continue. + */ + boolean canSupportMoreChannels(); + + /** + * find possible choices for other pathing. + */ + IReadOnlyCollection getPossibleOptions(); + + /** + * add one to the channel count, this is mostly for cables. + */ + void incrementChannelCount(int usedChannels); + + /** + * get the grid flags for this IPathItem. + * + * @return the flag set. + */ + public EnumSet getFlags(); + + /** + * channels are done, wrap it up. + * + * @return + */ + void finalizeChannels(); + +} diff --git a/me/pathfinding/PathSegment.java b/src/main/java/appeng/me/pathfinding/PathSegment.java similarity index 95% rename from me/pathfinding/PathSegment.java rename to src/main/java/appeng/me/pathfinding/PathSegment.java index ca98f1252..0f514ea02 100644 --- a/me/pathfinding/PathSegment.java +++ b/src/main/java/appeng/me/pathfinding/PathSegment.java @@ -1,141 +1,141 @@ -package appeng.me.pathfinding; - -import java.util.EnumSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridMultiblock; -import appeng.api.networking.IGridNode; -import appeng.me.cache.PathGridCache; - -public class PathSegment -{ - - public boolean isDead; - - static class RouteComplete extends Exception - { - - private static final long serialVersionUID = 810456465120286110L; - - }; - - PathGridCache pgc; - - public PathSegment(PathGridCache myPGC, List open, Set semiopen, Set closed) - { - this.open = open; - this.semiopen = semiopen; - this.closed = closed; - pgc = myPGC; - isDead = false; - } - - List open; - Set semiopen; - Set closed; - - public boolean step() - { - List oldOpen = open; - open = new LinkedList(); - - for (IPathItem i : oldOpen) - { - for (IPathItem pi : i.getPossibleOptions()) - { - EnumSet flags = pi.getFlags(); - - if ( !closed.contains( pi ) ) - { - pi.setControllerRoute( i, true ); - - if ( flags.contains( GridFlags.REQUIRE_CHANNEL ) ) - { - // close the semi open. - if ( !semiopen.contains( pi ) ) - { - boolean worked = false; - - if ( flags.contains( GridFlags.COMPRESSED_CHANNEL ) ) - worked = useDenseChannel( pi ); - else - worked = useChannel( pi ); - - if ( worked && flags.contains( GridFlags.MULTIBLOCK ) ) - { - Iterator oni = ((IGridMultiblock) ((IGridNode) pi).getGridBlock()).getMultiblockNodes(); - while (oni.hasNext()) - { - IGridNode otherNodes = oni.next(); - if ( otherNodes != pi ) - semiopen.add( (IPathItem) otherNodes ); - } - } - } - else - { - pi.incrementChannelCount( 1 ); // give a channel. - semiopen.remove( pi ); - } - } - - closed.add( pi ); - open.add( pi ); - } - } - } - - return open.isEmpty(); - } - - private boolean useChannel(IPathItem start) - { - IPathItem pi = start; - while (pi != null) - { - if ( !pi.canSupportMoreChannels() ) - return false; - - pi = pi.getControllerRoute(); - } - - pi = start; - while (pi != null) - { - pgc.channelsByBlocks++; - pi.incrementChannelCount( 1 ); - pi = pi.getControllerRoute(); - } - - pgc.channelsInUse++; - return true; - } - - private boolean useDenseChannel(IPathItem start) - { - IPathItem pi = start; - while (pi != null) - { - if ( !pi.canSupportMoreChannels() || pi.getFlags().contains( GridFlags.CANNOT_CARRY_COMPRESSED ) ) - return false; - - pi = pi.getControllerRoute(); - } - - pi = start; - while (pi != null) - { - pgc.channelsByBlocks++; - pi.incrementChannelCount( 1 ); - pi = pi.getControllerRoute(); - } - - pgc.channelsInUse++; - return true; - } - -} +package appeng.me.pathfinding; + +import java.util.EnumSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGridMultiblock; +import appeng.api.networking.IGridNode; +import appeng.me.cache.PathGridCache; + +public class PathSegment +{ + + public boolean isDead; + + static class RouteComplete extends Exception + { + + private static final long serialVersionUID = 810456465120286110L; + + }; + + PathGridCache pgc; + + public PathSegment(PathGridCache myPGC, List open, Set semiopen, Set closed) + { + this.open = open; + this.semiopen = semiopen; + this.closed = closed; + pgc = myPGC; + isDead = false; + } + + List open; + Set semiopen; + Set closed; + + public boolean step() + { + List oldOpen = open; + open = new LinkedList(); + + for (IPathItem i : oldOpen) + { + for (IPathItem pi : i.getPossibleOptions()) + { + EnumSet flags = pi.getFlags(); + + if ( !closed.contains( pi ) ) + { + pi.setControllerRoute( i, true ); + + if ( flags.contains( GridFlags.REQUIRE_CHANNEL ) ) + { + // close the semi open. + if ( !semiopen.contains( pi ) ) + { + boolean worked = false; + + if ( flags.contains( GridFlags.COMPRESSED_CHANNEL ) ) + worked = useDenseChannel( pi ); + else + worked = useChannel( pi ); + + if ( worked && flags.contains( GridFlags.MULTIBLOCK ) ) + { + Iterator oni = ((IGridMultiblock) ((IGridNode) pi).getGridBlock()).getMultiblockNodes(); + while (oni.hasNext()) + { + IGridNode otherNodes = oni.next(); + if ( otherNodes != pi ) + semiopen.add( (IPathItem) otherNodes ); + } + } + } + else + { + pi.incrementChannelCount( 1 ); // give a channel. + semiopen.remove( pi ); + } + } + + closed.add( pi ); + open.add( pi ); + } + } + } + + return open.isEmpty(); + } + + private boolean useChannel(IPathItem start) + { + IPathItem pi = start; + while (pi != null) + { + if ( !pi.canSupportMoreChannels() ) + return false; + + pi = pi.getControllerRoute(); + } + + pi = start; + while (pi != null) + { + pgc.channelsByBlocks++; + pi.incrementChannelCount( 1 ); + pi = pi.getControllerRoute(); + } + + pgc.channelsInUse++; + return true; + } + + private boolean useDenseChannel(IPathItem start) + { + IPathItem pi = start; + while (pi != null) + { + if ( !pi.canSupportMoreChannels() || pi.getFlags().contains( GridFlags.CANNOT_CARRY_COMPRESSED ) ) + return false; + + pi = pi.getControllerRoute(); + } + + pi = start; + while (pi != null) + { + pgc.channelsByBlocks++; + pi.incrementChannelCount( 1 ); + pi = pi.getControllerRoute(); + } + + pgc.channelsInUse++; + return true; + } + +} diff --git a/me/storage/AEExternalHandler.java b/src/main/java/appeng/me/storage/AEExternalHandler.java similarity index 96% rename from me/storage/AEExternalHandler.java rename to src/main/java/appeng/me/storage/AEExternalHandler.java index 4edd5fcdb..d15e1901f 100644 --- a/me/storage/AEExternalHandler.java +++ b/src/main/java/appeng/me/storage/AEExternalHandler.java @@ -1,60 +1,60 @@ -package appeng.me.storage; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.implementations.tiles.ITileStorageMonitorable; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IExternalStorageHandler; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IStorageMonitorable; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEFluidStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.tile.misc.TileCondenser; - -public class AEExternalHandler implements IExternalStorageHandler -{ - - @Override - public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource mySrc) - { - if ( channel == StorageChannel.ITEMS && te instanceof ITileStorageMonitorable ) - return ((ITileStorageMonitorable) te).getMonitorable( d, mySrc ) != null; - - return te instanceof TileCondenser; - } - - @Override - public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src) - { - if ( te instanceof TileCondenser ) - { - if ( channel == StorageChannel.ITEMS ) - return new VoidItemInventory( (TileCondenser) te ); - else - return new VoidFluidInventory( (TileCondenser) te ); - } - - if ( te instanceof ITileStorageMonitorable ) - { - ITileStorageMonitorable iface = (ITileStorageMonitorable) te; - IStorageMonitorable sm = iface.getMonitorable( d, src ); - - if ( channel == StorageChannel.ITEMS && sm != null ) - { - IMEInventory ii = sm.getItemInventory(); - if ( ii != null ) - return ii; - } - - if ( channel == StorageChannel.FLUIDS && sm != null ) - { - IMEInventory fi = sm.getFluidInventory(); - if ( fi != null ) - return fi; - } - } - - return null; - } -} +package appeng.me.storage; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.implementations.tiles.ITileStorageMonitorable; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IExternalStorageHandler; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IStorageMonitorable; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.tile.misc.TileCondenser; + +public class AEExternalHandler implements IExternalStorageHandler +{ + + @Override + public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource mySrc) + { + if ( channel == StorageChannel.ITEMS && te instanceof ITileStorageMonitorable ) + return ((ITileStorageMonitorable) te).getMonitorable( d, mySrc ) != null; + + return te instanceof TileCondenser; + } + + @Override + public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src) + { + if ( te instanceof TileCondenser ) + { + if ( channel == StorageChannel.ITEMS ) + return new VoidItemInventory( (TileCondenser) te ); + else + return new VoidFluidInventory( (TileCondenser) te ); + } + + if ( te instanceof ITileStorageMonitorable ) + { + ITileStorageMonitorable iface = (ITileStorageMonitorable) te; + IStorageMonitorable sm = iface.getMonitorable( d, src ); + + if ( channel == StorageChannel.ITEMS && sm != null ) + { + IMEInventory ii = sm.getItemInventory(); + if ( ii != null ) + return ii; + } + + if ( channel == StorageChannel.FLUIDS && sm != null ) + { + IMEInventory fi = sm.getFluidInventory(); + if ( fi != null ) + return fi; + } + } + + return null; + } +} diff --git a/me/storage/CellInventory.java b/src/main/java/appeng/me/storage/CellInventory.java similarity index 100% rename from me/storage/CellInventory.java rename to src/main/java/appeng/me/storage/CellInventory.java diff --git a/me/storage/CellInventoryHandler.java b/src/main/java/appeng/me/storage/CellInventoryHandler.java similarity index 100% rename from me/storage/CellInventoryHandler.java rename to src/main/java/appeng/me/storage/CellInventoryHandler.java diff --git a/me/storage/CreativeCellInventory.java b/src/main/java/appeng/me/storage/CreativeCellInventory.java similarity index 100% rename from me/storage/CreativeCellInventory.java rename to src/main/java/appeng/me/storage/CreativeCellInventory.java diff --git a/me/storage/DriveWatcher.java b/src/main/java/appeng/me/storage/DriveWatcher.java similarity index 95% rename from me/storage/DriveWatcher.java rename to src/main/java/appeng/me/storage/DriveWatcher.java index 830bbd174..1dc4e6e9d 100644 --- a/me/storage/DriveWatcher.java +++ b/src/main/java/appeng/me/storage/DriveWatcher.java @@ -1,63 +1,63 @@ -package appeng.me.storage; - -import net.minecraft.item.ItemStack; -import appeng.api.config.Actionable; -import appeng.api.implementations.tiles.IChestOrDrive; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.ICellHandler; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.data.IAEStack; - -public class DriveWatcher> extends MEInventoryHandler -{ - - int oldStatus = 0; - final ItemStack is; - final ICellHandler handler; - final IChestOrDrive cord; - - public DriveWatcher(IMEInventory i, ItemStack is, ICellHandler han, IChestOrDrive cod) { - super( i, i.getChannel() ); - this.is = is; - handler = han; - cord = cod; - } - - @Override - public T injectItems(T input, Actionable type, BaseActionSource src) - { - long size = input.getStackSize(); - - T a = super.injectItems( input, type, src ); - - if ( a == null || a.getStackSize() != size ) - { - int newStatus = handler.getStatusForCell( is, getInternal() ); - - if ( newStatus != oldStatus ) - { - cord.blinkCell( getSlot() ); - } - } - - return a; - } - - @Override - public T extractItems(T request, Actionable type, BaseActionSource src) - { - T a = super.extractItems( request, type, src ); - - if ( a != null ) - { - int newStatus = handler.getStatusForCell( is, getInternal() ); - - if ( newStatus != oldStatus ) - { - cord.blinkCell( getSlot() ); - } - } - - return a; - } -} +package appeng.me.storage; + +import net.minecraft.item.ItemStack; +import appeng.api.config.Actionable; +import appeng.api.implementations.tiles.IChestOrDrive; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.ICellHandler; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.data.IAEStack; + +public class DriveWatcher> extends MEInventoryHandler +{ + + int oldStatus = 0; + final ItemStack is; + final ICellHandler handler; + final IChestOrDrive cord; + + public DriveWatcher(IMEInventory i, ItemStack is, ICellHandler han, IChestOrDrive cod) { + super( i, i.getChannel() ); + this.is = is; + handler = han; + cord = cod; + } + + @Override + public T injectItems(T input, Actionable type, BaseActionSource src) + { + long size = input.getStackSize(); + + T a = super.injectItems( input, type, src ); + + if ( a == null || a.getStackSize() != size ) + { + int newStatus = handler.getStatusForCell( is, getInternal() ); + + if ( newStatus != oldStatus ) + { + cord.blinkCell( getSlot() ); + } + } + + return a; + } + + @Override + public T extractItems(T request, Actionable type, BaseActionSource src) + { + T a = super.extractItems( request, type, src ); + + if ( a != null ) + { + int newStatus = handler.getStatusForCell( is, getInternal() ); + + if ( newStatus != oldStatus ) + { + cord.blinkCell( getSlot() ); + } + } + + return a; + } +} diff --git a/me/storage/ItemWatcher.java b/src/main/java/appeng/me/storage/ItemWatcher.java similarity index 94% rename from me/storage/ItemWatcher.java rename to src/main/java/appeng/me/storage/ItemWatcher.java index 08a990f68..0b65b7993 100644 --- a/me/storage/ItemWatcher.java +++ b/src/main/java/appeng/me/storage/ItemWatcher.java @@ -1,171 +1,171 @@ -package appeng.me.storage; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; - -import appeng.api.networking.storage.IStackWatcher; -import appeng.api.networking.storage.IStackWatcherHost; -import appeng.api.storage.data.IAEStack; -import appeng.me.cache.GridStorageCache; - -/** - * Maintain my interests, and a global watch list, they should always be fully synchronized. - */ -public class ItemWatcher implements IStackWatcher -{ - - class ItemWatcherIterator implements Iterator - { - - final ItemWatcher watcher; - final Iterator interestIterator; - IAEStack myLast; - - public ItemWatcherIterator(ItemWatcher parent, Iterator i) { - watcher = parent; - interestIterator = i; - } - - @Override - public boolean hasNext() - { - return interestIterator.hasNext(); - } - - @Override - public IAEStack next() - { - return myLast = interestIterator.next(); - } - - @Override - public void remove() - { - gsc.interestManager.remove( myLast, watcher ); - interestIterator.remove(); - } - - }; - - GridStorageCache gsc; - IStackWatcherHost myObject; - HashSet myInterests = new HashSet(); - - public ItemWatcher(GridStorageCache cache, IStackWatcherHost host) { - gsc = cache; - myObject = host; - } - - public IStackWatcherHost getHost() - { - return myObject; - } - - @Override - public boolean add(IAEStack e) - { - if ( myInterests.contains( e ) ) - return false; - - return myInterests.add( e.copy() ) && gsc.interestManager.put( e, this ); - } - - @Override - public boolean addAll(Collection c) - { - boolean didChange = false; - - for (IAEStack o : c) - didChange = add( o ) || didChange; - - return didChange; - } - - @Override - public void clear() - { - Iterator i = myInterests.iterator(); - while (i.hasNext()) - { - gsc.interestManager.remove( i.next(), this ); - i.remove(); - } - } - - @Override - public boolean contains(Object o) - { - return myInterests.contains( o ); - } - - @Override - public boolean containsAll(Collection c) - { - return myInterests.containsAll( c ); - } - - @Override - public boolean isEmpty() - { - return myInterests.isEmpty(); - } - - @Override - public Iterator iterator() - { - return new ItemWatcherIterator( this, myInterests.iterator() ); - } - - @Override - public boolean remove(Object o) - { - return myInterests.remove( o ) && gsc.interestManager.remove( (IAEStack)o, this ); - } - - @Override - public boolean removeAll(Collection c) - { - boolean didSomething = false; - for (Object o : c) - didSomething = remove( o ) || didSomething; - return didSomething; - } - - @Override - public boolean retainAll(Collection c) - { - boolean changed = false; - Iterator i = iterator(); - - while (i.hasNext()) - { - if ( !c.contains( i.next() ) ) - { - i.remove(); - changed = true; - } - } - - return changed; - } - - @Override - public int size() - { - return myInterests.size(); - } - - @Override - public Object[] toArray() - { - return myInterests.toArray(); - } - - @Override - public T[] toArray(T[] a) - { - return myInterests.toArray( a ); - } - -} +package appeng.me.storage; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; + +import appeng.api.networking.storage.IStackWatcher; +import appeng.api.networking.storage.IStackWatcherHost; +import appeng.api.storage.data.IAEStack; +import appeng.me.cache.GridStorageCache; + +/** + * Maintain my interests, and a global watch list, they should always be fully synchronized. + */ +public class ItemWatcher implements IStackWatcher +{ + + class ItemWatcherIterator implements Iterator + { + + final ItemWatcher watcher; + final Iterator interestIterator; + IAEStack myLast; + + public ItemWatcherIterator(ItemWatcher parent, Iterator i) { + watcher = parent; + interestIterator = i; + } + + @Override + public boolean hasNext() + { + return interestIterator.hasNext(); + } + + @Override + public IAEStack next() + { + return myLast = interestIterator.next(); + } + + @Override + public void remove() + { + gsc.interestManager.remove( myLast, watcher ); + interestIterator.remove(); + } + + }; + + GridStorageCache gsc; + IStackWatcherHost myObject; + HashSet myInterests = new HashSet(); + + public ItemWatcher(GridStorageCache cache, IStackWatcherHost host) { + gsc = cache; + myObject = host; + } + + public IStackWatcherHost getHost() + { + return myObject; + } + + @Override + public boolean add(IAEStack e) + { + if ( myInterests.contains( e ) ) + return false; + + return myInterests.add( e.copy() ) && gsc.interestManager.put( e, this ); + } + + @Override + public boolean addAll(Collection c) + { + boolean didChange = false; + + for (IAEStack o : c) + didChange = add( o ) || didChange; + + return didChange; + } + + @Override + public void clear() + { + Iterator i = myInterests.iterator(); + while (i.hasNext()) + { + gsc.interestManager.remove( i.next(), this ); + i.remove(); + } + } + + @Override + public boolean contains(Object o) + { + return myInterests.contains( o ); + } + + @Override + public boolean containsAll(Collection c) + { + return myInterests.containsAll( c ); + } + + @Override + public boolean isEmpty() + { + return myInterests.isEmpty(); + } + + @Override + public Iterator iterator() + { + return new ItemWatcherIterator( this, myInterests.iterator() ); + } + + @Override + public boolean remove(Object o) + { + return myInterests.remove( o ) && gsc.interestManager.remove( (IAEStack)o, this ); + } + + @Override + public boolean removeAll(Collection c) + { + boolean didSomething = false; + for (Object o : c) + didSomething = remove( o ) || didSomething; + return didSomething; + } + + @Override + public boolean retainAll(Collection c) + { + boolean changed = false; + Iterator i = iterator(); + + while (i.hasNext()) + { + if ( !c.contains( i.next() ) ) + { + i.remove(); + changed = true; + } + } + + return changed; + } + + @Override + public int size() + { + return myInterests.size(); + } + + @Override + public Object[] toArray() + { + return myInterests.toArray(); + } + + @Override + public T[] toArray(T[] a) + { + return myInterests.toArray( a ); + } + +} diff --git a/me/storage/MEIInventoryWrapper.java b/src/main/java/appeng/me/storage/MEIInventoryWrapper.java similarity index 100% rename from me/storage/MEIInventoryWrapper.java rename to src/main/java/appeng/me/storage/MEIInventoryWrapper.java diff --git a/me/storage/MEInventoryHandler.java b/src/main/java/appeng/me/storage/MEInventoryHandler.java similarity index 96% rename from me/storage/MEInventoryHandler.java rename to src/main/java/appeng/me/storage/MEInventoryHandler.java index 0b05c57fc..8bc33a730 100644 --- a/me/storage/MEInventoryHandler.java +++ b/src/main/java/appeng/me/storage/MEInventoryHandler.java @@ -1,122 +1,122 @@ -package appeng.me.storage; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.IncludeExclude; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; -import appeng.util.prioitylist.DefaultPriorityList; -import appeng.util.prioitylist.IPartitionList; - -public class MEInventoryHandler> implements IMEInventoryHandler -{ - - final StorageChannel channel; - final protected IMEMonitor monitor; - final protected IMEInventoryHandler internal; - - public int myPriority = 0; - public IncludeExclude myWhitelist = IncludeExclude.WHITELIST; - public AccessRestriction myAccess = AccessRestriction.READ_WRITE; - public IPartitionList myPartitionList = new DefaultPriorityList(); - - public MEInventoryHandler(IMEInventory i, StorageChannel channel) { - this.channel = channel; - - if ( i instanceof IMEInventoryHandler ) - internal = (IMEInventoryHandler) i; - else - internal = new MEPassthru( i, channel ); - - monitor = internal instanceof IMEMonitor ? (IMEMonitor) internal : null; - } - - @Override - public T injectItems(T input, Actionable type, BaseActionSource src) - { - if ( !this.canAccept( input ) ) - return input; - - return internal.injectItems( input, type, src ); - } - - @Override - public T extractItems(T request, Actionable type, BaseActionSource src) - { - if ( !getAccess().hasPermission( AccessRestriction.READ ) ) - return null; - - return internal.extractItems( request, type, src ); - } - - @Override - public IItemList getAvailableItems(IItemList out) - { - if ( !getAccess().hasPermission( AccessRestriction.READ ) ) - return out; - - return internal.getAvailableItems( out ); - } - - @Override - public StorageChannel getChannel() - { - return internal.getChannel(); - } - - @Override - public AccessRestriction getAccess() - { - return myAccess.restrictPermissions( internal.getAccess() ); - } - - @Override - public boolean isPrioritized(T input) - { - if ( myWhitelist == IncludeExclude.WHITELIST ) - return myPartitionList.isListed( input ) || internal.isPrioritized( input ); - return false; - } - - @Override - public boolean canAccept(T input) - { - if ( !getAccess().hasPermission( AccessRestriction.WRITE ) ) - return false; - - if ( myWhitelist == IncludeExclude.BLACKLIST && myPartitionList.isListed( input ) ) - return false; - if ( myPartitionList.isEmpty() || myWhitelist == IncludeExclude.BLACKLIST ) - return internal.canAccept( input ); - return myPartitionList.isListed( input ) && internal.canAccept( input ); - } - - @Override - public int getPriority() - { - return myPriority; - } - - @Override - public int getSlot() - { - return internal.getSlot(); - } - - public IMEInventory getInternal() - { - return internal; - } - - @Override - public boolean validForPass(int i) - { - return true; - } - -} +package appeng.me.storage; + +import appeng.api.config.AccessRestriction; +import appeng.api.config.Actionable; +import appeng.api.config.IncludeExclude; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; +import appeng.util.prioitylist.DefaultPriorityList; +import appeng.util.prioitylist.IPartitionList; + +public class MEInventoryHandler> implements IMEInventoryHandler +{ + + final StorageChannel channel; + final protected IMEMonitor monitor; + final protected IMEInventoryHandler internal; + + public int myPriority = 0; + public IncludeExclude myWhitelist = IncludeExclude.WHITELIST; + public AccessRestriction myAccess = AccessRestriction.READ_WRITE; + public IPartitionList myPartitionList = new DefaultPriorityList(); + + public MEInventoryHandler(IMEInventory i, StorageChannel channel) { + this.channel = channel; + + if ( i instanceof IMEInventoryHandler ) + internal = (IMEInventoryHandler) i; + else + internal = new MEPassthru( i, channel ); + + monitor = internal instanceof IMEMonitor ? (IMEMonitor) internal : null; + } + + @Override + public T injectItems(T input, Actionable type, BaseActionSource src) + { + if ( !this.canAccept( input ) ) + return input; + + return internal.injectItems( input, type, src ); + } + + @Override + public T extractItems(T request, Actionable type, BaseActionSource src) + { + if ( !getAccess().hasPermission( AccessRestriction.READ ) ) + return null; + + return internal.extractItems( request, type, src ); + } + + @Override + public IItemList getAvailableItems(IItemList out) + { + if ( !getAccess().hasPermission( AccessRestriction.READ ) ) + return out; + + return internal.getAvailableItems( out ); + } + + @Override + public StorageChannel getChannel() + { + return internal.getChannel(); + } + + @Override + public AccessRestriction getAccess() + { + return myAccess.restrictPermissions( internal.getAccess() ); + } + + @Override + public boolean isPrioritized(T input) + { + if ( myWhitelist == IncludeExclude.WHITELIST ) + return myPartitionList.isListed( input ) || internal.isPrioritized( input ); + return false; + } + + @Override + public boolean canAccept(T input) + { + if ( !getAccess().hasPermission( AccessRestriction.WRITE ) ) + return false; + + if ( myWhitelist == IncludeExclude.BLACKLIST && myPartitionList.isListed( input ) ) + return false; + if ( myPartitionList.isEmpty() || myWhitelist == IncludeExclude.BLACKLIST ) + return internal.canAccept( input ); + return myPartitionList.isListed( input ) && internal.canAccept( input ); + } + + @Override + public int getPriority() + { + return myPriority; + } + + @Override + public int getSlot() + { + return internal.getSlot(); + } + + public IMEInventory getInternal() + { + return internal; + } + + @Override + public boolean validForPass(int i) + { + return true; + } + +} diff --git a/me/storage/MEMonitorIInventory.java b/src/main/java/appeng/me/storage/MEMonitorIInventory.java similarity index 95% rename from me/storage/MEMonitorIInventory.java rename to src/main/java/appeng/me/storage/MEMonitorIInventory.java index 4200eb181..c6ec818ca 100644 --- a/me/storage/MEMonitorIInventory.java +++ b/src/main/java/appeng/me/storage/MEMonitorIInventory.java @@ -1,290 +1,290 @@ -package appeng.me.storage; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map.Entry; -import java.util.NavigableMap; -import java.util.TreeMap; - -import net.minecraft.item.ItemStack; -import appeng.api.AEApi; -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.StorageFilter; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IMEMonitorHandlerReceiver; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.ItemSlot; - -public class MEMonitorIInventory implements IMEInventory, IMEMonitor -{ - - class CachedItemStack - { - - public CachedItemStack(ItemStack is) - { - if ( is == null ) - { - itemStack = null; - aeStack = null; - } - else - { - itemStack = is.copy(); - aeStack = AEApi.instance().storage().createItemStack( is ); - } - } - - final ItemStack itemStack; - final IAEItemStack aeStack; - }; - - final InventoryAdaptor adaptor; - - final TreeMap memory; - final IItemList list = AEApi.instance().storage().createItemList(); - final HashMap, Object> listeners = new HashMap(); - - public BaseActionSource mySource; - public StorageFilter mode = StorageFilter.EXTRACTABLE_ONLY; - - @Override - public void addListener(IMEMonitorHandlerReceiver l, Object verificationToken) - { - listeners.put( l, verificationToken ); - } - - @Override - public void removeListener(IMEMonitorHandlerReceiver l) - { - listeners.remove( l ); - } - - public MEMonitorIInventory(InventoryAdaptor adaptor) - { - this.adaptor = adaptor; - memory = new TreeMap(); - } - - @Override - public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) - { - ItemStack out = null; - - if ( type == Actionable.SIMULATE ) - out = adaptor.simulateAdd( input.getItemStack() ); - else - out = adaptor.addItems( input.getItemStack() ); - - onTick(); - - if ( out == null ) - return null; - - // better then doing construction from scratch :3 - IAEItemStack o = input.copy(); - o.setStackSize( out.stackSize ); - return o; - } - - @Override - public AccessRestriction getAccess() - { - return AccessRestriction.READ_WRITE; - } - - @Override - public boolean isPrioritized(IAEItemStack input) - { - return false; - } - - @Override - public boolean canAccept(IAEItemStack input) - { - return true; - } - - @Override - public int getPriority() - { - return 0; - } - - @Override - public int getSlot() - { - return 0; - } - - @Override - public IItemList getStorageList() - { - return list; - } - - @Override - public IItemList getAvailableItems(IItemList out) - { - for (CachedItemStack is : memory.values()) - out.addStorage( is.aeStack ); - - return out; - } - - @Override - public IAEItemStack extractItems(IAEItemStack request, Actionable type, BaseActionSource src) - { - ItemStack out = null; - - if ( type == Actionable.SIMULATE ) - out = adaptor.simulateRemove( (int) request.getStackSize(), request.getItemStack(), null ); - else - out = adaptor.removeItems( (int) request.getStackSize(), request.getItemStack(), null ); - - if ( out == null ) - return null; - - // better then doing construction from scratch :3 - IAEItemStack o = request.copy(); - o.setStackSize( out.stackSize ); - - onTick(); - - return o; - } - - public TickRateModulation onTick() - { - boolean changed = false; - - LinkedList changes = new LinkedList(); - - int high = 0; - list.resetStatus(); - for (ItemSlot is : adaptor) - { - CachedItemStack old = memory.get( is.slot ); - high = Math.max( high, is.slot ); - - ItemStack newIS = is == null || is.isExtractable == false && mode == StorageFilter.EXTRACTABLE_ONLY ? null : is.getItemStack(); - ItemStack oldIS = old == null ? null : old.itemStack; - - if ( isDifferent( newIS, oldIS ) ) - { - CachedItemStack cis = new CachedItemStack( is.getItemStack() ); - memory.put( is.slot, cis ); - - if ( old != null && old.aeStack != null ) - { - old.aeStack.setStackSize( -old.aeStack.getStackSize() ); - changes.add( old.aeStack ); - } - - if ( cis != null && cis.aeStack != null ) - { - changes.add( cis.aeStack ); - list.add( cis.aeStack ); - } - - changed = true; - } - else if ( is != null ) - { - int newSize = (newIS == null ? 0 : newIS.stackSize); - int diff = newSize - (oldIS == null ? 0 : oldIS.stackSize); - - IAEItemStack stack = (old == null || old.aeStack == null ? AEApi.instance().storage().createItemStack( newIS ) : old.aeStack.copy()); - if ( stack != null ) - { - stack.setStackSize( newSize ); - list.add( stack ); - } - - if ( diff != 0 && stack != null ) - { - CachedItemStack cis = new CachedItemStack( is.getItemStack() ); - memory.put( is.slot, cis ); - - IAEItemStack a = stack.copy(); - a.setStackSize( diff ); - changes.add( a ); - changed = true; - } - } - } - - // detect dropped items; should fix non IISided Inventory Changes. - NavigableMap end = memory.tailMap( high, false ); - if ( !end.isEmpty() ) - { - for (CachedItemStack cis : end.values()) - { - if ( cis != null && cis.aeStack != null ) - { - IAEItemStack a = cis.aeStack.copy(); - a.setStackSize( -a.getStackSize() ); - changes.add( a ); - changed = true; - } - } - end.clear(); - } - - if ( !changes.isEmpty() ) - postDifference( changes ); - - return changed ? TickRateModulation.URGENT : TickRateModulation.SLOWER; - } - - private boolean isDifferent(ItemStack a, ItemStack b) - { - if ( a == b && b == null ) - return false; - - if ( (a == null && b != null) || (a != null && b == null) ) - return true; - - return !Platform.isSameItemPrecise( a, b ); - } - - private void postDifference(Iterable a) - { - // AELog.info( a.getItemStack().getUnlocalizedName() + " @ " + a.getStackSize() ); - if ( a != null ) - { - Iterator, Object>> i = listeners.entrySet().iterator(); - while (i.hasNext()) - { - Entry, Object> l = i.next(); - IMEMonitorHandlerReceiver key = l.getKey(); - if ( key.isValid( l.getValue() ) ) - key.postChange( this, a, mySource ); - else - i.remove(); - } - } - } - - @Override - public StorageChannel getChannel() - { - return StorageChannel.ITEMS; - } - - @Override - public boolean validForPass(int i) - { - return true; - } - -} +package appeng.me.storage; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map.Entry; +import java.util.NavigableMap; +import java.util.TreeMap; + +import net.minecraft.item.ItemStack; +import appeng.api.AEApi; +import appeng.api.config.AccessRestriction; +import appeng.api.config.Actionable; +import appeng.api.config.StorageFilter; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.IMEMonitorHandlerReceiver; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.util.InventoryAdaptor; +import appeng.util.Platform; +import appeng.util.inv.ItemSlot; + +public class MEMonitorIInventory implements IMEInventory, IMEMonitor +{ + + class CachedItemStack + { + + public CachedItemStack(ItemStack is) + { + if ( is == null ) + { + itemStack = null; + aeStack = null; + } + else + { + itemStack = is.copy(); + aeStack = AEApi.instance().storage().createItemStack( is ); + } + } + + final ItemStack itemStack; + final IAEItemStack aeStack; + }; + + final InventoryAdaptor adaptor; + + final TreeMap memory; + final IItemList list = AEApi.instance().storage().createItemList(); + final HashMap, Object> listeners = new HashMap(); + + public BaseActionSource mySource; + public StorageFilter mode = StorageFilter.EXTRACTABLE_ONLY; + + @Override + public void addListener(IMEMonitorHandlerReceiver l, Object verificationToken) + { + listeners.put( l, verificationToken ); + } + + @Override + public void removeListener(IMEMonitorHandlerReceiver l) + { + listeners.remove( l ); + } + + public MEMonitorIInventory(InventoryAdaptor adaptor) + { + this.adaptor = adaptor; + memory = new TreeMap(); + } + + @Override + public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) + { + ItemStack out = null; + + if ( type == Actionable.SIMULATE ) + out = adaptor.simulateAdd( input.getItemStack() ); + else + out = adaptor.addItems( input.getItemStack() ); + + onTick(); + + if ( out == null ) + return null; + + // better then doing construction from scratch :3 + IAEItemStack o = input.copy(); + o.setStackSize( out.stackSize ); + return o; + } + + @Override + public AccessRestriction getAccess() + { + return AccessRestriction.READ_WRITE; + } + + @Override + public boolean isPrioritized(IAEItemStack input) + { + return false; + } + + @Override + public boolean canAccept(IAEItemStack input) + { + return true; + } + + @Override + public int getPriority() + { + return 0; + } + + @Override + public int getSlot() + { + return 0; + } + + @Override + public IItemList getStorageList() + { + return list; + } + + @Override + public IItemList getAvailableItems(IItemList out) + { + for (CachedItemStack is : memory.values()) + out.addStorage( is.aeStack ); + + return out; + } + + @Override + public IAEItemStack extractItems(IAEItemStack request, Actionable type, BaseActionSource src) + { + ItemStack out = null; + + if ( type == Actionable.SIMULATE ) + out = adaptor.simulateRemove( (int) request.getStackSize(), request.getItemStack(), null ); + else + out = adaptor.removeItems( (int) request.getStackSize(), request.getItemStack(), null ); + + if ( out == null ) + return null; + + // better then doing construction from scratch :3 + IAEItemStack o = request.copy(); + o.setStackSize( out.stackSize ); + + onTick(); + + return o; + } + + public TickRateModulation onTick() + { + boolean changed = false; + + LinkedList changes = new LinkedList(); + + int high = 0; + list.resetStatus(); + for (ItemSlot is : adaptor) + { + CachedItemStack old = memory.get( is.slot ); + high = Math.max( high, is.slot ); + + ItemStack newIS = is == null || is.isExtractable == false && mode == StorageFilter.EXTRACTABLE_ONLY ? null : is.getItemStack(); + ItemStack oldIS = old == null ? null : old.itemStack; + + if ( isDifferent( newIS, oldIS ) ) + { + CachedItemStack cis = new CachedItemStack( is.getItemStack() ); + memory.put( is.slot, cis ); + + if ( old != null && old.aeStack != null ) + { + old.aeStack.setStackSize( -old.aeStack.getStackSize() ); + changes.add( old.aeStack ); + } + + if ( cis != null && cis.aeStack != null ) + { + changes.add( cis.aeStack ); + list.add( cis.aeStack ); + } + + changed = true; + } + else if ( is != null ) + { + int newSize = (newIS == null ? 0 : newIS.stackSize); + int diff = newSize - (oldIS == null ? 0 : oldIS.stackSize); + + IAEItemStack stack = (old == null || old.aeStack == null ? AEApi.instance().storage().createItemStack( newIS ) : old.aeStack.copy()); + if ( stack != null ) + { + stack.setStackSize( newSize ); + list.add( stack ); + } + + if ( diff != 0 && stack != null ) + { + CachedItemStack cis = new CachedItemStack( is.getItemStack() ); + memory.put( is.slot, cis ); + + IAEItemStack a = stack.copy(); + a.setStackSize( diff ); + changes.add( a ); + changed = true; + } + } + } + + // detect dropped items; should fix non IISided Inventory Changes. + NavigableMap end = memory.tailMap( high, false ); + if ( !end.isEmpty() ) + { + for (CachedItemStack cis : end.values()) + { + if ( cis != null && cis.aeStack != null ) + { + IAEItemStack a = cis.aeStack.copy(); + a.setStackSize( -a.getStackSize() ); + changes.add( a ); + changed = true; + } + } + end.clear(); + } + + if ( !changes.isEmpty() ) + postDifference( changes ); + + return changed ? TickRateModulation.URGENT : TickRateModulation.SLOWER; + } + + private boolean isDifferent(ItemStack a, ItemStack b) + { + if ( a == b && b == null ) + return false; + + if ( (a == null && b != null) || (a != null && b == null) ) + return true; + + return !Platform.isSameItemPrecise( a, b ); + } + + private void postDifference(Iterable a) + { + // AELog.info( a.getItemStack().getUnlocalizedName() + " @ " + a.getStackSize() ); + if ( a != null ) + { + Iterator, Object>> i = listeners.entrySet().iterator(); + while (i.hasNext()) + { + Entry, Object> l = i.next(); + IMEMonitorHandlerReceiver key = l.getKey(); + if ( key.isValid( l.getValue() ) ) + key.postChange( this, a, mySource ); + else + i.remove(); + } + } + } + + @Override + public StorageChannel getChannel() + { + return StorageChannel.ITEMS; + } + + @Override + public boolean validForPass(int i) + { + return true; + } + +} diff --git a/me/storage/MEMonitorPassthu.java b/src/main/java/appeng/me/storage/MEMonitorPassthu.java similarity index 96% rename from me/storage/MEMonitorPassthu.java rename to src/main/java/appeng/me/storage/MEMonitorPassthu.java index 3587e30a1..366149071 100644 --- a/me/storage/MEMonitorPassthu.java +++ b/src/main/java/appeng/me/storage/MEMonitorPassthu.java @@ -1,121 +1,121 @@ -package appeng.me.storage; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; - -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IMEMonitorHandlerReceiver; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; -import appeng.util.Platform; -import appeng.util.inv.ItemListIgnoreCrafting; - -public class MEMonitorPassthu> extends MEPassthru implements IMEMonitor, IMEMonitorHandlerReceiver -{ - - HashMap, Object> listeners = new HashMap(); - IMEMonitor monitor; - - public BaseActionSource changeSource; - - public MEMonitorPassthu(IMEInventory i, StorageChannel channel) { - super( i, channel ); - if ( i instanceof IMEMonitor ) - monitor = (IMEMonitor) i; - } - - @Override - public void setInternal(IMEInventory i) - { - if ( monitor != null ) - monitor.removeListener( this ); - - monitor = null; - IItemList before = getInternal() == null ? channel.createList() : getInternal() - .getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); - - super.setInternal( i ); - if ( i instanceof IMEMonitor ) - monitor = (IMEMonitor) i; - - IItemList after = getInternal() == null ? channel.createList() : getInternal() - .getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); - - if ( monitor != null ) - monitor.addListener( this, monitor ); - - Platform.postListChanges( before, after, this, changeSource ); - } - - @Override - public IItemList getAvailableItems(IItemList out) - { - super.getAvailableItems( new ItemListIgnoreCrafting( out ) ); - return out; - } - - @Override - public void addListener(IMEMonitorHandlerReceiver l, Object verificationToken) - { - listeners.put( l, verificationToken ); - } - - @Override - public void removeListener(IMEMonitorHandlerReceiver l) - { - listeners.remove( l ); - } - - @Override - public IItemList getStorageList() - { - if ( monitor == null ) - { - IItemList out = channel.createList(); - getInternal().getAvailableItems( new ItemListIgnoreCrafting( out ) ); - return out; - } - return monitor.getStorageList(); - } - - @Override - public boolean isValid(Object verificationToken) - { - return verificationToken == monitor; - } - - @Override - public void postChange(IBaseMonitor monitor, Iterable change, BaseActionSource source) - { - Iterator, Object>> i = listeners.entrySet().iterator(); - while (i.hasNext()) - { - Entry, Object> e = i.next(); - IMEMonitorHandlerReceiver recv = e.getKey(); - if ( recv.isValid( e.getValue() ) ) - recv.postChange( this, change, source ); - else - i.remove(); - } - } - - @Override - public void onListUpdate() - { - Iterator, Object>> i = listeners.entrySet().iterator(); - while (i.hasNext()) - { - Entry, Object> e = i.next(); - IMEMonitorHandlerReceiver recv = e.getKey(); - if ( recv.isValid( e.getValue() ) ) - recv.onListUpdate(); - else - i.remove(); - } - } -} +package appeng.me.storage; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; + +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.storage.IBaseMonitor; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.IMEMonitorHandlerReceiver; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; +import appeng.util.Platform; +import appeng.util.inv.ItemListIgnoreCrafting; + +public class MEMonitorPassthu> extends MEPassthru implements IMEMonitor, IMEMonitorHandlerReceiver +{ + + HashMap, Object> listeners = new HashMap(); + IMEMonitor monitor; + + public BaseActionSource changeSource; + + public MEMonitorPassthu(IMEInventory i, StorageChannel channel) { + super( i, channel ); + if ( i instanceof IMEMonitor ) + monitor = (IMEMonitor) i; + } + + @Override + public void setInternal(IMEInventory i) + { + if ( monitor != null ) + monitor.removeListener( this ); + + monitor = null; + IItemList before = getInternal() == null ? channel.createList() : getInternal() + .getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); + + super.setInternal( i ); + if ( i instanceof IMEMonitor ) + monitor = (IMEMonitor) i; + + IItemList after = getInternal() == null ? channel.createList() : getInternal() + .getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); + + if ( monitor != null ) + monitor.addListener( this, monitor ); + + Platform.postListChanges( before, after, this, changeSource ); + } + + @Override + public IItemList getAvailableItems(IItemList out) + { + super.getAvailableItems( new ItemListIgnoreCrafting( out ) ); + return out; + } + + @Override + public void addListener(IMEMonitorHandlerReceiver l, Object verificationToken) + { + listeners.put( l, verificationToken ); + } + + @Override + public void removeListener(IMEMonitorHandlerReceiver l) + { + listeners.remove( l ); + } + + @Override + public IItemList getStorageList() + { + if ( monitor == null ) + { + IItemList out = channel.createList(); + getInternal().getAvailableItems( new ItemListIgnoreCrafting( out ) ); + return out; + } + return monitor.getStorageList(); + } + + @Override + public boolean isValid(Object verificationToken) + { + return verificationToken == monitor; + } + + @Override + public void postChange(IBaseMonitor monitor, Iterable change, BaseActionSource source) + { + Iterator, Object>> i = listeners.entrySet().iterator(); + while (i.hasNext()) + { + Entry, Object> e = i.next(); + IMEMonitorHandlerReceiver recv = e.getKey(); + if ( recv.isValid( e.getValue() ) ) + recv.postChange( this, change, source ); + else + i.remove(); + } + } + + @Override + public void onListUpdate() + { + Iterator, Object>> i = listeners.entrySet().iterator(); + while (i.hasNext()) + { + Entry, Object> e = i.next(); + IMEMonitorHandlerReceiver recv = e.getKey(); + if ( recv.isValid( e.getValue() ) ) + recv.onListUpdate(); + else + i.remove(); + } + } +} diff --git a/me/storage/MEPassthru.java b/src/main/java/appeng/me/storage/MEPassthru.java similarity index 94% rename from me/storage/MEPassthru.java rename to src/main/java/appeng/me/storage/MEPassthru.java index 7e0756ad6..1763c8165 100644 --- a/me/storage/MEPassthru.java +++ b/src/main/java/appeng/me/storage/MEPassthru.java @@ -1,93 +1,93 @@ -package appeng.me.storage; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; - -public class MEPassthru> implements IMEInventoryHandler -{ - - private IMEInventory internal; - final protected StorageChannel channel; - - protected IMEInventory getInternal() - { - return internal; - } - - public MEPassthru(IMEInventory i, StorageChannel channel) { - this.channel = channel; - setInternal( i ); - } - - public void setInternal(IMEInventory i) - { - internal = i; - } - - @Override - public T injectItems(T input, Actionable type, BaseActionSource src) - { - return internal.injectItems( input, type, src ); - } - - @Override - public T extractItems(T request, Actionable type, BaseActionSource src) - { - return internal.extractItems( request, type, src ); - } - - @Override - public IItemList getAvailableItems(IItemList out) - { - return internal.getAvailableItems( out ); - } - - @Override - public StorageChannel getChannel() - { - return internal.getChannel(); - } - - @Override - public AccessRestriction getAccess() - { - return AccessRestriction.READ_WRITE; - } - - @Override - public boolean isPrioritized(T input) - { - return false; - } - - @Override - public boolean canAccept(T input) - { - return true; - } - - @Override - public int getPriority() - { - return 0; - } - - @Override - public int getSlot() - { - return 0; - } - - @Override - public boolean validForPass(int i) - { - return true; - } - -} +package appeng.me.storage; + +import appeng.api.config.AccessRestriction; +import appeng.api.config.Actionable; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IMEInventory; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; + +public class MEPassthru> implements IMEInventoryHandler +{ + + private IMEInventory internal; + final protected StorageChannel channel; + + protected IMEInventory getInternal() + { + return internal; + } + + public MEPassthru(IMEInventory i, StorageChannel channel) { + this.channel = channel; + setInternal( i ); + } + + public void setInternal(IMEInventory i) + { + internal = i; + } + + @Override + public T injectItems(T input, Actionable type, BaseActionSource src) + { + return internal.injectItems( input, type, src ); + } + + @Override + public T extractItems(T request, Actionable type, BaseActionSource src) + { + return internal.extractItems( request, type, src ); + } + + @Override + public IItemList getAvailableItems(IItemList out) + { + return internal.getAvailableItems( out ); + } + + @Override + public StorageChannel getChannel() + { + return internal.getChannel(); + } + + @Override + public AccessRestriction getAccess() + { + return AccessRestriction.READ_WRITE; + } + + @Override + public boolean isPrioritized(T input) + { + return false; + } + + @Override + public boolean canAccept(T input) + { + return true; + } + + @Override + public int getPriority() + { + return 0; + } + + @Override + public int getSlot() + { + return 0; + } + + @Override + public boolean validForPass(int i) + { + return true; + } + +} diff --git a/me/storage/NetworkInventoryHandler.java b/src/main/java/appeng/me/storage/NetworkInventoryHandler.java similarity index 95% rename from me/storage/NetworkInventoryHandler.java rename to src/main/java/appeng/me/storage/NetworkInventoryHandler.java index fa2450c3b..9f7cfca4b 100644 --- a/me/storage/NetworkInventoryHandler.java +++ b/src/main/java/appeng/me/storage/NetworkInventoryHandler.java @@ -1,287 +1,287 @@ -package appeng.me.storage; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.TreeMap; - -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.SecurityPermissions; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.security.ISecurityGrid; -import appeng.api.networking.security.MachineSource; -import appeng.api.networking.security.PlayerSource; -import appeng.api.storage.IMEInventoryHandler; -import appeng.api.storage.StorageChannel; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; -import appeng.me.cache.SecurityCache; -import appeng.util.ItemSorters; - -public class NetworkInventoryHandler> implements IMEInventoryHandler -{ - - private final static Comparator prioritySorter = new Comparator() { - - @Override - public int compare(Integer o1, Integer o2) - { - return ItemSorters.compareInt( o2, o1 ); - } - - }; - - final StorageChannel myChannel; - final SecurityCache security; - - // final TreeMultimap> priorityInventory; - final TreeMap>> priorityInventory; - - public NetworkInventoryHandler(StorageChannel chan, SecurityCache security) { - myChannel = chan; - this.security = security; - priorityInventory = new TreeMap( prioritySorter ); // TreeMultimap.create( prioritySorter, hashSorter ); - } - - public void addNewStorage(IMEInventoryHandler h) - { - int priority = h.getPriority(); - List> list = priorityInventory.get( priority ); - if ( list == null ) - priorityInventory.put( priority, list = new ArrayList() ); - - list.add( h ); - } - - static int currentPass = 0; - int myPass = 0; - static final ThreadLocal depthMod = new ThreadLocal(); - static final ThreadLocal depthSim = new ThreadLocal(); - - private LinkedList getDepth(Actionable type) - { - ThreadLocal depth = type == Actionable.MODULATE ? depthMod : depthSim; - - LinkedList s = depth.get(); - - if ( s == null ) - depth.set( s = new LinkedList() ); - - return s; - } - - private boolean diveList(NetworkInventoryHandler networkInventoryHandler, Actionable type) - { - LinkedList cDepth = getDepth( type ); - if ( cDepth.contains( networkInventoryHandler ) ) - return true; - - cDepth.push( this ); - return false; - } - - private boolean diveIteration(NetworkInventoryHandler networkInventoryHandler, Actionable type) - { - LinkedList cDepth = getDepth( type ); - if ( cDepth.isEmpty() ) - { - currentPass++; - myPass = currentPass; - } - else - { - if ( currentPass == myPass ) - return true; - else - myPass = currentPass; - } - - cDepth.push( this ); - return false; - } - - private void surface(NetworkInventoryHandler networkInventoryHandler, Actionable type) - { - if ( getDepth( type ).pop() != this ) - throw new RuntimeException( "Invalid Access to Networked Storage API detected." ); - } - - private boolean testPermission(BaseActionSource src, SecurityPermissions permission) - { - if ( src.isPlayer() ) - { - if ( !security.hasPermission( ((PlayerSource) src).player, permission ) ) - return true; - } - else if ( src.isMachine() ) - { - if ( security.isAvailable() ) - { - IGridNode n = ((MachineSource) src).via.getActionableNode(); - if ( n == null ) - return true; - - IGrid gn = n.getGrid(); - if ( gn != security.myGrid ) - { - int playerID = -1; - - ISecurityGrid sg = gn.getCache( ISecurityGrid.class ); - playerID = sg.getOwner(); - - if ( !security.hasPermission( playerID, permission ) ) - return true; - } - } - } - - return false; - } - - @Override - public T injectItems(T input, Actionable type, BaseActionSource src) - { - if ( diveList( this, type ) ) - return input; - - if ( testPermission( src, SecurityPermissions.INJECT ) ) - { - surface( this, type ); - return input; - } - - Iterator>> i = priorityInventory.values().iterator();// asMap().entrySet().iterator(); - - while (i.hasNext()) - { - List> invList = i.next(); - - Iterator> ii = invList.iterator(); - while (ii.hasNext() && input != null) - { - IMEInventoryHandler inv = ii.next(); - - if ( inv.validForPass( 1 ) && inv.canAccept( input ) - && (inv.isPrioritized( input ) || inv.extractItems( input, Actionable.SIMULATE, src ) != null) ) - input = inv.injectItems( input, type, src ); - } - - ii = invList.iterator(); - while (ii.hasNext() && input != null) - { - IMEInventoryHandler inv = ii.next(); - if ( inv.validForPass( 2 ) && inv.canAccept( input ) )// ignore crafting on the second pass. - input = inv.injectItems( input, type, src ); - } - } - - surface( this, type ); - - return input; - } - - @Override - public T extractItems(T request, Actionable mode, BaseActionSource src) - { - if ( diveList( this, mode ) ) - return null; - - if ( testPermission( src, SecurityPermissions.EXTRACT ) ) - { - surface( this, mode ); - return null; - } - - Iterator>> i = priorityInventory.descendingMap().values().iterator();// priorityInventory.asMap().descendingMap().entrySet().iterator(); - - T output = request.copy(); - request = request.copy(); - output.setStackSize( 0 ); - long req = request.getStackSize(); - - while (i.hasNext()) - { - List> invList = i.next(); - - Iterator> ii = invList.iterator(); - while (ii.hasNext() && output.getStackSize() < req) - { - IMEInventoryHandler inv = ii.next(); - - request.setStackSize( req - output.getStackSize() ); - output.add( inv.extractItems( request, mode, src ) ); - } - } - - surface( this, mode ); - - if ( output.getStackSize() <= 0 ) - return null; - - return output; - } - - @Override - public IItemList getAvailableItems(IItemList out) - { - if ( diveIteration( this, Actionable.SIMULATE ) ) - return out; - - // for (Entry> h : priorityInventory.entries()) - for (List> i : priorityInventory.values()) - for (IMEInventoryHandler j : i) - out = j.getAvailableItems( out ); - - surface( this, Actionable.SIMULATE ); - - return out; - } - - @Override - public StorageChannel getChannel() - { - return myChannel; - } - - @Override - public AccessRestriction getAccess() - { - return AccessRestriction.READ_WRITE; - } - - @Override - public boolean isPrioritized(T input) - { - return false; - } - - @Override - public boolean canAccept(T input) - { - return true; - } - - @Override - public int getPriority() - { - return 0; - } - - @Override - public int getSlot() - { - return 0; - } - - @Override - public boolean validForPass(int i) - { - return true; - } - -} +package appeng.me.storage; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.TreeMap; + +import appeng.api.config.AccessRestriction; +import appeng.api.config.Actionable; +import appeng.api.config.SecurityPermissions; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridNode; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.security.ISecurityGrid; +import appeng.api.networking.security.MachineSource; +import appeng.api.networking.security.PlayerSource; +import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.StorageChannel; +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; +import appeng.me.cache.SecurityCache; +import appeng.util.ItemSorters; + +public class NetworkInventoryHandler> implements IMEInventoryHandler +{ + + private final static Comparator prioritySorter = new Comparator() { + + @Override + public int compare(Integer o1, Integer o2) + { + return ItemSorters.compareInt( o2, o1 ); + } + + }; + + final StorageChannel myChannel; + final SecurityCache security; + + // final TreeMultimap> priorityInventory; + final TreeMap>> priorityInventory; + + public NetworkInventoryHandler(StorageChannel chan, SecurityCache security) { + myChannel = chan; + this.security = security; + priorityInventory = new TreeMap( prioritySorter ); // TreeMultimap.create( prioritySorter, hashSorter ); + } + + public void addNewStorage(IMEInventoryHandler h) + { + int priority = h.getPriority(); + List> list = priorityInventory.get( priority ); + if ( list == null ) + priorityInventory.put( priority, list = new ArrayList() ); + + list.add( h ); + } + + static int currentPass = 0; + int myPass = 0; + static final ThreadLocal depthMod = new ThreadLocal(); + static final ThreadLocal depthSim = new ThreadLocal(); + + private LinkedList getDepth(Actionable type) + { + ThreadLocal depth = type == Actionable.MODULATE ? depthMod : depthSim; + + LinkedList s = depth.get(); + + if ( s == null ) + depth.set( s = new LinkedList() ); + + return s; + } + + private boolean diveList(NetworkInventoryHandler networkInventoryHandler, Actionable type) + { + LinkedList cDepth = getDepth( type ); + if ( cDepth.contains( networkInventoryHandler ) ) + return true; + + cDepth.push( this ); + return false; + } + + private boolean diveIteration(NetworkInventoryHandler networkInventoryHandler, Actionable type) + { + LinkedList cDepth = getDepth( type ); + if ( cDepth.isEmpty() ) + { + currentPass++; + myPass = currentPass; + } + else + { + if ( currentPass == myPass ) + return true; + else + myPass = currentPass; + } + + cDepth.push( this ); + return false; + } + + private void surface(NetworkInventoryHandler networkInventoryHandler, Actionable type) + { + if ( getDepth( type ).pop() != this ) + throw new RuntimeException( "Invalid Access to Networked Storage API detected." ); + } + + private boolean testPermission(BaseActionSource src, SecurityPermissions permission) + { + if ( src.isPlayer() ) + { + if ( !security.hasPermission( ((PlayerSource) src).player, permission ) ) + return true; + } + else if ( src.isMachine() ) + { + if ( security.isAvailable() ) + { + IGridNode n = ((MachineSource) src).via.getActionableNode(); + if ( n == null ) + return true; + + IGrid gn = n.getGrid(); + if ( gn != security.myGrid ) + { + int playerID = -1; + + ISecurityGrid sg = gn.getCache( ISecurityGrid.class ); + playerID = sg.getOwner(); + + if ( !security.hasPermission( playerID, permission ) ) + return true; + } + } + } + + return false; + } + + @Override + public T injectItems(T input, Actionable type, BaseActionSource src) + { + if ( diveList( this, type ) ) + return input; + + if ( testPermission( src, SecurityPermissions.INJECT ) ) + { + surface( this, type ); + return input; + } + + Iterator>> i = priorityInventory.values().iterator();// asMap().entrySet().iterator(); + + while (i.hasNext()) + { + List> invList = i.next(); + + Iterator> ii = invList.iterator(); + while (ii.hasNext() && input != null) + { + IMEInventoryHandler inv = ii.next(); + + if ( inv.validForPass( 1 ) && inv.canAccept( input ) + && (inv.isPrioritized( input ) || inv.extractItems( input, Actionable.SIMULATE, src ) != null) ) + input = inv.injectItems( input, type, src ); + } + + ii = invList.iterator(); + while (ii.hasNext() && input != null) + { + IMEInventoryHandler inv = ii.next(); + if ( inv.validForPass( 2 ) && inv.canAccept( input ) )// ignore crafting on the second pass. + input = inv.injectItems( input, type, src ); + } + } + + surface( this, type ); + + return input; + } + + @Override + public T extractItems(T request, Actionable mode, BaseActionSource src) + { + if ( diveList( this, mode ) ) + return null; + + if ( testPermission( src, SecurityPermissions.EXTRACT ) ) + { + surface( this, mode ); + return null; + } + + Iterator>> i = priorityInventory.descendingMap().values().iterator();// priorityInventory.asMap().descendingMap().entrySet().iterator(); + + T output = request.copy(); + request = request.copy(); + output.setStackSize( 0 ); + long req = request.getStackSize(); + + while (i.hasNext()) + { + List> invList = i.next(); + + Iterator> ii = invList.iterator(); + while (ii.hasNext() && output.getStackSize() < req) + { + IMEInventoryHandler inv = ii.next(); + + request.setStackSize( req - output.getStackSize() ); + output.add( inv.extractItems( request, mode, src ) ); + } + } + + surface( this, mode ); + + if ( output.getStackSize() <= 0 ) + return null; + + return output; + } + + @Override + public IItemList getAvailableItems(IItemList out) + { + if ( diveIteration( this, Actionable.SIMULATE ) ) + return out; + + // for (Entry> h : priorityInventory.entries()) + for (List> i : priorityInventory.values()) + for (IMEInventoryHandler j : i) + out = j.getAvailableItems( out ); + + surface( this, Actionable.SIMULATE ); + + return out; + } + + @Override + public StorageChannel getChannel() + { + return myChannel; + } + + @Override + public AccessRestriction getAccess() + { + return AccessRestriction.READ_WRITE; + } + + @Override + public boolean isPrioritized(T input) + { + return false; + } + + @Override + public boolean canAccept(T input) + { + return true; + } + + @Override + public int getPriority() + { + return 0; + } + + @Override + public int getSlot() + { + return 0; + } + + @Override + public boolean validForPass(int i) + { + return true; + } + +} diff --git a/me/storage/NullInventory.java b/src/main/java/appeng/me/storage/NullInventory.java similarity index 100% rename from me/storage/NullInventory.java rename to src/main/java/appeng/me/storage/NullInventory.java diff --git a/me/storage/SecurityInventory.java b/src/main/java/appeng/me/storage/SecurityInventory.java similarity index 100% rename from me/storage/SecurityInventory.java rename to src/main/java/appeng/me/storage/SecurityInventory.java diff --git a/me/storage/VoidFluidInventory.java b/src/main/java/appeng/me/storage/VoidFluidInventory.java similarity index 100% rename from me/storage/VoidFluidInventory.java rename to src/main/java/appeng/me/storage/VoidFluidInventory.java diff --git a/me/storage/VoidItemInventory.java b/src/main/java/appeng/me/storage/VoidItemInventory.java similarity index 100% rename from me/storage/VoidItemInventory.java rename to src/main/java/appeng/me/storage/VoidItemInventory.java diff --git a/parts/AEBasePart.java b/src/main/java/appeng/parts/AEBasePart.java similarity index 95% rename from parts/AEBasePart.java rename to src/main/java/appeng/parts/AEBasePart.java index bdf541298..382888e26 100644 --- a/parts/AEBasePart.java +++ b/src/main/java/appeng/parts/AEBasePart.java @@ -1,516 +1,516 @@ -package appeng.parts; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Random; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.config.Upgrades; -import appeng.api.implementations.IUpgradeableHost; -import appeng.api.implementations.items.IMemoryCard; -import appeng.api.implementations.items.MemoryCardMessages; -import appeng.api.implementations.tiles.ISegmentedInventory; -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.IActionHost; -import appeng.api.parts.BusSupport; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.parts.ISimplifiedBundle; -import appeng.api.parts.PartItemStack; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.api.util.DimensionalCoord; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.helpers.ICustomNameObject; -import appeng.helpers.IPriorityHost; -import appeng.me.helpers.AENetworkProxy; -import appeng.me.helpers.IGridProxyable; -import appeng.parts.networking.PartCable; -import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.util.Platform; -import appeng.util.SettingsFrom; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradeableHost, ICustomNameObject -{ - - protected ISimplifiedBundle renderCache = null; - - protected AENetworkProxy proxy; - protected TileEntity tile = null; - protected IPartHost host = null; - protected ForgeDirection side = null; - - protected final ItemStack is; - - public AEBasePart(Class c, ItemStack is) { - this.is = is; - proxy = new AENetworkProxy( this, "part", is, this instanceof PartCable ); - proxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) - { - rh.setBounds( 1, 1, 1, 15, 15, 15 ); - rh.renderInventoryBox( renderer ); - - rh.setBounds( 1, 1, 1, 15, 15, 15 ); - rh.renderInventoryBox( renderer ); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) - { - rh.setBounds( 1, 1, 1, 15, 15, 15 ); - rh.renderBlock( x, y, z, renderer ); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer) - { - - } - - @Override - public ItemStack getItemStack(PartItemStack type) - { - if ( type == PartItemStack.Network ) - { - ItemStack copy = is.copy(); - copy.setTagCompound( null ); - return copy; - } - return is; - } - - @Override - public boolean isSolid() - { - return false; - } - - @Override - public void onNeighborChanged() - { - - } - - @Override - public boolean canConnectRedstone() - { - return false; - } - - @Override - public void readFromNBT(NBTTagCompound data) - { - proxy.readFromNBT( data ); - } - - @Override - public void writeToNBT(NBTTagCompound data) - { - proxy.writeToNBT( data ); - } - - @Override - public int isProvidingStrongPower() - { - return 0; - } - - @Override - public int isProvidingWeakPower() - { - return 0; - } - - @Override - public void writeToStream(ByteBuf data) throws IOException - { - - } - - @Override - public boolean readFromStream(ByteBuf data) throws IOException - { - return false; - } - - @Override - public IGridNode getGridNode() - { - return proxy.getNode(); - } - - @Override - public void onEntityCollision(Entity entity) - { - - } - - @Override - public void removeFromWorld() - { - proxy.invalidate(); - } - - @Override - public void addToWorld() - { - proxy.onReady(); - } - - @Override - public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile) - { - this.side = side; - this.tile = tile; - this.host = host; - } - - public IPartHost getHost() - { - return host; - } - - @Override - public IGridNode getExternalFacingNode() - { - return null; - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) - { - return proxy.getNode(); - } - - protected AEColor getColor() - { - if ( getHost() == null ) - return AEColor.Transparent; - return getHost().getColor(); - } - - @Override - public DimensionalCoord getLocation() - { - return new DimensionalCoord( tile ); - } - - @Override - public void getBoxes(IPartCollisionHelper bch) - { - - } - - @Override - @SideOnly(Side.CLIENT) - public void randomDisplayTick(World world, int x, int y, int z, Random r) - { - - } - - @Override - public int getLightLevel() - { - return 0; - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.GLASS; - } - - @Override - public void getDrops(List drops, boolean wrenched) - { - - } - - @Override - public int cableConnectionRenderTo() - { - return 3; - } - - @Override - public void gridChanged() - { - - } - - @Override - public boolean isLadder(EntityLivingBase entity) - { - return false; - } - - @Override - public IConfigManager getConfigManager() - { - return null; - } - - @Override - public IInventory getInventoryByName(String name) - { - return null; - } - - @Override - public int getInstalledUpgrades(Upgrades u) - { - return 0; - } - - /** - * depending on the from, different settings will be accepted, don't call this with null - * - * @param from - * @param compound - */ - public void uploadSettings(SettingsFrom from, NBTTagCompound compound) - { - if ( compound != null && this instanceof IConfigurableObject ) - { - IConfigManager cm = ((IConfigurableObject) this).getConfigManager(); - if ( cm != null ) - cm.readFromNBT( compound ); - } - - if ( this instanceof IPriorityHost ) - { - IPriorityHost pHost = (IPriorityHost) this; - pHost.setPriority( compound.getInteger( "priority" ) ); - } - - if ( this instanceof ISegmentedInventory ) - { - IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" ); - if ( inv != null && inv instanceof AppEngInternalAEInventory ) - { - AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv; - AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() ); - tmp.readFromNBT( compound, "config" ); - for (int x = 0; x < tmp.getSizeInventory(); x++) - target.setInventorySlotContents( x, tmp.getStackInSlot( x ) ); - } - } - } - - /** - * null means nothing to store... - * - * @param from - * @return - */ - public NBTTagCompound downloadSettings(SettingsFrom from) - { - NBTTagCompound output = new NBTTagCompound(); - - if ( this instanceof IConfigurableObject ) - { - IConfigManager cm = this.getConfigManager(); - if ( cm != null ) - cm.writeToNBT( output ); - } - - if ( this instanceof IPriorityHost ) - { - IPriorityHost pHost = (IPriorityHost) this; - output.setInteger( "priority", pHost.getPriority() ); - } - - if ( this instanceof ISegmentedInventory ) - { - IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" ); - if ( inv != null && inv instanceof AppEngInternalAEInventory ) - { - ((AppEngInternalAEInventory) inv).writeToNBT( output, "config" ); - } - } - - return output.hasNoTags() ? null : output; - } - - public boolean useStandardMemoryCard() - { - return true; - } - - private boolean useMemoryCard(EntityPlayer player) - { - ItemStack memCardIS = player.inventory.getCurrentItem(); - - if ( memCardIS != null && useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard ) - { - IMemoryCard memc = (IMemoryCard) memCardIS.getItem(); - - ItemStack is = getItemStack( PartItemStack.Network ); - - // Blocks and parts share the same soul! - if ( AEApi.instance().parts().partInterface.sameAsStack( is ) ) - is = AEApi.instance().blocks().blockInterface.stack( 1 ); - - String name = is.getUnlocalizedName(); - - if ( player.isSneaking() ) - { - NBTTagCompound data = downloadSettings( SettingsFrom.MEMORY_CARD ); - if ( data != null ) - { - memc.setMemoryCardContents( memCardIS, name, data ); - memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED ); - } - } - else - { - String storedName = memc.getSettingsName( memCardIS ); - NBTTagCompound data = memc.getData( memCardIS ); - if ( name.equals( storedName ) ) - { - uploadSettings( SettingsFrom.MEMORY_CARD, data ); - memc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED ); - } - else - memc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE ); - } - return true; - } - return false; - } - - @Override - final public boolean onActivate(EntityPlayer player, Vec3 pos) - { - if ( useMemoryCard( player ) ) - return true; - - return onPartActivate( player, pos ); - } - - @Override - final public boolean onShiftActivate(EntityPlayer player, Vec3 pos) - { - if ( useMemoryCard( player ) ) - return true; - - return onPartShiftActivate( player, pos ); - } - - public boolean onPartActivate(EntityPlayer player, Vec3 pos) - { - return false; - } - - public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos) - { - return false; - } - - @Override - public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side) - { - proxy.setOwner( player ); - } - - @Override - public TileEntity getTile() - { - return tile; - } - - @Override - public void securityBreak() - { - if ( is.stackSize > 0 ) - { - List items = new ArrayList(); - items.add( is.copy() ); - host.removePart( side, false ); - Platform.spawnDrops( tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, items ); - is.stackSize = 0; - } - } - - @Override - public AENetworkProxy getProxy() - { - return proxy; - } - - @Override - public IGridNode getActionableNode() - { - return proxy.getNode(); - } - - @Override - public boolean canBePlacedOn(BusSupport what) - { - return what == BusSupport.CABLE; - } - - public void saveChanges() - { - host.markForSave(); - } - - @Override - public boolean requireDynamicRender() - { - return false; - } - - @Override - public String getCustomName() - { - return is.getDisplayName(); - } - - @Override - public boolean hasCustomName() - { - return is.hasDisplayName(); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getBreakingTexture() - { - return null; - } - - public void addEntityCrashInfo(CrashReportCategory crashreportcategory) - { - crashreportcategory.addCrashSection( "Part Side", side ); - } +package appeng.parts; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Random; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.config.Upgrades; +import appeng.api.implementations.IUpgradeableHost; +import appeng.api.implementations.items.IMemoryCard; +import appeng.api.implementations.items.MemoryCardMessages; +import appeng.api.implementations.tiles.ISegmentedInventory; +import appeng.api.networking.IGridNode; +import appeng.api.networking.security.IActionHost; +import appeng.api.parts.BusSupport; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.parts.ISimplifiedBundle; +import appeng.api.parts.PartItemStack; +import appeng.api.util.AECableType; +import appeng.api.util.AEColor; +import appeng.api.util.DimensionalCoord; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.helpers.ICustomNameObject; +import appeng.helpers.IPriorityHost; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.helpers.IGridProxyable; +import appeng.parts.networking.PartCable; +import appeng.tile.inventory.AppEngInternalAEInventory; +import appeng.util.Platform; +import appeng.util.SettingsFrom; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradeableHost, ICustomNameObject +{ + + protected ISimplifiedBundle renderCache = null; + + protected AENetworkProxy proxy; + protected TileEntity tile = null; + protected IPartHost host = null; + protected ForgeDirection side = null; + + protected final ItemStack is; + + public AEBasePart(Class c, ItemStack is) { + this.is = is; + proxy = new AENetworkProxy( this, "part", is, this instanceof PartCable ); + proxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) + { + rh.setBounds( 1, 1, 1, 15, 15, 15 ); + rh.renderInventoryBox( renderer ); + + rh.setBounds( 1, 1, 1, 15, 15, 15 ); + rh.renderInventoryBox( renderer ); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) + { + rh.setBounds( 1, 1, 1, 15, 15, 15 ); + rh.renderBlock( x, y, z, renderer ); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer) + { + + } + + @Override + public ItemStack getItemStack(PartItemStack type) + { + if ( type == PartItemStack.Network ) + { + ItemStack copy = is.copy(); + copy.setTagCompound( null ); + return copy; + } + return is; + } + + @Override + public boolean isSolid() + { + return false; + } + + @Override + public void onNeighborChanged() + { + + } + + @Override + public boolean canConnectRedstone() + { + return false; + } + + @Override + public void readFromNBT(NBTTagCompound data) + { + proxy.readFromNBT( data ); + } + + @Override + public void writeToNBT(NBTTagCompound data) + { + proxy.writeToNBT( data ); + } + + @Override + public int isProvidingStrongPower() + { + return 0; + } + + @Override + public int isProvidingWeakPower() + { + return 0; + } + + @Override + public void writeToStream(ByteBuf data) throws IOException + { + + } + + @Override + public boolean readFromStream(ByteBuf data) throws IOException + { + return false; + } + + @Override + public IGridNode getGridNode() + { + return proxy.getNode(); + } + + @Override + public void onEntityCollision(Entity entity) + { + + } + + @Override + public void removeFromWorld() + { + proxy.invalidate(); + } + + @Override + public void addToWorld() + { + proxy.onReady(); + } + + @Override + public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile) + { + this.side = side; + this.tile = tile; + this.host = host; + } + + public IPartHost getHost() + { + return host; + } + + @Override + public IGridNode getExternalFacingNode() + { + return null; + } + + @Override + public IGridNode getGridNode(ForgeDirection dir) + { + return proxy.getNode(); + } + + protected AEColor getColor() + { + if ( getHost() == null ) + return AEColor.Transparent; + return getHost().getColor(); + } + + @Override + public DimensionalCoord getLocation() + { + return new DimensionalCoord( tile ); + } + + @Override + public void getBoxes(IPartCollisionHelper bch) + { + + } + + @Override + @SideOnly(Side.CLIENT) + public void randomDisplayTick(World world, int x, int y, int z, Random r) + { + + } + + @Override + public int getLightLevel() + { + return 0; + } + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.GLASS; + } + + @Override + public void getDrops(List drops, boolean wrenched) + { + + } + + @Override + public int cableConnectionRenderTo() + { + return 3; + } + + @Override + public void gridChanged() + { + + } + + @Override + public boolean isLadder(EntityLivingBase entity) + { + return false; + } + + @Override + public IConfigManager getConfigManager() + { + return null; + } + + @Override + public IInventory getInventoryByName(String name) + { + return null; + } + + @Override + public int getInstalledUpgrades(Upgrades u) + { + return 0; + } + + /** + * depending on the from, different settings will be accepted, don't call this with null + * + * @param from + * @param compound + */ + public void uploadSettings(SettingsFrom from, NBTTagCompound compound) + { + if ( compound != null && this instanceof IConfigurableObject ) + { + IConfigManager cm = ((IConfigurableObject) this).getConfigManager(); + if ( cm != null ) + cm.readFromNBT( compound ); + } + + if ( this instanceof IPriorityHost ) + { + IPriorityHost pHost = (IPriorityHost) this; + pHost.setPriority( compound.getInteger( "priority" ) ); + } + + if ( this instanceof ISegmentedInventory ) + { + IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" ); + if ( inv != null && inv instanceof AppEngInternalAEInventory ) + { + AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv; + AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() ); + tmp.readFromNBT( compound, "config" ); + for (int x = 0; x < tmp.getSizeInventory(); x++) + target.setInventorySlotContents( x, tmp.getStackInSlot( x ) ); + } + } + } + + /** + * null means nothing to store... + * + * @param from + * @return + */ + public NBTTagCompound downloadSettings(SettingsFrom from) + { + NBTTagCompound output = new NBTTagCompound(); + + if ( this instanceof IConfigurableObject ) + { + IConfigManager cm = this.getConfigManager(); + if ( cm != null ) + cm.writeToNBT( output ); + } + + if ( this instanceof IPriorityHost ) + { + IPriorityHost pHost = (IPriorityHost) this; + output.setInteger( "priority", pHost.getPriority() ); + } + + if ( this instanceof ISegmentedInventory ) + { + IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" ); + if ( inv != null && inv instanceof AppEngInternalAEInventory ) + { + ((AppEngInternalAEInventory) inv).writeToNBT( output, "config" ); + } + } + + return output.hasNoTags() ? null : output; + } + + public boolean useStandardMemoryCard() + { + return true; + } + + private boolean useMemoryCard(EntityPlayer player) + { + ItemStack memCardIS = player.inventory.getCurrentItem(); + + if ( memCardIS != null && useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard ) + { + IMemoryCard memc = (IMemoryCard) memCardIS.getItem(); + + ItemStack is = getItemStack( PartItemStack.Network ); + + // Blocks and parts share the same soul! + if ( AEApi.instance().parts().partInterface.sameAsStack( is ) ) + is = AEApi.instance().blocks().blockInterface.stack( 1 ); + + String name = is.getUnlocalizedName(); + + if ( player.isSneaking() ) + { + NBTTagCompound data = downloadSettings( SettingsFrom.MEMORY_CARD ); + if ( data != null ) + { + memc.setMemoryCardContents( memCardIS, name, data ); + memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED ); + } + } + else + { + String storedName = memc.getSettingsName( memCardIS ); + NBTTagCompound data = memc.getData( memCardIS ); + if ( name.equals( storedName ) ) + { + uploadSettings( SettingsFrom.MEMORY_CARD, data ); + memc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED ); + } + else + memc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE ); + } + return true; + } + return false; + } + + @Override + final public boolean onActivate(EntityPlayer player, Vec3 pos) + { + if ( useMemoryCard( player ) ) + return true; + + return onPartActivate( player, pos ); + } + + @Override + final public boolean onShiftActivate(EntityPlayer player, Vec3 pos) + { + if ( useMemoryCard( player ) ) + return true; + + return onPartShiftActivate( player, pos ); + } + + public boolean onPartActivate(EntityPlayer player, Vec3 pos) + { + return false; + } + + public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos) + { + return false; + } + + @Override + public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side) + { + proxy.setOwner( player ); + } + + @Override + public TileEntity getTile() + { + return tile; + } + + @Override + public void securityBreak() + { + if ( is.stackSize > 0 ) + { + List items = new ArrayList(); + items.add( is.copy() ); + host.removePart( side, false ); + Platform.spawnDrops( tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, items ); + is.stackSize = 0; + } + } + + @Override + public AENetworkProxy getProxy() + { + return proxy; + } + + @Override + public IGridNode getActionableNode() + { + return proxy.getNode(); + } + + @Override + public boolean canBePlacedOn(BusSupport what) + { + return what == BusSupport.CABLE; + } + + public void saveChanges() + { + host.markForSave(); + } + + @Override + public boolean requireDynamicRender() + { + return false; + } + + @Override + public String getCustomName() + { + return is.getDisplayName(); + } + + @Override + public boolean hasCustomName() + { + return is.hasDisplayName(); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getBreakingTexture() + { + return null; + } + + public void addEntityCrashInfo(CrashReportCategory crashreportcategory) + { + crashreportcategory.addCrashSection( "Part Side", side ); + } } \ No newline at end of file diff --git a/parts/BusCollisionHelper.java b/src/main/java/appeng/parts/BusCollisionHelper.java similarity index 95% rename from parts/BusCollisionHelper.java rename to src/main/java/appeng/parts/BusCollisionHelper.java index 451dfbf64..f69ef3d4e 100644 --- a/parts/BusCollisionHelper.java +++ b/src/main/java/appeng/parts/BusCollisionHelper.java @@ -1,155 +1,155 @@ -package appeng.parts; - -import java.util.List; - -import net.minecraft.entity.Entity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.parts.IPartCollisionHelper; - -public class BusCollisionHelper implements IPartCollisionHelper -{ - - final List boxes; - - final private ForgeDirection x; - final private ForgeDirection y; - final private ForgeDirection z; - - final private Entity entity; - final private boolean isVisual; - - public BusCollisionHelper(List boxes, ForgeDirection x, ForgeDirection y, ForgeDirection z, Entity e, boolean visual) { - this.boxes = boxes; - this.x = x; - this.y = y; - this.z = z; - entity = e; - isVisual = visual; - } - - public BusCollisionHelper(List boxes, ForgeDirection s, Entity e, boolean visual) { - this.boxes = boxes; - entity = e; - isVisual = visual; - - switch (s) - { - case DOWN: - x = ForgeDirection.EAST; - y = ForgeDirection.NORTH; - z = ForgeDirection.DOWN; - break; - case UP: - x = ForgeDirection.EAST; - y = ForgeDirection.SOUTH; - z = ForgeDirection.UP; - break; - case EAST: - x = ForgeDirection.SOUTH; - y = ForgeDirection.UP; - z = ForgeDirection.EAST; - break; - case WEST: - x = ForgeDirection.NORTH; - y = ForgeDirection.UP; - z = ForgeDirection.WEST; - break; - case NORTH: - x = ForgeDirection.WEST; - y = ForgeDirection.UP; - z = ForgeDirection.NORTH; - break; - case SOUTH: - x = ForgeDirection.EAST; - y = ForgeDirection.UP; - z = ForgeDirection.SOUTH; - break; - case UNKNOWN: - default: - x = ForgeDirection.EAST; - y = ForgeDirection.UP; - z = ForgeDirection.SOUTH; - break; - } - } - - @Override - public boolean isBBCollision() - { - return !isVisual; - } - - /** - * pretty much useless... - */ - public Entity getEntity() - { - return entity; - } - - @Override - public void addBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) - { - minX /= 16.0; - minY /= 16.0; - minZ /= 16.0; - maxX /= 16.0; - maxY /= 16.0; - maxZ /= 16.0; - - double aX = minX * x.offsetX + minY * y.offsetX + minZ * z.offsetX; - double aY = minX * x.offsetY + minY * y.offsetY + minZ * z.offsetY; - double aZ = minX * x.offsetZ + minY * y.offsetZ + minZ * z.offsetZ; - - double bX = maxX * x.offsetX + maxY * y.offsetX + maxZ * z.offsetX; - double bY = maxX * x.offsetY + maxY * y.offsetY + maxZ * z.offsetY; - double bZ = maxX * x.offsetZ + maxY * y.offsetZ + maxZ * z.offsetZ; - - if ( x.offsetX + y.offsetX + z.offsetX < 0 ) - { - aX += 1; - bX += 1; - } - - if ( x.offsetY + y.offsetY + z.offsetY < 0 ) - { - aY += 1; - bY += 1; - } - - if ( x.offsetZ + y.offsetZ + z.offsetZ < 0 ) - { - aZ += 1; - bZ += 1; - } - - minX = Math.min( aX, bX ); - minY = Math.min( aY, bY ); - minZ = Math.min( aZ, bZ ); - maxX = Math.max( aX, bX ); - maxY = Math.max( aY, bY ); - maxZ = Math.max( aZ, bZ ); - - boxes.add( AxisAlignedBB.getBoundingBox( minX, minY, minZ, maxX, maxY, maxZ ) ); - } - - @Override - public ForgeDirection getWorldX() - { - return x; - } - - @Override - public ForgeDirection getWorldY() - { - return y; - } - - @Override - public ForgeDirection getWorldZ() - { - return z; - } - -} +package appeng.parts; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.parts.IPartCollisionHelper; + +public class BusCollisionHelper implements IPartCollisionHelper +{ + + final List boxes; + + final private ForgeDirection x; + final private ForgeDirection y; + final private ForgeDirection z; + + final private Entity entity; + final private boolean isVisual; + + public BusCollisionHelper(List boxes, ForgeDirection x, ForgeDirection y, ForgeDirection z, Entity e, boolean visual) { + this.boxes = boxes; + this.x = x; + this.y = y; + this.z = z; + entity = e; + isVisual = visual; + } + + public BusCollisionHelper(List boxes, ForgeDirection s, Entity e, boolean visual) { + this.boxes = boxes; + entity = e; + isVisual = visual; + + switch (s) + { + case DOWN: + x = ForgeDirection.EAST; + y = ForgeDirection.NORTH; + z = ForgeDirection.DOWN; + break; + case UP: + x = ForgeDirection.EAST; + y = ForgeDirection.SOUTH; + z = ForgeDirection.UP; + break; + case EAST: + x = ForgeDirection.SOUTH; + y = ForgeDirection.UP; + z = ForgeDirection.EAST; + break; + case WEST: + x = ForgeDirection.NORTH; + y = ForgeDirection.UP; + z = ForgeDirection.WEST; + break; + case NORTH: + x = ForgeDirection.WEST; + y = ForgeDirection.UP; + z = ForgeDirection.NORTH; + break; + case SOUTH: + x = ForgeDirection.EAST; + y = ForgeDirection.UP; + z = ForgeDirection.SOUTH; + break; + case UNKNOWN: + default: + x = ForgeDirection.EAST; + y = ForgeDirection.UP; + z = ForgeDirection.SOUTH; + break; + } + } + + @Override + public boolean isBBCollision() + { + return !isVisual; + } + + /** + * pretty much useless... + */ + public Entity getEntity() + { + return entity; + } + + @Override + public void addBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) + { + minX /= 16.0; + minY /= 16.0; + minZ /= 16.0; + maxX /= 16.0; + maxY /= 16.0; + maxZ /= 16.0; + + double aX = minX * x.offsetX + minY * y.offsetX + minZ * z.offsetX; + double aY = minX * x.offsetY + minY * y.offsetY + minZ * z.offsetY; + double aZ = minX * x.offsetZ + minY * y.offsetZ + minZ * z.offsetZ; + + double bX = maxX * x.offsetX + maxY * y.offsetX + maxZ * z.offsetX; + double bY = maxX * x.offsetY + maxY * y.offsetY + maxZ * z.offsetY; + double bZ = maxX * x.offsetZ + maxY * y.offsetZ + maxZ * z.offsetZ; + + if ( x.offsetX + y.offsetX + z.offsetX < 0 ) + { + aX += 1; + bX += 1; + } + + if ( x.offsetY + y.offsetY + z.offsetY < 0 ) + { + aY += 1; + bY += 1; + } + + if ( x.offsetZ + y.offsetZ + z.offsetZ < 0 ) + { + aZ += 1; + bZ += 1; + } + + minX = Math.min( aX, bX ); + minY = Math.min( aY, bY ); + minZ = Math.min( aZ, bZ ); + maxX = Math.max( aX, bX ); + maxY = Math.max( aY, bY ); + maxZ = Math.max( aZ, bZ ); + + boxes.add( AxisAlignedBB.getBoundingBox( minX, minY, minZ, maxX, maxY, maxZ ) ); + } + + @Override + public ForgeDirection getWorldX() + { + return x; + } + + @Override + public ForgeDirection getWorldY() + { + return y; + } + + @Override + public ForgeDirection getWorldZ() + { + return z; + } + +} diff --git a/parts/CableBusContainer.java b/src/main/java/appeng/parts/CableBusContainer.java similarity index 95% rename from parts/CableBusContainer.java rename to src/main/java/appeng/parts/CableBusContainer.java index 993b3a4c2..06c690ce7 100644 --- a/parts/CableBusContainer.java +++ b/src/main/java/appeng/parts/CableBusContainer.java @@ -1,1005 +1,1005 @@ -package appeng.parts; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; -import java.util.EnumSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.Set; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.config.YesNo; -import appeng.api.exceptions.FailedConnection; -import appeng.api.implementations.parts.IPartCable; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.parts.IFacadeContainer; -import appeng.api.parts.IFacadePart; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartItem; -import appeng.api.parts.LayerFlags; -import appeng.api.parts.PartItemStack; -import appeng.api.parts.SelectedPart; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.api.util.DimensionalCoord; -import appeng.client.render.CableRenderHelper; -import appeng.core.AELog; -import appeng.core.AppEng; -import appeng.facade.FacadeContainer; -import appeng.helpers.AEMultiTile; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.ICLApi; -import appeng.me.GridConnection; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class CableBusContainer extends CableBusStorage implements AEMultiTile, ICableBusContainer -{ - - private EnumSet myLayerFlags = EnumSet.noneOf( LayerFlags.class ); - - public YesNo hasRedstone = YesNo.UNDECIDED; - public IPartHost tcb; - - boolean inWorld = false; - public boolean requiresDynamicRender = false; - - @Override - public boolean isInWorld() - { - return inWorld; - } - - public void setHost(IPartHost host) - { - tcb.clearContainer(); - tcb = host; - } - - public CableBusContainer(IPartHost host) { - tcb = host; - } - - @Override - public IPart getPart(ForgeDirection side) - { - if ( side == ForgeDirection.UNKNOWN ) - return getCenter(); - return getSide( side ); - } - - public void rotateLeft() - { - IPart newSides[] = new IPart[6]; - - newSides[ForgeDirection.UP.ordinal()] = getSide( ForgeDirection.UP ); - newSides[ForgeDirection.DOWN.ordinal()] = getSide( ForgeDirection.DOWN ); - - newSides[ForgeDirection.EAST.ordinal()] = getSide( ForgeDirection.NORTH ); - newSides[ForgeDirection.SOUTH.ordinal()] = getSide( ForgeDirection.EAST ); - newSides[ForgeDirection.WEST.ordinal()] = getSide( ForgeDirection.SOUTH ); - newSides[ForgeDirection.NORTH.ordinal()] = getSide( ForgeDirection.WEST ); - - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - setSide( dir, newSides[dir.ordinal()] ); - - getFacadeContainer().rotateLeft(); - } - - public void updateDynamicRender() - { - requiresDynamicRender = false; - for (ForgeDirection s : ForgeDirection.VALID_DIRECTIONS) - { - IPart p = getPart( s ); - if ( p != null ) - requiresDynamicRender = requiresDynamicRender || p.requireDynamicRender(); - } - } - - @Override - public void removePart(ForgeDirection side, boolean suppressUpdate) - { - if ( side == ForgeDirection.UNKNOWN ) - { - if ( getCenter() != null ) - getCenter().removeFromWorld(); - setCenter( null ); - } - else - { - if ( getSide( side ) != null ) - getSide( side ).removeFromWorld(); - setSide( side, null ); - } - - if ( !suppressUpdate ) - { - updateDynamicRender(); - updateConnections(); - markForUpdate(); - markForSave(); - partChanged(); - } - } - - /** - * use for FMP - */ - public void updateConnections() - { - if ( getCenter() != null ) - { - EnumSet sides = EnumSet.allOf( ForgeDirection.class ); - - for (ForgeDirection s : ForgeDirection.VALID_DIRECTIONS) - { - if ( getPart( s ) != null || isBlocked( s ) ) - sides.remove( s ); - } - - getCenter().setValidSides( sides ); - IGridNode n = getCenter().getGridNode(); - if ( n != null ) - n.updateState(); - } - } - - @Override - public boolean canAddPart(ItemStack is, ForgeDirection side) - { - if ( PartPlacement.isFacade( is, side ) != null ) - return true; - - if ( is.getItem() instanceof IPartItem ) - { - IPartItem bi = (IPartItem) is.getItem(); - - is = is.copy(); - is.stackSize = 1; - - IPart bp = bi.createPartFromItemStack( is ); - if ( bp != null ) - { - if ( bp instanceof IPartCable ) - { - boolean canPlace = true; - for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) - if ( getPart( d ) != null && !getPart( d ).canBePlacedOn( ((IPartCable) bp).supportsBuses() ) ) - canPlace = false; - - if ( !canPlace ) - return false; - - return getPart( ForgeDirection.UNKNOWN ) == null; - } - else if ( !(bp instanceof IPartCable) && side != ForgeDirection.UNKNOWN ) - { - IPart cable = getPart( ForgeDirection.UNKNOWN ); - if ( cable != null && !bp.canBePlacedOn( ((IPartCable) cable).supportsBuses() ) ) - return false; - - return getPart( side ) == null; - } - } - } - return false; - } - - @Override - public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer player) - { - if ( canAddPart( is, side ) ) - { - if ( is.getItem() instanceof IPartItem ) - { - IPartItem bi = (IPartItem) is.getItem(); - - is = is.copy(); - is.stackSize = 1; - - IPart bp = bi.createPartFromItemStack( is ); - if ( bp instanceof IPartCable ) - { - boolean canPlace = true; - for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) - if ( getPart( d ) != null && !getPart( d ).canBePlacedOn( ((IPartCable) bp).supportsBuses() ) ) - canPlace = false; - - if ( !canPlace ) - return null; - - if ( getPart( ForgeDirection.UNKNOWN ) != null ) - return null; - - setCenter( (IPartCable) bp ); - bp.setPartHostInfo( ForgeDirection.UNKNOWN, this, tcb.getTile() ); - - if ( player != null ) - bp.onPlacement( player, is, side ); - - if ( inWorld ) - bp.addToWorld(); - - IGridNode cn = getCenter().getGridNode(); - if ( cn != null ) - { - for (ForgeDirection ins : ForgeDirection.VALID_DIRECTIONS) - { - IPart sbp = getPart( ins ); - if ( sbp != null ) - { - IGridNode sn = sbp.getGridNode(); - if ( sn != null && cn != null ) - { - try - { - new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN ); - } - catch (FailedConnection e) - { - // ekk! - - bp.removeFromWorld(); - setCenter( null ); - return null; - } - } - } - } - } - - updateConnections(); - markForUpdate(); - markForSave(); - partChanged(); - return ForgeDirection.UNKNOWN; - } - else if ( bp != null && !(bp instanceof IPartCable) && side != ForgeDirection.UNKNOWN ) - { - IPart cable = getPart( ForgeDirection.UNKNOWN ); - if ( cable != null && !bp.canBePlacedOn( ((IPartCable) cable).supportsBuses() ) ) - return null; - - setSide( side, bp ); - bp.setPartHostInfo( side, this, this.getTile() ); - - if ( player != null ) - bp.onPlacement( player, is, side ); - - if ( inWorld ) - bp.addToWorld(); - - if ( getCenter() != null ) - { - IGridNode cn = getCenter().getGridNode(); - IGridNode sn = bp.getGridNode(); - - if ( cn != null && sn != null ) - { - try - { - new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN ); - } - catch (FailedConnection e) - { - // ekk! - - bp.removeFromWorld(); - setSide( side, null ); - return null; - } - } - } - - updateDynamicRender(); - updateConnections(); - markForUpdate(); - markForSave(); - partChanged(); - return side; - } - } - } - return null; - } - - private static final ThreadLocal isLoading = new ThreadLocal(); - - public static boolean isLoading() - { - Boolean is = isLoading.get(); - return is != null && is == true; - } - - public void addToWorld() - { - if ( inWorld ) - return; - - inWorld = true; - isLoading.set( true ); - - TileEntity te = getTile(); - - // start with the center, then install the side parts into the grid. - for (int x = 6; x >= 0; x--) - { - ForgeDirection s = ForgeDirection.getOrientation( x ); - IPart part = getPart( s ); - - if ( part != null ) - { - part.setPartHostInfo( s, this, te ); - part.addToWorld(); - - if ( s != ForgeDirection.UNKNOWN ) - { - IGridNode sn = part.getGridNode(); - if ( sn != null ) - { - // this is a really stupid if statement, why was this - // here? - // if ( !sn.getConnections().iterator().hasNext() ) - - IPart center = getPart( ForgeDirection.UNKNOWN ); - if ( center != null ) - { - IGridNode cn = center.getGridNode(); - if ( cn != null ) - { - try - { - AEApi.instance().createGridConnection( cn, sn ); - } - catch (FailedConnection e) - { - // ekk - } - } - } - - } - } - } - } - - partChanged(); - - isLoading.set( false ); - } - - public void removeFromWorld() - { - if ( !inWorld ) - return; - - inWorld = false; - - for (ForgeDirection s : ForgeDirection.values()) - { - IPart part = getPart( s ); - if ( part != null ) - part.removeFromWorld(); - } - - partChanged(); - } - - public boolean canConnectRedstone(EnumSet enumSet) - { - for (ForgeDirection dir : enumSet) - { - IPart part = getPart( dir ); - if ( part != null && part.canConnectRedstone() ) - return true; - } - return false; - } - - @Override - public IGridNode getGridNode(ForgeDirection side) - { - IPart part = getPart( side ); - if ( part != null ) - { - IGridNode n = part.getExternalFacingNode(); - if ( n != null ) - return n; - } - - if ( getCenter() != null ) - return getCenter().getGridNode(); - - return null; - } - - public Iterable getSelectedBoundingBoxsFromPool(boolean ignoreCableConnections, boolean includeFacades, Entity e, boolean visual) - { - List boxes = new LinkedList(); - - IFacadeContainer fc = getFacadeContainer(); - for (ForgeDirection s : ForgeDirection.values()) - { - IPartCollisionHelper bch = new BusCollisionHelper( boxes, s, e, visual ); - - IPart part = getPart( s ); - if ( part != null ) - { - if ( ignoreCableConnections && part instanceof IPartCable ) - bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 ); - else - part.getBoxes( bch ); - } - - if ( AEApi.instance().partHelper().getCableRenderMode().opaqueFacades || !visual ) - { - if ( includeFacades && s != null && s != ForgeDirection.UNKNOWN ) - { - IFacadePart fp = fc.getFacade( s ); - if ( fp != null ) - fp.getBoxes( bch, e ); - } - } - } - - return boxes; - } - - public void onEntityCollision(Entity entity) - { - for (ForgeDirection s : ForgeDirection.values()) - { - IPart part = getPart( s ); - if ( part != null ) - part.onEntityCollision( entity ); - } - } - - public boolean isEmpty() - { - IFacadeContainer fc = getFacadeContainer(); - for (ForgeDirection s : ForgeDirection.values()) - { - IPart part = getPart( s ); - if ( part != null ) - return false; - - if ( s != ForgeDirection.UNKNOWN ) - { - IFacadePart fp = fc.getFacade( s ); - if ( fp != null ) - return false; - } - } - return true; - } - - public void onNeighborChanged() - { - hasRedstone = YesNo.UNDECIDED; - - for (ForgeDirection s : ForgeDirection.values()) - { - IPart part = getPart( s ); - if ( part != null ) - part.onNeighborChanged(); - } - } - - private void updateRedstone() - { - TileEntity te = getTile(); - hasRedstone = te.getWorldObj().isBlockIndirectlyGettingPowered( te.xCoord, te.yCoord, te.zCoord ) ? YesNo.YES : YesNo.NO; - } - - public boolean isSolidOnSide(ForgeDirection side) - { - if ( side == null || side == ForgeDirection.UNKNOWN ) - return false; - - // facades are solid.. - IFacadePart fp = getFacadeContainer().getFacade( side ); - if ( fp != null ) - return true; - - // buses can be too. - IPart part = getPart( side ); - return part != null && part.isSolid(); - } - - public int isProvidingWeakPower(ForgeDirection side) - { - IPart part = getPart( side ); - return part != null ? part.isProvidingWeakPower() : 0; - } - - public int isProvidingStrongPower(ForgeDirection side) - { - IPart part = getPart( side ); - return part != null ? part.isProvidingStrongPower() : 0; - } - - @SideOnly(Side.CLIENT) - public void renderStatic(double x, double y, double z) - { - CableRenderHelper.getInstance().renderStatic( this, getFacadeContainer() ); - } - - @SideOnly(Side.CLIENT) - public void renderDynamic(double x, double y, double z) - { - CableRenderHelper.getInstance().renderDynamic( this, x, y, z ); - } - - public void writeToStream(ByteBuf data) throws IOException - { - int sides = 0; - for (int x = 0; x < 7; x++) - { - IPart p = getPart( ForgeDirection.getOrientation( x ) ); - if ( p != null ) - { - sides = sides | (1 << x); - } - } - - data.writeByte( (byte) sides ); - - for (int x = 0; x < 7; x++) - { - ItemStack is = null; - IPart p = getPart( ForgeDirection.getOrientation( x ) ); - if ( p != null ) - { - is = p.getItemStack( PartItemStack.Network ); - - data.writeShort( Item.getIdFromItem( is.getItem() ) ); - data.writeShort( is.getItemDamage() ); - - if ( p != null ) - p.writeToStream( data ); - } - } - - getFacadeContainer().writeToStream( data ); - } - - public boolean readFromStream(ByteBuf data) throws IOException - { - byte sides = data.readByte(); - - boolean updateBlock = false; - - for (int x = 0; x < 7; x++) - { - ForgeDirection side = ForgeDirection.getOrientation( x ); - if ( ((sides & (1 << x)) == (1 << x)) ) - { - IPart p = getPart( side ); - - short itemID = data.readShort(); - short dmgValue = data.readShort(); - - Item myItem = Item.getItemById( itemID ); - - ItemStack current = p != null ? p.getItemStack( PartItemStack.Network ) : null; - if ( current != null && current.getItem() == myItem && current.getItemDamage() == dmgValue ) - { - if ( p.readFromStream( data ) ) - updateBlock = true; - } - else - { - removePart( side, false ); - side = addPart( new ItemStack( myItem, 1, dmgValue ), side, null ); - if ( side != null ) - { - p = getPart( side ); - p.readFromStream( data ); - } - else - throw new RuntimeException( "Invalid Stream For CableBus Container." ); - } - } - else if ( getPart( side ) != null ) - removePart( side, false ); - } - - if ( getFacadeContainer().readFromStream( data ) ) - return true; - - return updateBlock; - } - - ForgeDirection getSide(IPart part) - { - if ( getCenter() == part ) - return ForgeDirection.UNKNOWN; - else - { - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) - if ( getSide( side ) == part ) - { - return side; - } - } - throw new RuntimeException( "Uhh Bad Part on Side." ); - } - - public void writeToNBT(NBTTagCompound data) - { - data.setInteger( "hasRedstone", hasRedstone.ordinal() ); - - IFacadeContainer fc = getFacadeContainer(); - for (ForgeDirection s : ForgeDirection.values()) - { - fc.writeToNBT( data ); - - IPart part = getPart( s ); - if ( part != null ) - { - NBTTagCompound def = new NBTTagCompound(); - part.getItemStack( PartItemStack.World ).writeToNBT( def ); - - NBTTagCompound extra = new NBTTagCompound(); - part.writeToNBT( extra ); - - data.setTag( "def:" + getSide( part ).ordinal(), def ); - data.setTag( "extra:" + getSide( part ).ordinal(), extra ); - } - } - } - - public void readFromNBT(NBTTagCompound data) - { - if ( data.hasKey( "hasRedstone" ) ) - hasRedstone = YesNo.values()[data.getInteger( "hasRedstone" )]; - - for (int x = 0; x < 7; x++) - { - ForgeDirection side = ForgeDirection.getOrientation( x ); - - NBTTagCompound def = data.getCompoundTag( "def:" + side.ordinal() ); - NBTTagCompound extra = data.getCompoundTag( "extra:" + side.ordinal() ); - if ( def != null && extra != null ) - { - IPart p = getPart( side ); - ItemStack iss = ItemStack.loadItemStackFromNBT( def ); - if ( iss == null ) - continue; - - ItemStack current = p == null ? null : p.getItemStack( PartItemStack.World ); - - if ( Platform.isSameItemType( iss, current ) ) - p.readFromNBT( extra ); - else - { - removePart( side, true ); - side = addPart( iss, side, null ); - if ( side != null ) - { - p = getPart( side ); - p.readFromNBT( extra ); - } - else - { - AELog.warning( "Invalid NBT For CableBus Container: " + iss.getItem().getClass().getName() + " is not a valid part; it was ignored." ); - } - } - } - else - removePart( side, false ); - } - - getFacadeContainer().readFromNBT( data ); - } - - public List getDrops(List drops) - { - for (ForgeDirection s : ForgeDirection.values()) - { - IPart part = getPart( s ); - if ( part != null ) - { - drops.add( part.getItemStack( PartItemStack.Break ) ); - part.getDrops( drops, false ); - } - - if ( s != ForgeDirection.UNKNOWN ) - { - IFacadePart fp = getFacadeContainer().getFacade( s ); - if ( fp != null ) - drops.add( fp.getItemStack() ); - } - } - - return drops; - } - - public List getNoDrops(List drops) - { - for (ForgeDirection s : ForgeDirection.values()) - { - IPart part = getPart( s ); - if ( part != null ) - { - part.getDrops( drops, false ); - } - } - - return drops; - } - - @Override - public void markForUpdate() - { - tcb.markForUpdate(); - } - - @Override - public DimensionalCoord getLocation() - { - return tcb.getLocation(); - } - - @Override - public TileEntity getTile() - { - return tcb.getTile(); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - IPart part = getPart( dir ); - if ( part != null && part instanceof IGridHost ) - { - AECableType t = ((IGridHost) part).getCableConnectionType( dir ); - if ( t != null && t != AECableType.NONE ) - return t; - } - - if ( getCenter() != null ) - { - IPartCable c = getCenter(); - return c.getCableConnectionType(); - } - return AECableType.NONE; - } - - @Override - public AEColor getColor() - { - if ( getCenter() != null ) - { - IPartCable c = getCenter(); - return c.getCableColor(); - } - return AEColor.Transparent; - } - - @Override - public IFacadeContainer getFacadeContainer() - { - return new FacadeContainer( this ); - } - - @Override - public void clearContainer() - { - throw new RuntimeException( "Now that is silly!" ); - } - - @Override - public boolean isBlocked(ForgeDirection side) - { - return tcb.isBlocked( side ); - } - - public int getLightValue() - { - int light = 0; - - for (ForgeDirection d : ForgeDirection.values()) - { - IPart p = getPart( d ); - if ( p != null ) - light = Math.max( p.getLightLevel(), light ); - } - - if ( light > 0 && AppEng.instance.isIntegrationEnabled( IntegrationType.CLApi ) ) - return ((ICLApi) AppEng.instance.getIntegration( IntegrationType.CLApi )).colorLight( getColor(), light ); - - return light; - } - - @Override - public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) - { - IPart cable = getPart( ForgeDirection.UNKNOWN ); - if ( cable != null ) - { - IPartCable pc = (IPartCable) cable; - return pc.changeColor( colour, who ); - } - return false; - } - - public boolean activate(EntityPlayer player, Vec3 pos) - { - SelectedPart p = selectPart( pos ); - if ( p != null && p.part != null ) - { - return p.part.onActivate( player, pos ); - } - return false; - } - - @Override - public SelectedPart selectPart(Vec3 pos) - { - for (ForgeDirection side : ForgeDirection.values()) - { - IPart p = getPart( side ); - if ( p != null ) - { - List boxes = new LinkedList(); - - IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); - p.getBoxes( bch ); - for (AxisAlignedBB bb : boxes) - { - bb = bb.expand( 0.002, 0.002, 0.002 ); - if ( bb.isVecInside( pos ) ) - { - return new SelectedPart( p, side ); - } - } - } - } - - if ( AEApi.instance().partHelper().getCableRenderMode().opaqueFacades ) - { - IFacadeContainer fc = getFacadeContainer(); - for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) - { - IFacadePart p = fc.getFacade( side ); - if ( p != null ) - { - List boxes = new LinkedList(); - - IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); - p.getBoxes( bch, null ); - for (AxisAlignedBB bb : boxes) - { - bb = bb.expand( 0.01, 0.01, 0.01 ); - if ( bb.isVecInside( pos ) ) - { - return new SelectedPart( p, side ); - } - } - } - } - } - - return new SelectedPart(); - } - - @Override - public void partChanged() - { - if ( getCenter() == null ) - { - List facades = new LinkedList(); - - IFacadeContainer fc = getFacadeContainer(); - for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) - { - IFacadePart fp = fc.getFacade( d ); - if ( fp != null ) - { - facades.add( fp.getItemStack() ); - fc.removeFacade( tcb, d ); - } - } - - if ( facades != null && !facades.isEmpty() ) - { - TileEntity te = tcb.getTile(); - Platform.spawnDrops( te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, facades ); - } - } - - tcb.partChanged(); - } - - @Override - public void markForSave() - { - tcb.markForSave(); - } - - public void randomDisplayTick(World world, int x, int y, int z, Random r) - { - for (ForgeDirection side : ForgeDirection.values()) - { - IPart p = getPart( side ); - if ( p != null ) - { - p.randomDisplayTick( world, x, y, z, r ); - } - } - } - - @Override - public boolean hasRedstone(ForgeDirection side) - { - if ( hasRedstone == YesNo.UNDECIDED ) - updateRedstone(); - - return hasRedstone == YesNo.YES; - } - - public boolean isLadder(EntityLivingBase entity) - { - for (ForgeDirection side : ForgeDirection.values()) - { - IPart p = getPart( side ); - if ( p != null ) - { - if ( p.isLadder( entity ) ) - return true; - } - } - - return false; - } - - @Override - public void securityBreak() - { - for (ForgeDirection d : ForgeDirection.values()) - { - IPart p = getPart( d ); - if ( p != null && p instanceof IGridHost ) - ((IGridHost) p).securityBreak(); - } - } - - @Override - public Set getLayerFlags() - { - return myLayerFlags; - } - - @Override - public void cleanup() - { - tcb.cleanup(); - } - - @Override - public void notifyNeighbors() - { - tcb.notifyNeighbors(); - } - -} +package appeng.parts; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.util.EnumSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.config.YesNo; +import appeng.api.exceptions.FailedConnection; +import appeng.api.implementations.parts.IPartCable; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.parts.IFacadeContainer; +import appeng.api.parts.IFacadePart; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartItem; +import appeng.api.parts.LayerFlags; +import appeng.api.parts.PartItemStack; +import appeng.api.parts.SelectedPart; +import appeng.api.util.AECableType; +import appeng.api.util.AEColor; +import appeng.api.util.DimensionalCoord; +import appeng.client.render.CableRenderHelper; +import appeng.core.AELog; +import appeng.core.AppEng; +import appeng.facade.FacadeContainer; +import appeng.helpers.AEMultiTile; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.ICLApi; +import appeng.me.GridConnection; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class CableBusContainer extends CableBusStorage implements AEMultiTile, ICableBusContainer +{ + + private EnumSet myLayerFlags = EnumSet.noneOf( LayerFlags.class ); + + public YesNo hasRedstone = YesNo.UNDECIDED; + public IPartHost tcb; + + boolean inWorld = false; + public boolean requiresDynamicRender = false; + + @Override + public boolean isInWorld() + { + return inWorld; + } + + public void setHost(IPartHost host) + { + tcb.clearContainer(); + tcb = host; + } + + public CableBusContainer(IPartHost host) { + tcb = host; + } + + @Override + public IPart getPart(ForgeDirection side) + { + if ( side == ForgeDirection.UNKNOWN ) + return getCenter(); + return getSide( side ); + } + + public void rotateLeft() + { + IPart newSides[] = new IPart[6]; + + newSides[ForgeDirection.UP.ordinal()] = getSide( ForgeDirection.UP ); + newSides[ForgeDirection.DOWN.ordinal()] = getSide( ForgeDirection.DOWN ); + + newSides[ForgeDirection.EAST.ordinal()] = getSide( ForgeDirection.NORTH ); + newSides[ForgeDirection.SOUTH.ordinal()] = getSide( ForgeDirection.EAST ); + newSides[ForgeDirection.WEST.ordinal()] = getSide( ForgeDirection.SOUTH ); + newSides[ForgeDirection.NORTH.ordinal()] = getSide( ForgeDirection.WEST ); + + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + setSide( dir, newSides[dir.ordinal()] ); + + getFacadeContainer().rotateLeft(); + } + + public void updateDynamicRender() + { + requiresDynamicRender = false; + for (ForgeDirection s : ForgeDirection.VALID_DIRECTIONS) + { + IPart p = getPart( s ); + if ( p != null ) + requiresDynamicRender = requiresDynamicRender || p.requireDynamicRender(); + } + } + + @Override + public void removePart(ForgeDirection side, boolean suppressUpdate) + { + if ( side == ForgeDirection.UNKNOWN ) + { + if ( getCenter() != null ) + getCenter().removeFromWorld(); + setCenter( null ); + } + else + { + if ( getSide( side ) != null ) + getSide( side ).removeFromWorld(); + setSide( side, null ); + } + + if ( !suppressUpdate ) + { + updateDynamicRender(); + updateConnections(); + markForUpdate(); + markForSave(); + partChanged(); + } + } + + /** + * use for FMP + */ + public void updateConnections() + { + if ( getCenter() != null ) + { + EnumSet sides = EnumSet.allOf( ForgeDirection.class ); + + for (ForgeDirection s : ForgeDirection.VALID_DIRECTIONS) + { + if ( getPart( s ) != null || isBlocked( s ) ) + sides.remove( s ); + } + + getCenter().setValidSides( sides ); + IGridNode n = getCenter().getGridNode(); + if ( n != null ) + n.updateState(); + } + } + + @Override + public boolean canAddPart(ItemStack is, ForgeDirection side) + { + if ( PartPlacement.isFacade( is, side ) != null ) + return true; + + if ( is.getItem() instanceof IPartItem ) + { + IPartItem bi = (IPartItem) is.getItem(); + + is = is.copy(); + is.stackSize = 1; + + IPart bp = bi.createPartFromItemStack( is ); + if ( bp != null ) + { + if ( bp instanceof IPartCable ) + { + boolean canPlace = true; + for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) + if ( getPart( d ) != null && !getPart( d ).canBePlacedOn( ((IPartCable) bp).supportsBuses() ) ) + canPlace = false; + + if ( !canPlace ) + return false; + + return getPart( ForgeDirection.UNKNOWN ) == null; + } + else if ( !(bp instanceof IPartCable) && side != ForgeDirection.UNKNOWN ) + { + IPart cable = getPart( ForgeDirection.UNKNOWN ); + if ( cable != null && !bp.canBePlacedOn( ((IPartCable) cable).supportsBuses() ) ) + return false; + + return getPart( side ) == null; + } + } + } + return false; + } + + @Override + public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer player) + { + if ( canAddPart( is, side ) ) + { + if ( is.getItem() instanceof IPartItem ) + { + IPartItem bi = (IPartItem) is.getItem(); + + is = is.copy(); + is.stackSize = 1; + + IPart bp = bi.createPartFromItemStack( is ); + if ( bp instanceof IPartCable ) + { + boolean canPlace = true; + for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) + if ( getPart( d ) != null && !getPart( d ).canBePlacedOn( ((IPartCable) bp).supportsBuses() ) ) + canPlace = false; + + if ( !canPlace ) + return null; + + if ( getPart( ForgeDirection.UNKNOWN ) != null ) + return null; + + setCenter( (IPartCable) bp ); + bp.setPartHostInfo( ForgeDirection.UNKNOWN, this, tcb.getTile() ); + + if ( player != null ) + bp.onPlacement( player, is, side ); + + if ( inWorld ) + bp.addToWorld(); + + IGridNode cn = getCenter().getGridNode(); + if ( cn != null ) + { + for (ForgeDirection ins : ForgeDirection.VALID_DIRECTIONS) + { + IPart sbp = getPart( ins ); + if ( sbp != null ) + { + IGridNode sn = sbp.getGridNode(); + if ( sn != null && cn != null ) + { + try + { + new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN ); + } + catch (FailedConnection e) + { + // ekk! + + bp.removeFromWorld(); + setCenter( null ); + return null; + } + } + } + } + } + + updateConnections(); + markForUpdate(); + markForSave(); + partChanged(); + return ForgeDirection.UNKNOWN; + } + else if ( bp != null && !(bp instanceof IPartCable) && side != ForgeDirection.UNKNOWN ) + { + IPart cable = getPart( ForgeDirection.UNKNOWN ); + if ( cable != null && !bp.canBePlacedOn( ((IPartCable) cable).supportsBuses() ) ) + return null; + + setSide( side, bp ); + bp.setPartHostInfo( side, this, this.getTile() ); + + if ( player != null ) + bp.onPlacement( player, is, side ); + + if ( inWorld ) + bp.addToWorld(); + + if ( getCenter() != null ) + { + IGridNode cn = getCenter().getGridNode(); + IGridNode sn = bp.getGridNode(); + + if ( cn != null && sn != null ) + { + try + { + new GridConnection( (IGridNode) cn, (IGridNode) sn, ForgeDirection.UNKNOWN ); + } + catch (FailedConnection e) + { + // ekk! + + bp.removeFromWorld(); + setSide( side, null ); + return null; + } + } + } + + updateDynamicRender(); + updateConnections(); + markForUpdate(); + markForSave(); + partChanged(); + return side; + } + } + } + return null; + } + + private static final ThreadLocal isLoading = new ThreadLocal(); + + public static boolean isLoading() + { + Boolean is = isLoading.get(); + return is != null && is == true; + } + + public void addToWorld() + { + if ( inWorld ) + return; + + inWorld = true; + isLoading.set( true ); + + TileEntity te = getTile(); + + // start with the center, then install the side parts into the grid. + for (int x = 6; x >= 0; x--) + { + ForgeDirection s = ForgeDirection.getOrientation( x ); + IPart part = getPart( s ); + + if ( part != null ) + { + part.setPartHostInfo( s, this, te ); + part.addToWorld(); + + if ( s != ForgeDirection.UNKNOWN ) + { + IGridNode sn = part.getGridNode(); + if ( sn != null ) + { + // this is a really stupid if statement, why was this + // here? + // if ( !sn.getConnections().iterator().hasNext() ) + + IPart center = getPart( ForgeDirection.UNKNOWN ); + if ( center != null ) + { + IGridNode cn = center.getGridNode(); + if ( cn != null ) + { + try + { + AEApi.instance().createGridConnection( cn, sn ); + } + catch (FailedConnection e) + { + // ekk + } + } + } + + } + } + } + } + + partChanged(); + + isLoading.set( false ); + } + + public void removeFromWorld() + { + if ( !inWorld ) + return; + + inWorld = false; + + for (ForgeDirection s : ForgeDirection.values()) + { + IPart part = getPart( s ); + if ( part != null ) + part.removeFromWorld(); + } + + partChanged(); + } + + public boolean canConnectRedstone(EnumSet enumSet) + { + for (ForgeDirection dir : enumSet) + { + IPart part = getPart( dir ); + if ( part != null && part.canConnectRedstone() ) + return true; + } + return false; + } + + @Override + public IGridNode getGridNode(ForgeDirection side) + { + IPart part = getPart( side ); + if ( part != null ) + { + IGridNode n = part.getExternalFacingNode(); + if ( n != null ) + return n; + } + + if ( getCenter() != null ) + return getCenter().getGridNode(); + + return null; + } + + public Iterable getSelectedBoundingBoxsFromPool(boolean ignoreCableConnections, boolean includeFacades, Entity e, boolean visual) + { + List boxes = new LinkedList(); + + IFacadeContainer fc = getFacadeContainer(); + for (ForgeDirection s : ForgeDirection.values()) + { + IPartCollisionHelper bch = new BusCollisionHelper( boxes, s, e, visual ); + + IPart part = getPart( s ); + if ( part != null ) + { + if ( ignoreCableConnections && part instanceof IPartCable ) + bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 ); + else + part.getBoxes( bch ); + } + + if ( AEApi.instance().partHelper().getCableRenderMode().opaqueFacades || !visual ) + { + if ( includeFacades && s != null && s != ForgeDirection.UNKNOWN ) + { + IFacadePart fp = fc.getFacade( s ); + if ( fp != null ) + fp.getBoxes( bch, e ); + } + } + } + + return boxes; + } + + public void onEntityCollision(Entity entity) + { + for (ForgeDirection s : ForgeDirection.values()) + { + IPart part = getPart( s ); + if ( part != null ) + part.onEntityCollision( entity ); + } + } + + public boolean isEmpty() + { + IFacadeContainer fc = getFacadeContainer(); + for (ForgeDirection s : ForgeDirection.values()) + { + IPart part = getPart( s ); + if ( part != null ) + return false; + + if ( s != ForgeDirection.UNKNOWN ) + { + IFacadePart fp = fc.getFacade( s ); + if ( fp != null ) + return false; + } + } + return true; + } + + public void onNeighborChanged() + { + hasRedstone = YesNo.UNDECIDED; + + for (ForgeDirection s : ForgeDirection.values()) + { + IPart part = getPart( s ); + if ( part != null ) + part.onNeighborChanged(); + } + } + + private void updateRedstone() + { + TileEntity te = getTile(); + hasRedstone = te.getWorldObj().isBlockIndirectlyGettingPowered( te.xCoord, te.yCoord, te.zCoord ) ? YesNo.YES : YesNo.NO; + } + + public boolean isSolidOnSide(ForgeDirection side) + { + if ( side == null || side == ForgeDirection.UNKNOWN ) + return false; + + // facades are solid.. + IFacadePart fp = getFacadeContainer().getFacade( side ); + if ( fp != null ) + return true; + + // buses can be too. + IPart part = getPart( side ); + return part != null && part.isSolid(); + } + + public int isProvidingWeakPower(ForgeDirection side) + { + IPart part = getPart( side ); + return part != null ? part.isProvidingWeakPower() : 0; + } + + public int isProvidingStrongPower(ForgeDirection side) + { + IPart part = getPart( side ); + return part != null ? part.isProvidingStrongPower() : 0; + } + + @SideOnly(Side.CLIENT) + public void renderStatic(double x, double y, double z) + { + CableRenderHelper.getInstance().renderStatic( this, getFacadeContainer() ); + } + + @SideOnly(Side.CLIENT) + public void renderDynamic(double x, double y, double z) + { + CableRenderHelper.getInstance().renderDynamic( this, x, y, z ); + } + + public void writeToStream(ByteBuf data) throws IOException + { + int sides = 0; + for (int x = 0; x < 7; x++) + { + IPart p = getPart( ForgeDirection.getOrientation( x ) ); + if ( p != null ) + { + sides = sides | (1 << x); + } + } + + data.writeByte( (byte) sides ); + + for (int x = 0; x < 7; x++) + { + ItemStack is = null; + IPart p = getPart( ForgeDirection.getOrientation( x ) ); + if ( p != null ) + { + is = p.getItemStack( PartItemStack.Network ); + + data.writeShort( Item.getIdFromItem( is.getItem() ) ); + data.writeShort( is.getItemDamage() ); + + if ( p != null ) + p.writeToStream( data ); + } + } + + getFacadeContainer().writeToStream( data ); + } + + public boolean readFromStream(ByteBuf data) throws IOException + { + byte sides = data.readByte(); + + boolean updateBlock = false; + + for (int x = 0; x < 7; x++) + { + ForgeDirection side = ForgeDirection.getOrientation( x ); + if ( ((sides & (1 << x)) == (1 << x)) ) + { + IPart p = getPart( side ); + + short itemID = data.readShort(); + short dmgValue = data.readShort(); + + Item myItem = Item.getItemById( itemID ); + + ItemStack current = p != null ? p.getItemStack( PartItemStack.Network ) : null; + if ( current != null && current.getItem() == myItem && current.getItemDamage() == dmgValue ) + { + if ( p.readFromStream( data ) ) + updateBlock = true; + } + else + { + removePart( side, false ); + side = addPart( new ItemStack( myItem, 1, dmgValue ), side, null ); + if ( side != null ) + { + p = getPart( side ); + p.readFromStream( data ); + } + else + throw new RuntimeException( "Invalid Stream For CableBus Container." ); + } + } + else if ( getPart( side ) != null ) + removePart( side, false ); + } + + if ( getFacadeContainer().readFromStream( data ) ) + return true; + + return updateBlock; + } + + ForgeDirection getSide(IPart part) + { + if ( getCenter() == part ) + return ForgeDirection.UNKNOWN; + else + { + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + if ( getSide( side ) == part ) + { + return side; + } + } + throw new RuntimeException( "Uhh Bad Part on Side." ); + } + + public void writeToNBT(NBTTagCompound data) + { + data.setInteger( "hasRedstone", hasRedstone.ordinal() ); + + IFacadeContainer fc = getFacadeContainer(); + for (ForgeDirection s : ForgeDirection.values()) + { + fc.writeToNBT( data ); + + IPart part = getPart( s ); + if ( part != null ) + { + NBTTagCompound def = new NBTTagCompound(); + part.getItemStack( PartItemStack.World ).writeToNBT( def ); + + NBTTagCompound extra = new NBTTagCompound(); + part.writeToNBT( extra ); + + data.setTag( "def:" + getSide( part ).ordinal(), def ); + data.setTag( "extra:" + getSide( part ).ordinal(), extra ); + } + } + } + + public void readFromNBT(NBTTagCompound data) + { + if ( data.hasKey( "hasRedstone" ) ) + hasRedstone = YesNo.values()[data.getInteger( "hasRedstone" )]; + + for (int x = 0; x < 7; x++) + { + ForgeDirection side = ForgeDirection.getOrientation( x ); + + NBTTagCompound def = data.getCompoundTag( "def:" + side.ordinal() ); + NBTTagCompound extra = data.getCompoundTag( "extra:" + side.ordinal() ); + if ( def != null && extra != null ) + { + IPart p = getPart( side ); + ItemStack iss = ItemStack.loadItemStackFromNBT( def ); + if ( iss == null ) + continue; + + ItemStack current = p == null ? null : p.getItemStack( PartItemStack.World ); + + if ( Platform.isSameItemType( iss, current ) ) + p.readFromNBT( extra ); + else + { + removePart( side, true ); + side = addPart( iss, side, null ); + if ( side != null ) + { + p = getPart( side ); + p.readFromNBT( extra ); + } + else + { + AELog.warning( "Invalid NBT For CableBus Container: " + iss.getItem().getClass().getName() + " is not a valid part; it was ignored." ); + } + } + } + else + removePart( side, false ); + } + + getFacadeContainer().readFromNBT( data ); + } + + public List getDrops(List drops) + { + for (ForgeDirection s : ForgeDirection.values()) + { + IPart part = getPart( s ); + if ( part != null ) + { + drops.add( part.getItemStack( PartItemStack.Break ) ); + part.getDrops( drops, false ); + } + + if ( s != ForgeDirection.UNKNOWN ) + { + IFacadePart fp = getFacadeContainer().getFacade( s ); + if ( fp != null ) + drops.add( fp.getItemStack() ); + } + } + + return drops; + } + + public List getNoDrops(List drops) + { + for (ForgeDirection s : ForgeDirection.values()) + { + IPart part = getPart( s ); + if ( part != null ) + { + part.getDrops( drops, false ); + } + } + + return drops; + } + + @Override + public void markForUpdate() + { + tcb.markForUpdate(); + } + + @Override + public DimensionalCoord getLocation() + { + return tcb.getLocation(); + } + + @Override + public TileEntity getTile() + { + return tcb.getTile(); + } + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + IPart part = getPart( dir ); + if ( part != null && part instanceof IGridHost ) + { + AECableType t = ((IGridHost) part).getCableConnectionType( dir ); + if ( t != null && t != AECableType.NONE ) + return t; + } + + if ( getCenter() != null ) + { + IPartCable c = getCenter(); + return c.getCableConnectionType(); + } + return AECableType.NONE; + } + + @Override + public AEColor getColor() + { + if ( getCenter() != null ) + { + IPartCable c = getCenter(); + return c.getCableColor(); + } + return AEColor.Transparent; + } + + @Override + public IFacadeContainer getFacadeContainer() + { + return new FacadeContainer( this ); + } + + @Override + public void clearContainer() + { + throw new RuntimeException( "Now that is silly!" ); + } + + @Override + public boolean isBlocked(ForgeDirection side) + { + return tcb.isBlocked( side ); + } + + public int getLightValue() + { + int light = 0; + + for (ForgeDirection d : ForgeDirection.values()) + { + IPart p = getPart( d ); + if ( p != null ) + light = Math.max( p.getLightLevel(), light ); + } + + if ( light > 0 && AppEng.instance.isIntegrationEnabled( IntegrationType.CLApi ) ) + return ((ICLApi) AppEng.instance.getIntegration( IntegrationType.CLApi )).colorLight( getColor(), light ); + + return light; + } + + @Override + public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) + { + IPart cable = getPart( ForgeDirection.UNKNOWN ); + if ( cable != null ) + { + IPartCable pc = (IPartCable) cable; + return pc.changeColor( colour, who ); + } + return false; + } + + public boolean activate(EntityPlayer player, Vec3 pos) + { + SelectedPart p = selectPart( pos ); + if ( p != null && p.part != null ) + { + return p.part.onActivate( player, pos ); + } + return false; + } + + @Override + public SelectedPart selectPart(Vec3 pos) + { + for (ForgeDirection side : ForgeDirection.values()) + { + IPart p = getPart( side ); + if ( p != null ) + { + List boxes = new LinkedList(); + + IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); + p.getBoxes( bch ); + for (AxisAlignedBB bb : boxes) + { + bb = bb.expand( 0.002, 0.002, 0.002 ); + if ( bb.isVecInside( pos ) ) + { + return new SelectedPart( p, side ); + } + } + } + } + + if ( AEApi.instance().partHelper().getCableRenderMode().opaqueFacades ) + { + IFacadeContainer fc = getFacadeContainer(); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + IFacadePart p = fc.getFacade( side ); + if ( p != null ) + { + List boxes = new LinkedList(); + + IPartCollisionHelper bch = new BusCollisionHelper( boxes, side, null, true ); + p.getBoxes( bch, null ); + for (AxisAlignedBB bb : boxes) + { + bb = bb.expand( 0.01, 0.01, 0.01 ); + if ( bb.isVecInside( pos ) ) + { + return new SelectedPart( p, side ); + } + } + } + } + } + + return new SelectedPart(); + } + + @Override + public void partChanged() + { + if ( getCenter() == null ) + { + List facades = new LinkedList(); + + IFacadeContainer fc = getFacadeContainer(); + for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) + { + IFacadePart fp = fc.getFacade( d ); + if ( fp != null ) + { + facades.add( fp.getItemStack() ); + fc.removeFacade( tcb, d ); + } + } + + if ( facades != null && !facades.isEmpty() ) + { + TileEntity te = tcb.getTile(); + Platform.spawnDrops( te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, facades ); + } + } + + tcb.partChanged(); + } + + @Override + public void markForSave() + { + tcb.markForSave(); + } + + public void randomDisplayTick(World world, int x, int y, int z, Random r) + { + for (ForgeDirection side : ForgeDirection.values()) + { + IPart p = getPart( side ); + if ( p != null ) + { + p.randomDisplayTick( world, x, y, z, r ); + } + } + } + + @Override + public boolean hasRedstone(ForgeDirection side) + { + if ( hasRedstone == YesNo.UNDECIDED ) + updateRedstone(); + + return hasRedstone == YesNo.YES; + } + + public boolean isLadder(EntityLivingBase entity) + { + for (ForgeDirection side : ForgeDirection.values()) + { + IPart p = getPart( side ); + if ( p != null ) + { + if ( p.isLadder( entity ) ) + return true; + } + } + + return false; + } + + @Override + public void securityBreak() + { + for (ForgeDirection d : ForgeDirection.values()) + { + IPart p = getPart( d ); + if ( p != null && p instanceof IGridHost ) + ((IGridHost) p).securityBreak(); + } + } + + @Override + public Set getLayerFlags() + { + return myLayerFlags; + } + + @Override + public void cleanup() + { + tcb.cleanup(); + } + + @Override + public void notifyNeighbors() + { + tcb.notifyNeighbors(); + } + +} diff --git a/parts/CableBusStorage.java b/src/main/java/appeng/parts/CableBusStorage.java similarity index 100% rename from parts/CableBusStorage.java rename to src/main/java/appeng/parts/CableBusStorage.java diff --git a/parts/ICableBusContainer.java b/src/main/java/appeng/parts/ICableBusContainer.java similarity index 96% rename from parts/ICableBusContainer.java rename to src/main/java/appeng/parts/ICableBusContainer.java index 08155da8d..7ce04e5ed 100644 --- a/parts/ICableBusContainer.java +++ b/src/main/java/appeng/parts/ICableBusContainer.java @@ -1,47 +1,47 @@ -package appeng.parts; - -import java.util.EnumSet; -import java.util.Random; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.parts.SelectedPart; -import appeng.api.util.AEColor; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public interface ICableBusContainer -{ - - int isProvidingStrongPower(ForgeDirection opposite); - - int isProvidingWeakPower(ForgeDirection opposite); - - boolean canConnectRedstone(EnumSet of); - - void onEntityCollision(Entity e); - - boolean activate(EntityPlayer player, Vec3 vecFromPool); - - void onNeighborChanged(); - - boolean isSolidOnSide(ForgeDirection side); - - boolean isEmpty(); - - SelectedPart selectPart(Vec3 v3); - - boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who); - - boolean isLadder(EntityLivingBase entity); - - @SideOnly(Side.CLIENT) - void randomDisplayTick(World world, int x, int y, int z, Random r); - - int getLightValue(); - -} +package appeng.parts; + +import java.util.EnumSet; +import java.util.Random; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.parts.SelectedPart; +import appeng.api.util.AEColor; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public interface ICableBusContainer +{ + + int isProvidingStrongPower(ForgeDirection opposite); + + int isProvidingWeakPower(ForgeDirection opposite); + + boolean canConnectRedstone(EnumSet of); + + void onEntityCollision(Entity e); + + boolean activate(EntityPlayer player, Vec3 vecFromPool); + + void onNeighborChanged(); + + boolean isSolidOnSide(ForgeDirection side); + + boolean isEmpty(); + + SelectedPart selectPart(Vec3 v3); + + boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who); + + boolean isLadder(EntityLivingBase entity); + + @SideOnly(Side.CLIENT) + void randomDisplayTick(World world, int x, int y, int z, Random r); + + int getLightValue(); + +} diff --git a/parts/NullCableBusContainer.java b/src/main/java/appeng/parts/NullCableBusContainer.java similarity index 94% rename from parts/NullCableBusContainer.java rename to src/main/java/appeng/parts/NullCableBusContainer.java index af5af111d..9ca4d9a8d 100644 --- a/parts/NullCableBusContainer.java +++ b/src/main/java/appeng/parts/NullCableBusContainer.java @@ -1,96 +1,96 @@ -package appeng.parts; - -import java.util.EnumSet; -import java.util.Random; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.parts.SelectedPart; -import appeng.api.util.AEColor; - -public class NullCableBusContainer implements ICableBusContainer -{ - - @Override - public int isProvidingStrongPower(ForgeDirection opposite) - { - return 0; - } - - @Override - public int isProvidingWeakPower(ForgeDirection opposite) - { - return 0; - } - - @Override - public boolean canConnectRedstone(EnumSet of) - { - return false; - } - - @Override - public void onEntityCollision(Entity e) - { - - } - - @Override - public boolean activate(EntityPlayer player, Vec3 vecFromPool) - { - return false; - } - - @Override - public void onNeighborChanged() - { - - } - - @Override - public boolean isSolidOnSide(ForgeDirection side) - { - return false; - } - - @Override - public boolean isEmpty() - { - return true; - } - - @Override - public SelectedPart selectPart(Vec3 v3) - { - return new SelectedPart(); - } - - @Override - public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) - { - return false; - } - - @Override - public boolean isLadder(EntityLivingBase entity) - { - return false; - } - - @Override - public void randomDisplayTick(World world, int x, int y, int z, Random r) - { - - } - - @Override - public int getLightValue() - { - return 0; - } - -} +package appeng.parts; + +import java.util.EnumSet; +import java.util.Random; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.parts.SelectedPart; +import appeng.api.util.AEColor; + +public class NullCableBusContainer implements ICableBusContainer +{ + + @Override + public int isProvidingStrongPower(ForgeDirection opposite) + { + return 0; + } + + @Override + public int isProvidingWeakPower(ForgeDirection opposite) + { + return 0; + } + + @Override + public boolean canConnectRedstone(EnumSet of) + { + return false; + } + + @Override + public void onEntityCollision(Entity e) + { + + } + + @Override + public boolean activate(EntityPlayer player, Vec3 vecFromPool) + { + return false; + } + + @Override + public void onNeighborChanged() + { + + } + + @Override + public boolean isSolidOnSide(ForgeDirection side) + { + return false; + } + + @Override + public boolean isEmpty() + { + return true; + } + + @Override + public SelectedPart selectPart(Vec3 v3) + { + return new SelectedPart(); + } + + @Override + public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) + { + return false; + } + + @Override + public boolean isLadder(EntityLivingBase entity) + { + return false; + } + + @Override + public void randomDisplayTick(World world, int x, int y, int z, Random r) + { + + } + + @Override + public int getLightValue() + { + return 0; + } + +} diff --git a/parts/PartBasicState.java b/src/main/java/appeng/parts/PartBasicState.java similarity index 96% rename from parts/PartBasicState.java rename to src/main/java/appeng/parts/PartBasicState.java index 6fedb290f..117f19a83 100644 --- a/parts/PartBasicState.java +++ b/src/main/java/appeng/parts/PartBasicState.java @@ -1,139 +1,139 @@ -package appeng.parts; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.implementations.IPowerChannelState; -import appeng.api.networking.GridFlags; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.parts.IPartRenderHelper; -import appeng.client.texture.CableBusTextures; -import appeng.me.GridAccessException; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class PartBasicState extends AEBasePart implements IPowerChannelState -{ - - protected final int POWERED_FLAG = 1; - protected final int CHANNEL_FLAG = 2; - - protected int clientFlags = 0; // sent as byte. - - @MENetworkEventSubscribe - public void chanRender(MENetworkChannelsChanged c) - { - getHost().markForUpdate(); - } - - @MENetworkEventSubscribe - public void powerRender(MENetworkPowerStatusChange c) - { - getHost().markForUpdate(); - } - - public void setColors(boolean hasChan, boolean hasPower) - { - if ( hasChan ) - { - int l = 14; - Tessellator.instance.setBrightness( l << 20 | l << 4 ); - Tessellator.instance.setColorOpaque_I( getColor().blackVariant ); - } - else if ( hasPower ) - { - int l = 9; - Tessellator.instance.setBrightness( l << 20 | l << 4 ); - Tessellator.instance.setColorOpaque_I( getColor().whiteVariant ); - } - else - { - Tessellator.instance.setBrightness( 0 ); - Tessellator.instance.setColorOpaque_I( 0x000000 ); - } - } - - @SideOnly(Side.CLIENT) - public void renderLights(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) - { - rh.normalRendering(); - setColors( (clientFlags & (POWERED_FLAG | CHANNEL_FLAG)) == (POWERED_FLAG | CHANNEL_FLAG), (clientFlags & POWERED_FLAG) == POWERED_FLAG ); - rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.EAST, renderer ); - rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.WEST, renderer ); - rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.UP, renderer ); - rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.DOWN, renderer ); - } - - @Override - public void writeToStream(ByteBuf data) throws IOException - { - super.writeToStream( data ); - - clientFlags = 0; - - try - { - if ( proxy.getEnergy().isNetworkPowered() ) - clientFlags |= POWERED_FLAG; - - if ( proxy.getNode().meetsChannelRequirements() ) - clientFlags |= CHANNEL_FLAG; - - clientFlags = populateFlags( clientFlags ); - } - catch (GridAccessException e) - { - // meh - } - - data.writeByte( (byte) clientFlags ); - } - - protected int populateFlags(int cf) - { - return cf; - } - - @Override - public boolean readFromStream(ByteBuf data) throws IOException - { - boolean eh = super.readFromStream( data ); - - int old = clientFlags; - clientFlags = data.readByte(); - - return eh || old != clientFlags; - } - - public PartBasicState(Class c, ItemStack is) { - super( c, is ); - proxy.setFlags( GridFlags.REQUIRE_CHANNEL ); - } - - @Override - public boolean isPowered() - { - return (clientFlags & POWERED_FLAG) == POWERED_FLAG; - } - - @Override - public boolean isActive() - { - return (clientFlags & CHANNEL_FLAG) == CHANNEL_FLAG; - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getBreakingTexture() - { - return CableBusTextures.PartTransitionPlaneBack.getIcon(); - } -} +package appeng.parts; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.implementations.IPowerChannelState; +import appeng.api.networking.GridFlags; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.api.parts.IPartRenderHelper; +import appeng.client.texture.CableBusTextures; +import appeng.me.GridAccessException; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartBasicState extends AEBasePart implements IPowerChannelState +{ + + protected final int POWERED_FLAG = 1; + protected final int CHANNEL_FLAG = 2; + + protected int clientFlags = 0; // sent as byte. + + @MENetworkEventSubscribe + public void chanRender(MENetworkChannelsChanged c) + { + getHost().markForUpdate(); + } + + @MENetworkEventSubscribe + public void powerRender(MENetworkPowerStatusChange c) + { + getHost().markForUpdate(); + } + + public void setColors(boolean hasChan, boolean hasPower) + { + if ( hasChan ) + { + int l = 14; + Tessellator.instance.setBrightness( l << 20 | l << 4 ); + Tessellator.instance.setColorOpaque_I( getColor().blackVariant ); + } + else if ( hasPower ) + { + int l = 9; + Tessellator.instance.setBrightness( l << 20 | l << 4 ); + Tessellator.instance.setColorOpaque_I( getColor().whiteVariant ); + } + else + { + Tessellator.instance.setBrightness( 0 ); + Tessellator.instance.setColorOpaque_I( 0x000000 ); + } + } + + @SideOnly(Side.CLIENT) + public void renderLights(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) + { + rh.normalRendering(); + setColors( (clientFlags & (POWERED_FLAG | CHANNEL_FLAG)) == (POWERED_FLAG | CHANNEL_FLAG), (clientFlags & POWERED_FLAG) == POWERED_FLAG ); + rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.EAST, renderer ); + rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.WEST, renderer ); + rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.UP, renderer ); + rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.DOWN, renderer ); + } + + @Override + public void writeToStream(ByteBuf data) throws IOException + { + super.writeToStream( data ); + + clientFlags = 0; + + try + { + if ( proxy.getEnergy().isNetworkPowered() ) + clientFlags |= POWERED_FLAG; + + if ( proxy.getNode().meetsChannelRequirements() ) + clientFlags |= CHANNEL_FLAG; + + clientFlags = populateFlags( clientFlags ); + } + catch (GridAccessException e) + { + // meh + } + + data.writeByte( (byte) clientFlags ); + } + + protected int populateFlags(int cf) + { + return cf; + } + + @Override + public boolean readFromStream(ByteBuf data) throws IOException + { + boolean eh = super.readFromStream( data ); + + int old = clientFlags; + clientFlags = data.readByte(); + + return eh || old != clientFlags; + } + + public PartBasicState(Class c, ItemStack is) { + super( c, is ); + proxy.setFlags( GridFlags.REQUIRE_CHANNEL ); + } + + @Override + public boolean isPowered() + { + return (clientFlags & POWERED_FLAG) == POWERED_FLAG; + } + + @Override + public boolean isActive() + { + return (clientFlags & CHANNEL_FLAG) == CHANNEL_FLAG; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getBreakingTexture() + { + return CableBusTextures.PartTransitionPlaneBack.getIcon(); + } +} diff --git a/parts/PartPlacement.java b/src/main/java/appeng/parts/PartPlacement.java similarity index 100% rename from parts/PartPlacement.java rename to src/main/java/appeng/parts/PartPlacement.java diff --git a/parts/automation/NonNullArrayIterator.java b/src/main/java/appeng/parts/automation/NonNullArrayIterator.java similarity index 100% rename from parts/automation/NonNullArrayIterator.java rename to src/main/java/appeng/parts/automation/NonNullArrayIterator.java diff --git a/parts/automation/PartAnnihilationPlane.java b/src/main/java/appeng/parts/automation/PartAnnihilationPlane.java similarity index 100% rename from parts/automation/PartAnnihilationPlane.java rename to src/main/java/appeng/parts/automation/PartAnnihilationPlane.java diff --git a/parts/automation/PartExportBus.java b/src/main/java/appeng/parts/automation/PartExportBus.java similarity index 100% rename from parts/automation/PartExportBus.java rename to src/main/java/appeng/parts/automation/PartExportBus.java diff --git a/parts/automation/PartFormationPlane.java b/src/main/java/appeng/parts/automation/PartFormationPlane.java similarity index 100% rename from parts/automation/PartFormationPlane.java rename to src/main/java/appeng/parts/automation/PartFormationPlane.java diff --git a/parts/automation/PartImportBus.java b/src/main/java/appeng/parts/automation/PartImportBus.java similarity index 100% rename from parts/automation/PartImportBus.java rename to src/main/java/appeng/parts/automation/PartImportBus.java diff --git a/parts/automation/PartLevelEmitter.java b/src/main/java/appeng/parts/automation/PartLevelEmitter.java similarity index 100% rename from parts/automation/PartLevelEmitter.java rename to src/main/java/appeng/parts/automation/PartLevelEmitter.java diff --git a/parts/automation/PartSharedItemBus.java b/src/main/java/appeng/parts/automation/PartSharedItemBus.java similarity index 100% rename from parts/automation/PartSharedItemBus.java rename to src/main/java/appeng/parts/automation/PartSharedItemBus.java diff --git a/parts/automation/PartUpgradeable.java b/src/main/java/appeng/parts/automation/PartUpgradeable.java similarity index 100% rename from parts/automation/PartUpgradeable.java rename to src/main/java/appeng/parts/automation/PartUpgradeable.java diff --git a/parts/automation/UpgradeInventory.java b/src/main/java/appeng/parts/automation/UpgradeInventory.java similarity index 100% rename from parts/automation/UpgradeInventory.java rename to src/main/java/appeng/parts/automation/UpgradeInventory.java diff --git a/parts/layers/InvLayerData.java b/src/main/java/appeng/parts/layers/InvLayerData.java similarity index 100% rename from parts/layers/InvLayerData.java rename to src/main/java/appeng/parts/layers/InvLayerData.java diff --git a/parts/layers/InvSot.java b/src/main/java/appeng/parts/layers/InvSot.java similarity index 100% rename from parts/layers/InvSot.java rename to src/main/java/appeng/parts/layers/InvSot.java diff --git a/parts/layers/LayerIBatteryProvider.java b/src/main/java/appeng/parts/layers/LayerIBatteryProvider.java similarity index 100% rename from parts/layers/LayerIBatteryProvider.java rename to src/main/java/appeng/parts/layers/LayerIBatteryProvider.java diff --git a/parts/layers/LayerIEnergyHandler.java b/src/main/java/appeng/parts/layers/LayerIEnergyHandler.java similarity index 100% rename from parts/layers/LayerIEnergyHandler.java rename to src/main/java/appeng/parts/layers/LayerIEnergyHandler.java diff --git a/parts/layers/LayerIEnergySink.java b/src/main/java/appeng/parts/layers/LayerIEnergySink.java similarity index 100% rename from parts/layers/LayerIEnergySink.java rename to src/main/java/appeng/parts/layers/LayerIEnergySink.java diff --git a/parts/layers/LayerIEnergySource.java b/src/main/java/appeng/parts/layers/LayerIEnergySource.java similarity index 100% rename from parts/layers/LayerIEnergySource.java rename to src/main/java/appeng/parts/layers/LayerIEnergySource.java diff --git a/parts/layers/LayerIFluidHandler.java b/src/main/java/appeng/parts/layers/LayerIFluidHandler.java similarity index 100% rename from parts/layers/LayerIFluidHandler.java rename to src/main/java/appeng/parts/layers/LayerIFluidHandler.java diff --git a/parts/layers/LayerIPipeConnection.java b/src/main/java/appeng/parts/layers/LayerIPipeConnection.java similarity index 100% rename from parts/layers/LayerIPipeConnection.java rename to src/main/java/appeng/parts/layers/LayerIPipeConnection.java diff --git a/parts/layers/LayerIPowerEmitter.java b/src/main/java/appeng/parts/layers/LayerIPowerEmitter.java similarity index 100% rename from parts/layers/LayerIPowerEmitter.java rename to src/main/java/appeng/parts/layers/LayerIPowerEmitter.java diff --git a/parts/layers/LayerIPowerReceptor.java b/src/main/java/appeng/parts/layers/LayerIPowerReceptor.java similarity index 100% rename from parts/layers/LayerIPowerReceptor.java rename to src/main/java/appeng/parts/layers/LayerIPowerReceptor.java diff --git a/parts/layers/LayerISidedInventory.java b/src/main/java/appeng/parts/layers/LayerISidedInventory.java similarity index 100% rename from parts/layers/LayerISidedInventory.java rename to src/main/java/appeng/parts/layers/LayerISidedInventory.java diff --git a/parts/layers/LayerITileStorageMonitorable.java b/src/main/java/appeng/parts/layers/LayerITileStorageMonitorable.java similarity index 100% rename from parts/layers/LayerITileStorageMonitorable.java rename to src/main/java/appeng/parts/layers/LayerITileStorageMonitorable.java diff --git a/parts/misc/PartCableAnchor.java b/src/main/java/appeng/parts/misc/PartCableAnchor.java similarity index 100% rename from parts/misc/PartCableAnchor.java rename to src/main/java/appeng/parts/misc/PartCableAnchor.java diff --git a/parts/misc/PartInterface.java b/src/main/java/appeng/parts/misc/PartInterface.java similarity index 100% rename from parts/misc/PartInterface.java rename to src/main/java/appeng/parts/misc/PartInterface.java diff --git a/parts/misc/PartInvertedToggleBus.java b/src/main/java/appeng/parts/misc/PartInvertedToggleBus.java similarity index 100% rename from parts/misc/PartInvertedToggleBus.java rename to src/main/java/appeng/parts/misc/PartInvertedToggleBus.java diff --git a/parts/misc/PartStorageBus.java b/src/main/java/appeng/parts/misc/PartStorageBus.java similarity index 100% rename from parts/misc/PartStorageBus.java rename to src/main/java/appeng/parts/misc/PartStorageBus.java diff --git a/parts/misc/PartToggleBus.java b/src/main/java/appeng/parts/misc/PartToggleBus.java similarity index 100% rename from parts/misc/PartToggleBus.java rename to src/main/java/appeng/parts/misc/PartToggleBus.java diff --git a/parts/networking/PartCable.java b/src/main/java/appeng/parts/networking/PartCable.java similarity index 96% rename from parts/networking/PartCable.java rename to src/main/java/appeng/parts/networking/PartCable.java index aa6b4404f..b72b62583 100644 --- a/parts/networking/PartCable.java +++ b/src/main/java/appeng/parts/networking/PartCable.java @@ -1,1031 +1,1031 @@ -package appeng.parts.networking; - -import appeng.client.texture.FlippableIcon; -import io.netty.buffer.ByteBuf; - -import java.io.IOException; -import java.util.EnumSet; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import appeng.api.AEApi; -import appeng.api.config.SecurityPermissions; -import appeng.api.implementations.parts.IPartCable; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridConnection; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.parts.BusSupport; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.api.util.IReadOnlyCollection; -import appeng.block.AEBaseBlock; -import appeng.client.texture.CableBusTextures; -import appeng.client.texture.TaughtIcon; -import appeng.items.parts.ItemMultiPart; -import appeng.me.GridAccessException; -import appeng.me.helpers.AENetworkProxy; -import appeng.parts.AEBasePart; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class PartCable extends AEBasePart implements IPartCable -{ - - int channelsOnSide[] = new int[] { 0, 0, 0, 0, 0, 0 }; - - EnumSet connections = EnumSet.noneOf( ForgeDirection.class ); - boolean powered = false; - - public PartCable(Class c, ItemStack is) { - super( c, is ); - proxy.setFlags( GridFlags.PREFERRED ); - proxy.setIdlePowerUsage( 0.0 ); - proxy.myColor = AEColor.values()[((ItemMultiPart) is.getItem()).variantOf( is.getItemDamage() )]; - } - - @Override - public boolean isConnected(ForgeDirection side) - { - return connections.contains( side ); - } - - @Override - public BusSupport supportsBuses() - { - return BusSupport.CABLE; - } - - public IIcon getGlassTexture(AEColor c) - { - switch (c) - { - case Black: - return CableBusTextures.MECable_Black.getIcon(); - case Blue: - return CableBusTextures.MECable_Blue.getIcon(); - case Brown: - return CableBusTextures.MECable_Brown.getIcon(); - case Cyan: - return CableBusTextures.MECable_Cyan.getIcon(); - case Gray: - return CableBusTextures.MECable_Grey.getIcon(); - case Green: - return CableBusTextures.MECable_Green.getIcon(); - case LightBlue: - return CableBusTextures.MECable_LightBlue.getIcon(); - case LightGray: - return CableBusTextures.MECable_LightGrey.getIcon(); - case Lime: - return CableBusTextures.MECable_Lime.getIcon(); - case Magenta: - return CableBusTextures.MECable_Magenta.getIcon(); - case Orange: - return CableBusTextures.MECable_Orange.getIcon(); - case Pink: - return CableBusTextures.MECable_Pink.getIcon(); - case Purple: - return CableBusTextures.MECable_Purple.getIcon(); - case Red: - return CableBusTextures.MECable_Red.getIcon(); - case White: - return CableBusTextures.MECable_White.getIcon(); - case Yellow: - return CableBusTextures.MECable_Yellow.getIcon(); - default: - } - return AEApi.instance().parts().partCableGlass.item( AEColor.Transparent ).getIconIndex( - AEApi.instance().parts().partCableGlass.stack( AEColor.Transparent, 1 ) ); - } - - public IIcon getTexture(AEColor c) - { - return getGlassTexture( c ); - } - - public IIcon getCoveredTexture(AEColor c) - { - switch (c) - { - case Black: - return CableBusTextures.MECovered_Black.getIcon(); - case Blue: - return CableBusTextures.MECovered_Blue.getIcon(); - case Brown: - return CableBusTextures.MECovered_Brown.getIcon(); - case Cyan: - return CableBusTextures.MECovered_Cyan.getIcon(); - case Gray: - return CableBusTextures.MECovered_Gray.getIcon(); - case Green: - return CableBusTextures.MECovered_Green.getIcon(); - case LightBlue: - return CableBusTextures.MECovered_LightBlue.getIcon(); - case LightGray: - return CableBusTextures.MECovered_LightGrey.getIcon(); - case Lime: - return CableBusTextures.MECovered_Lime.getIcon(); - case Magenta: - return CableBusTextures.MECovered_Magenta.getIcon(); - case Orange: - return CableBusTextures.MECovered_Orange.getIcon(); - case Pink: - return CableBusTextures.MECovered_Pink.getIcon(); - case Purple: - return CableBusTextures.MECovered_Purple.getIcon(); - case Red: - return CableBusTextures.MECovered_Red.getIcon(); - case White: - return CableBusTextures.MECovered_White.getIcon(); - case Yellow: - return CableBusTextures.MECovered_Yellow.getIcon(); - default: - } - return AEApi.instance().parts().partCableCovered.item( AEColor.Transparent ).getIconIndex( - AEApi.instance().parts().partCableCovered.stack( AEColor.Transparent, 1 ) ); - } - - public IIcon getSmartTexture(AEColor c) - { - switch (c) - { - case Black: - return CableBusTextures.MESmart_Black.getIcon(); - case Blue: - return CableBusTextures.MESmart_Blue.getIcon(); - case Brown: - return CableBusTextures.MESmart_Brown.getIcon(); - case Cyan: - return CableBusTextures.MESmart_Cyan.getIcon(); - case Gray: - return CableBusTextures.MESmart_Gray.getIcon(); - case Green: - return CableBusTextures.MESmart_Green.getIcon(); - case LightBlue: - return CableBusTextures.MESmart_LightBlue.getIcon(); - case LightGray: - return CableBusTextures.MESmart_LightGrey.getIcon(); - case Lime: - return CableBusTextures.MESmart_Lime.getIcon(); - case Magenta: - return CableBusTextures.MESmart_Magenta.getIcon(); - case Orange: - return CableBusTextures.MESmart_Orange.getIcon(); - case Pink: - return CableBusTextures.MESmart_Pink.getIcon(); - case Purple: - return CableBusTextures.MESmart_Purple.getIcon(); - case Red: - return CableBusTextures.MESmart_Red.getIcon(); - case White: - return CableBusTextures.MESmart_White.getIcon(); - case Yellow: - return CableBusTextures.MESmart_Yellow.getIcon(); - default: - } - return AEApi.instance().parts().partCableCovered.item( AEColor.Transparent ).getIconIndex( - AEApi.instance().parts().partCableSmart.stack( AEColor.Transparent, 1 ) ); - } - - @Override - public AEColor getCableColor() - { - return proxy.myColor; - } - - @Override - public AECableType getCableConnectionType() - { - return AECableType.GLASS; - } - - public AENetworkProxy getProxy() - { - return proxy; - } - - public void markForUpdate() - { - getHost().markForUpdate(); - } - - @Override - public void writeToNBT(NBTTagCompound data) - { - super.writeToNBT( data ); - - if ( Platform.isServer() ) - { - IGridNode node = getGridNode(); - int howMany = 0; - - if ( node != null ) - { - for (IGridConnection gc : node.getConnections()) - howMany = Math.max( gc.getUsedChannels(), howMany ); - - data.setByte( "usedChannels", (byte) howMany ); - } - } - - } - - @Override - public void writeToStream(ByteBuf data) throws IOException - { - int cs = 0; - int sideOut = 0; - - IGridNode n = getGridNode(); - if ( n != null ) - { - for (ForgeDirection thisSide : ForgeDirection.VALID_DIRECTIONS) - { - IPart part = getHost().getPart( thisSide ); - if ( part != null ) - { - if ( part.getGridNode() != null ) - { - IReadOnlyCollection set = part.getGridNode().getConnections(); - for (IGridConnection gc : set) - { - if ( proxy.getNode().hasFlag( GridFlags.DENSE_CAPACITY ) && gc.getOtherSide( proxy.getNode() ).hasFlag( GridFlags.DENSE_CAPACITY ) ) - sideOut |= (gc.getUsedChannels() / 4) << (4 * thisSide.ordinal()); - else - sideOut |= (gc.getUsedChannels()) << (4 * thisSide.ordinal()); - } - } - } - } - - for (IGridConnection gc : n.getConnections()) - { - ForgeDirection side = gc.getDirection( n ); - if ( side != ForgeDirection.UNKNOWN ) - { - boolean isTier2a = proxy.getNode().hasFlag( GridFlags.DENSE_CAPACITY ); - boolean isTier2b = gc.getOtherSide( proxy.getNode() ).hasFlag( GridFlags.DENSE_CAPACITY ); - - if ( isTier2a && isTier2b ) - sideOut |= (gc.getUsedChannels() / 4) << (4 * side.ordinal()); - else - sideOut |= gc.getUsedChannels() << (4 * side.ordinal()); - cs |= (1 << side.ordinal()); - } - } - } - - try - { - if ( proxy.getEnergy().isNetworkPowered() ) - cs |= (1 << ForgeDirection.UNKNOWN.ordinal()); - } - catch (GridAccessException e) - { - // aww... - } - - data.writeByte( (byte) cs ); - data.writeInt( sideOut ); - } - - @Override - public boolean readFromStream(ByteBuf data) throws IOException - { - int cs = data.readByte(); - int sideOut = data.readInt(); - - EnumSet myC = connections.clone(); - boolean wasPowered = powered; - powered = false; - boolean chchanged = false; - - for (ForgeDirection d : ForgeDirection.values()) - { - if ( d != ForgeDirection.UNKNOWN ) - { - int ch = (sideOut >> (d.ordinal() * 4)) & 0xF; - if ( ch != channelsOnSide[d.ordinal()] ) - { - chchanged = true; - channelsOnSide[d.ordinal()] = ch; - } - } - - if ( d == ForgeDirection.UNKNOWN ) - { - int id = 1 << d.ordinal(); - if ( id == (cs & id) ) - powered = true; - } - else - { - int id = 1 << d.ordinal(); - if ( id == (cs & id) ) - connections.add( d ); - else - connections.remove( d ); - } - } - - return !myC.equals( connections ) || wasPowered != powered || chchanged; - } - - @Override - public void getBoxes(IPartCollisionHelper bch) - { - bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 ); - - if ( Platform.isServer() ) - { - IGridNode n = getGridNode(); - if ( n != null ) - connections = n.getConnectedSides(); - else - connections.clear(); - } - - IPartHost ph = getHost(); - if ( ph != null ) - { - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - { - IPart p = ph.getPart( dir ); - if ( p instanceof IGridHost ) - { - double dist = p.cableConnectionRenderTo(); - - if ( dist > 8 ) - continue; - - switch (dir) - { - case DOWN: - bch.addBox( 6.0, dist, 6.0, 10.0, 6.0, 10.0 ); - break; - case EAST: - bch.addBox( 10.0, 6.0, 6.0, 16.0 - dist, 10.0, 10.0 ); - break; - case NORTH: - bch.addBox( 6.0, 6.0, dist, 10.0, 10.0, 6.0 ); - break; - case SOUTH: - bch.addBox( 6.0, 6.0, 10.0, 10.0, 10.0, 16.0 - dist ); - break; - case UP: - bch.addBox( 6.0, 10.0, 6.0, 10.0, 16.0 - dist, 10.0 ); - break; - case WEST: - bch.addBox( dist, 6.0, 6.0, 6.0, 10.0, 10.0 ); - break; - default: - continue; - } - } - } - } - - for (ForgeDirection of : connections) - { - switch (of) - { - case DOWN: - bch.addBox( 6.0, 0.0, 6.0, 10.0, 6.0, 10.0 ); - break; - case EAST: - bch.addBox( 10.0, 6.0, 6.0, 16.0, 10.0, 10.0 ); - break; - case NORTH: - bch.addBox( 6.0, 6.0, 0.0, 10.0, 10.0, 6.0 ); - break; - case SOUTH: - bch.addBox( 6.0, 6.0, 10.0, 10.0, 10.0, 16.0 ); - break; - case UP: - bch.addBox( 6.0, 10.0, 6.0, 10.0, 16.0, 10.0 ); - break; - case WEST: - bch.addBox( 0.0, 6.0, 6.0, 6.0, 10.0, 10.0 ); - break; - default: - continue; - } - } - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) - { - GL11.glTranslated( -0.0, -0.0, 0.3 ); - - rh.setTexture( getTexture( getCableColor() ) ); - rh.setBounds( 6.0f, 6.0f, 2.0f, 10.0f, 10.0f, 14.0f ); - rh.renderInventoryBox( renderer ); - rh.setTexture( null ); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getBreakingTexture() - { - return getTexture( getCableColor() ); - } - - @SideOnly(Side.CLIENT) - public void renderGlassConnection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, ForgeDirection of) - { - TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ ); - IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; - IGridHost gh = te instanceof IGridHost ? (IGridHost) te : null; - - rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) ); - - if ( gh != null && ccph != null && gh.getCableConnectionType( of ) == AECableType.GLASS && ccph.getColor() != AEColor.Transparent - && ccph.getPart( of.getOpposite() ) == null ) - rh.setTexture( getTexture( ccph.getColor() ) ); - else if ( ccph == null && gh != null && gh.getCableConnectionType( of ) != AECableType.GLASS ) - { - rh.setTexture( getCoveredTexture( getCableColor() ) ); - switch (of) - { - case DOWN: - rh.setBounds( 5, 0, 5, 11, 4, 11 ); - break; - case EAST: - rh.setBounds( 12, 5, 5, 16, 11, 11 ); - break; - case NORTH: - rh.setBounds( 5, 5, 0, 11, 11, 4 ); - break; - case SOUTH: - rh.setBounds( 5, 5, 12, 11, 11, 16 ); - break; - case UP: - rh.setBounds( 5, 12, 5, 11, 16, 11 ); - break; - case WEST: - rh.setBounds( 0, 5, 5, 4, 11, 11 ); - break; - default: - return; - } - - rh.renderBlock( x, y, z, renderer ); - rh.setTexture( getTexture( getCableColor() ) ); - } - else - rh.setTexture( getTexture( getCableColor() ) ); - - switch (of) - { - case DOWN: - rh.setBounds( 6, 0, 6, 10, 6, 10 ); - break; - case EAST: - rh.setBounds( 10, 6, 6, 16, 10, 10 ); - break; - case NORTH: - rh.setBounds( 6, 6, 0, 10, 10, 6 ); - break; - case SOUTH: - rh.setBounds( 6, 6, 10, 10, 10, 16 ); - break; - case UP: - rh.setBounds( 6, 10, 6, 10, 16, 10 ); - break; - case WEST: - rh.setBounds( 0, 6, 6, 6, 10, 10 ); - break; - default: - return; - } - - rh.renderBlock( x, y, z, renderer ); - rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); - } - - protected CableBusTextures getChannelTex(int i, boolean b) - { - if ( !powered ) - i = 0; - - if ( b ) - { - switch (i) - { - default: - return CableBusTextures.Channels10; - case 5: - return CableBusTextures.Channels11; - case 6: - return CableBusTextures.Channels12; - case 7: - return CableBusTextures.Channels13; - case 8: - return CableBusTextures.Channels14; - } - } - else - { - switch (i) - { - case 0: - return CableBusTextures.Channels00; - case 1: - return CableBusTextures.Channels01; - case 2: - return CableBusTextures.Channels02; - case 3: - return CableBusTextures.Channels03; - default: - return CableBusTextures.Channels04; - } - } - } - - @SideOnly(Side.CLIENT) - public void renderCoveredConnection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, int channels, ForgeDirection of) - { - TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ ); - IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; - IGridHost ghh = te instanceof IGridHost ? (IGridHost) te : null; - boolean isSmart = false; - - rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) ); - if ( ghh != null && ccph != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && ccph.getPart( of.getOpposite() ) == null - && ccph.getColor() != AEColor.Transparent ) - rh.setTexture( getGlassTexture( ccph.getColor() ) ); - else if ( ccph == null && ghh != null && ghh.getCableConnectionType( of ) != AECableType.GLASS ) - { - rh.setTexture( getCoveredTexture( getCableColor() ) ); - switch (of) - { - case DOWN: - rh.setBounds( 5, 0, 5, 11, 4, 11 ); - break; - case EAST: - rh.setBounds( 12, 5, 5, 16, 11, 11 ); - break; - case NORTH: - rh.setBounds( 5, 5, 0, 11, 11, 4 ); - break; - case SOUTH: - rh.setBounds( 5, 5, 12, 11, 11, 16 ); - break; - case UP: - rh.setBounds( 5, 12, 5, 11, 16, 11 ); - break; - case WEST: - rh.setBounds( 0, 5, 5, 4, 11, 11 ); - break; - default: - return; - } - - rh.renderBlock( x, y, z, renderer ); - - rh.setTexture( getTexture( getCableColor() ) ); - } - else if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) == AECableType.COVERED && ccph.getColor() != AEColor.Transparent - && ccph.getPart( of.getOpposite() ) == null ) - rh.setTexture( getCoveredTexture( ccph.getColor() ) ); - else if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) == AECableType.SMART && ccph.getPart( of.getOpposite() ) == null ) - { - isSmart = true; - rh.setTexture( getSmartTexture( getCableColor() ) ); - } - else - rh.setTexture( getCoveredTexture( getCableColor() ) ); - - switch (of) - { - case DOWN: - rh.setBounds( 6, 0, 6, 10, 5, 10 ); - break; - case EAST: - rh.setBounds( 11, 6, 6, 16, 10, 10 ); - break; - case NORTH: - rh.setBounds( 6, 6, 0, 10, 10, 5 ); - break; - case SOUTH: - rh.setBounds( 6, 6, 11, 10, 10, 16 ); - break; - case UP: - rh.setBounds( 6, 11, 6, 10, 16, 10 ); - break; - case WEST: - rh.setBounds( 0, 6, 6, 5, 10, 10 ); - break; - default: - return; - } - - rh.renderBlock( x, y, z, renderer ); - rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); - - if ( isSmart ) - { - setSmartConnectionRotations( of, renderer ); - IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); - IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); - - if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) - { - AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); - FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); - ico.setFlip( false, true ); - } - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); - rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); - rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - } - - rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); - } - - @SideOnly(Side.CLIENT) - public void renderSmartConection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, int channels, ForgeDirection of) - { - TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ ); - IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; - IGridHost ghh = te instanceof IGridHost ? (IGridHost) te : null; - boolean isGlass = false; - AEColor myColor = getCableColor(); - - rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) ); - - if ( ghh != null && ccph != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && ccph.getPart( of.getOpposite() ) == null - && ccph.getColor() != AEColor.Transparent ) - { - isGlass = true; - rh.setTexture( getGlassTexture( myColor = ccph.getColor() ) ); - } - else if ( ccph == null && ghh != null && ghh.getCableConnectionType( of.getOpposite() ) != AECableType.GLASS ) - { - rh.setTexture( getSmartTexture( myColor ) ); - switch (of) - { - case DOWN: - rh.setBounds( 5, 0, 5, 11, 4, 11 ); - break; - case EAST: - rh.setBounds( 12, 5, 5, 16, 11, 11 ); - break; - case NORTH: - rh.setBounds( 5, 5, 0, 11, 11, 4 ); - break; - case SOUTH: - rh.setBounds( 5, 5, 12, 11, 11, 16 ); - break; - case UP: - rh.setBounds( 5, 12, 5, 11, 16, 11 ); - break; - case WEST: - rh.setBounds( 0, 5, 5, 4, 11, 11 ); - break; - default: - return; - } - rh.renderBlock( x, y, z, renderer ); - - if ( true ) - { - setSmartConnectionRotations( of, renderer ); - IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); - IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); - - if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) - { - AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); - FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); - ico.setFlip( false, true ); - } - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - Tessellator.instance.setColorOpaque_I( myColor.blackVariant ); - rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); - rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - } - - rh.setTexture( getTexture( getCableColor() ) ); - } - - else if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) != AECableType.GLASS && ccph.getColor() != AEColor.Transparent - && ccph.getPart( of.getOpposite() ) == null ) - rh.setTexture( getSmartTexture( myColor = ccph.getColor() ) ); - else - rh.setTexture( getSmartTexture( getCableColor() ) ); - - switch (of) - { - case DOWN: - rh.setBounds( 6, 0, 6, 10, 5, 10 ); - break; - case EAST: - rh.setBounds( 11, 6, 6, 16, 10, 10 ); - break; - case NORTH: - rh.setBounds( 6, 6, 0, 10, 10, 5 ); - break; - case SOUTH: - rh.setBounds( 6, 6, 11, 10, 10, 16 ); - break; - case UP: - rh.setBounds( 6, 11, 6, 10, 16, 10 ); - break; - case WEST: - rh.setBounds( 0, 6, 6, 5, 10, 10 ); - break; - default: - return; - } - - rh.renderBlock( x, y, z, renderer ); - rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); - - if ( !isGlass ) - { - setSmartConnectionRotations( of, renderer ); - - IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); - IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - Tessellator.instance.setColorOpaque_I( myColor.blackVariant ); - rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); - rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - } - - } - - @SideOnly(Side.CLIENT) - protected void setSmartConnectionRotations(ForgeDirection of, RenderBlocks renderer) - { - switch (of) - { - case UP: - case DOWN: - renderer.uvRotateTop = 0; - renderer.uvRotateBottom = 0; - renderer.uvRotateSouth = 3; - renderer.uvRotateEast = 3; - break; - case NORTH: - case SOUTH: - renderer.uvRotateTop = 3; - renderer.uvRotateBottom = 3; - renderer.uvRotateNorth = 1; - renderer.uvRotateSouth = 2; - renderer.uvRotateWest = 1; - break; - case EAST: - case WEST: - renderer.uvRotateEast = 2; - renderer.uvRotateWest = 1; - renderer.uvRotateBottom = 2; - renderer.uvRotateTop = 1; - renderer.uvRotateSouth = 3; - renderer.uvRotateNorth = 0; - break; - default: - break; - - } - - } - - @SideOnly(Side.CLIENT) - protected void renderAllFaces(AEBaseBlock blk, int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) - { - rh.setBounds( (float) renderer.renderMinX * 16.0f, (float) renderer.renderMinY * 16.0f, (float) renderer.renderMinZ * 16.0f, - (float) renderer.renderMaxX * 16.0f, (float) renderer.renderMaxY * 16.0f, (float) renderer.renderMaxZ * 16.0f ); - rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.WEST ), ForgeDirection.WEST, renderer ); - rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.EAST ), ForgeDirection.EAST, renderer ); - rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.NORTH ), ForgeDirection.NORTH, renderer ); - rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.SOUTH ), ForgeDirection.SOUTH, renderer ); - rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.DOWN ), ForgeDirection.DOWN, renderer ); - rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.UP ), ForgeDirection.UP, renderer ); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) - { - renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); - boolean useCovered = false; - boolean requireDetailed = false; - - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) - { - IPart p = getHost().getPart( dir ); - if ( p != null && p instanceof IGridHost ) - { - IGridHost igh = (IGridHost) p; - AECableType type = igh.getCableConnectionType( dir.getOpposite() ); - if ( type == AECableType.COVERED || type == AECableType.SMART ) - { - useCovered = true; - break; - } - } - else if ( connections.contains( dir ) ) - { - TileEntity te = this.tile.getWorldObj().getTileEntity( x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ ); - IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; - IGridHost gh = te instanceof IGridHost ? (IGridHost) te : null; - if ( ccph == null && gh != null && gh.getCableConnectionType( dir ) != AECableType.GLASS ) - requireDetailed = true; - } - } - - if ( useCovered ) - { - rh.setTexture( getCoveredTexture( getCableColor() ) ); - } - else - { - rh.setTexture( getTexture( getCableColor() ) ); - } - - IPartHost ph = getHost(); - for (ForgeDirection of : EnumSet.complementOf( connections )) - { - IPart bp = ph.getPart( of ); - if ( bp instanceof IGridHost ) - { - int len = bp.cableConnectionRenderTo(); - if ( len < 8 ) - { - switch (of) - { - case DOWN: - rh.setBounds( 6, len, 6, 10, 6, 10 ); - break; - case EAST: - rh.setBounds( 10, 6, 6, 16 - len, 10, 10 ); - break; - case NORTH: - rh.setBounds( 6, 6, len, 10, 10, 6 ); - break; - case SOUTH: - rh.setBounds( 6, 6, 10, 10, 10, 16 - len ); - break; - case UP: - rh.setBounds( 6, 10, 6, 10, 16 - len, 10 ); - break; - case WEST: - rh.setBounds( len, 6, 6, 6, 10, 10 ); - break; - default: - continue; - } - rh.renderBlock( x, y, z, renderer ); - } - } - } - - if ( connections.size() != 2 || !nonLinear( connections ) || useCovered || requireDetailed ) - { - if ( useCovered ) - { - rh.setBounds( 5, 5, 5, 11, 11, 11 ); - rh.renderBlock( x, y, z, renderer ); - } - else - { - rh.setBounds( 6, 6, 6, 10, 10, 10 ); - rh.renderBlock( x, y, z, renderer ); - } - - for (ForgeDirection of : connections) - { - renderGlassConnection( x, y, z, rh, renderer, of ); - } - } - else - { - IIcon def = getTexture( getCableColor() ); - rh.setTexture( def ); - - for (ForgeDirection of : connections) - { - rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); - switch (of) - { - case DOWN: - case UP: - renderer.setRenderBounds( 6 / 16.0, 0, 6 / 16.0, 10 / 16.0, 16 / 16.0, 10 / 16.0 ); - break; - case EAST: - case WEST: - renderer.uvRotateEast = renderer.uvRotateWest = 1; - renderer.uvRotateBottom = renderer.uvRotateTop = 1; - renderer.setRenderBounds( 0, 6 / 16.0, 6 / 16.0, 16 / 16.0, 10 / 16.0, 10 / 16.0 ); - break; - case NORTH: - case SOUTH: - renderer.uvRotateNorth = renderer.uvRotateSouth = 1; - renderer.setRenderBounds( 6 / 16.0, 6 / 16.0, 0, 10 / 16.0, 10 / 16.0, 16 / 16.0 ); - break; - default: - continue; - } - } - - rh.renderBlockCurrentBounds( x, y, z, renderer ); - } - - rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); - rh.setTexture( null ); - } - - @Override - public boolean changeColor(AEColor newColor, EntityPlayer who) - { - if ( getCableColor() != newColor ) - { - ItemStack newPart = null; - - if ( getCableConnectionType() == AECableType.GLASS ) - newPart = AEApi.instance().parts().partCableGlass.stack( newColor, 1 ); - else if ( getCableConnectionType() == AECableType.COVERED ) - newPart = AEApi.instance().parts().partCableCovered.stack( newColor, 1 ); - else if ( getCableConnectionType() == AECableType.SMART ) - newPart = AEApi.instance().parts().partCableSmart.stack( newColor, 1 ); - else if ( getCableConnectionType() == AECableType.DENSE ) - newPart = AEApi.instance().parts().partCableDense.stack( newColor, 1 ); - - boolean hasPermission = true; - - try - { - hasPermission = proxy.getSecurity().hasPermission( who, SecurityPermissions.BUILD ); - } - catch (GridAccessException e) - { - // :P - } - - if ( newPart != null && hasPermission ) - { - if ( Platform.isClient() ) - return true; - - getHost().removePart( ForgeDirection.UNKNOWN, true ); - getHost().addPart( newPart, ForgeDirection.UNKNOWN, who ); - return true; - } - } - return false; - } - - @Override - public void setValidSides(EnumSet sides) - { - proxy.setValidSides( sides ); - } - - protected boolean nonLinear(EnumSet sides) - { - return (sides.contains( ForgeDirection.EAST ) && sides.contains( ForgeDirection.WEST )) - || (sides.contains( ForgeDirection.NORTH ) && sides.contains( ForgeDirection.SOUTH )) - || (sides.contains( ForgeDirection.UP ) && sides.contains( ForgeDirection.DOWN )); - } - -} +package appeng.parts.networking; + +import appeng.client.texture.FlippableIcon; +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.util.EnumSet; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import appeng.api.AEApi; +import appeng.api.config.SecurityPermissions; +import appeng.api.implementations.parts.IPartCable; +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGridConnection; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.parts.BusSupport; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.util.AECableType; +import appeng.api.util.AEColor; +import appeng.api.util.IReadOnlyCollection; +import appeng.block.AEBaseBlock; +import appeng.client.texture.CableBusTextures; +import appeng.client.texture.TaughtIcon; +import appeng.items.parts.ItemMultiPart; +import appeng.me.GridAccessException; +import appeng.me.helpers.AENetworkProxy; +import appeng.parts.AEBasePart; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartCable extends AEBasePart implements IPartCable +{ + + int channelsOnSide[] = new int[] { 0, 0, 0, 0, 0, 0 }; + + EnumSet connections = EnumSet.noneOf( ForgeDirection.class ); + boolean powered = false; + + public PartCable(Class c, ItemStack is) { + super( c, is ); + proxy.setFlags( GridFlags.PREFERRED ); + proxy.setIdlePowerUsage( 0.0 ); + proxy.myColor = AEColor.values()[((ItemMultiPart) is.getItem()).variantOf( is.getItemDamage() )]; + } + + @Override + public boolean isConnected(ForgeDirection side) + { + return connections.contains( side ); + } + + @Override + public BusSupport supportsBuses() + { + return BusSupport.CABLE; + } + + public IIcon getGlassTexture(AEColor c) + { + switch (c) + { + case Black: + return CableBusTextures.MECable_Black.getIcon(); + case Blue: + return CableBusTextures.MECable_Blue.getIcon(); + case Brown: + return CableBusTextures.MECable_Brown.getIcon(); + case Cyan: + return CableBusTextures.MECable_Cyan.getIcon(); + case Gray: + return CableBusTextures.MECable_Grey.getIcon(); + case Green: + return CableBusTextures.MECable_Green.getIcon(); + case LightBlue: + return CableBusTextures.MECable_LightBlue.getIcon(); + case LightGray: + return CableBusTextures.MECable_LightGrey.getIcon(); + case Lime: + return CableBusTextures.MECable_Lime.getIcon(); + case Magenta: + return CableBusTextures.MECable_Magenta.getIcon(); + case Orange: + return CableBusTextures.MECable_Orange.getIcon(); + case Pink: + return CableBusTextures.MECable_Pink.getIcon(); + case Purple: + return CableBusTextures.MECable_Purple.getIcon(); + case Red: + return CableBusTextures.MECable_Red.getIcon(); + case White: + return CableBusTextures.MECable_White.getIcon(); + case Yellow: + return CableBusTextures.MECable_Yellow.getIcon(); + default: + } + return AEApi.instance().parts().partCableGlass.item( AEColor.Transparent ).getIconIndex( + AEApi.instance().parts().partCableGlass.stack( AEColor.Transparent, 1 ) ); + } + + public IIcon getTexture(AEColor c) + { + return getGlassTexture( c ); + } + + public IIcon getCoveredTexture(AEColor c) + { + switch (c) + { + case Black: + return CableBusTextures.MECovered_Black.getIcon(); + case Blue: + return CableBusTextures.MECovered_Blue.getIcon(); + case Brown: + return CableBusTextures.MECovered_Brown.getIcon(); + case Cyan: + return CableBusTextures.MECovered_Cyan.getIcon(); + case Gray: + return CableBusTextures.MECovered_Gray.getIcon(); + case Green: + return CableBusTextures.MECovered_Green.getIcon(); + case LightBlue: + return CableBusTextures.MECovered_LightBlue.getIcon(); + case LightGray: + return CableBusTextures.MECovered_LightGrey.getIcon(); + case Lime: + return CableBusTextures.MECovered_Lime.getIcon(); + case Magenta: + return CableBusTextures.MECovered_Magenta.getIcon(); + case Orange: + return CableBusTextures.MECovered_Orange.getIcon(); + case Pink: + return CableBusTextures.MECovered_Pink.getIcon(); + case Purple: + return CableBusTextures.MECovered_Purple.getIcon(); + case Red: + return CableBusTextures.MECovered_Red.getIcon(); + case White: + return CableBusTextures.MECovered_White.getIcon(); + case Yellow: + return CableBusTextures.MECovered_Yellow.getIcon(); + default: + } + return AEApi.instance().parts().partCableCovered.item( AEColor.Transparent ).getIconIndex( + AEApi.instance().parts().partCableCovered.stack( AEColor.Transparent, 1 ) ); + } + + public IIcon getSmartTexture(AEColor c) + { + switch (c) + { + case Black: + return CableBusTextures.MESmart_Black.getIcon(); + case Blue: + return CableBusTextures.MESmart_Blue.getIcon(); + case Brown: + return CableBusTextures.MESmart_Brown.getIcon(); + case Cyan: + return CableBusTextures.MESmart_Cyan.getIcon(); + case Gray: + return CableBusTextures.MESmart_Gray.getIcon(); + case Green: + return CableBusTextures.MESmart_Green.getIcon(); + case LightBlue: + return CableBusTextures.MESmart_LightBlue.getIcon(); + case LightGray: + return CableBusTextures.MESmart_LightGrey.getIcon(); + case Lime: + return CableBusTextures.MESmart_Lime.getIcon(); + case Magenta: + return CableBusTextures.MESmart_Magenta.getIcon(); + case Orange: + return CableBusTextures.MESmart_Orange.getIcon(); + case Pink: + return CableBusTextures.MESmart_Pink.getIcon(); + case Purple: + return CableBusTextures.MESmart_Purple.getIcon(); + case Red: + return CableBusTextures.MESmart_Red.getIcon(); + case White: + return CableBusTextures.MESmart_White.getIcon(); + case Yellow: + return CableBusTextures.MESmart_Yellow.getIcon(); + default: + } + return AEApi.instance().parts().partCableCovered.item( AEColor.Transparent ).getIconIndex( + AEApi.instance().parts().partCableSmart.stack( AEColor.Transparent, 1 ) ); + } + + @Override + public AEColor getCableColor() + { + return proxy.myColor; + } + + @Override + public AECableType getCableConnectionType() + { + return AECableType.GLASS; + } + + public AENetworkProxy getProxy() + { + return proxy; + } + + public void markForUpdate() + { + getHost().markForUpdate(); + } + + @Override + public void writeToNBT(NBTTagCompound data) + { + super.writeToNBT( data ); + + if ( Platform.isServer() ) + { + IGridNode node = getGridNode(); + int howMany = 0; + + if ( node != null ) + { + for (IGridConnection gc : node.getConnections()) + howMany = Math.max( gc.getUsedChannels(), howMany ); + + data.setByte( "usedChannels", (byte) howMany ); + } + } + + } + + @Override + public void writeToStream(ByteBuf data) throws IOException + { + int cs = 0; + int sideOut = 0; + + IGridNode n = getGridNode(); + if ( n != null ) + { + for (ForgeDirection thisSide : ForgeDirection.VALID_DIRECTIONS) + { + IPart part = getHost().getPart( thisSide ); + if ( part != null ) + { + if ( part.getGridNode() != null ) + { + IReadOnlyCollection set = part.getGridNode().getConnections(); + for (IGridConnection gc : set) + { + if ( proxy.getNode().hasFlag( GridFlags.DENSE_CAPACITY ) && gc.getOtherSide( proxy.getNode() ).hasFlag( GridFlags.DENSE_CAPACITY ) ) + sideOut |= (gc.getUsedChannels() / 4) << (4 * thisSide.ordinal()); + else + sideOut |= (gc.getUsedChannels()) << (4 * thisSide.ordinal()); + } + } + } + } + + for (IGridConnection gc : n.getConnections()) + { + ForgeDirection side = gc.getDirection( n ); + if ( side != ForgeDirection.UNKNOWN ) + { + boolean isTier2a = proxy.getNode().hasFlag( GridFlags.DENSE_CAPACITY ); + boolean isTier2b = gc.getOtherSide( proxy.getNode() ).hasFlag( GridFlags.DENSE_CAPACITY ); + + if ( isTier2a && isTier2b ) + sideOut |= (gc.getUsedChannels() / 4) << (4 * side.ordinal()); + else + sideOut |= gc.getUsedChannels() << (4 * side.ordinal()); + cs |= (1 << side.ordinal()); + } + } + } + + try + { + if ( proxy.getEnergy().isNetworkPowered() ) + cs |= (1 << ForgeDirection.UNKNOWN.ordinal()); + } + catch (GridAccessException e) + { + // aww... + } + + data.writeByte( (byte) cs ); + data.writeInt( sideOut ); + } + + @Override + public boolean readFromStream(ByteBuf data) throws IOException + { + int cs = data.readByte(); + int sideOut = data.readInt(); + + EnumSet myC = connections.clone(); + boolean wasPowered = powered; + powered = false; + boolean chchanged = false; + + for (ForgeDirection d : ForgeDirection.values()) + { + if ( d != ForgeDirection.UNKNOWN ) + { + int ch = (sideOut >> (d.ordinal() * 4)) & 0xF; + if ( ch != channelsOnSide[d.ordinal()] ) + { + chchanged = true; + channelsOnSide[d.ordinal()] = ch; + } + } + + if ( d == ForgeDirection.UNKNOWN ) + { + int id = 1 << d.ordinal(); + if ( id == (cs & id) ) + powered = true; + } + else + { + int id = 1 << d.ordinal(); + if ( id == (cs & id) ) + connections.add( d ); + else + connections.remove( d ); + } + } + + return !myC.equals( connections ) || wasPowered != powered || chchanged; + } + + @Override + public void getBoxes(IPartCollisionHelper bch) + { + bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 ); + + if ( Platform.isServer() ) + { + IGridNode n = getGridNode(); + if ( n != null ) + connections = n.getConnectedSides(); + else + connections.clear(); + } + + IPartHost ph = getHost(); + if ( ph != null ) + { + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + IPart p = ph.getPart( dir ); + if ( p instanceof IGridHost ) + { + double dist = p.cableConnectionRenderTo(); + + if ( dist > 8 ) + continue; + + switch (dir) + { + case DOWN: + bch.addBox( 6.0, dist, 6.0, 10.0, 6.0, 10.0 ); + break; + case EAST: + bch.addBox( 10.0, 6.0, 6.0, 16.0 - dist, 10.0, 10.0 ); + break; + case NORTH: + bch.addBox( 6.0, 6.0, dist, 10.0, 10.0, 6.0 ); + break; + case SOUTH: + bch.addBox( 6.0, 6.0, 10.0, 10.0, 10.0, 16.0 - dist ); + break; + case UP: + bch.addBox( 6.0, 10.0, 6.0, 10.0, 16.0 - dist, 10.0 ); + break; + case WEST: + bch.addBox( dist, 6.0, 6.0, 6.0, 10.0, 10.0 ); + break; + default: + continue; + } + } + } + } + + for (ForgeDirection of : connections) + { + switch (of) + { + case DOWN: + bch.addBox( 6.0, 0.0, 6.0, 10.0, 6.0, 10.0 ); + break; + case EAST: + bch.addBox( 10.0, 6.0, 6.0, 16.0, 10.0, 10.0 ); + break; + case NORTH: + bch.addBox( 6.0, 6.0, 0.0, 10.0, 10.0, 6.0 ); + break; + case SOUTH: + bch.addBox( 6.0, 6.0, 10.0, 10.0, 10.0, 16.0 ); + break; + case UP: + bch.addBox( 6.0, 10.0, 6.0, 10.0, 16.0, 10.0 ); + break; + case WEST: + bch.addBox( 0.0, 6.0, 6.0, 6.0, 10.0, 10.0 ); + break; + default: + continue; + } + } + } + + @Override + @SideOnly(Side.CLIENT) + public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) + { + GL11.glTranslated( -0.0, -0.0, 0.3 ); + + rh.setTexture( getTexture( getCableColor() ) ); + rh.setBounds( 6.0f, 6.0f, 2.0f, 10.0f, 10.0f, 14.0f ); + rh.renderInventoryBox( renderer ); + rh.setTexture( null ); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getBreakingTexture() + { + return getTexture( getCableColor() ); + } + + @SideOnly(Side.CLIENT) + public void renderGlassConnection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, ForgeDirection of) + { + TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ ); + IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; + IGridHost gh = te instanceof IGridHost ? (IGridHost) te : null; + + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) ); + + if ( gh != null && ccph != null && gh.getCableConnectionType( of ) == AECableType.GLASS && ccph.getColor() != AEColor.Transparent + && ccph.getPart( of.getOpposite() ) == null ) + rh.setTexture( getTexture( ccph.getColor() ) ); + else if ( ccph == null && gh != null && gh.getCableConnectionType( of ) != AECableType.GLASS ) + { + rh.setTexture( getCoveredTexture( getCableColor() ) ); + switch (of) + { + case DOWN: + rh.setBounds( 5, 0, 5, 11, 4, 11 ); + break; + case EAST: + rh.setBounds( 12, 5, 5, 16, 11, 11 ); + break; + case NORTH: + rh.setBounds( 5, 5, 0, 11, 11, 4 ); + break; + case SOUTH: + rh.setBounds( 5, 5, 12, 11, 11, 16 ); + break; + case UP: + rh.setBounds( 5, 12, 5, 11, 16, 11 ); + break; + case WEST: + rh.setBounds( 0, 5, 5, 4, 11, 11 ); + break; + default: + return; + } + + rh.renderBlock( x, y, z, renderer ); + rh.setTexture( getTexture( getCableColor() ) ); + } + else + rh.setTexture( getTexture( getCableColor() ) ); + + switch (of) + { + case DOWN: + rh.setBounds( 6, 0, 6, 10, 6, 10 ); + break; + case EAST: + rh.setBounds( 10, 6, 6, 16, 10, 10 ); + break; + case NORTH: + rh.setBounds( 6, 6, 0, 10, 10, 6 ); + break; + case SOUTH: + rh.setBounds( 6, 6, 10, 10, 10, 16 ); + break; + case UP: + rh.setBounds( 6, 10, 6, 10, 16, 10 ); + break; + case WEST: + rh.setBounds( 0, 6, 6, 6, 10, 10 ); + break; + default: + return; + } + + rh.renderBlock( x, y, z, renderer ); + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); + } + + protected CableBusTextures getChannelTex(int i, boolean b) + { + if ( !powered ) + i = 0; + + if ( b ) + { + switch (i) + { + default: + return CableBusTextures.Channels10; + case 5: + return CableBusTextures.Channels11; + case 6: + return CableBusTextures.Channels12; + case 7: + return CableBusTextures.Channels13; + case 8: + return CableBusTextures.Channels14; + } + } + else + { + switch (i) + { + case 0: + return CableBusTextures.Channels00; + case 1: + return CableBusTextures.Channels01; + case 2: + return CableBusTextures.Channels02; + case 3: + return CableBusTextures.Channels03; + default: + return CableBusTextures.Channels04; + } + } + } + + @SideOnly(Side.CLIENT) + public void renderCoveredConnection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, int channels, ForgeDirection of) + { + TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ ); + IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; + IGridHost ghh = te instanceof IGridHost ? (IGridHost) te : null; + boolean isSmart = false; + + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) ); + if ( ghh != null && ccph != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && ccph.getPart( of.getOpposite() ) == null + && ccph.getColor() != AEColor.Transparent ) + rh.setTexture( getGlassTexture( ccph.getColor() ) ); + else if ( ccph == null && ghh != null && ghh.getCableConnectionType( of ) != AECableType.GLASS ) + { + rh.setTexture( getCoveredTexture( getCableColor() ) ); + switch (of) + { + case DOWN: + rh.setBounds( 5, 0, 5, 11, 4, 11 ); + break; + case EAST: + rh.setBounds( 12, 5, 5, 16, 11, 11 ); + break; + case NORTH: + rh.setBounds( 5, 5, 0, 11, 11, 4 ); + break; + case SOUTH: + rh.setBounds( 5, 5, 12, 11, 11, 16 ); + break; + case UP: + rh.setBounds( 5, 12, 5, 11, 16, 11 ); + break; + case WEST: + rh.setBounds( 0, 5, 5, 4, 11, 11 ); + break; + default: + return; + } + + rh.renderBlock( x, y, z, renderer ); + + rh.setTexture( getTexture( getCableColor() ) ); + } + else if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) == AECableType.COVERED && ccph.getColor() != AEColor.Transparent + && ccph.getPart( of.getOpposite() ) == null ) + rh.setTexture( getCoveredTexture( ccph.getColor() ) ); + else if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) == AECableType.SMART && ccph.getPart( of.getOpposite() ) == null ) + { + isSmart = true; + rh.setTexture( getSmartTexture( getCableColor() ) ); + } + else + rh.setTexture( getCoveredTexture( getCableColor() ) ); + + switch (of) + { + case DOWN: + rh.setBounds( 6, 0, 6, 10, 5, 10 ); + break; + case EAST: + rh.setBounds( 11, 6, 6, 16, 10, 10 ); + break; + case NORTH: + rh.setBounds( 6, 6, 0, 10, 10, 5 ); + break; + case SOUTH: + rh.setBounds( 6, 6, 11, 10, 10, 16 ); + break; + case UP: + rh.setBounds( 6, 11, 6, 10, 16, 10 ); + break; + case WEST: + rh.setBounds( 0, 6, 6, 5, 10, 10 ); + break; + default: + return; + } + + rh.renderBlock( x, y, z, renderer ); + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); + + if ( isSmart ) + { + setSmartConnectionRotations( of, renderer ); + IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); + IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); + + if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) + { + AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); + FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); + ico.setFlip( false, true ); + } + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); + rh.setTexture( defa, defa, defa, defa, defa, defa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); + rh.setTexture( defb, defb, defb, defb, defb, defb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + } + + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); + } + + @SideOnly(Side.CLIENT) + public void renderSmartConection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, int channels, ForgeDirection of) + { + TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ ); + IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; + IGridHost ghh = te instanceof IGridHost ? (IGridHost) te : null; + boolean isGlass = false; + AEColor myColor = getCableColor(); + + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of ) ) ); + + if ( ghh != null && ccph != null && ghh.getCableConnectionType( of.getOpposite() ) == AECableType.GLASS && ccph.getPart( of.getOpposite() ) == null + && ccph.getColor() != AEColor.Transparent ) + { + isGlass = true; + rh.setTexture( getGlassTexture( myColor = ccph.getColor() ) ); + } + else if ( ccph == null && ghh != null && ghh.getCableConnectionType( of.getOpposite() ) != AECableType.GLASS ) + { + rh.setTexture( getSmartTexture( myColor ) ); + switch (of) + { + case DOWN: + rh.setBounds( 5, 0, 5, 11, 4, 11 ); + break; + case EAST: + rh.setBounds( 12, 5, 5, 16, 11, 11 ); + break; + case NORTH: + rh.setBounds( 5, 5, 0, 11, 11, 4 ); + break; + case SOUTH: + rh.setBounds( 5, 5, 12, 11, 11, 16 ); + break; + case UP: + rh.setBounds( 5, 12, 5, 11, 16, 11 ); + break; + case WEST: + rh.setBounds( 0, 5, 5, 4, 11, 11 ); + break; + default: + return; + } + rh.renderBlock( x, y, z, renderer ); + + if ( true ) + { + setSmartConnectionRotations( of, renderer ); + IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); + IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); + + if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) + { + AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); + FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); + ico.setFlip( false, true ); + } + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + Tessellator.instance.setColorOpaque_I( myColor.blackVariant ); + rh.setTexture( defa, defa, defa, defa, defa, defa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); + rh.setTexture( defb, defb, defb, defb, defb, defb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + } + + rh.setTexture( getTexture( getCableColor() ) ); + } + + else if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) != AECableType.GLASS && ccph.getColor() != AEColor.Transparent + && ccph.getPart( of.getOpposite() ) == null ) + rh.setTexture( getSmartTexture( myColor = ccph.getColor() ) ); + else + rh.setTexture( getSmartTexture( getCableColor() ) ); + + switch (of) + { + case DOWN: + rh.setBounds( 6, 0, 6, 10, 5, 10 ); + break; + case EAST: + rh.setBounds( 11, 6, 6, 16, 10, 10 ); + break; + case NORTH: + rh.setBounds( 6, 6, 0, 10, 10, 5 ); + break; + case SOUTH: + rh.setBounds( 6, 6, 11, 10, 10, 16 ); + break; + case UP: + rh.setBounds( 6, 11, 6, 10, 16, 10 ); + break; + case WEST: + rh.setBounds( 0, 6, 6, 5, 10, 10 ); + break; + default: + return; + } + + rh.renderBlock( x, y, z, renderer ); + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); + + if ( !isGlass ) + { + setSmartConnectionRotations( of, renderer ); + + IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); + IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + Tessellator.instance.setColorOpaque_I( myColor.blackVariant ); + rh.setTexture( defa, defa, defa, defa, defa, defa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); + rh.setTexture( defb, defb, defb, defb, defb, defb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + } + + } + + @SideOnly(Side.CLIENT) + protected void setSmartConnectionRotations(ForgeDirection of, RenderBlocks renderer) + { + switch (of) + { + case UP: + case DOWN: + renderer.uvRotateTop = 0; + renderer.uvRotateBottom = 0; + renderer.uvRotateSouth = 3; + renderer.uvRotateEast = 3; + break; + case NORTH: + case SOUTH: + renderer.uvRotateTop = 3; + renderer.uvRotateBottom = 3; + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 2; + renderer.uvRotateWest = 1; + break; + case EAST: + case WEST: + renderer.uvRotateEast = 2; + renderer.uvRotateWest = 1; + renderer.uvRotateBottom = 2; + renderer.uvRotateTop = 1; + renderer.uvRotateSouth = 3; + renderer.uvRotateNorth = 0; + break; + default: + break; + + } + + } + + @SideOnly(Side.CLIENT) + protected void renderAllFaces(AEBaseBlock blk, int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) + { + rh.setBounds( (float) renderer.renderMinX * 16.0f, (float) renderer.renderMinY * 16.0f, (float) renderer.renderMinZ * 16.0f, + (float) renderer.renderMaxX * 16.0f, (float) renderer.renderMaxY * 16.0f, (float) renderer.renderMaxZ * 16.0f ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.WEST ), ForgeDirection.WEST, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.EAST ), ForgeDirection.EAST, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.NORTH ), ForgeDirection.NORTH, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.SOUTH ), ForgeDirection.SOUTH, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.DOWN ), ForgeDirection.DOWN, renderer ); + rh.renderFace( x, y, z, blk.getRendererInstance().getTexture( ForgeDirection.UP ), ForgeDirection.UP, renderer ); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) + { + renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); + boolean useCovered = false; + boolean requireDetailed = false; + + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + IPart p = getHost().getPart( dir ); + if ( p != null && p instanceof IGridHost ) + { + IGridHost igh = (IGridHost) p; + AECableType type = igh.getCableConnectionType( dir.getOpposite() ); + if ( type == AECableType.COVERED || type == AECableType.SMART ) + { + useCovered = true; + break; + } + } + else if ( connections.contains( dir ) ) + { + TileEntity te = this.tile.getWorldObj().getTileEntity( x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ ); + IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; + IGridHost gh = te instanceof IGridHost ? (IGridHost) te : null; + if ( ccph == null && gh != null && gh.getCableConnectionType( dir ) != AECableType.GLASS ) + requireDetailed = true; + } + } + + if ( useCovered ) + { + rh.setTexture( getCoveredTexture( getCableColor() ) ); + } + else + { + rh.setTexture( getTexture( getCableColor() ) ); + } + + IPartHost ph = getHost(); + for (ForgeDirection of : EnumSet.complementOf( connections )) + { + IPart bp = ph.getPart( of ); + if ( bp instanceof IGridHost ) + { + int len = bp.cableConnectionRenderTo(); + if ( len < 8 ) + { + switch (of) + { + case DOWN: + rh.setBounds( 6, len, 6, 10, 6, 10 ); + break; + case EAST: + rh.setBounds( 10, 6, 6, 16 - len, 10, 10 ); + break; + case NORTH: + rh.setBounds( 6, 6, len, 10, 10, 6 ); + break; + case SOUTH: + rh.setBounds( 6, 6, 10, 10, 10, 16 - len ); + break; + case UP: + rh.setBounds( 6, 10, 6, 10, 16 - len, 10 ); + break; + case WEST: + rh.setBounds( len, 6, 6, 6, 10, 10 ); + break; + default: + continue; + } + rh.renderBlock( x, y, z, renderer ); + } + } + } + + if ( connections.size() != 2 || !nonLinear( connections ) || useCovered || requireDetailed ) + { + if ( useCovered ) + { + rh.setBounds( 5, 5, 5, 11, 11, 11 ); + rh.renderBlock( x, y, z, renderer ); + } + else + { + rh.setBounds( 6, 6, 6, 10, 10, 10 ); + rh.renderBlock( x, y, z, renderer ); + } + + for (ForgeDirection of : connections) + { + renderGlassConnection( x, y, z, rh, renderer, of ); + } + } + else + { + IIcon def = getTexture( getCableColor() ); + rh.setTexture( def ); + + for (ForgeDirection of : connections) + { + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); + switch (of) + { + case DOWN: + case UP: + renderer.setRenderBounds( 6 / 16.0, 0, 6 / 16.0, 10 / 16.0, 16 / 16.0, 10 / 16.0 ); + break; + case EAST: + case WEST: + renderer.uvRotateEast = renderer.uvRotateWest = 1; + renderer.uvRotateBottom = renderer.uvRotateTop = 1; + renderer.setRenderBounds( 0, 6 / 16.0, 6 / 16.0, 16 / 16.0, 10 / 16.0, 10 / 16.0 ); + break; + case NORTH: + case SOUTH: + renderer.uvRotateNorth = renderer.uvRotateSouth = 1; + renderer.setRenderBounds( 6 / 16.0, 6 / 16.0, 0, 10 / 16.0, 10 / 16.0, 16 / 16.0 ); + break; + default: + continue; + } + } + + rh.renderBlockCurrentBounds( x, y, z, renderer ); + } + + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); + rh.setTexture( null ); + } + + @Override + public boolean changeColor(AEColor newColor, EntityPlayer who) + { + if ( getCableColor() != newColor ) + { + ItemStack newPart = null; + + if ( getCableConnectionType() == AECableType.GLASS ) + newPart = AEApi.instance().parts().partCableGlass.stack( newColor, 1 ); + else if ( getCableConnectionType() == AECableType.COVERED ) + newPart = AEApi.instance().parts().partCableCovered.stack( newColor, 1 ); + else if ( getCableConnectionType() == AECableType.SMART ) + newPart = AEApi.instance().parts().partCableSmart.stack( newColor, 1 ); + else if ( getCableConnectionType() == AECableType.DENSE ) + newPart = AEApi.instance().parts().partCableDense.stack( newColor, 1 ); + + boolean hasPermission = true; + + try + { + hasPermission = proxy.getSecurity().hasPermission( who, SecurityPermissions.BUILD ); + } + catch (GridAccessException e) + { + // :P + } + + if ( newPart != null && hasPermission ) + { + if ( Platform.isClient() ) + return true; + + getHost().removePart( ForgeDirection.UNKNOWN, true ); + getHost().addPart( newPart, ForgeDirection.UNKNOWN, who ); + return true; + } + } + return false; + } + + @Override + public void setValidSides(EnumSet sides) + { + proxy.setValidSides( sides ); + } + + protected boolean nonLinear(EnumSet sides) + { + return (sides.contains( ForgeDirection.EAST ) && sides.contains( ForgeDirection.WEST )) + || (sides.contains( ForgeDirection.NORTH ) && sides.contains( ForgeDirection.SOUTH )) + || (sides.contains( ForgeDirection.UP ) && sides.contains( ForgeDirection.DOWN )); + } + +} diff --git a/parts/networking/PartCableCovered.java b/src/main/java/appeng/parts/networking/PartCableCovered.java similarity index 96% rename from parts/networking/PartCableCovered.java rename to src/main/java/appeng/parts/networking/PartCableCovered.java index 9b17d2503..36f461d8c 100644 --- a/parts/networking/PartCableCovered.java +++ b/src/main/java/appeng/parts/networking/PartCableCovered.java @@ -1,243 +1,243 @@ -package appeng.parts.networking; - -import java.util.EnumSet; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.client.texture.OffsetIcon; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class PartCableCovered extends PartCable -{ - - @MENetworkEventSubscribe - public void channelUpdated(MENetworkChannelsChanged c) - { - getHost().markForUpdate(); - } - - @MENetworkEventSubscribe - public void powerRender(MENetworkPowerStatusChange c) - { - getHost().markForUpdate(); - } - - public PartCableCovered(Class c, ItemStack is) { - super( c, is ); - } - - public PartCableCovered(ItemStack is) { - this( PartCableCovered.class, is ); - } - - @Override - public IIcon getTexture(AEColor c) - { - return getCoveredTexture( c ); - } - - @Override - public AECableType getCableConnectionType() - { - return AECableType.COVERED; - } - - @Override - public void getBoxes(IPartCollisionHelper bch) - { - bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 ); - - if ( Platform.isServer() ) - { - IGridNode n = getGridNode(); - if ( n != null ) - connections = n.getConnectedSides(); - else - connections.clear(); - } - - for (ForgeDirection of : connections) - { - switch (of) - { - case DOWN: - bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 ); - break; - case EAST: - bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 ); - break; - case NORTH: - bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 ); - break; - case SOUTH: - bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 ); - break; - case UP: - bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 ); - break; - case WEST: - bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 ); - break; - default: - continue; - } - } - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) - { - GL11.glTranslated( -0.0, -0.0, 0.3 ); - - rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f ); - float offu = 0; - float offv = 9; - - OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN )) - { - rh.renderInventoryFace( main, side, renderer ); - } - - offu = 9; - offv = 0; - main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST )) - { - rh.renderInventoryFace( main, side, renderer ); - } - - main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH )) - { - rh.renderInventoryFace( main, side, renderer ); - } - - rh.setTexture( null ); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) - { - renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); - rh.setTexture( getTexture( getCableColor() ) ); - - EnumSet sides = connections.clone(); - - boolean hasBuses = false; - IPartHost ph = getHost(); - for (ForgeDirection of : EnumSet.complementOf( connections )) - { - IPart bp = ph.getPart( of ); - if ( bp instanceof IGridHost ) - { - if ( of != ForgeDirection.UNKNOWN ) - { - sides.add( of ); - hasBuses = true; - } - - int len = bp.cableConnectionRenderTo(); - if ( len < 8 ) - { - switch (of) - { - case DOWN: - rh.setBounds( 6, len, 6, 10, 5, 10 ); - break; - case EAST: - rh.setBounds( 11, 6, 6, 16 - len, 10, 10 ); - break; - case NORTH: - rh.setBounds( 6, 6, len, 10, 10, 5 ); - break; - case SOUTH: - rh.setBounds( 6, 6, 11, 10, 10, 16 - len ); - break; - case UP: - rh.setBounds( 6, 11, 6, 10, 16 - len, 10 ); - break; - case WEST: - rh.setBounds( len, 6, 6, 5, 10, 10 ); - break; - default: - continue; - } - rh.renderBlock( x, y, z, renderer ); - } - } - } - - if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses ) - { - for (ForgeDirection of : connections) - { - renderCoveredConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); - } - - rh.setTexture( getTexture( getCableColor() ) ); - rh.setBounds( 5, 5, 5, 11, 11, 11 ); - rh.renderBlock( x, y, z, renderer ); - } - else - { - IIcon def = getTexture( getCableColor() ); - IIcon off = new OffsetIcon( def, 0, -12 ); - for (ForgeDirection of : connections) - { - switch (of) - { - case DOWN: - case UP: - rh.setTexture( def, def, off, off, off, off ); - renderer.setRenderBounds( 5 / 16.0, 0, 5 / 16.0, 11 / 16.0, 16 / 16.0, 11 / 16.0 ); - break; - case EAST: - case WEST: - rh.setTexture( off, off, off, off, def, def ); - renderer.uvRotateEast = renderer.uvRotateWest = 1; - renderer.uvRotateBottom = renderer.uvRotateTop = 1; - renderer.setRenderBounds( 0, 5 / 16.0, 5 / 16.0, 16 / 16.0, 11 / 16.0, 11 / 16.0 ); - break; - case NORTH: - case SOUTH: - rh.setTexture( off, off, def, def, off, off ); - renderer.uvRotateNorth = renderer.uvRotateSouth = 1; - renderer.setRenderBounds( 5 / 16.0, 5 / 16.0, 0, 11 / 16.0, 11 / 16.0, 16 / 16.0 ); - break; - default: - continue; - } - } - - rh.renderBlockCurrentBounds( x, y, z, renderer ); - } - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - rh.setTexture( null ); - } - -} +package appeng.parts.networking; + +import java.util.EnumSet; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.util.AECableType; +import appeng.api.util.AEColor; +import appeng.client.texture.OffsetIcon; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartCableCovered extends PartCable +{ + + @MENetworkEventSubscribe + public void channelUpdated(MENetworkChannelsChanged c) + { + getHost().markForUpdate(); + } + + @MENetworkEventSubscribe + public void powerRender(MENetworkPowerStatusChange c) + { + getHost().markForUpdate(); + } + + public PartCableCovered(Class c, ItemStack is) { + super( c, is ); + } + + public PartCableCovered(ItemStack is) { + this( PartCableCovered.class, is ); + } + + @Override + public IIcon getTexture(AEColor c) + { + return getCoveredTexture( c ); + } + + @Override + public AECableType getCableConnectionType() + { + return AECableType.COVERED; + } + + @Override + public void getBoxes(IPartCollisionHelper bch) + { + bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 ); + + if ( Platform.isServer() ) + { + IGridNode n = getGridNode(); + if ( n != null ) + connections = n.getConnectedSides(); + else + connections.clear(); + } + + for (ForgeDirection of : connections) + { + switch (of) + { + case DOWN: + bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 ); + break; + case EAST: + bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 ); + break; + case NORTH: + bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 ); + break; + case SOUTH: + bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 ); + break; + case UP: + bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 ); + break; + case WEST: + bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 ); + break; + default: + continue; + } + } + } + + @Override + @SideOnly(Side.CLIENT) + public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) + { + GL11.glTranslated( -0.0, -0.0, 0.3 ); + + rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f ); + float offu = 0; + float offv = 9; + + OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN )) + { + rh.renderInventoryFace( main, side, renderer ); + } + + offu = 9; + offv = 0; + main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST )) + { + rh.renderInventoryFace( main, side, renderer ); + } + + main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH )) + { + rh.renderInventoryFace( main, side, renderer ); + } + + rh.setTexture( null ); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) + { + renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); + rh.setTexture( getTexture( getCableColor() ) ); + + EnumSet sides = connections.clone(); + + boolean hasBuses = false; + IPartHost ph = getHost(); + for (ForgeDirection of : EnumSet.complementOf( connections )) + { + IPart bp = ph.getPart( of ); + if ( bp instanceof IGridHost ) + { + if ( of != ForgeDirection.UNKNOWN ) + { + sides.add( of ); + hasBuses = true; + } + + int len = bp.cableConnectionRenderTo(); + if ( len < 8 ) + { + switch (of) + { + case DOWN: + rh.setBounds( 6, len, 6, 10, 5, 10 ); + break; + case EAST: + rh.setBounds( 11, 6, 6, 16 - len, 10, 10 ); + break; + case NORTH: + rh.setBounds( 6, 6, len, 10, 10, 5 ); + break; + case SOUTH: + rh.setBounds( 6, 6, 11, 10, 10, 16 - len ); + break; + case UP: + rh.setBounds( 6, 11, 6, 10, 16 - len, 10 ); + break; + case WEST: + rh.setBounds( len, 6, 6, 5, 10, 10 ); + break; + default: + continue; + } + rh.renderBlock( x, y, z, renderer ); + } + } + } + + if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses ) + { + for (ForgeDirection of : connections) + { + renderCoveredConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); + } + + rh.setTexture( getTexture( getCableColor() ) ); + rh.setBounds( 5, 5, 5, 11, 11, 11 ); + rh.renderBlock( x, y, z, renderer ); + } + else + { + IIcon def = getTexture( getCableColor() ); + IIcon off = new OffsetIcon( def, 0, -12 ); + for (ForgeDirection of : connections) + { + switch (of) + { + case DOWN: + case UP: + rh.setTexture( def, def, off, off, off, off ); + renderer.setRenderBounds( 5 / 16.0, 0, 5 / 16.0, 11 / 16.0, 16 / 16.0, 11 / 16.0 ); + break; + case EAST: + case WEST: + rh.setTexture( off, off, off, off, def, def ); + renderer.uvRotateEast = renderer.uvRotateWest = 1; + renderer.uvRotateBottom = renderer.uvRotateTop = 1; + renderer.setRenderBounds( 0, 5 / 16.0, 5 / 16.0, 16 / 16.0, 11 / 16.0, 11 / 16.0 ); + break; + case NORTH: + case SOUTH: + rh.setTexture( off, off, def, def, off, off ); + renderer.uvRotateNorth = renderer.uvRotateSouth = 1; + renderer.setRenderBounds( 5 / 16.0, 5 / 16.0, 0, 11 / 16.0, 11 / 16.0, 16 / 16.0 ); + break; + default: + continue; + } + } + + rh.renderBlockCurrentBounds( x, y, z, renderer ); + } + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + rh.setTexture( null ); + } + +} diff --git a/parts/networking/PartCableGlass.java b/src/main/java/appeng/parts/networking/PartCableGlass.java similarity index 94% rename from parts/networking/PartCableGlass.java rename to src/main/java/appeng/parts/networking/PartCableGlass.java index dee9e5cfc..9ec24bcea 100644 --- a/parts/networking/PartCableGlass.java +++ b/src/main/java/appeng/parts/networking/PartCableGlass.java @@ -1,16 +1,16 @@ -package appeng.parts.networking; - -import net.minecraft.item.ItemStack; - -public class PartCableGlass extends PartCable -{ - - public PartCableGlass(Class c, ItemStack is) { - super( c, is ); - } - - public PartCableGlass(ItemStack is) { - this( PartCableGlass.class, is ); - } - -} +package appeng.parts.networking; + +import net.minecraft.item.ItemStack; + +public class PartCableGlass extends PartCable +{ + + public PartCableGlass(Class c, ItemStack is) { + super( c, is ); + } + + public PartCableGlass(ItemStack is) { + this( PartCableGlass.class, is ); + } + +} diff --git a/parts/networking/PartCableSmart.java b/src/main/java/appeng/parts/networking/PartCableSmart.java similarity index 96% rename from parts/networking/PartCableSmart.java rename to src/main/java/appeng/parts/networking/PartCableSmart.java index aa953070a..517ed49e5 100644 --- a/parts/networking/PartCableSmart.java +++ b/src/main/java/appeng/parts/networking/PartCableSmart.java @@ -1,355 +1,355 @@ -package appeng.parts.networking; - -import java.util.EnumSet; - -import appeng.client.texture.FlippableIcon; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.parts.IPart; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.block.AEBaseBlock; -import appeng.client.texture.OffsetIcon; -import appeng.client.texture.TaughtIcon; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class PartCableSmart extends PartCable -{ - - @MENetworkEventSubscribe - public void channelUpdated(MENetworkChannelsChanged c) - { - getHost().markForUpdate(); - } - - @MENetworkEventSubscribe - public void powerRender(MENetworkPowerStatusChange c) - { - getHost().markForUpdate(); - } - - public PartCableSmart(Class c, ItemStack is) { - super( c, is ); - } - - public PartCableSmart(ItemStack is) { - this( PartCableSmart.class, is ); - } - - @Override - public AECableType getCableConnectionType() - { - return AECableType.SMART; - } - - @Override - public IIcon getTexture(AEColor c) - { - return getSmartTexture( c ); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) - { - GL11.glTranslated( -0.0, -0.0, 0.3 ); - - float offu = 0; - float offv = 9; - - OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); - OffsetIcon ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv ); - OffsetIcon ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN )) - { - rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f ); - rh.renderInventoryFace( main, side, renderer ); - rh.renderInventoryFace( ch1, side, renderer ); - rh.renderInventoryFace( ch2, side, renderer ); - } - - offu = 9; - offv = 0; - main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); - ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv ); - ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST )) - { - rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f ); - rh.renderInventoryFace( main, side, renderer ); - rh.renderInventoryFace( ch1, side, renderer ); - rh.renderInventoryFace( ch2, side, renderer ); - } - - main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 ); - ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), 0, 0 ); - ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), 0, 0 ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH )) - { - rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f ); - rh.renderInventoryFace( main, side, renderer ); - rh.renderInventoryFace( ch1, side, renderer ); - rh.renderInventoryFace( ch2, side, renderer ); - } - - rh.setTexture( null ); - } - - @Override - public void getBoxes(IPartCollisionHelper bch) - { - bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 ); - - if ( Platform.isServer() ) - { - IGridNode n = getGridNode(); - if ( n != null ) - connections = n.getConnectedSides(); - else - connections.clear(); - } - - for (ForgeDirection of : connections) - { - switch (of) - { - case DOWN: - bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 ); - break; - case EAST: - bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 ); - break; - case NORTH: - bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 ); - break; - case SOUTH: - bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 ); - break; - case UP: - bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 ); - break; - case WEST: - bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 ); - break; - default: - continue; - } - } - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) - { - renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); - rh.setTexture( getTexture( getCableColor() ) ); - - EnumSet sides = connections.clone(); - - boolean hasBuses = false; - IPartHost ph = getHost(); - for (ForgeDirection of : EnumSet.complementOf( connections )) - { - IPart bp = ph.getPart( of ); - if ( bp instanceof IGridHost ) - { - if ( of != ForgeDirection.UNKNOWN ) - { - sides.add( of ); - hasBuses = true; - } - - int len = bp.cableConnectionRenderTo(); - if ( len < 8 ) - { - switch (of) - { - case DOWN: - rh.setBounds( 6, len, 6, 10, 5, 10 ); - break; - case EAST: - rh.setBounds( 11, 6, 6, 16 - len, 10, 10 ); - break; - case NORTH: - rh.setBounds( 6, 6, len, 10, 10, 5 ); - break; - case SOUTH: - rh.setBounds( 6, 6, 11, 10, 10, 16 - len ); - break; - case UP: - rh.setBounds( 6, 11, 6, 10, 16 - len, 10 ); - break; - case WEST: - rh.setBounds( len, 6, 6, 5, 10, 10 ); - break; - default: - continue; - } - rh.renderBlock( x, y, z, renderer ); - - setSmartConnectionRotations( of, renderer ); - IIcon defa = new TaughtIcon( getChannelTex( channelsOnSide[of.ordinal()], false ).getIcon(), -0.2f ); - IIcon defb = new TaughtIcon( getChannelTex( channelsOnSide[of.ordinal()], true ).getIcon(), -0.2f ); - - if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) - { - AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); - FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); - ico.setFlip( false, true ); - } - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); - rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); - rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - - rh.setTexture( getTexture( getCableColor() ) ); - } - } - } - - if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses ) - { - for (ForgeDirection of : connections) - { - renderSmartConection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); - } - - rh.setTexture( getCoveredTexture( getCableColor() ) ); - rh.setBounds( 5, 5, 5, 11, 11, 11 ); - rh.renderBlock( x, y, z, renderer ); - } - else - { - ForgeDirection selectedSide = ForgeDirection.UNKNOWN; - - for (ForgeDirection of : connections) - { - selectedSide = of; - break; - } - - int channels = channelsOnSide[selectedSide.ordinal()]; - IIcon def = getTexture( getCableColor() ); - IIcon off = new OffsetIcon( def, 0, -12 ); - - IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); - IIcon offa = new OffsetIcon( defa, 0, -12 ); - - IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); - IIcon offb = new OffsetIcon( defb, 0, -12 ); - - switch (selectedSide) - { - case DOWN: - case UP: - renderer.setRenderBounds( 5 / 16.0, 0, 5 / 16.0, 11 / 16.0, 16 / 16.0, 11 / 16.0 ); - rh.setTexture( def, def, off, off, off, off ); - rh.renderBlockCurrentBounds( x, y, z, renderer ); - - renderer.uvRotateTop = 0; - renderer.uvRotateBottom = 0; - renderer.uvRotateSouth = 3; - renderer.uvRotateEast = 3; - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - - Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); - rh.setTexture( defa, defa, offa, offa, offa, offa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); - rh.setTexture( defb, defb, offb, offb, offb, offb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - break; - case EAST: - case WEST: - rh.setTexture( off, off, off, off, def, def ); - renderer.uvRotateEast = 2; - renderer.uvRotateWest = 1; - renderer.uvRotateBottom = 2; - renderer.uvRotateTop = 1; - renderer.uvRotateSouth = 0; - renderer.uvRotateNorth = 0; - - AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); - FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); - ico.setFlip( false, true ); - - renderer.setRenderBounds( 0, 5 / 16.0, 5 / 16.0, 16 / 16.0, 11 / 16.0, 11 / 16.0 ); - rh.renderBlockCurrentBounds( x, y, z, renderer ); - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - - FlippableIcon fpA = new FlippableIcon( defa ); - FlippableIcon fpB = new FlippableIcon( defb ); - - fpA = new FlippableIcon( defa ); - fpB = new FlippableIcon( defb ); - - fpA.setFlip( true, false ); - fpB.setFlip( true, false ); - - Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); - rh.setTexture( offa, offa, offa, offa, defa, fpA ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); - rh.setTexture( offb, offb, offb, offb, defb, fpB ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - break; - case NORTH: - case SOUTH: - rh.setTexture( off, off, def, def, off, off ); - renderer.uvRotateTop = 3; - renderer.uvRotateBottom = 3; - renderer.uvRotateNorth = 1; - renderer.uvRotateSouth = 2; - renderer.uvRotateWest = 1; - renderer.setRenderBounds( 5 / 16.0, 5 / 16.0, 0, 11 / 16.0, 11 / 16.0, 16 / 16.0 ); - rh.renderBlockCurrentBounds( x, y, z, renderer ); - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - - Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); - rh.setTexture( offa, offa, defa, defa, offa, offa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); - rh.setTexture( offb, offb, defb, defb, offb, offb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - break; - default: - break; - } - } - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - rh.setTexture( null ); - } -} +package appeng.parts.networking; + +import java.util.EnumSet; + +import appeng.client.texture.FlippableIcon; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.api.parts.IPart; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.util.AECableType; +import appeng.api.util.AEColor; +import appeng.block.AEBaseBlock; +import appeng.client.texture.OffsetIcon; +import appeng.client.texture.TaughtIcon; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartCableSmart extends PartCable +{ + + @MENetworkEventSubscribe + public void channelUpdated(MENetworkChannelsChanged c) + { + getHost().markForUpdate(); + } + + @MENetworkEventSubscribe + public void powerRender(MENetworkPowerStatusChange c) + { + getHost().markForUpdate(); + } + + public PartCableSmart(Class c, ItemStack is) { + super( c, is ); + } + + public PartCableSmart(ItemStack is) { + this( PartCableSmart.class, is ); + } + + @Override + public AECableType getCableConnectionType() + { + return AECableType.SMART; + } + + @Override + public IIcon getTexture(AEColor c) + { + return getSmartTexture( c ); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) + { + GL11.glTranslated( -0.0, -0.0, 0.3 ); + + float offu = 0; + float offv = 9; + + OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); + OffsetIcon ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv ); + OffsetIcon ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN )) + { + rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f ); + rh.renderInventoryFace( main, side, renderer ); + rh.renderInventoryFace( ch1, side, renderer ); + rh.renderInventoryFace( ch2, side, renderer ); + } + + offu = 9; + offv = 0; + main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); + ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv ); + ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST )) + { + rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f ); + rh.renderInventoryFace( main, side, renderer ); + rh.renderInventoryFace( ch1, side, renderer ); + rh.renderInventoryFace( ch2, side, renderer ); + } + + main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 ); + ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), 0, 0 ); + ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), 0, 0 ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH )) + { + rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f ); + rh.renderInventoryFace( main, side, renderer ); + rh.renderInventoryFace( ch1, side, renderer ); + rh.renderInventoryFace( ch2, side, renderer ); + } + + rh.setTexture( null ); + } + + @Override + public void getBoxes(IPartCollisionHelper bch) + { + bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 ); + + if ( Platform.isServer() ) + { + IGridNode n = getGridNode(); + if ( n != null ) + connections = n.getConnectedSides(); + else + connections.clear(); + } + + for (ForgeDirection of : connections) + { + switch (of) + { + case DOWN: + bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 ); + break; + case EAST: + bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 ); + break; + case NORTH: + bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 ); + break; + case SOUTH: + bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 ); + break; + case UP: + bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 ); + break; + case WEST: + bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 ); + break; + default: + continue; + } + } + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) + { + renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); + rh.setTexture( getTexture( getCableColor() ) ); + + EnumSet sides = connections.clone(); + + boolean hasBuses = false; + IPartHost ph = getHost(); + for (ForgeDirection of : EnumSet.complementOf( connections )) + { + IPart bp = ph.getPart( of ); + if ( bp instanceof IGridHost ) + { + if ( of != ForgeDirection.UNKNOWN ) + { + sides.add( of ); + hasBuses = true; + } + + int len = bp.cableConnectionRenderTo(); + if ( len < 8 ) + { + switch (of) + { + case DOWN: + rh.setBounds( 6, len, 6, 10, 5, 10 ); + break; + case EAST: + rh.setBounds( 11, 6, 6, 16 - len, 10, 10 ); + break; + case NORTH: + rh.setBounds( 6, 6, len, 10, 10, 5 ); + break; + case SOUTH: + rh.setBounds( 6, 6, 11, 10, 10, 16 - len ); + break; + case UP: + rh.setBounds( 6, 11, 6, 10, 16 - len, 10 ); + break; + case WEST: + rh.setBounds( len, 6, 6, 5, 10, 10 ); + break; + default: + continue; + } + rh.renderBlock( x, y, z, renderer ); + + setSmartConnectionRotations( of, renderer ); + IIcon defa = new TaughtIcon( getChannelTex( channelsOnSide[of.ordinal()], false ).getIcon(), -0.2f ); + IIcon defb = new TaughtIcon( getChannelTex( channelsOnSide[of.ordinal()], true ).getIcon(), -0.2f ); + + if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) + { + AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); + FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); + ico.setFlip( false, true ); + } + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); + rh.setTexture( defa, defa, defa, defa, defa, defa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); + rh.setTexture( defb, defb, defb, defb, defb, defb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + + rh.setTexture( getTexture( getCableColor() ) ); + } + } + } + + if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses ) + { + for (ForgeDirection of : connections) + { + renderSmartConection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); + } + + rh.setTexture( getCoveredTexture( getCableColor() ) ); + rh.setBounds( 5, 5, 5, 11, 11, 11 ); + rh.renderBlock( x, y, z, renderer ); + } + else + { + ForgeDirection selectedSide = ForgeDirection.UNKNOWN; + + for (ForgeDirection of : connections) + { + selectedSide = of; + break; + } + + int channels = channelsOnSide[selectedSide.ordinal()]; + IIcon def = getTexture( getCableColor() ); + IIcon off = new OffsetIcon( def, 0, -12 ); + + IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); + IIcon offa = new OffsetIcon( defa, 0, -12 ); + + IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); + IIcon offb = new OffsetIcon( defb, 0, -12 ); + + switch (selectedSide) + { + case DOWN: + case UP: + renderer.setRenderBounds( 5 / 16.0, 0, 5 / 16.0, 11 / 16.0, 16 / 16.0, 11 / 16.0 ); + rh.setTexture( def, def, off, off, off, off ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); + + renderer.uvRotateTop = 0; + renderer.uvRotateBottom = 0; + renderer.uvRotateSouth = 3; + renderer.uvRotateEast = 3; + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + + Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); + rh.setTexture( defa, defa, offa, offa, offa, offa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); + rh.setTexture( defb, defb, offb, offb, offb, offb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + break; + case EAST: + case WEST: + rh.setTexture( off, off, off, off, def, def ); + renderer.uvRotateEast = 2; + renderer.uvRotateWest = 1; + renderer.uvRotateBottom = 2; + renderer.uvRotateTop = 1; + renderer.uvRotateSouth = 0; + renderer.uvRotateNorth = 0; + + AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); + FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); + ico.setFlip( false, true ); + + renderer.setRenderBounds( 0, 5 / 16.0, 5 / 16.0, 16 / 16.0, 11 / 16.0, 11 / 16.0 ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + + FlippableIcon fpA = new FlippableIcon( defa ); + FlippableIcon fpB = new FlippableIcon( defb ); + + fpA = new FlippableIcon( defa ); + fpB = new FlippableIcon( defb ); + + fpA.setFlip( true, false ); + fpB.setFlip( true, false ); + + Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); + rh.setTexture( offa, offa, offa, offa, defa, fpA ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); + rh.setTexture( offb, offb, offb, offb, defb, fpB ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + break; + case NORTH: + case SOUTH: + rh.setTexture( off, off, def, def, off, off ); + renderer.uvRotateTop = 3; + renderer.uvRotateBottom = 3; + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 2; + renderer.uvRotateWest = 1; + renderer.setRenderBounds( 5 / 16.0, 5 / 16.0, 0, 11 / 16.0, 11 / 16.0, 16 / 16.0 ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + + Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); + rh.setTexture( offa, offa, defa, defa, offa, offa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); + rh.setTexture( offb, offb, defb, defb, offb, offb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + break; + default: + break; + } + } + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + rh.setTexture( null ); + } +} diff --git a/parts/networking/PartDenseCable.java b/src/main/java/appeng/parts/networking/PartDenseCable.java similarity index 97% rename from parts/networking/PartDenseCable.java rename to src/main/java/appeng/parts/networking/PartDenseCable.java index 28a5e4c9f..0116a747f 100644 --- a/parts/networking/PartDenseCable.java +++ b/src/main/java/appeng/parts/networking/PartDenseCable.java @@ -1,501 +1,501 @@ -package appeng.parts.networking; - -import java.util.EnumSet; - -import appeng.client.texture.FlippableIcon; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import appeng.api.AEApi; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.parts.BusSupport; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.block.AEBaseBlock; -import appeng.client.texture.CableBusTextures; -import appeng.client.texture.OffsetIcon; -import appeng.client.texture.TaughtIcon; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class PartDenseCable extends PartCable -{ - - @Override - public BusSupport supportsBuses() - { - return BusSupport.DENSE_CABLE; - } - - @MENetworkEventSubscribe - public void channelUpdated(MENetworkChannelsChanged c) - { - getHost().markForUpdate(); - } - - @MENetworkEventSubscribe - public void powerRender(MENetworkPowerStatusChange c) - { - getHost().markForUpdate(); - } - - public PartDenseCable(Class c, ItemStack is) { - super( c, is ); - proxy.setFlags( GridFlags.DENSE_CAPACITY, GridFlags.PREFERRED ); - } - - public PartDenseCable(ItemStack is) { - this( PartDenseCable.class, is ); - } - - @Override - public AECableType getCableConnectionType() - { - return AECableType.DENSE; - } - - @Override - public IIcon getTexture(AEColor c) - { - if ( c == AEColor.Transparent ) - return AEApi.instance().parts().partCableSmart.stack( AEColor.Transparent, 1 ).getIconIndex(); - - return getSmartTexture( c ); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) - { - GL11.glTranslated( -0.0, -0.0, 0.3 ); - rh.setBounds( 4.0f, 4.0f, 2.0f, 12.0f, 12.0f, 14.0f ); - - float offu = 0; - float offv = 9; - - OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); - OffsetIcon ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv ); - OffsetIcon ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN )) - { - rh.renderInventoryFace( main, side, renderer ); - rh.renderInventoryFace( ch1, side, renderer ); - rh.renderInventoryFace( ch2, side, renderer ); - } - - offu = 9; - offv = 0; - main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); - ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv ); - ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST )) - { - rh.renderInventoryFace( main, side, renderer ); - rh.renderInventoryFace( ch1, side, renderer ); - rh.renderInventoryFace( ch2, side, renderer ); - } - - main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 ); - ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), 0, 0 ); - ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), 0, 0 ); - - for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH )) - { - rh.renderInventoryFace( main, side, renderer ); - rh.renderInventoryFace( ch1, side, renderer ); - rh.renderInventoryFace( ch2, side, renderer ); - } - - rh.setTexture( null ); - } - - @Override - public void getBoxes(IPartCollisionHelper bch) - { - boolean noLadder = !bch.isBBCollision(); - double min = noLadder ? 3.0 : 4.9; - double max = noLadder ? 13.0 : 11.1; - - bch.addBox( min, min, min, max, max, max ); - - if ( Platform.isServer() ) - { - IGridNode n = getGridNode(); - if ( n != null ) - connections = n.getConnectedSides(); - else - connections.clear(); - } - - for (ForgeDirection of : connections) - { - if ( isDense( of ) ) - { - switch (of) - { - case DOWN: - bch.addBox( min, 0.0, min, max, min, max ); - break; - case EAST: - bch.addBox( max, min, min, 16.0, max, max ); - break; - case NORTH: - bch.addBox( min, min, 0.0, max, max, min ); - break; - case SOUTH: - bch.addBox( min, min, max, max, max, 16.0 ); - break; - case UP: - bch.addBox( min, max, min, max, 16.0, max ); - break; - case WEST: - bch.addBox( 0.0, min, min, min, max, max ); - break; - default: - continue; - } - } - else - { - switch (of) - { - case DOWN: - bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 ); - break; - case EAST: - bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 ); - break; - case NORTH: - bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 ); - break; - case SOUTH: - bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 ); - break; - case UP: - bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 ); - break; - case WEST: - bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 ); - break; - default: - continue; - } - } - } - } - - private boolean isDense(ForgeDirection of) - { - TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + of.offsetX, tile.yCoord + of.offsetY, tile.zCoord + of.offsetZ ); - if ( te instanceof IGridHost ) - { - AECableType t = ((IGridHost) te).getCableConnectionType( of.getOpposite() ); - return t == AECableType.DENSE; - } - return false; - } - - private boolean isSmart(ForgeDirection of) - { - TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + of.offsetX, tile.yCoord + of.offsetY, tile.zCoord + of.offsetZ ); - if ( te instanceof IGridHost ) - { - AECableType t = ((IGridHost) te).getCableConnectionType( of.getOpposite() ); - return t == AECableType.SMART; - } - return false; - } - - @SideOnly(Side.CLIENT) - public void renderDenseConnection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, int channels, ForgeDirection of) - { - TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ ); - IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; - IGridHost ghh = te instanceof IGridHost ? (IGridHost) te : null; - boolean isGlass = false; - AEColor myColor = getCableColor(); - /* - * ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) == AECableType.GLASS && ccph.getPart( - * of.getOpposite() ) == null ) { isGlass = true; rh.setTexture( getGlassTexture( myColor = ccph.getColor() ) ); - * } else if ( ccph == null && ghh != null && ghh.getCableConnectionType( of ) != AECableType.GLASS ) { - * rh.setTexture( getSmartTexture( myColor ) ); switch (of) { case DOWN: rh.setBounds( 3, 0, 3, 13, 4, 13 ); - * break; case EAST: rh.setBounds( 12, 3, 3, 16, 13, 13 ); break; case NORTH: rh.setBounds( 3, 3, 0, 13, 13, 4 - * ); break; case SOUTH: rh.setBounds( 3, 3, 12, 13, 13, 16 ); break; case UP: rh.setBounds( 3, 12, 3, 13, 16, - * 13 ); break; case WEST: rh.setBounds( 0, 3, 3, 4, 13, 13 ); break; default: return; } rh.renderBlock( x, y, - * z, renderer ); - * - * if ( true ) { setSmartConnectionRotations( of, renderer ); IIcon defa = new TaughtIcon( getChannelTex( - * channels, false ).getIcon(), -0.2f ); IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), - * -0.2f ); - * - * if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) { AEBaseBlock blk = (AEBaseBlock) - * rh.getBlock(); FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); ico.setFlip( - * false, true ); } - * - * Tessellator.instance.setBrightness( 15 << 20 | 15 << 5 ); Tessellator.instance.setColorOpaque_I( - * myColor.mediumVariant ); rh.setTexture( defa, defa, defa, defa, defa, defa ); renderAllFaces( (AEBaseBlock) - * rh.getBlock(), x, y, z, renderer ); - * - * Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); rh.setTexture( defb, defb, defb, defb, defb, - * defb ); renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); - * - * renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = - * renderer.uvRotateTop = renderer.uvRotateWest = 0; } - * - * rh.setTexture( getTexture( getCableColor() ) ); } - */ - - rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); - if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) != AECableType.GLASS && ccph.getColor() != AEColor.Transparent - && ccph.getPart( of.getOpposite() ) == null ) - rh.setTexture( getTexture( myColor = ccph.getColor() ) ); - else - rh.setTexture( getTexture( getCableColor() ) ); - - switch (of) - { - case DOWN: - rh.setBounds( 4, 0, 4, 12, 5, 12 ); - break; - case EAST: - rh.setBounds( 11, 4, 4, 16, 12, 12 ); - break; - case NORTH: - rh.setBounds( 4, 4, 0, 12, 12, 5 ); - break; - case SOUTH: - rh.setBounds( 4, 4, 11, 12, 12, 16 ); - break; - case UP: - rh.setBounds( 4, 11, 4, 12, 16, 12 ); - break; - case WEST: - rh.setBounds( 0, 4, 4, 5, 12, 12 ); - break; - default: - return; - } - - rh.renderBlock( x, y, z, renderer ); - - rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); - if ( !isGlass ) - { - setSmartConnectionRotations( of, renderer ); - - IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); - IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - Tessellator.instance.setColorOpaque_I( myColor.blackVariant ); - rh.setTexture( defa, defa, defa, defa, defa, defa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); - rh.setTexture( defb, defb, defb, defb, defb, defb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - } - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) - { - renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); - rh.setTexture( getTexture( getCableColor() ) ); - - EnumSet sides = connections.clone(); - - boolean hasBuses = false; - for (ForgeDirection of : connections) - { - if ( !isDense( of ) ) - hasBuses = true; - } - - if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses ) - { - for (ForgeDirection of : connections) - { - if ( isDense( of ) ) - renderDenseConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); - else if ( isSmart( of ) ) - renderSmartConection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); - else - renderCoveredConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); - } - - rh.setTexture( getDenseTexture( getCableColor() ) ); - rh.setBounds( 3, 3, 3, 13, 13, 13 ); - rh.renderBlock( x, y, z, renderer ); - } - else - { - ForgeDirection selectedSide = ForgeDirection.UNKNOWN; - - for (ForgeDirection of : connections) - { - selectedSide = of; - break; - } - - int channels = channelsOnSide[selectedSide.ordinal()]; - IIcon def = getTexture( getCableColor() ); - IIcon off = new OffsetIcon( def, 0, -12 ); - - IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); - IIcon offa = new OffsetIcon( defa, 0, -12 ); - - IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); - IIcon offb = new OffsetIcon( defb, 0, -12 ); - - switch (selectedSide) - { - case DOWN: - case UP: - renderer.setRenderBounds( 3 / 16.0, 0, 3 / 16.0, 13 / 16.0, 16 / 16.0, 13 / 16.0 ); - rh.setTexture( def, def, off, off, off, off ); - rh.renderBlockCurrentBounds( x, y, z, renderer ); - - renderer.uvRotateTop = 0; - renderer.uvRotateBottom = 0; - renderer.uvRotateSouth = 3; - renderer.uvRotateEast = 3; - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - - Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); - rh.setTexture( defa, defa, offa, offa, offa, offa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); - rh.setTexture( defb, defb, offb, offb, offb, offb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - break; - case EAST: - case WEST: - rh.setTexture( off, off, off, off, def, def ); - renderer.uvRotateEast = 2; - renderer.uvRotateWest = 1; - renderer.uvRotateBottom = 2; - renderer.uvRotateTop = 1; - renderer.uvRotateSouth = 0; - renderer.uvRotateNorth = 0; - - AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); - FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); - ico.setFlip( false, true ); - - renderer.setRenderBounds( 0, 3 / 16.0, 3 / 16.0, 16 / 16.0, 13 / 16.0, 13 / 16.0 ); - rh.renderBlockCurrentBounds( x, y, z, renderer ); - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - - FlippableIcon fpA = new FlippableIcon( defa ); - FlippableIcon fpB = new FlippableIcon( defb ); - - fpA = new FlippableIcon( defa ); - fpB = new FlippableIcon( defb ); - - fpA.setFlip( true, false ); - fpB.setFlip( true, false ); - - Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); - rh.setTexture( offa, offa, offa, offa, defa, fpA ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); - rh.setTexture( offb, offb, offb, offb, defb, fpB ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - break; - case NORTH: - case SOUTH: - rh.setTexture( off, off, def, def, off, off ); - renderer.uvRotateTop = 3; - renderer.uvRotateBottom = 3; - renderer.uvRotateNorth = 1; - renderer.uvRotateSouth = 2; - renderer.uvRotateWest = 1; - renderer.setRenderBounds( 3 / 16.0, 3 / 16.0, 0, 13 / 16.0, 13 / 16.0, 16 / 16.0 ); - rh.renderBlockCurrentBounds( x, y, z, renderer ); - - Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); - - Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); - rh.setTexture( offa, offa, defa, defa, offa, offa ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - - Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); - rh.setTexture( offb, offb, defb, defb, offb, offb ); - renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); - break; - default: - break; - } - } - - renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; - rh.setTexture( null ); - } - - private IIcon getDenseTexture(AEColor c) - { - switch (c) - { - case Black: - return CableBusTextures.MEDense_Black.getIcon(); - case Blue: - return CableBusTextures.MEDense_Blue.getIcon(); - case Brown: - return CableBusTextures.MEDense_Brown.getIcon(); - case Cyan: - return CableBusTextures.MEDense_Cyan.getIcon(); - case Gray: - return CableBusTextures.MEDense_Gray.getIcon(); - case Green: - return CableBusTextures.MEDense_Green.getIcon(); - case LightBlue: - return CableBusTextures.MEDense_LightBlue.getIcon(); - case LightGray: - return CableBusTextures.MEDense_LightGrey.getIcon(); - case Lime: - return CableBusTextures.MEDense_Lime.getIcon(); - case Magenta: - return CableBusTextures.MEDense_Magenta.getIcon(); - case Orange: - return CableBusTextures.MEDense_Orange.getIcon(); - case Pink: - return CableBusTextures.MEDense_Pink.getIcon(); - case Purple: - return CableBusTextures.MEDense_Purple.getIcon(); - case Red: - return CableBusTextures.MEDense_Red.getIcon(); - case White: - return CableBusTextures.MEDense_White.getIcon(); - case Yellow: - return CableBusTextures.MEDense_Yellow.getIcon(); - default: - } - - return is.getIconIndex(); - } -} +package appeng.parts.networking; + +import java.util.EnumSet; + +import appeng.client.texture.FlippableIcon; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import appeng.api.AEApi; +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.api.parts.BusSupport; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.util.AECableType; +import appeng.api.util.AEColor; +import appeng.block.AEBaseBlock; +import appeng.client.texture.CableBusTextures; +import appeng.client.texture.OffsetIcon; +import appeng.client.texture.TaughtIcon; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartDenseCable extends PartCable +{ + + @Override + public BusSupport supportsBuses() + { + return BusSupport.DENSE_CABLE; + } + + @MENetworkEventSubscribe + public void channelUpdated(MENetworkChannelsChanged c) + { + getHost().markForUpdate(); + } + + @MENetworkEventSubscribe + public void powerRender(MENetworkPowerStatusChange c) + { + getHost().markForUpdate(); + } + + public PartDenseCable(Class c, ItemStack is) { + super( c, is ); + proxy.setFlags( GridFlags.DENSE_CAPACITY, GridFlags.PREFERRED ); + } + + public PartDenseCable(ItemStack is) { + this( PartDenseCable.class, is ); + } + + @Override + public AECableType getCableConnectionType() + { + return AECableType.DENSE; + } + + @Override + public IIcon getTexture(AEColor c) + { + if ( c == AEColor.Transparent ) + return AEApi.instance().parts().partCableSmart.stack( AEColor.Transparent, 1 ).getIconIndex(); + + return getSmartTexture( c ); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) + { + GL11.glTranslated( -0.0, -0.0, 0.3 ); + rh.setBounds( 4.0f, 4.0f, 2.0f, 12.0f, 12.0f, 14.0f ); + + float offu = 0; + float offv = 9; + + OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); + OffsetIcon ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv ); + OffsetIcon ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN )) + { + rh.renderInventoryFace( main, side, renderer ); + rh.renderInventoryFace( ch1, side, renderer ); + rh.renderInventoryFace( ch2, side, renderer ); + } + + offu = 9; + offv = 0; + main = new OffsetIcon( getTexture( getCableColor() ), offu, offv ); + ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv ); + ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST )) + { + rh.renderInventoryFace( main, side, renderer ); + rh.renderInventoryFace( ch1, side, renderer ); + rh.renderInventoryFace( ch2, side, renderer ); + } + + main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 ); + ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), 0, 0 ); + ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), 0, 0 ); + + for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH )) + { + rh.renderInventoryFace( main, side, renderer ); + rh.renderInventoryFace( ch1, side, renderer ); + rh.renderInventoryFace( ch2, side, renderer ); + } + + rh.setTexture( null ); + } + + @Override + public void getBoxes(IPartCollisionHelper bch) + { + boolean noLadder = !bch.isBBCollision(); + double min = noLadder ? 3.0 : 4.9; + double max = noLadder ? 13.0 : 11.1; + + bch.addBox( min, min, min, max, max, max ); + + if ( Platform.isServer() ) + { + IGridNode n = getGridNode(); + if ( n != null ) + connections = n.getConnectedSides(); + else + connections.clear(); + } + + for (ForgeDirection of : connections) + { + if ( isDense( of ) ) + { + switch (of) + { + case DOWN: + bch.addBox( min, 0.0, min, max, min, max ); + break; + case EAST: + bch.addBox( max, min, min, 16.0, max, max ); + break; + case NORTH: + bch.addBox( min, min, 0.0, max, max, min ); + break; + case SOUTH: + bch.addBox( min, min, max, max, max, 16.0 ); + break; + case UP: + bch.addBox( min, max, min, max, 16.0, max ); + break; + case WEST: + bch.addBox( 0.0, min, min, min, max, max ); + break; + default: + continue; + } + } + else + { + switch (of) + { + case DOWN: + bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 ); + break; + case EAST: + bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 ); + break; + case NORTH: + bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 ); + break; + case SOUTH: + bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 ); + break; + case UP: + bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 ); + break; + case WEST: + bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 ); + break; + default: + continue; + } + } + } + } + + private boolean isDense(ForgeDirection of) + { + TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + of.offsetX, tile.yCoord + of.offsetY, tile.zCoord + of.offsetZ ); + if ( te instanceof IGridHost ) + { + AECableType t = ((IGridHost) te).getCableConnectionType( of.getOpposite() ); + return t == AECableType.DENSE; + } + return false; + } + + private boolean isSmart(ForgeDirection of) + { + TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + of.offsetX, tile.yCoord + of.offsetY, tile.zCoord + of.offsetZ ); + if ( te instanceof IGridHost ) + { + AECableType t = ((IGridHost) te).getCableConnectionType( of.getOpposite() ); + return t == AECableType.SMART; + } + return false; + } + + @SideOnly(Side.CLIENT) + public void renderDenseConnection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, int channels, ForgeDirection of) + { + TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ ); + IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null; + IGridHost ghh = te instanceof IGridHost ? (IGridHost) te : null; + boolean isGlass = false; + AEColor myColor = getCableColor(); + /* + * ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) == AECableType.GLASS && ccph.getPart( + * of.getOpposite() ) == null ) { isGlass = true; rh.setTexture( getGlassTexture( myColor = ccph.getColor() ) ); + * } else if ( ccph == null && ghh != null && ghh.getCableConnectionType( of ) != AECableType.GLASS ) { + * rh.setTexture( getSmartTexture( myColor ) ); switch (of) { case DOWN: rh.setBounds( 3, 0, 3, 13, 4, 13 ); + * break; case EAST: rh.setBounds( 12, 3, 3, 16, 13, 13 ); break; case NORTH: rh.setBounds( 3, 3, 0, 13, 13, 4 + * ); break; case SOUTH: rh.setBounds( 3, 3, 12, 13, 13, 16 ); break; case UP: rh.setBounds( 3, 12, 3, 13, 16, + * 13 ); break; case WEST: rh.setBounds( 0, 3, 3, 4, 13, 13 ); break; default: return; } rh.renderBlock( x, y, + * z, renderer ); + * + * if ( true ) { setSmartConnectionRotations( of, renderer ); IIcon defa = new TaughtIcon( getChannelTex( + * channels, false ).getIcon(), -0.2f ); IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), + * -0.2f ); + * + * if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) { AEBaseBlock blk = (AEBaseBlock) + * rh.getBlock(); FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); ico.setFlip( + * false, true ); } + * + * Tessellator.instance.setBrightness( 15 << 20 | 15 << 5 ); Tessellator.instance.setColorOpaque_I( + * myColor.mediumVariant ); rh.setTexture( defa, defa, defa, defa, defa, defa ); renderAllFaces( (AEBaseBlock) + * rh.getBlock(), x, y, z, renderer ); + * + * Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); rh.setTexture( defb, defb, defb, defb, defb, + * defb ); renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer ); + * + * renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = + * renderer.uvRotateTop = renderer.uvRotateWest = 0; } + * + * rh.setTexture( getTexture( getCableColor() ) ); } + */ + + rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) ); + if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) != AECableType.GLASS && ccph.getColor() != AEColor.Transparent + && ccph.getPart( of.getOpposite() ) == null ) + rh.setTexture( getTexture( myColor = ccph.getColor() ) ); + else + rh.setTexture( getTexture( getCableColor() ) ); + + switch (of) + { + case DOWN: + rh.setBounds( 4, 0, 4, 12, 5, 12 ); + break; + case EAST: + rh.setBounds( 11, 4, 4, 16, 12, 12 ); + break; + case NORTH: + rh.setBounds( 4, 4, 0, 12, 12, 5 ); + break; + case SOUTH: + rh.setBounds( 4, 4, 11, 12, 12, 16 ); + break; + case UP: + rh.setBounds( 4, 11, 4, 12, 16, 12 ); + break; + case WEST: + rh.setBounds( 0, 4, 4, 5, 12, 12 ); + break; + default: + return; + } + + rh.renderBlock( x, y, z, renderer ); + + rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) ); + if ( !isGlass ) + { + setSmartConnectionRotations( of, renderer ); + + IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); + IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + Tessellator.instance.setColorOpaque_I( myColor.blackVariant ); + rh.setTexture( defa, defa, defa, defa, defa, defa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); + rh.setTexture( defb, defb, defb, defb, defb, defb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + } + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) + { + renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache ); + rh.setTexture( getTexture( getCableColor() ) ); + + EnumSet sides = connections.clone(); + + boolean hasBuses = false; + for (ForgeDirection of : connections) + { + if ( !isDense( of ) ) + hasBuses = true; + } + + if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses ) + { + for (ForgeDirection of : connections) + { + if ( isDense( of ) ) + renderDenseConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); + else if ( isSmart( of ) ) + renderSmartConection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); + else + renderCoveredConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of ); + } + + rh.setTexture( getDenseTexture( getCableColor() ) ); + rh.setBounds( 3, 3, 3, 13, 13, 13 ); + rh.renderBlock( x, y, z, renderer ); + } + else + { + ForgeDirection selectedSide = ForgeDirection.UNKNOWN; + + for (ForgeDirection of : connections) + { + selectedSide = of; + break; + } + + int channels = channelsOnSide[selectedSide.ordinal()]; + IIcon def = getTexture( getCableColor() ); + IIcon off = new OffsetIcon( def, 0, -12 ); + + IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f ); + IIcon offa = new OffsetIcon( defa, 0, -12 ); + + IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f ); + IIcon offb = new OffsetIcon( defb, 0, -12 ); + + switch (selectedSide) + { + case DOWN: + case UP: + renderer.setRenderBounds( 3 / 16.0, 0, 3 / 16.0, 13 / 16.0, 16 / 16.0, 13 / 16.0 ); + rh.setTexture( def, def, off, off, off, off ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); + + renderer.uvRotateTop = 0; + renderer.uvRotateBottom = 0; + renderer.uvRotateSouth = 3; + renderer.uvRotateEast = 3; + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + + Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); + rh.setTexture( defa, defa, offa, offa, offa, offa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); + rh.setTexture( defb, defb, offb, offb, offb, offb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + break; + case EAST: + case WEST: + rh.setTexture( off, off, off, off, def, def ); + renderer.uvRotateEast = 2; + renderer.uvRotateWest = 1; + renderer.uvRotateBottom = 2; + renderer.uvRotateTop = 1; + renderer.uvRotateSouth = 0; + renderer.uvRotateNorth = 0; + + AEBaseBlock blk = (AEBaseBlock) rh.getBlock(); + FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); + ico.setFlip( false, true ); + + renderer.setRenderBounds( 0, 3 / 16.0, 3 / 16.0, 16 / 16.0, 13 / 16.0, 13 / 16.0 ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + + FlippableIcon fpA = new FlippableIcon( defa ); + FlippableIcon fpB = new FlippableIcon( defb ); + + fpA = new FlippableIcon( defa ); + fpB = new FlippableIcon( defb ); + + fpA.setFlip( true, false ); + fpB.setFlip( true, false ); + + Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); + rh.setTexture( offa, offa, offa, offa, defa, fpA ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); + rh.setTexture( offb, offb, offb, offb, defb, fpB ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + break; + case NORTH: + case SOUTH: + rh.setTexture( off, off, def, def, off, off ); + renderer.uvRotateTop = 3; + renderer.uvRotateBottom = 3; + renderer.uvRotateNorth = 1; + renderer.uvRotateSouth = 2; + renderer.uvRotateWest = 1; + renderer.setRenderBounds( 3 / 16.0, 3 / 16.0, 0, 13 / 16.0, 13 / 16.0, 16 / 16.0 ); + rh.renderBlockCurrentBounds( x, y, z, renderer ); + + Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 ); + + Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant ); + rh.setTexture( offa, offa, defa, defa, offa, offa ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + + Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant ); + rh.setTexture( offb, offb, defb, defb, offb, offb ); + renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer ); + break; + default: + break; + } + } + + renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; + rh.setTexture( null ); + } + + private IIcon getDenseTexture(AEColor c) + { + switch (c) + { + case Black: + return CableBusTextures.MEDense_Black.getIcon(); + case Blue: + return CableBusTextures.MEDense_Blue.getIcon(); + case Brown: + return CableBusTextures.MEDense_Brown.getIcon(); + case Cyan: + return CableBusTextures.MEDense_Cyan.getIcon(); + case Gray: + return CableBusTextures.MEDense_Gray.getIcon(); + case Green: + return CableBusTextures.MEDense_Green.getIcon(); + case LightBlue: + return CableBusTextures.MEDense_LightBlue.getIcon(); + case LightGray: + return CableBusTextures.MEDense_LightGrey.getIcon(); + case Lime: + return CableBusTextures.MEDense_Lime.getIcon(); + case Magenta: + return CableBusTextures.MEDense_Magenta.getIcon(); + case Orange: + return CableBusTextures.MEDense_Orange.getIcon(); + case Pink: + return CableBusTextures.MEDense_Pink.getIcon(); + case Purple: + return CableBusTextures.MEDense_Purple.getIcon(); + case Red: + return CableBusTextures.MEDense_Red.getIcon(); + case White: + return CableBusTextures.MEDense_White.getIcon(); + case Yellow: + return CableBusTextures.MEDense_Yellow.getIcon(); + default: + } + + return is.getIconIndex(); + } +} diff --git a/parts/networking/PartQuartzFiber.java b/src/main/java/appeng/parts/networking/PartQuartzFiber.java similarity index 95% rename from parts/networking/PartQuartzFiber.java rename to src/main/java/appeng/parts/networking/PartQuartzFiber.java index bf83c1f1e..3217e9230 100644 --- a/parts/networking/PartQuartzFiber.java +++ b/src/main/java/appeng/parts/networking/PartQuartzFiber.java @@ -1,218 +1,218 @@ -package appeng.parts.networking; - -import java.util.EnumSet; -import java.util.Set; - -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - -import appeng.api.config.Actionable; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.energy.IEnergyGridProvider; -import appeng.api.parts.IPartCollisionHelper; -import appeng.api.parts.IPartHost; -import appeng.api.parts.IPartRenderHelper; -import appeng.api.util.AECableType; -import appeng.me.GridAccessException; -import appeng.me.helpers.AENetworkProxy; -import appeng.parts.AEBasePart; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider -{ - - AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", proxy.getMachineRepresentation(), true ); - - public PartQuartzFiber(ItemStack is) { - super( PartQuartzFiber.class, is ); - proxy.setIdlePowerUsage( 0 ); - proxy.setFlags( GridFlags.CANNOT_CARRY ); - outerProxy.setIdlePowerUsage( 0 ); - outerProxy.setFlags( GridFlags.CANNOT_CARRY ); - } - - @Override - public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side) - { - super.onPlacement( player, held, side ); - outerProxy.setOwner( player ); - } - - @Override - public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile) - { - super.setPartHostInfo( side, host, tile ); - outerProxy.setValidSides( EnumSet.of( side ) ); - } - - @Override - public void readFromNBT(NBTTagCompound extra) - { - super.readFromNBT( extra ); - outerProxy.readFromNBT( extra ); - } - - @Override - public void writeToNBT(NBTTagCompound extra) - { - super.writeToNBT( extra ); - outerProxy.writeToNBT( extra ); - } - - @Override - public void addToWorld() - { - super.addToWorld(); - outerProxy.onReady(); - } - - @Override - public void removeFromWorld() - { - super.removeFromWorld(); - outerProxy.invalidate(); - } - - @Override - public IGridNode getExternalFacingNode() - { - return outerProxy.getNode(); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.GLASS; - } - - @Override - @SideOnly(Side.CLIENT) - public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) - { - IIcon myIcon = is.getIconIndex(); - rh.setTexture( myIcon ); - rh.setBounds( 6, 6, 10, 10, 10, 16 ); - rh.renderBlock( x, y, z, renderer ); - rh.setTexture( null ); - } - - @Override - public void getBoxes(IPartCollisionHelper bch) - { - bch.addBox( 6, 6, 10, 10, 10, 16 ); - } - - @Override - @SideOnly(Side.CLIENT) - public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) - { - GL11.glTranslated( -0.2, -0.3, 0.0 ); - - rh.setTexture( is.getIconIndex() ); - rh.setBounds( 6.0f, 6.0f, 5.0f, 10.0f, 10.0f, 11.0f ); - rh.renderInventoryBox( renderer ); - rh.setTexture( null ); - } - - @Override - public double extractAEPower(double amt, Actionable mode, Set seen) - { - double acquiredPower = 0; - - try - { - IEnergyGrid eg = proxy.getEnergy(); - acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen ); - } - catch (GridAccessException e) - { - // :P - } - - try - { - IEnergyGrid eg = outerProxy.getEnergy(); - acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen ); - } - catch (GridAccessException e) - { - // :P - } - - return acquiredPower; - } - - @Override - public double injectAEPower(double amt, Actionable mode, Set seen) - { - - try - { - IEnergyGrid eg = proxy.getEnergy(); - if ( !seen.contains( eg ) ) - return eg.injectAEPower( amt, mode, seen ); - } - catch (GridAccessException e) - { - // :P - } - - try - { - IEnergyGrid eg = outerProxy.getEnergy(); - if ( !seen.contains( eg ) ) - return eg.injectAEPower( amt, mode, seen ); - } - catch (GridAccessException e) - { - // :P - } - - return amt; - } - - @Override - public int cableConnectionRenderTo() - { - return 16; - } - - @Override - public double getEnergyDemand(double amt, Set seen) - { - double demand = 0; - - try - { - IEnergyGrid eg = proxy.getEnergy(); - demand += eg.getEnergyDemand( amt - demand, seen ); - } - catch (GridAccessException e) - { - // :P - } - - try - { - IEnergyGrid eg = outerProxy.getEnergy(); - demand += eg.getEnergyDemand( amt - demand, seen ); - } - catch (GridAccessException e) - { - // :P - } - - return demand; - } - -} +package appeng.parts.networking; + +import java.util.EnumSet; +import java.util.Set; + +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import appeng.api.config.Actionable; +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.energy.IEnergyGridProvider; +import appeng.api.parts.IPartCollisionHelper; +import appeng.api.parts.IPartHost; +import appeng.api.parts.IPartRenderHelper; +import appeng.api.util.AECableType; +import appeng.me.GridAccessException; +import appeng.me.helpers.AENetworkProxy; +import appeng.parts.AEBasePart; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider +{ + + AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", proxy.getMachineRepresentation(), true ); + + public PartQuartzFiber(ItemStack is) { + super( PartQuartzFiber.class, is ); + proxy.setIdlePowerUsage( 0 ); + proxy.setFlags( GridFlags.CANNOT_CARRY ); + outerProxy.setIdlePowerUsage( 0 ); + outerProxy.setFlags( GridFlags.CANNOT_CARRY ); + } + + @Override + public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side) + { + super.onPlacement( player, held, side ); + outerProxy.setOwner( player ); + } + + @Override + public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile) + { + super.setPartHostInfo( side, host, tile ); + outerProxy.setValidSides( EnumSet.of( side ) ); + } + + @Override + public void readFromNBT(NBTTagCompound extra) + { + super.readFromNBT( extra ); + outerProxy.readFromNBT( extra ); + } + + @Override + public void writeToNBT(NBTTagCompound extra) + { + super.writeToNBT( extra ); + outerProxy.writeToNBT( extra ); + } + + @Override + public void addToWorld() + { + super.addToWorld(); + outerProxy.onReady(); + } + + @Override + public void removeFromWorld() + { + super.removeFromWorld(); + outerProxy.invalidate(); + } + + @Override + public IGridNode getExternalFacingNode() + { + return outerProxy.getNode(); + } + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.GLASS; + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) + { + IIcon myIcon = is.getIconIndex(); + rh.setTexture( myIcon ); + rh.setBounds( 6, 6, 10, 10, 10, 16 ); + rh.renderBlock( x, y, z, renderer ); + rh.setTexture( null ); + } + + @Override + public void getBoxes(IPartCollisionHelper bch) + { + bch.addBox( 6, 6, 10, 10, 10, 16 ); + } + + @Override + @SideOnly(Side.CLIENT) + public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) + { + GL11.glTranslated( -0.2, -0.3, 0.0 ); + + rh.setTexture( is.getIconIndex() ); + rh.setBounds( 6.0f, 6.0f, 5.0f, 10.0f, 10.0f, 11.0f ); + rh.renderInventoryBox( renderer ); + rh.setTexture( null ); + } + + @Override + public double extractAEPower(double amt, Actionable mode, Set seen) + { + double acquiredPower = 0; + + try + { + IEnergyGrid eg = proxy.getEnergy(); + acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen ); + } + catch (GridAccessException e) + { + // :P + } + + try + { + IEnergyGrid eg = outerProxy.getEnergy(); + acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen ); + } + catch (GridAccessException e) + { + // :P + } + + return acquiredPower; + } + + @Override + public double injectAEPower(double amt, Actionable mode, Set seen) + { + + try + { + IEnergyGrid eg = proxy.getEnergy(); + if ( !seen.contains( eg ) ) + return eg.injectAEPower( amt, mode, seen ); + } + catch (GridAccessException e) + { + // :P + } + + try + { + IEnergyGrid eg = outerProxy.getEnergy(); + if ( !seen.contains( eg ) ) + return eg.injectAEPower( amt, mode, seen ); + } + catch (GridAccessException e) + { + // :P + } + + return amt; + } + + @Override + public int cableConnectionRenderTo() + { + return 16; + } + + @Override + public double getEnergyDemand(double amt, Set seen) + { + double demand = 0; + + try + { + IEnergyGrid eg = proxy.getEnergy(); + demand += eg.getEnergyDemand( amt - demand, seen ); + } + catch (GridAccessException e) + { + // :P + } + + try + { + IEnergyGrid eg = outerProxy.getEnergy(); + demand += eg.getEnergyDemand( amt - demand, seen ); + } + catch (GridAccessException e) + { + // :P + } + + return demand; + } + +} diff --git a/parts/p2p/PartP2PBCPower.java b/src/main/java/appeng/parts/p2p/PartP2PBCPower.java similarity index 95% rename from parts/p2p/PartP2PBCPower.java rename to src/main/java/appeng/parts/p2p/PartP2PBCPower.java index 6dc9ec090..c62b01e66 100644 --- a/parts/p2p/PartP2PBCPower.java +++ b/src/main/java/appeng/parts/p2p/PartP2PBCPower.java @@ -1,442 +1,442 @@ -package appeng.parts.p2p; - -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.PowerUnits; -import appeng.api.config.TunnelType; -import appeng.api.networking.IGridNode; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.core.AppEng; -import appeng.core.settings.TickRates; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.IMJ5; -import appeng.integration.abstraction.IMJ6; -import appeng.integration.abstraction.helpers.BaseMJperdition; -import appeng.me.GridAccessException; -import appeng.me.cache.helpers.TunnelCollection; -import appeng.transformer.annotations.integration.Interface; -import appeng.transformer.annotations.integration.InterfaceList; -import appeng.transformer.annotations.integration.Method; -import buildcraft.api.mj.IBatteryObject; -import buildcraft.api.mj.ISidedBatteryProvider; -import buildcraft.api.mj.MjAPI; -import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerHandler; -import buildcraft.api.power.PowerHandler.PowerReceiver; -import buildcraft.api.power.PowerHandler.Type; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@InterfaceList(value = { @Interface(iface = "buildcraft.api.mj.ISidedBatteryProvider", iname = "MJ6"), - @Interface(iface = "buildcraft.api.mj.IBatteryObject", iname = "MJ6"), @Interface(iface = "buildcraft.api.power.IPowerReceptor", iname = "MJ5"), - @Interface(iface = "appeng.api.networking.ticking.IGridTickable", iname = "MJ5") }) -public class PartP2PBCPower extends PartP2PTunnel implements IPowerReceptor, ISidedBatteryProvider, IBatteryObject, IGridTickable -{ - - BaseMJperdition pp; - - public TunnelType getTunnelType() - { - return TunnelType.BC_POWER; - } - - public PartP2PBCPower(ItemStack is) { - super( is ); - - if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) && !AppEng.instance.isIntegrationEnabled( IntegrationType.MJ6 ) ) - throw new RuntimeException( "MJ Not installed!" ); - - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) ) - { - pp = (BaseMJperdition) ((IMJ5) AppEng.instance.getIntegration( IntegrationType.MJ5 )).createPerdition( this ); - if ( pp != null ) - pp.configure( 1, 380, 1.0f / 5.0f, 1000 ); - } - } - - @Override - @Method(iname = "MJ5") - public TickingRequest getTickingRequest(IGridNode node) - { - return new TickingRequest( TickRates.MJTunnel.min, TickRates.MJTunnel.max, false, false ); - } - - @Override - @Method(iname = "MJ5") - public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) - { - if ( !output && proxy.isActive() ) - { - float totalRequiredPower = 0.0f; - TunnelCollection tunnelset; - - try - { - tunnelset = getOutputs(); - } - catch (GridAccessException e) - { - return TickRateModulation.IDLE; - } - - for (PartP2PBCPower o : tunnelset) - { - IPowerReceptor target = o.getPowerTarget(); - if ( target != null ) - { - PowerReceiver tp = target.getPowerReceiver( side.getOpposite() ); - if ( tp != null ) - { - double howmuch = tp.powerRequest(); - - if ( howmuch > tp.getMaxEnergyReceived() ) - howmuch = tp.getMaxEnergyReceived(); - - if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() ) - { - totalRequiredPower += howmuch; - } - } - } - } - - if ( totalRequiredPower < 0.1 ) - return TickRateModulation.SLOWER; - - double currentTotal = pp.getPowerReceiver().getEnergyStored(); - if ( currentTotal < 0.01 ) - return TickRateModulation.SLOWER; - - for (PartP2PBCPower o : tunnelset) - { - IPowerReceptor target = o.getPowerTarget(); - if ( target != null ) - { - PowerReceiver tp = target.getPowerReceiver( side.getOpposite() ); - if ( tp != null ) - { - double howmuch = tp.powerRequest(); - - if ( howmuch > tp.getMaxEnergyReceived() ) - howmuch = tp.getMaxEnergyReceived(); - - if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() ) - { - double toPull = currentTotal * (howmuch / totalRequiredPower); - double pulled = pp.useEnergy( 0, toPull, true ); - QueueTunnelDrain( PowerUnits.MJ, pulled ); - - tp.receiveEnergy( Type.PIPE, pulled, o.side.getOpposite() ); - } - } - } - } - - return TickRateModulation.FASTER; - } - - return TickRateModulation.SLOWER; - } - - public float getPowerDrainPerTick() - { - return 0.5f; - }; - - @Method(iname = "MJ6") - private IBatteryObject getTargetBattery() - { - TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); - if ( te != null ) - { - IBatteryObject bo = MjAPI.getMjBattery( te, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite() ); - if ( bo != null ) - return bo; - - return ((IMJ6) AppEng.instance.getIntegration( IntegrationType.MJ6 )).provider( te, side.getOpposite() ); - } - return null; - } - - @Method(iname = "MJ5") - private IPowerReceptor getPowerTarget() - { - TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); - if ( te != null ) - { - if ( te instanceof IPowerReceptor ) - return (IPowerReceptor) te; - } - return null; - } - - @Override - public void writeToNBT(NBTTagCompound tag) - { - super.writeToNBT( tag ); - if ( pp != null ) - pp.writeToNBT( tag ); - } - - @Override - public void readFromNBT(NBTTagCompound tag) - { - super.readFromNBT( tag ); - if ( pp != null ) - pp.readFromNBT( tag ); - } - - @SideOnly(Side.CLIENT) - public IIcon getTypeTexture() - { - return Blocks.emerald_block.getBlockTextureFromSide( 0 ); - } - - @Override - @Method(iname = "MJ5") - public PowerReceiver getPowerReceiver(ForgeDirection side) - { - if ( side.equals( side ) ) - return ((BaseMJperdition) pp).getPowerReceiver(); - return null; - } - - @Override - @Method(iname = "MJ5") - public void doWork(PowerHandler workProvider) - { - - } - - @Override - public World getWorld() - { - return tile.getWorldObj(); - } - - @Override - @Method(iname = "MJ6") - public IBatteryObject getMjBattery(String kind, ForgeDirection direction) - { - return this; - } - - @Override - @Method(iname = "MJ6") - public double getEnergyRequested() - { - try - { - double totalRequiredPower = 0.0f; - - for (PartP2PBCPower g : getOutputs()) - { - IBatteryObject o = g.getTargetBattery(); - if ( o != null ) - totalRequiredPower += o.getEnergyRequested(); - } - - return totalRequiredPower; - } - catch (GridAccessException e) - { - return 0; - } - } - - @Override - @Method(iname = "MJ6") - public double addEnergy(double mj) - { - return addEnergyInternal( mj, false, false ); - } - - @Override - @Method(iname = "MJ6") - public double addEnergy(double mj, boolean ignoreCycleLimit) - { - return addEnergyInternal( mj, true, ignoreCycleLimit ); - } - - @Method(iname = "MJ6") - private double addEnergyInternal(double mj, boolean cycleLimitMode, boolean ignoreCycleLimit) - { - if ( output || !proxy.isActive() ) - return 0; - - double originalInput = mj; - - try - { - TunnelCollection outs = getOutputs(); - - double outputs = 0; - for (PartP2PBCPower g : outs) - { - IBatteryObject o = g.getTargetBattery(); - if ( o != null ) - { - outputs = outputs + 1.0; - } - } - - if ( outputs < 0.0000001 ) - return 0; - - for (PartP2PBCPower g : outs) - { - IBatteryObject o = g.getTargetBattery(); - if ( o != null ) - { - double fraction = originalInput / outputs; - if ( cycleLimitMode ) - fraction = o.addEnergy( fraction ); - else - fraction = o.addEnergy( fraction, ignoreCycleLimit ); - mj -= fraction; - } - } - - if ( mj > 0 ) - { - for (PartP2PBCPower g : outs) - { - IBatteryObject o = g.getTargetBattery(); - if ( o != null ) - { - if ( cycleLimitMode ) - mj = mj - o.addEnergy( mj ); - else - mj = mj - o.addEnergy( mj, ignoreCycleLimit ); - } - } - } - - return originalInput - mj; - } - catch (GridAccessException e) - { - return 0; - } - } - - @Override - @Method(iname = "MJ6") - public double getEnergyStored() - { - try - { - double totalRequiredPower = 0.0f; - - for (PartP2PBCPower g : getOutputs()) - { - IBatteryObject o = g.getTargetBattery(); - if ( o != null ) - totalRequiredPower += o.getEnergyStored(); - } - - return totalRequiredPower; - } - catch (GridAccessException e) - { - return 0; - } - } - - @Override - @Method(iname = "MJ6") - public void setEnergyStored(double mj) - { - // EHh?! - } - - @Override - public double maxCapacity() - { - try - { - double totalRequiredPower = 0.0f; - - for (PartP2PBCPower g : getOutputs()) - { - IBatteryObject o = g.getTargetBattery(); - if ( o != null ) - totalRequiredPower += o.maxCapacity(); - } - - return totalRequiredPower; - } - catch (GridAccessException e) - { - return 0; - } - } - - @Override - @Method(iname = "MJ6") - public double minimumConsumption() - { - try - { - double totalRequiredPower = 1000000000000.0; - - for (PartP2PBCPower g : getOutputs()) - { - IBatteryObject o = g.getTargetBattery(); - if ( o != null ) - totalRequiredPower = Math.min( totalRequiredPower, o.minimumConsumption() ); - } - - return totalRequiredPower; - } - catch (GridAccessException e) - { - return 0; - } - } - - @Override - @Method(iname = "MJ6") - public double maxReceivedPerCycle() - { - try - { - double totalRequiredPower = 1000000.0; - - for (PartP2PBCPower g : getOutputs()) - { - IBatteryObject o = g.getTargetBattery(); - if ( o != null ) - totalRequiredPower = Math.min( totalRequiredPower, o.maxReceivedPerCycle() ); - } - - return totalRequiredPower; - } - catch (GridAccessException e) - { - return 0; - } - } - - @Override - @Method(iname = "MJ6") - public IBatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption) - { - return this; - } - - @Override - @Method(iname = "MJ6") - public String kind() - { - return "tunnel"; - } - -} +package appeng.parts.p2p; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.PowerUnits; +import appeng.api.config.TunnelType; +import appeng.api.networking.IGridNode; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; +import appeng.core.AppEng; +import appeng.core.settings.TickRates; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.IMJ5; +import appeng.integration.abstraction.IMJ6; +import appeng.integration.abstraction.helpers.BaseMJperdition; +import appeng.me.GridAccessException; +import appeng.me.cache.helpers.TunnelCollection; +import appeng.transformer.annotations.integration.Interface; +import appeng.transformer.annotations.integration.InterfaceList; +import appeng.transformer.annotations.integration.Method; +import buildcraft.api.mj.IBatteryObject; +import buildcraft.api.mj.ISidedBatteryProvider; +import buildcraft.api.mj.MjAPI; +import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; +import buildcraft.api.power.PowerHandler.Type; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@InterfaceList(value = { @Interface(iface = "buildcraft.api.mj.ISidedBatteryProvider", iname = "MJ6"), + @Interface(iface = "buildcraft.api.mj.IBatteryObject", iname = "MJ6"), @Interface(iface = "buildcraft.api.power.IPowerReceptor", iname = "MJ5"), + @Interface(iface = "appeng.api.networking.ticking.IGridTickable", iname = "MJ5") }) +public class PartP2PBCPower extends PartP2PTunnel implements IPowerReceptor, ISidedBatteryProvider, IBatteryObject, IGridTickable +{ + + BaseMJperdition pp; + + public TunnelType getTunnelType() + { + return TunnelType.BC_POWER; + } + + public PartP2PBCPower(ItemStack is) { + super( is ); + + if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) && !AppEng.instance.isIntegrationEnabled( IntegrationType.MJ6 ) ) + throw new RuntimeException( "MJ Not installed!" ); + + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) ) + { + pp = (BaseMJperdition) ((IMJ5) AppEng.instance.getIntegration( IntegrationType.MJ5 )).createPerdition( this ); + if ( pp != null ) + pp.configure( 1, 380, 1.0f / 5.0f, 1000 ); + } + } + + @Override + @Method(iname = "MJ5") + public TickingRequest getTickingRequest(IGridNode node) + { + return new TickingRequest( TickRates.MJTunnel.min, TickRates.MJTunnel.max, false, false ); + } + + @Override + @Method(iname = "MJ5") + public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + { + if ( !output && proxy.isActive() ) + { + float totalRequiredPower = 0.0f; + TunnelCollection tunnelset; + + try + { + tunnelset = getOutputs(); + } + catch (GridAccessException e) + { + return TickRateModulation.IDLE; + } + + for (PartP2PBCPower o : tunnelset) + { + IPowerReceptor target = o.getPowerTarget(); + if ( target != null ) + { + PowerReceiver tp = target.getPowerReceiver( side.getOpposite() ); + if ( tp != null ) + { + double howmuch = tp.powerRequest(); + + if ( howmuch > tp.getMaxEnergyReceived() ) + howmuch = tp.getMaxEnergyReceived(); + + if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() ) + { + totalRequiredPower += howmuch; + } + } + } + } + + if ( totalRequiredPower < 0.1 ) + return TickRateModulation.SLOWER; + + double currentTotal = pp.getPowerReceiver().getEnergyStored(); + if ( currentTotal < 0.01 ) + return TickRateModulation.SLOWER; + + for (PartP2PBCPower o : tunnelset) + { + IPowerReceptor target = o.getPowerTarget(); + if ( target != null ) + { + PowerReceiver tp = target.getPowerReceiver( side.getOpposite() ); + if ( tp != null ) + { + double howmuch = tp.powerRequest(); + + if ( howmuch > tp.getMaxEnergyReceived() ) + howmuch = tp.getMaxEnergyReceived(); + + if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() ) + { + double toPull = currentTotal * (howmuch / totalRequiredPower); + double pulled = pp.useEnergy( 0, toPull, true ); + QueueTunnelDrain( PowerUnits.MJ, pulled ); + + tp.receiveEnergy( Type.PIPE, pulled, o.side.getOpposite() ); + } + } + } + } + + return TickRateModulation.FASTER; + } + + return TickRateModulation.SLOWER; + } + + public float getPowerDrainPerTick() + { + return 0.5f; + }; + + @Method(iname = "MJ6") + private IBatteryObject getTargetBattery() + { + TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); + if ( te != null ) + { + IBatteryObject bo = MjAPI.getMjBattery( te, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite() ); + if ( bo != null ) + return bo; + + return ((IMJ6) AppEng.instance.getIntegration( IntegrationType.MJ6 )).provider( te, side.getOpposite() ); + } + return null; + } + + @Method(iname = "MJ5") + private IPowerReceptor getPowerTarget() + { + TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); + if ( te != null ) + { + if ( te instanceof IPowerReceptor ) + return (IPowerReceptor) te; + } + return null; + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT( tag ); + if ( pp != null ) + pp.writeToNBT( tag ); + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT( tag ); + if ( pp != null ) + pp.readFromNBT( tag ); + } + + @SideOnly(Side.CLIENT) + public IIcon getTypeTexture() + { + return Blocks.emerald_block.getBlockTextureFromSide( 0 ); + } + + @Override + @Method(iname = "MJ5") + public PowerReceiver getPowerReceiver(ForgeDirection side) + { + if ( side.equals( side ) ) + return ((BaseMJperdition) pp).getPowerReceiver(); + return null; + } + + @Override + @Method(iname = "MJ5") + public void doWork(PowerHandler workProvider) + { + + } + + @Override + public World getWorld() + { + return tile.getWorldObj(); + } + + @Override + @Method(iname = "MJ6") + public IBatteryObject getMjBattery(String kind, ForgeDirection direction) + { + return this; + } + + @Override + @Method(iname = "MJ6") + public double getEnergyRequested() + { + try + { + double totalRequiredPower = 0.0f; + + for (PartP2PBCPower g : getOutputs()) + { + IBatteryObject o = g.getTargetBattery(); + if ( o != null ) + totalRequiredPower += o.getEnergyRequested(); + } + + return totalRequiredPower; + } + catch (GridAccessException e) + { + return 0; + } + } + + @Override + @Method(iname = "MJ6") + public double addEnergy(double mj) + { + return addEnergyInternal( mj, false, false ); + } + + @Override + @Method(iname = "MJ6") + public double addEnergy(double mj, boolean ignoreCycleLimit) + { + return addEnergyInternal( mj, true, ignoreCycleLimit ); + } + + @Method(iname = "MJ6") + private double addEnergyInternal(double mj, boolean cycleLimitMode, boolean ignoreCycleLimit) + { + if ( output || !proxy.isActive() ) + return 0; + + double originalInput = mj; + + try + { + TunnelCollection outs = getOutputs(); + + double outputs = 0; + for (PartP2PBCPower g : outs) + { + IBatteryObject o = g.getTargetBattery(); + if ( o != null ) + { + outputs = outputs + 1.0; + } + } + + if ( outputs < 0.0000001 ) + return 0; + + for (PartP2PBCPower g : outs) + { + IBatteryObject o = g.getTargetBattery(); + if ( o != null ) + { + double fraction = originalInput / outputs; + if ( cycleLimitMode ) + fraction = o.addEnergy( fraction ); + else + fraction = o.addEnergy( fraction, ignoreCycleLimit ); + mj -= fraction; + } + } + + if ( mj > 0 ) + { + for (PartP2PBCPower g : outs) + { + IBatteryObject o = g.getTargetBattery(); + if ( o != null ) + { + if ( cycleLimitMode ) + mj = mj - o.addEnergy( mj ); + else + mj = mj - o.addEnergy( mj, ignoreCycleLimit ); + } + } + } + + return originalInput - mj; + } + catch (GridAccessException e) + { + return 0; + } + } + + @Override + @Method(iname = "MJ6") + public double getEnergyStored() + { + try + { + double totalRequiredPower = 0.0f; + + for (PartP2PBCPower g : getOutputs()) + { + IBatteryObject o = g.getTargetBattery(); + if ( o != null ) + totalRequiredPower += o.getEnergyStored(); + } + + return totalRequiredPower; + } + catch (GridAccessException e) + { + return 0; + } + } + + @Override + @Method(iname = "MJ6") + public void setEnergyStored(double mj) + { + // EHh?! + } + + @Override + public double maxCapacity() + { + try + { + double totalRequiredPower = 0.0f; + + for (PartP2PBCPower g : getOutputs()) + { + IBatteryObject o = g.getTargetBattery(); + if ( o != null ) + totalRequiredPower += o.maxCapacity(); + } + + return totalRequiredPower; + } + catch (GridAccessException e) + { + return 0; + } + } + + @Override + @Method(iname = "MJ6") + public double minimumConsumption() + { + try + { + double totalRequiredPower = 1000000000000.0; + + for (PartP2PBCPower g : getOutputs()) + { + IBatteryObject o = g.getTargetBattery(); + if ( o != null ) + totalRequiredPower = Math.min( totalRequiredPower, o.minimumConsumption() ); + } + + return totalRequiredPower; + } + catch (GridAccessException e) + { + return 0; + } + } + + @Override + @Method(iname = "MJ6") + public double maxReceivedPerCycle() + { + try + { + double totalRequiredPower = 1000000.0; + + for (PartP2PBCPower g : getOutputs()) + { + IBatteryObject o = g.getTargetBattery(); + if ( o != null ) + totalRequiredPower = Math.min( totalRequiredPower, o.maxReceivedPerCycle() ); + } + + return totalRequiredPower; + } + catch (GridAccessException e) + { + return 0; + } + } + + @Override + @Method(iname = "MJ6") + public IBatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption) + { + return this; + } + + @Override + @Method(iname = "MJ6") + public String kind() + { + return "tunnel"; + } + +} diff --git a/parts/p2p/PartP2PIC2Power.java b/src/main/java/appeng/parts/p2p/PartP2PIC2Power.java similarity index 95% rename from parts/p2p/PartP2PIC2Power.java rename to src/main/java/appeng/parts/p2p/PartP2PIC2Power.java index 8b62fdd42..bc07d1018 100644 --- a/parts/p2p/PartP2PIC2Power.java +++ b/src/main/java/appeng/parts/p2p/PartP2PIC2Power.java @@ -1,232 +1,232 @@ -package appeng.parts.p2p; - -import java.util.LinkedList; - -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.PowerUnits; -import appeng.api.config.TunnelType; -import appeng.core.AppEng; -import appeng.integration.IntegrationType; -import appeng.me.GridAccessException; -import appeng.me.cache.helpers.TunnelCollection; -import appeng.transformer.annotations.integration.Interface; -import appeng.transformer.annotations.integration.InterfaceList; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@InterfaceList(value = { @Interface(iface = "ic2.api.energy.tile.IEnergySink", iname = "IC2"), - @Interface(iface = "ic2.api.energy.tile.IEnergySource", iname = "IC2") }) -public class PartP2PIC2Power extends PartP2PTunnel implements ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource -{ - - public TunnelType getTunnelType() - { - return TunnelType.IC2_POWER; - } - - public PartP2PIC2Power(ItemStack is) { - super( is ); - - if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) ) - throw new RuntimeException( "IC2 Not installed!" ); - } - - // two packet buffering... - double OutputEnergyA; - double OutputEnergyB; - - // two packet buffering... - double OutputVoltageA; - double OutputVoltageB; - - @Override - public void writeToNBT(NBTTagCompound tag) - { - super.writeToNBT( tag ); - tag.setDouble( "OutputPacket", OutputEnergyA ); - tag.setDouble( "OutputPacket2", OutputEnergyB ); - tag.setDouble( "OutputVoltageA", OutputVoltageA ); - tag.setDouble( "OutputVoltageB", OutputVoltageB ); - } - - @Override - public void readFromNBT(NBTTagCompound tag) - { - super.readFromNBT( tag ); - OutputEnergyA = tag.getDouble( "OutputPacket" ); - OutputEnergyB = tag.getDouble( "OutputPacket2" ); - OutputVoltageA = tag.getDouble( "OutputVoltageA" ); - OutputVoltageB = tag.getDouble( "OutputVoltageB" ); - } - - @SideOnly(Side.CLIENT) - public IIcon getTypeTexture() - { - return Blocks.diamond_block.getBlockTextureFromSide( 0 ); - } - - @Override - public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) - { - if ( !output ) - return direction.equals( side ); - return false; - } - - @Override - public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) - { - if ( output ) - return direction.equals( side ); - return false; - } - - @Override - public double getDemandedEnergy() - { - if ( output ) - return 0; - - try - { - for (PartP2PIC2Power t : getOutputs()) - { - if ( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 ) - { - return 2048; - } - } - } - catch (GridAccessException e) - { - return 0; - } - - return 0; - } - - @Override - public void onTunnelNetworkChange() - { - getHost().notifyNeighbors(); - } - - @Override - public void onTunnelConfigChange() - { - getHost().partChanged(); - } - - public float getPowerDrainPerTick() - { - return 0.5f; - }; - - @Override - public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) - { - TunnelCollection outs; - try - { - outs = getOutputs(); - } - catch (GridAccessException e) - { - return amount; - } - - if ( outs.isEmpty() ) - return amount; - - LinkedList Options = new LinkedList(); - for (PartP2PIC2Power o : outs) - { - if ( o.OutputEnergyA <= 0.01 ) - Options.add( o ); - } - - if ( Options.isEmpty() ) - { - for (PartP2PIC2Power o : outs) - if ( o.OutputEnergyB <= 0.01 ) - Options.add( o ); - } - - if ( Options.isEmpty() ) - { - for (PartP2PIC2Power o : outs) - Options.add( o ); - } - - if ( Options.isEmpty() ) - return amount; - - PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options ); - - if ( x != null && x.OutputEnergyA <= 0.001 ) - { - QueueTunnelDrain( PowerUnits.EU, amount ); - x.OutputEnergyA = amount; - x.OutputVoltageA = voltage; - return 0; - } - - if ( x != null && x.OutputEnergyB <= 0.001 ) - { - QueueTunnelDrain( PowerUnits.EU, amount ); - x.OutputEnergyB = amount; - x.OutputVoltageB = voltage; - return 0; - } - - return amount; - } - - @Override - public int getSinkTier() - { - return 4; - } - - @Override - public double getOfferedEnergy() - { - if ( output ) - return OutputEnergyA; - return 0; - } - - @Override - public void drawEnergy(double amount) - { - OutputEnergyA -= amount; - if ( OutputEnergyA < 0.001 ) - { - OutputEnergyA = OutputEnergyB; - OutputEnergyB = 0; - - OutputVoltageA = OutputVoltageB; - OutputVoltageB = 0; - } - } - - @Override - public int getSourceTier() - { - if ( output ) - return calculateTierFromVoltage( OutputVoltageA ); - return 4; - } - - private int calculateTierFromVoltage(double voltage) - { - return ic2.api.energy.EnergyNet.instance.getTierFromPower( voltage ); - } - -} +package appeng.parts.p2p; + +import java.util.LinkedList; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.PowerUnits; +import appeng.api.config.TunnelType; +import appeng.core.AppEng; +import appeng.integration.IntegrationType; +import appeng.me.GridAccessException; +import appeng.me.cache.helpers.TunnelCollection; +import appeng.transformer.annotations.integration.Interface; +import appeng.transformer.annotations.integration.InterfaceList; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@InterfaceList(value = { @Interface(iface = "ic2.api.energy.tile.IEnergySink", iname = "IC2"), + @Interface(iface = "ic2.api.energy.tile.IEnergySource", iname = "IC2") }) +public class PartP2PIC2Power extends PartP2PTunnel implements ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource +{ + + public TunnelType getTunnelType() + { + return TunnelType.IC2_POWER; + } + + public PartP2PIC2Power(ItemStack is) { + super( is ); + + if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) ) + throw new RuntimeException( "IC2 Not installed!" ); + } + + // two packet buffering... + double OutputEnergyA; + double OutputEnergyB; + + // two packet buffering... + double OutputVoltageA; + double OutputVoltageB; + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT( tag ); + tag.setDouble( "OutputPacket", OutputEnergyA ); + tag.setDouble( "OutputPacket2", OutputEnergyB ); + tag.setDouble( "OutputVoltageA", OutputVoltageA ); + tag.setDouble( "OutputVoltageB", OutputVoltageB ); + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT( tag ); + OutputEnergyA = tag.getDouble( "OutputPacket" ); + OutputEnergyB = tag.getDouble( "OutputPacket2" ); + OutputVoltageA = tag.getDouble( "OutputVoltageA" ); + OutputVoltageB = tag.getDouble( "OutputVoltageB" ); + } + + @SideOnly(Side.CLIENT) + public IIcon getTypeTexture() + { + return Blocks.diamond_block.getBlockTextureFromSide( 0 ); + } + + @Override + public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) + { + if ( !output ) + return direction.equals( side ); + return false; + } + + @Override + public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) + { + if ( output ) + return direction.equals( side ); + return false; + } + + @Override + public double getDemandedEnergy() + { + if ( output ) + return 0; + + try + { + for (PartP2PIC2Power t : getOutputs()) + { + if ( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 ) + { + return 2048; + } + } + } + catch (GridAccessException e) + { + return 0; + } + + return 0; + } + + @Override + public void onTunnelNetworkChange() + { + getHost().notifyNeighbors(); + } + + @Override + public void onTunnelConfigChange() + { + getHost().partChanged(); + } + + public float getPowerDrainPerTick() + { + return 0.5f; + }; + + @Override + public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) + { + TunnelCollection outs; + try + { + outs = getOutputs(); + } + catch (GridAccessException e) + { + return amount; + } + + if ( outs.isEmpty() ) + return amount; + + LinkedList Options = new LinkedList(); + for (PartP2PIC2Power o : outs) + { + if ( o.OutputEnergyA <= 0.01 ) + Options.add( o ); + } + + if ( Options.isEmpty() ) + { + for (PartP2PIC2Power o : outs) + if ( o.OutputEnergyB <= 0.01 ) + Options.add( o ); + } + + if ( Options.isEmpty() ) + { + for (PartP2PIC2Power o : outs) + Options.add( o ); + } + + if ( Options.isEmpty() ) + return amount; + + PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options ); + + if ( x != null && x.OutputEnergyA <= 0.001 ) + { + QueueTunnelDrain( PowerUnits.EU, amount ); + x.OutputEnergyA = amount; + x.OutputVoltageA = voltage; + return 0; + } + + if ( x != null && x.OutputEnergyB <= 0.001 ) + { + QueueTunnelDrain( PowerUnits.EU, amount ); + x.OutputEnergyB = amount; + x.OutputVoltageB = voltage; + return 0; + } + + return amount; + } + + @Override + public int getSinkTier() + { + return 4; + } + + @Override + public double getOfferedEnergy() + { + if ( output ) + return OutputEnergyA; + return 0; + } + + @Override + public void drawEnergy(double amount) + { + OutputEnergyA -= amount; + if ( OutputEnergyA < 0.001 ) + { + OutputEnergyA = OutputEnergyB; + OutputEnergyB = 0; + + OutputVoltageA = OutputVoltageB; + OutputVoltageB = 0; + } + } + + @Override + public int getSourceTier() + { + if ( output ) + return calculateTierFromVoltage( OutputVoltageA ); + return 4; + } + + private int calculateTierFromVoltage(double voltage) + { + return ic2.api.energy.EnergyNet.instance.getTierFromPower( voltage ); + } + +} diff --git a/parts/p2p/PartP2PItems.java b/src/main/java/appeng/parts/p2p/PartP2PItems.java similarity index 95% rename from parts/p2p/PartP2PItems.java rename to src/main/java/appeng/parts/p2p/PartP2PItems.java index fef463dfa..fc67d4e76 100644 --- a/parts/p2p/PartP2PItems.java +++ b/src/main/java/appeng/parts/p2p/PartP2PItems.java @@ -1,362 +1,362 @@ -package appeng.parts.p2p; - -import java.util.LinkedList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityChest; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.TunnelType; -import appeng.api.networking.IGridNode; -import appeng.api.networking.events.MENetworkBootingStatusChange; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.core.AppEng; -import appeng.core.settings.TickRates; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.IBC; -import appeng.me.GridAccessException; -import appeng.me.cache.helpers.TunnelCollection; -import appeng.tile.inventory.AppEngNullInventory; -import appeng.transformer.annotations.integration.Interface; -import appeng.transformer.annotations.integration.Method; -import appeng.util.Platform; -import appeng.util.inv.WrapperBCPipe; -import appeng.util.inv.WrapperChainedInventory; -import appeng.util.inv.WrapperMCISidedInventory; -import buildcraft.api.transport.IPipeConnection; -import buildcraft.api.transport.IPipeTile.PipeType; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@Interface(iface = "buildcraft.api.transport.IPipeConnection", iname = "BC") -public class PartP2PItems extends PartP2PTunnel implements IPipeConnection, IInventory, ISidedInventory, IGridTickable -{ - - public TunnelType getTunnelType() - { - return TunnelType.ITEM; - } - - public PartP2PItems(ItemStack is) { - super( is ); - } - - int oldSize = 0; - boolean requested; - IInventory cachedInv; - - LinkedList which = new LinkedList(); - - IInventory getOutputInv() - { - IInventory output = null; - - if ( proxy.isActive() ) - { - TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); - - if ( which.contains( this ) ) - return null; - - which.add( this ); - - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) ) - { - IBC buildcraft = (IBC) AppEng.instance.getIntegration( IntegrationType.BC ); - if ( buildcraft != null ) - { - if ( buildcraft.isPipe( te, side.getOpposite() ) ) - { - try - { - output = new WrapperBCPipe( te, side.getOpposite() ); - } - catch (Throwable ignore) - { - } - } - } - } - - /* - * if ( AppEng.instance.isIntegrationEnabled( "TE" ) ) { ITE thermal = (ITE) AppEng.instance.getIntegration( - * "TE" ); if ( thermal != null ) { if ( thermal.isPipe( te, side.getOpposite() ) ) { try { output = new - * WrapperTEPipe( te, side.getOpposite() ); } catch (Throwable ignore) { } } } } - */ - - if ( output == null ) - { - if ( te instanceof TileEntityChest ) - { - output = Platform.GetChestInv( te ); - } - else if ( te instanceof ISidedInventory ) - { - output = new WrapperMCISidedInventory( (ISidedInventory) te, side.getOpposite() ); - } - else if ( te instanceof IInventory ) - { - output = (IInventory) te; - } - } - - which.pop(); - } - - return output; - } - - @Override - public void onNeighborChanged() - { - cachedInv = null; - PartP2PItems input = getInput(); - if ( input != null && output ) - input.onTunnelNetworkChange(); - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) - { - return new TickingRequest( TickRates.ItemTunnel.min, TickRates.ItemTunnel.max, false, false ); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) - { - boolean wasReq = requested; - - if ( requested && cachedInv != null ) - ((WrapperChainedInventory) cachedInv).cycleOrder(); - - requested = false; - return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER; - } - - IInventory getDest() - { - requested = true; - - if ( cachedInv != null ) - return cachedInv; - - List outs = new LinkedList(); - TunnelCollection itemTunnels; - - try - { - itemTunnels = getOutputs(); - } - catch (GridAccessException e) - { - return new AppEngNullInventory(); - } - - for (PartP2PItems t : itemTunnels) - { - IInventory inv = t.getOutputInv(); - if ( inv != null ) - { - if ( Platform.getRandomInt() % 2 == 0 ) - outs.add( inv ); - else - outs.add( 0, inv ); - } - } - - return cachedInv = new WrapperChainedInventory( outs ); - } - - @MENetworkEventSubscribe - public void changeStateA(MENetworkBootingStatusChange bs) - { - if ( !output ) - { - cachedInv = null; - int olderSize = oldSize; - oldSize = getDest().getSizeInventory(); - if ( olderSize != oldSize ) - { - getHost().notifyNeighbors(); - } - } - } - - @MENetworkEventSubscribe - public void changeStateB(MENetworkChannelsChanged bs) - { - if ( !output ) - { - cachedInv = null; - int olderSize = oldSize; - oldSize = getDest().getSizeInventory(); - if ( olderSize != oldSize ) - { - getHost().notifyNeighbors(); - } - } - } - - @MENetworkEventSubscribe - public void changeStateC(MENetworkPowerStatusChange bs) - { - if ( !output ) - { - cachedInv = null; - int olderSize = oldSize; - oldSize = getDest().getSizeInventory(); - if ( olderSize != oldSize ) - { - getHost().notifyNeighbors(); - } - } - } - - @Override - public void onTunnelNetworkChange() - { - if ( !output ) - { - cachedInv = null; - int olderSize = oldSize; - oldSize = getDest().getSizeInventory(); - if ( olderSize != oldSize ) - { - getHost().notifyNeighbors(); - } - } - else - { - PartP2PItems input = getInput(); - if ( input != null ) - input.getHost().notifyNeighbors(); - } - } - - @SideOnly(Side.CLIENT) - public IIcon getTypeTexture() - { - return Blocks.hopper.getBlockTextureFromSide( 0 ); - } - - @Override - public int getSizeInventory() - { - return getDest().getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) - { - return getDest().getStackInSlot( i ); - } - - @Override - public ItemStack decrStackSize(int i, int j) - { - return getDest().decrStackSize( i, j ); - } - - @Override - public ItemStack getStackInSlotOnClosing(int i) - { - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) - { - getDest().setInventorySlotContents( i, itemstack ); - } - - @Override - public String getInventoryName() - { - return null; - } - - @Override - public boolean hasCustomInventoryName() - { - return false; - } - - @Override - public int getInventoryStackLimit() - { - return getDest().getInventoryStackLimit(); - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { - } - - @Override - public boolean isItemValidForSlot(int i, net.minecraft.item.ItemStack itemstack) - { - return getDest().isItemValidForSlot( i, itemstack ); - } - - @Override - public int[] getAccessibleSlotsFromSide(int var1) - { - int[] slots = new int[getSizeInventory()]; - for (int x = 0; x < getSizeInventory(); x++) - slots[x] = x; - return slots; - } - - public float getPowerDrainPerTick() - { - return 2.0f; - }; - - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) - { - return getDest().isItemValidForSlot( i, itemstack ); - } - - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) - { - return false; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return false; - } - - @Override - @Method(iname = "BC") - public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with) - { - return side.equals( with ) && type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT; - } - - @Override - public void markDirty() - { - // eh? - } - -} +package appeng.parts.p2p; + +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.TunnelType; +import appeng.api.networking.IGridNode; +import appeng.api.networking.events.MENetworkBootingStatusChange; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; +import appeng.core.AppEng; +import appeng.core.settings.TickRates; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.IBC; +import appeng.me.GridAccessException; +import appeng.me.cache.helpers.TunnelCollection; +import appeng.tile.inventory.AppEngNullInventory; +import appeng.transformer.annotations.integration.Interface; +import appeng.transformer.annotations.integration.Method; +import appeng.util.Platform; +import appeng.util.inv.WrapperBCPipe; +import appeng.util.inv.WrapperChainedInventory; +import appeng.util.inv.WrapperMCISidedInventory; +import buildcraft.api.transport.IPipeConnection; +import buildcraft.api.transport.IPipeTile.PipeType; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@Interface(iface = "buildcraft.api.transport.IPipeConnection", iname = "BC") +public class PartP2PItems extends PartP2PTunnel implements IPipeConnection, IInventory, ISidedInventory, IGridTickable +{ + + public TunnelType getTunnelType() + { + return TunnelType.ITEM; + } + + public PartP2PItems(ItemStack is) { + super( is ); + } + + int oldSize = 0; + boolean requested; + IInventory cachedInv; + + LinkedList which = new LinkedList(); + + IInventory getOutputInv() + { + IInventory output = null; + + if ( proxy.isActive() ) + { + TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); + + if ( which.contains( this ) ) + return null; + + which.add( this ); + + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) ) + { + IBC buildcraft = (IBC) AppEng.instance.getIntegration( IntegrationType.BC ); + if ( buildcraft != null ) + { + if ( buildcraft.isPipe( te, side.getOpposite() ) ) + { + try + { + output = new WrapperBCPipe( te, side.getOpposite() ); + } + catch (Throwable ignore) + { + } + } + } + } + + /* + * if ( AppEng.instance.isIntegrationEnabled( "TE" ) ) { ITE thermal = (ITE) AppEng.instance.getIntegration( + * "TE" ); if ( thermal != null ) { if ( thermal.isPipe( te, side.getOpposite() ) ) { try { output = new + * WrapperTEPipe( te, side.getOpposite() ); } catch (Throwable ignore) { } } } } + */ + + if ( output == null ) + { + if ( te instanceof TileEntityChest ) + { + output = Platform.GetChestInv( te ); + } + else if ( te instanceof ISidedInventory ) + { + output = new WrapperMCISidedInventory( (ISidedInventory) te, side.getOpposite() ); + } + else if ( te instanceof IInventory ) + { + output = (IInventory) te; + } + } + + which.pop(); + } + + return output; + } + + @Override + public void onNeighborChanged() + { + cachedInv = null; + PartP2PItems input = getInput(); + if ( input != null && output ) + input.onTunnelNetworkChange(); + } + + @Override + public TickingRequest getTickingRequest(IGridNode node) + { + return new TickingRequest( TickRates.ItemTunnel.min, TickRates.ItemTunnel.max, false, false ); + } + + @Override + public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + { + boolean wasReq = requested; + + if ( requested && cachedInv != null ) + ((WrapperChainedInventory) cachedInv).cycleOrder(); + + requested = false; + return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER; + } + + IInventory getDest() + { + requested = true; + + if ( cachedInv != null ) + return cachedInv; + + List outs = new LinkedList(); + TunnelCollection itemTunnels; + + try + { + itemTunnels = getOutputs(); + } + catch (GridAccessException e) + { + return new AppEngNullInventory(); + } + + for (PartP2PItems t : itemTunnels) + { + IInventory inv = t.getOutputInv(); + if ( inv != null ) + { + if ( Platform.getRandomInt() % 2 == 0 ) + outs.add( inv ); + else + outs.add( 0, inv ); + } + } + + return cachedInv = new WrapperChainedInventory( outs ); + } + + @MENetworkEventSubscribe + public void changeStateA(MENetworkBootingStatusChange bs) + { + if ( !output ) + { + cachedInv = null; + int olderSize = oldSize; + oldSize = getDest().getSizeInventory(); + if ( olderSize != oldSize ) + { + getHost().notifyNeighbors(); + } + } + } + + @MENetworkEventSubscribe + public void changeStateB(MENetworkChannelsChanged bs) + { + if ( !output ) + { + cachedInv = null; + int olderSize = oldSize; + oldSize = getDest().getSizeInventory(); + if ( olderSize != oldSize ) + { + getHost().notifyNeighbors(); + } + } + } + + @MENetworkEventSubscribe + public void changeStateC(MENetworkPowerStatusChange bs) + { + if ( !output ) + { + cachedInv = null; + int olderSize = oldSize; + oldSize = getDest().getSizeInventory(); + if ( olderSize != oldSize ) + { + getHost().notifyNeighbors(); + } + } + } + + @Override + public void onTunnelNetworkChange() + { + if ( !output ) + { + cachedInv = null; + int olderSize = oldSize; + oldSize = getDest().getSizeInventory(); + if ( olderSize != oldSize ) + { + getHost().notifyNeighbors(); + } + } + else + { + PartP2PItems input = getInput(); + if ( input != null ) + input.getHost().notifyNeighbors(); + } + } + + @SideOnly(Side.CLIENT) + public IIcon getTypeTexture() + { + return Blocks.hopper.getBlockTextureFromSide( 0 ); + } + + @Override + public int getSizeInventory() + { + return getDest().getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(int i) + { + return getDest().getStackInSlot( i ); + } + + @Override + public ItemStack decrStackSize(int i, int j) + { + return getDest().decrStackSize( i, j ); + } + + @Override + public ItemStack getStackInSlotOnClosing(int i) + { + return null; + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) + { + getDest().setInventorySlotContents( i, itemstack ); + } + + @Override + public String getInventoryName() + { + return null; + } + + @Override + public boolean hasCustomInventoryName() + { + return false; + } + + @Override + public int getInventoryStackLimit() + { + return getDest().getInventoryStackLimit(); + } + + @Override + public void openInventory() + { + } + + @Override + public void closeInventory() + { + } + + @Override + public boolean isItemValidForSlot(int i, net.minecraft.item.ItemStack itemstack) + { + return getDest().isItemValidForSlot( i, itemstack ); + } + + @Override + public int[] getAccessibleSlotsFromSide(int var1) + { + int[] slots = new int[getSizeInventory()]; + for (int x = 0; x < getSizeInventory(); x++) + slots[x] = x; + return slots; + } + + public float getPowerDrainPerTick() + { + return 2.0f; + }; + + @Override + public boolean canInsertItem(int i, ItemStack itemstack, int j) + { + return getDest().isItemValidForSlot( i, itemstack ); + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) + { + return false; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return false; + } + + @Override + @Method(iname = "BC") + public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with) + { + return side.equals( with ) && type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT; + } + + @Override + public void markDirty() + { + // eh? + } + +} diff --git a/parts/p2p/PartP2PLight.java b/src/main/java/appeng/parts/p2p/PartP2PLight.java similarity index 100% rename from parts/p2p/PartP2PLight.java rename to src/main/java/appeng/parts/p2p/PartP2PLight.java diff --git a/parts/p2p/PartP2PLiquids.java b/src/main/java/appeng/parts/p2p/PartP2PLiquids.java similarity index 95% rename from parts/p2p/PartP2PLiquids.java rename to src/main/java/appeng/parts/p2p/PartP2PLiquids.java index 717db6825..192506657 100644 --- a/parts/p2p/PartP2PLiquids.java +++ b/src/main/java/appeng/parts/p2p/PartP2PLiquids.java @@ -1,264 +1,264 @@ -package appeng.parts.p2p; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Stack; - -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidHandler; -import appeng.api.config.TunnelType; -import appeng.me.GridAccessException; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class PartP2PLiquids extends PartP2PTunnel implements IFluidHandler -{ - - private final static FluidTankInfo[] activeTank = new FluidTankInfo[] { new FluidTankInfo( null, 10000 ) }; - private final static FluidTankInfo[] inactiveTank = new FluidTankInfo[] { new FluidTankInfo( null, 0 ) }; - - public TunnelType getTunnelType() - { - return TunnelType.FLUID; - } - - public PartP2PLiquids(ItemStack is) { - super( is ); - } - - private FluidTankInfo[] getTank() - { - if ( output ) - { - PartP2PLiquids tun = getInput(); - if ( tun != null ) - return activeTank; - } - else - { - try - { - if ( !getOutputs().isEmpty() ) - return activeTank; - } - catch (GridAccessException e) - { - // :( - } - } - return inactiveTank; - } - - IFluidHandler cachedTank; - - public float getPowerDrainPerTick() - { - return 2.0f; - }; - - private int tmpUsed; - - @Override - public void writeToNBT(NBTTagCompound tag) - { - super.writeToNBT( tag ); - } - - @Override - public void readFromNBT(NBTTagCompound tag) - { - super.readFromNBT( tag ); - } - - @SideOnly(Side.CLIENT) - public IIcon getTypeTexture() - { - return Blocks.lapis_block.getBlockTextureFromSide( 0 ); - } - - List getOutputs(Fluid input) - { - List outs = new LinkedList(); - - try - { - for (PartP2PLiquids l : getOutputs()) - { - IFluidHandler targ = l.getTarget(); - if ( targ != null ) - { - if ( targ.canFill( l.side.getOpposite(), input ) ) - outs.add( l ); - } - } - } - catch (GridAccessException e) - { - // :P - } - - return outs; - } - - @Override - public void onNeighborChanged() - { - cachedTank = null; - if ( output ) - { - PartP2PLiquids in = getInput(); - if ( in != null ) - in.onTunnelNetworkChange(); - } - }; - - @Override - public void onTunnelNetworkChange() - { - cachedTank = null; - } - - IFluidHandler getTarget() - { - if ( !proxy.isActive() ) - return null; - - if ( cachedTank != null ) - return cachedTank; - - TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); - if ( te instanceof IFluidHandler ) - return cachedTank = (IFluidHandler) te; - - return null; - } - - static final ThreadLocal> depth = new ThreadLocal>(); - - private Stack getDepth() - { - Stack s = depth.get(); - - if ( s == null ) - depth.set( s = new Stack() ); - - return s; - } - - @Override - public int fill(ForgeDirection from, FluidStack resource, boolean doFill) - { - Stack stack = getDepth(); - - for (PartP2PLiquids t : stack) - if ( t == this ) - return 0; - - stack.push( this ); - - List list = getOutputs( resource.getFluid() ); - int requestTotal = 0; - - Iterator i = list.iterator(); - while (i.hasNext()) - { - PartP2PLiquids l = i.next(); - IFluidHandler tank = l.getTarget(); - if ( tank != null ) - l.tmpUsed = tank.fill( l.side.getOpposite(), resource.copy(), false ); - else - l.tmpUsed = 0; - - if ( l.tmpUsed <= 0 ) - i.remove(); - else - requestTotal += l.tmpUsed; - } - - if ( requestTotal <= 0 ) - { - if ( stack.pop() != this ) - throw new RuntimeException( "Invalid Recursion detected." ); - - return 0; - } - - if ( !doFill ) - { - if ( stack.pop() != this ) - throw new RuntimeException( "Invalid Recursion detected." ); - - return Math.min( resource.amount, requestTotal ); - } - - int available = resource.amount; - int used = 0; - - i = list.iterator(); - while (i.hasNext()) - { - PartP2PLiquids l = i.next(); - - FluidStack insert = resource.copy(); - insert.amount = (int) Math.ceil( insert.amount * ((double) l.tmpUsed / (double) requestTotal) ); - if ( insert.amount > available ) - insert.amount = available; - - IFluidHandler tank = l.getTarget(); - if ( tank != null ) - l.tmpUsed = tank.fill( l.side.getOpposite(), insert.copy(), true ); - else - l.tmpUsed = 0; - - available -= insert.amount; - used += insert.amount; - } - - if ( stack.pop() != this ) - throw new RuntimeException( "Invalid Recursion detected." ); - - return used; - } - - @Override - public boolean canFill(ForgeDirection from, Fluid fluid) - { - return !output && from.equals( side ) && !getOutputs( fluid ).isEmpty(); - } - - @Override - public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) - { - return null; - } - - @Override - public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) - { - return null; - } - - @Override - public boolean canDrain(ForgeDirection from, Fluid fluid) - { - return false; - } - - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection from) - { - if ( from.equals( side ) ) - return getTank(); - return new FluidTankInfo[0]; - } - -} +package appeng.parts.p2p; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Stack; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; +import appeng.api.config.TunnelType; +import appeng.me.GridAccessException; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartP2PLiquids extends PartP2PTunnel implements IFluidHandler +{ + + private final static FluidTankInfo[] activeTank = new FluidTankInfo[] { new FluidTankInfo( null, 10000 ) }; + private final static FluidTankInfo[] inactiveTank = new FluidTankInfo[] { new FluidTankInfo( null, 0 ) }; + + public TunnelType getTunnelType() + { + return TunnelType.FLUID; + } + + public PartP2PLiquids(ItemStack is) { + super( is ); + } + + private FluidTankInfo[] getTank() + { + if ( output ) + { + PartP2PLiquids tun = getInput(); + if ( tun != null ) + return activeTank; + } + else + { + try + { + if ( !getOutputs().isEmpty() ) + return activeTank; + } + catch (GridAccessException e) + { + // :( + } + } + return inactiveTank; + } + + IFluidHandler cachedTank; + + public float getPowerDrainPerTick() + { + return 2.0f; + }; + + private int tmpUsed; + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT( tag ); + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT( tag ); + } + + @SideOnly(Side.CLIENT) + public IIcon getTypeTexture() + { + return Blocks.lapis_block.getBlockTextureFromSide( 0 ); + } + + List getOutputs(Fluid input) + { + List outs = new LinkedList(); + + try + { + for (PartP2PLiquids l : getOutputs()) + { + IFluidHandler targ = l.getTarget(); + if ( targ != null ) + { + if ( targ.canFill( l.side.getOpposite(), input ) ) + outs.add( l ); + } + } + } + catch (GridAccessException e) + { + // :P + } + + return outs; + } + + @Override + public void onNeighborChanged() + { + cachedTank = null; + if ( output ) + { + PartP2PLiquids in = getInput(); + if ( in != null ) + in.onTunnelNetworkChange(); + } + }; + + @Override + public void onTunnelNetworkChange() + { + cachedTank = null; + } + + IFluidHandler getTarget() + { + if ( !proxy.isActive() ) + return null; + + if ( cachedTank != null ) + return cachedTank; + + TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ ); + if ( te instanceof IFluidHandler ) + return cachedTank = (IFluidHandler) te; + + return null; + } + + static final ThreadLocal> depth = new ThreadLocal>(); + + private Stack getDepth() + { + Stack s = depth.get(); + + if ( s == null ) + depth.set( s = new Stack() ); + + return s; + } + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) + { + Stack stack = getDepth(); + + for (PartP2PLiquids t : stack) + if ( t == this ) + return 0; + + stack.push( this ); + + List list = getOutputs( resource.getFluid() ); + int requestTotal = 0; + + Iterator i = list.iterator(); + while (i.hasNext()) + { + PartP2PLiquids l = i.next(); + IFluidHandler tank = l.getTarget(); + if ( tank != null ) + l.tmpUsed = tank.fill( l.side.getOpposite(), resource.copy(), false ); + else + l.tmpUsed = 0; + + if ( l.tmpUsed <= 0 ) + i.remove(); + else + requestTotal += l.tmpUsed; + } + + if ( requestTotal <= 0 ) + { + if ( stack.pop() != this ) + throw new RuntimeException( "Invalid Recursion detected." ); + + return 0; + } + + if ( !doFill ) + { + if ( stack.pop() != this ) + throw new RuntimeException( "Invalid Recursion detected." ); + + return Math.min( resource.amount, requestTotal ); + } + + int available = resource.amount; + int used = 0; + + i = list.iterator(); + while (i.hasNext()) + { + PartP2PLiquids l = i.next(); + + FluidStack insert = resource.copy(); + insert.amount = (int) Math.ceil( insert.amount * ((double) l.tmpUsed / (double) requestTotal) ); + if ( insert.amount > available ) + insert.amount = available; + + IFluidHandler tank = l.getTarget(); + if ( tank != null ) + l.tmpUsed = tank.fill( l.side.getOpposite(), insert.copy(), true ); + else + l.tmpUsed = 0; + + available -= insert.amount; + used += insert.amount; + } + + if ( stack.pop() != this ) + throw new RuntimeException( "Invalid Recursion detected." ); + + return used; + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) + { + return !output && from.equals( side ) && !getOutputs( fluid ).isEmpty(); + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) + { + return null; + } + + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + return null; + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) + { + return false; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) + { + if ( from.equals( side ) ) + return getTank(); + return new FluidTankInfo[0]; + } + +} diff --git a/parts/p2p/PartP2PRFPower.java b/src/main/java/appeng/parts/p2p/PartP2PRFPower.java similarity index 100% rename from parts/p2p/PartP2PRFPower.java rename to src/main/java/appeng/parts/p2p/PartP2PRFPower.java diff --git a/parts/p2p/PartP2PRedstone.java b/src/main/java/appeng/parts/p2p/PartP2PRedstone.java similarity index 95% rename from parts/p2p/PartP2PRedstone.java rename to src/main/java/appeng/parts/p2p/PartP2PRedstone.java index d106805a9..38dd3bb39 100644 --- a/parts/p2p/PartP2PRedstone.java +++ b/src/main/java/appeng/parts/p2p/PartP2PRedstone.java @@ -1,190 +1,190 @@ -package appeng.parts.p2p; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockRedstoneWire; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; -import appeng.api.config.TunnelType; -import appeng.api.networking.events.MENetworkBootingStatusChange; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.me.GridAccessException; -import appeng.util.Platform; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class PartP2PRedstone extends PartP2PTunnel -{ - - public TunnelType getTunnelType() - { - return TunnelType.REDSTONE; - } - - public PartP2PRedstone(ItemStack is) { - super( is ); - } - - int power; - - @Override - public boolean canConnectRedstone() - { - return true; - } - - @Override - public int isProvidingStrongPower() - { - return output ? power : 0; - } - - @Override - public int isProvidingWeakPower() - { - return output ? power : 0; - } - - @Override - public void onTunnelNetworkChange() - { - setNetworkReady(); - } - - @MENetworkEventSubscribe - public void changeStateA(MENetworkBootingStatusChange bs) - { - setNetworkReady(); - } - - @MENetworkEventSubscribe - public void changeStateB(MENetworkChannelsChanged bs) - { - setNetworkReady(); - } - - @MENetworkEventSubscribe - public void changeStateC(MENetworkPowerStatusChange bs) - { - setNetworkReady(); - } - - public void setNetworkReady() - { - if ( output ) - { - PartP2PRedstone in = getInput(); - if ( in != null ) - putInput( ((PartP2PRedstone) in).power ); - } - } - - boolean recursive = false; - - protected void putInput(Object o) - { - if ( recursive ) - return; - - recursive = true; - if ( output && proxy.isActive() ) - { - int newPower = (Integer) o; - if ( power != newPower ) - { - power = newPower; - notifyNeighbors(); - } - } - recursive = false; - - } - - public void notifyNeighbors() - { - World worldObj = tile.getWorldObj(); - - int xCoord = tile.xCoord; - int yCoord = tile.yCoord; - int zCoord = tile.zCoord; - - Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord ); - - // and this cause sometimes it can go thought walls. - Platform.notifyBlocksOfNeighbors( worldObj, xCoord - 1, yCoord, zCoord ); - Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord - 1, zCoord ); - Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord - 1 ); - Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord + 1 ); - Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord + 1, zCoord ); - Platform.notifyBlocksOfNeighbors( worldObj, xCoord + 1, yCoord, zCoord ); - } - - @Override - public void writeToNBT(NBTTagCompound tag) - { - super.writeToNBT( tag ); - tag.setInteger( "power", power ); - } - - @Override - public void readFromNBT(NBTTagCompound tag) - { - super.readFromNBT( tag ); - power = tag.getInteger( "power" ); - } - - @SideOnly(Side.CLIENT) - public IIcon getTypeTexture() - { - return Blocks.redstone_block.getBlockTextureFromSide( 0 ); - } - - public float getPowerDrainPerTick() - { - return 0.5f; - }; - - @Override - public void onNeighborChanged() - { - if ( !output ) - { - int x = tile.xCoord + side.offsetX; - int y = tile.yCoord + side.offsetY; - int z = tile.zCoord + side.offsetZ; - - Block b = tile.getWorldObj().getBlock( x, y, z ); - if ( b != null && !output ) - { - int srcSide = side.ordinal(); - if ( b instanceof BlockRedstoneWire ) - srcSide = 1; - power = b.isProvidingStrongPower( tile.getWorldObj(), x, y, z, srcSide ); - power = Math.max( power, b.isProvidingWeakPower( tile.getWorldObj(), x, y, z, srcSide ) ); - sendToOutput( power ); - } - else - sendToOutput( 0 ); - } - } - - private void sendToOutput(int power) - { - try - { - for (PartP2PRedstone rs : getOutputs()) - { - rs.putInput( power ); - } - } - catch (GridAccessException e) - { - // :P - } - } - -} +package appeng.parts.p2p; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockRedstoneWire; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import appeng.api.config.TunnelType; +import appeng.api.networking.events.MENetworkBootingStatusChange; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.me.GridAccessException; +import appeng.util.Platform; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartP2PRedstone extends PartP2PTunnel +{ + + public TunnelType getTunnelType() + { + return TunnelType.REDSTONE; + } + + public PartP2PRedstone(ItemStack is) { + super( is ); + } + + int power; + + @Override + public boolean canConnectRedstone() + { + return true; + } + + @Override + public int isProvidingStrongPower() + { + return output ? power : 0; + } + + @Override + public int isProvidingWeakPower() + { + return output ? power : 0; + } + + @Override + public void onTunnelNetworkChange() + { + setNetworkReady(); + } + + @MENetworkEventSubscribe + public void changeStateA(MENetworkBootingStatusChange bs) + { + setNetworkReady(); + } + + @MENetworkEventSubscribe + public void changeStateB(MENetworkChannelsChanged bs) + { + setNetworkReady(); + } + + @MENetworkEventSubscribe + public void changeStateC(MENetworkPowerStatusChange bs) + { + setNetworkReady(); + } + + public void setNetworkReady() + { + if ( output ) + { + PartP2PRedstone in = getInput(); + if ( in != null ) + putInput( ((PartP2PRedstone) in).power ); + } + } + + boolean recursive = false; + + protected void putInput(Object o) + { + if ( recursive ) + return; + + recursive = true; + if ( output && proxy.isActive() ) + { + int newPower = (Integer) o; + if ( power != newPower ) + { + power = newPower; + notifyNeighbors(); + } + } + recursive = false; + + } + + public void notifyNeighbors() + { + World worldObj = tile.getWorldObj(); + + int xCoord = tile.xCoord; + int yCoord = tile.yCoord; + int zCoord = tile.zCoord; + + Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord ); + + // and this cause sometimes it can go thought walls. + Platform.notifyBlocksOfNeighbors( worldObj, xCoord - 1, yCoord, zCoord ); + Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord - 1, zCoord ); + Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord - 1 ); + Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord + 1 ); + Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord + 1, zCoord ); + Platform.notifyBlocksOfNeighbors( worldObj, xCoord + 1, yCoord, zCoord ); + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT( tag ); + tag.setInteger( "power", power ); + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT( tag ); + power = tag.getInteger( "power" ); + } + + @SideOnly(Side.CLIENT) + public IIcon getTypeTexture() + { + return Blocks.redstone_block.getBlockTextureFromSide( 0 ); + } + + public float getPowerDrainPerTick() + { + return 0.5f; + }; + + @Override + public void onNeighborChanged() + { + if ( !output ) + { + int x = tile.xCoord + side.offsetX; + int y = tile.yCoord + side.offsetY; + int z = tile.zCoord + side.offsetZ; + + Block b = tile.getWorldObj().getBlock( x, y, z ); + if ( b != null && !output ) + { + int srcSide = side.ordinal(); + if ( b instanceof BlockRedstoneWire ) + srcSide = 1; + power = b.isProvidingStrongPower( tile.getWorldObj(), x, y, z, srcSide ); + power = Math.max( power, b.isProvidingWeakPower( tile.getWorldObj(), x, y, z, srcSide ) ); + sendToOutput( power ); + } + else + sendToOutput( 0 ); + } + } + + private void sendToOutput(int power) + { + try + { + for (PartP2PRedstone rs : getOutputs()) + { + rs.putInput( power ); + } + } + catch (GridAccessException e) + { + // :P + } + } + +} diff --git a/parts/p2p/PartP2PTunnel.java b/src/main/java/appeng/parts/p2p/PartP2PTunnel.java similarity index 100% rename from parts/p2p/PartP2PTunnel.java rename to src/main/java/appeng/parts/p2p/PartP2PTunnel.java diff --git a/parts/p2p/PartP2PTunnelME.java b/src/main/java/appeng/parts/p2p/PartP2PTunnelME.java similarity index 100% rename from parts/p2p/PartP2PTunnelME.java rename to src/main/java/appeng/parts/p2p/PartP2PTunnelME.java diff --git a/parts/reporting/PartConversionMonitor.java b/src/main/java/appeng/parts/reporting/PartConversionMonitor.java similarity index 100% rename from parts/reporting/PartConversionMonitor.java rename to src/main/java/appeng/parts/reporting/PartConversionMonitor.java diff --git a/parts/reporting/PartCraftingTerminal.java b/src/main/java/appeng/parts/reporting/PartCraftingTerminal.java similarity index 100% rename from parts/reporting/PartCraftingTerminal.java rename to src/main/java/appeng/parts/reporting/PartCraftingTerminal.java diff --git a/parts/reporting/PartDarkMonitor.java b/src/main/java/appeng/parts/reporting/PartDarkMonitor.java similarity index 100% rename from parts/reporting/PartDarkMonitor.java rename to src/main/java/appeng/parts/reporting/PartDarkMonitor.java diff --git a/parts/reporting/PartInterfaceTerminal.java b/src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java similarity index 100% rename from parts/reporting/PartInterfaceTerminal.java rename to src/main/java/appeng/parts/reporting/PartInterfaceTerminal.java diff --git a/parts/reporting/PartMonitor.java b/src/main/java/appeng/parts/reporting/PartMonitor.java similarity index 100% rename from parts/reporting/PartMonitor.java rename to src/main/java/appeng/parts/reporting/PartMonitor.java diff --git a/parts/reporting/PartPatternTerminal.java b/src/main/java/appeng/parts/reporting/PartPatternTerminal.java similarity index 100% rename from parts/reporting/PartPatternTerminal.java rename to src/main/java/appeng/parts/reporting/PartPatternTerminal.java diff --git a/parts/reporting/PartSemiDarkMonitor.java b/src/main/java/appeng/parts/reporting/PartSemiDarkMonitor.java similarity index 100% rename from parts/reporting/PartSemiDarkMonitor.java rename to src/main/java/appeng/parts/reporting/PartSemiDarkMonitor.java diff --git a/parts/reporting/PartStorageMonitor.java b/src/main/java/appeng/parts/reporting/PartStorageMonitor.java similarity index 100% rename from parts/reporting/PartStorageMonitor.java rename to src/main/java/appeng/parts/reporting/PartStorageMonitor.java diff --git a/parts/reporting/PartTerminal.java b/src/main/java/appeng/parts/reporting/PartTerminal.java similarity index 100% rename from parts/reporting/PartTerminal.java rename to src/main/java/appeng/parts/reporting/PartTerminal.java diff --git a/recipes/AEItemResolver.java b/src/main/java/appeng/recipes/AEItemResolver.java similarity index 100% rename from recipes/AEItemResolver.java rename to src/main/java/appeng/recipes/AEItemResolver.java diff --git a/recipes/GroupIngredient.java b/src/main/java/appeng/recipes/GroupIngredient.java similarity index 100% rename from recipes/GroupIngredient.java rename to src/main/java/appeng/recipes/GroupIngredient.java diff --git a/recipes/Ingredient.java b/src/main/java/appeng/recipes/Ingredient.java similarity index 100% rename from recipes/Ingredient.java rename to src/main/java/appeng/recipes/Ingredient.java diff --git a/recipes/IngredientSet.java b/src/main/java/appeng/recipes/IngredientSet.java similarity index 100% rename from recipes/IngredientSet.java rename to src/main/java/appeng/recipes/IngredientSet.java diff --git a/recipes/MissedIngredientSet.java b/src/main/java/appeng/recipes/MissedIngredientSet.java similarity index 100% rename from recipes/MissedIngredientSet.java rename to src/main/java/appeng/recipes/MissedIngredientSet.java diff --git a/recipes/RecipeData.java b/src/main/java/appeng/recipes/RecipeData.java similarity index 100% rename from recipes/RecipeData.java rename to src/main/java/appeng/recipes/RecipeData.java diff --git a/recipes/RecipeHandler.java b/src/main/java/appeng/recipes/RecipeHandler.java similarity index 100% rename from recipes/RecipeHandler.java rename to src/main/java/appeng/recipes/RecipeHandler.java diff --git a/recipes/game/DisassembleRecipe.java b/src/main/java/appeng/recipes/game/DisassembleRecipe.java similarity index 100% rename from recipes/game/DisassembleRecipe.java rename to src/main/java/appeng/recipes/game/DisassembleRecipe.java diff --git a/recipes/game/FacadeRecipe.java b/src/main/java/appeng/recipes/game/FacadeRecipe.java similarity index 100% rename from recipes/game/FacadeRecipe.java rename to src/main/java/appeng/recipes/game/FacadeRecipe.java diff --git a/recipes/game/IRecipeBakeable.java b/src/main/java/appeng/recipes/game/IRecipeBakeable.java similarity index 95% rename from recipes/game/IRecipeBakeable.java rename to src/main/java/appeng/recipes/game/IRecipeBakeable.java index c93edc2e2..1dac5e211 100644 --- a/recipes/game/IRecipeBakeable.java +++ b/src/main/java/appeng/recipes/game/IRecipeBakeable.java @@ -1,12 +1,12 @@ -package appeng.recipes.game; - -import appeng.api.exceptions.MissingIngredientError; -import appeng.api.exceptions.RegistrationError; - - -public interface IRecipeBakeable -{ - - void bake() throws RegistrationError, MissingIngredientError; - -} +package appeng.recipes.game; + +import appeng.api.exceptions.MissingIngredientError; +import appeng.api.exceptions.RegistrationError; + + +public interface IRecipeBakeable +{ + + void bake() throws RegistrationError, MissingIngredientError; + +} diff --git a/recipes/game/ShapedRecipe.java b/src/main/java/appeng/recipes/game/ShapedRecipe.java similarity index 100% rename from recipes/game/ShapedRecipe.java rename to src/main/java/appeng/recipes/game/ShapedRecipe.java diff --git a/recipes/game/ShapelessRecipe.java b/src/main/java/appeng/recipes/game/ShapelessRecipe.java similarity index 100% rename from recipes/game/ShapelessRecipe.java rename to src/main/java/appeng/recipes/game/ShapelessRecipe.java diff --git a/recipes/handlers/Crusher.java b/src/main/java/appeng/recipes/handlers/Crusher.java similarity index 100% rename from recipes/handlers/Crusher.java rename to src/main/java/appeng/recipes/handlers/Crusher.java diff --git a/recipes/handlers/Grind.java b/src/main/java/appeng/recipes/handlers/Grind.java similarity index 100% rename from recipes/handlers/Grind.java rename to src/main/java/appeng/recipes/handlers/Grind.java diff --git a/recipes/handlers/GrindFZ.java b/src/main/java/appeng/recipes/handlers/GrindFZ.java similarity index 100% rename from recipes/handlers/GrindFZ.java rename to src/main/java/appeng/recipes/handlers/GrindFZ.java diff --git a/recipes/handlers/HCCrusher.java b/src/main/java/appeng/recipes/handlers/HCCrusher.java similarity index 100% rename from recipes/handlers/HCCrusher.java rename to src/main/java/appeng/recipes/handlers/HCCrusher.java diff --git a/recipes/handlers/IWebsiteSerializer.java b/src/main/java/appeng/recipes/handlers/IWebsiteSerializer.java similarity index 100% rename from recipes/handlers/IWebsiteSerializer.java rename to src/main/java/appeng/recipes/handlers/IWebsiteSerializer.java diff --git a/recipes/handlers/Inscribe.java b/src/main/java/appeng/recipes/handlers/Inscribe.java similarity index 100% rename from recipes/handlers/Inscribe.java rename to src/main/java/appeng/recipes/handlers/Inscribe.java diff --git a/recipes/handlers/Macerator.java b/src/main/java/appeng/recipes/handlers/Macerator.java similarity index 100% rename from recipes/handlers/Macerator.java rename to src/main/java/appeng/recipes/handlers/Macerator.java diff --git a/recipes/handlers/MekCrusher.java b/src/main/java/appeng/recipes/handlers/MekCrusher.java similarity index 100% rename from recipes/handlers/MekCrusher.java rename to src/main/java/appeng/recipes/handlers/MekCrusher.java diff --git a/recipes/handlers/MekEnrichment.java b/src/main/java/appeng/recipes/handlers/MekEnrichment.java similarity index 100% rename from recipes/handlers/MekEnrichment.java rename to src/main/java/appeng/recipes/handlers/MekEnrichment.java diff --git a/recipes/handlers/OreRegistration.java b/src/main/java/appeng/recipes/handlers/OreRegistration.java similarity index 100% rename from recipes/handlers/OreRegistration.java rename to src/main/java/appeng/recipes/handlers/OreRegistration.java diff --git a/recipes/handlers/Press.java b/src/main/java/appeng/recipes/handlers/Press.java similarity index 100% rename from recipes/handlers/Press.java rename to src/main/java/appeng/recipes/handlers/Press.java diff --git a/recipes/handlers/Pulverizer.java b/src/main/java/appeng/recipes/handlers/Pulverizer.java similarity index 100% rename from recipes/handlers/Pulverizer.java rename to src/main/java/appeng/recipes/handlers/Pulverizer.java diff --git a/recipes/handlers/Shaped.java b/src/main/java/appeng/recipes/handlers/Shaped.java similarity index 100% rename from recipes/handlers/Shaped.java rename to src/main/java/appeng/recipes/handlers/Shaped.java diff --git a/recipes/handlers/Shapeless.java b/src/main/java/appeng/recipes/handlers/Shapeless.java similarity index 100% rename from recipes/handlers/Shapeless.java rename to src/main/java/appeng/recipes/handlers/Shapeless.java diff --git a/recipes/handlers/Smelt.java b/src/main/java/appeng/recipes/handlers/Smelt.java similarity index 100% rename from recipes/handlers/Smelt.java rename to src/main/java/appeng/recipes/handlers/Smelt.java diff --git a/recipes/loader/ConfigLoader.java b/src/main/java/appeng/recipes/loader/ConfigLoader.java similarity index 100% rename from recipes/loader/ConfigLoader.java rename to src/main/java/appeng/recipes/loader/ConfigLoader.java diff --git a/recipes/loader/JarLoader.java b/src/main/java/appeng/recipes/loader/JarLoader.java similarity index 100% rename from recipes/loader/JarLoader.java rename to src/main/java/appeng/recipes/loader/JarLoader.java diff --git a/recipes/ores/IOreListener.java b/src/main/java/appeng/recipes/ores/IOreListener.java similarity index 94% rename from recipes/ores/IOreListener.java rename to src/main/java/appeng/recipes/ores/IOreListener.java index 1d57196ec..01621ff50 100644 --- a/recipes/ores/IOreListener.java +++ b/src/main/java/appeng/recipes/ores/IOreListener.java @@ -1,17 +1,17 @@ -package appeng.recipes.ores; - -import net.minecraft.item.ItemStack; - -public interface IOreListener -{ - - /** - * Called with various items registered in the dictionary. - * AppEng.oreDictionary.observe(...) to register them. - * - * @param Name - * @param item - */ - void oreRegistered(String Name, ItemStack item); - -} +package appeng.recipes.ores; + +import net.minecraft.item.ItemStack; + +public interface IOreListener +{ + + /** + * Called with various items registered in the dictionary. + * AppEng.oreDictionary.observe(...) to register them. + * + * @param Name + * @param item + */ + void oreRegistered(String Name, ItemStack item); + +} diff --git a/recipes/ores/OreDictionaryHandler.java b/src/main/java/appeng/recipes/ores/OreDictionaryHandler.java similarity index 95% rename from recipes/ores/OreDictionaryHandler.java rename to src/main/java/appeng/recipes/ores/OreDictionaryHandler.java index 65ef86456..8b91d3d2a 100644 --- a/recipes/ores/OreDictionaryHandler.java +++ b/src/main/java/appeng/recipes/ores/OreDictionaryHandler.java @@ -1,93 +1,93 @@ -package appeng.recipes.ores; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraftforge.oredict.OreDictionary; -import appeng.core.AELog; -import appeng.recipes.game.IRecipeBakeable; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; - -public class OreDictionaryHandler -{ - - public static final OreDictionaryHandler instance = new OreDictionaryHandler(); - - private List ol = new ArrayList(); - - private boolean enableRebaking = false; - - /** - * Just limit what items are sent to the final listeners, I got sick of strange items showing up... - * - * @param name - * @return - */ - private boolean shouldCare(String name) - { - return true; - } - - @SubscribeEvent - public void onOreDictionaryRegister(OreDictionary.OreRegisterEvent event) - { - if ( event.Name == null || event.Ore == null ) - return; - - if ( shouldCare( event.Name ) ) - { - for (IOreListener v : ol) - v.oreRegistered( event.Name, event.Ore ); - } - - if ( enableRebaking ) - bakeRecipes(); - } - - /** - * Adds a new IOreListener and immediately notifies it of any previous ores, any ores added latter will be added at - * that point. - * - * @param n - */ - public void observe(IOreListener n) - { - ol.add( n ); - - // notify the listener of any ore already in existence. - for (String name : OreDictionary.getOreNames()) - { - if ( name != null && shouldCare( name ) ) - { - for (ItemStack item : OreDictionary.getOres( name )) - { - if ( item != null ) - n.oreRegistered( name, item ); - } - } - } - } - - public void bakeRecipes() - { - enableRebaking = true; - - for (Object o : CraftingManager.getInstance().getRecipeList()) - { - if ( o instanceof IRecipeBakeable ) - { - try - { - ((IRecipeBakeable) o).bake(); - } - catch (Throwable e) - { - AELog.error( e ); - } - } - } - } - -} +package appeng.recipes.ores; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraftforge.oredict.OreDictionary; +import appeng.core.AELog; +import appeng.recipes.game.IRecipeBakeable; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class OreDictionaryHandler +{ + + public static final OreDictionaryHandler instance = new OreDictionaryHandler(); + + private List ol = new ArrayList(); + + private boolean enableRebaking = false; + + /** + * Just limit what items are sent to the final listeners, I got sick of strange items showing up... + * + * @param name + * @return + */ + private boolean shouldCare(String name) + { + return true; + } + + @SubscribeEvent + public void onOreDictionaryRegister(OreDictionary.OreRegisterEvent event) + { + if ( event.Name == null || event.Ore == null ) + return; + + if ( shouldCare( event.Name ) ) + { + for (IOreListener v : ol) + v.oreRegistered( event.Name, event.Ore ); + } + + if ( enableRebaking ) + bakeRecipes(); + } + + /** + * Adds a new IOreListener and immediately notifies it of any previous ores, any ores added latter will be added at + * that point. + * + * @param n + */ + public void observe(IOreListener n) + { + ol.add( n ); + + // notify the listener of any ore already in existence. + for (String name : OreDictionary.getOreNames()) + { + if ( name != null && shouldCare( name ) ) + { + for (ItemStack item : OreDictionary.getOres( name )) + { + if ( item != null ) + n.oreRegistered( name, item ); + } + } + } + } + + public void bakeRecipes() + { + enableRebaking = true; + + for (Object o : CraftingManager.getInstance().getRecipeList()) + { + if ( o instanceof IRecipeBakeable ) + { + try + { + ((IRecipeBakeable) o).bake(); + } + catch (Throwable e) + { + AELog.error( e ); + } + } + } + } + +} diff --git a/server/AECommand.java b/src/main/java/appeng/server/AECommand.java similarity index 100% rename from server/AECommand.java rename to src/main/java/appeng/server/AECommand.java diff --git a/server/AccessType.java b/src/main/java/appeng/server/AccessType.java similarity index 93% rename from server/AccessType.java rename to src/main/java/appeng/server/AccessType.java index 6cceb5c6e..768c71ec6 100644 --- a/server/AccessType.java +++ b/src/main/java/appeng/server/AccessType.java @@ -1,34 +1,34 @@ -package appeng.server; - -public enum AccessType -{ - /** - * allows basic access to manipulate the block via gui, or other. - */ - BLOCK_ACCESS, - - /** - * Can player deposit items into the network. - */ - NETWORK_DEPOSIT, - - /** - * can player withdraw items from the network. - */ - NETWORK_WITHDRAW, - - /** - * can player issue crafting requests? - */ - NETWORK_CRAFT, - - /** - * can player add new blocks to the network. - */ - NETWORK_BUILD, - - /** - * can player manipulate security settings. - */ - NETWORK_SECURITY -} +package appeng.server; + +public enum AccessType +{ + /** + * allows basic access to manipulate the block via gui, or other. + */ + BLOCK_ACCESS, + + /** + * Can player deposit items into the network. + */ + NETWORK_DEPOSIT, + + /** + * can player withdraw items from the network. + */ + NETWORK_WITHDRAW, + + /** + * can player issue crafting requests? + */ + NETWORK_CRAFT, + + /** + * can player add new blocks to the network. + */ + NETWORK_BUILD, + + /** + * can player manipulate security settings. + */ + NETWORK_SECURITY +} diff --git a/server/Commands.java b/src/main/java/appeng/server/Commands.java similarity index 100% rename from server/Commands.java rename to src/main/java/appeng/server/Commands.java diff --git a/server/ISubCommand.java b/src/main/java/appeng/server/ISubCommand.java similarity index 100% rename from server/ISubCommand.java rename to src/main/java/appeng/server/ISubCommand.java diff --git a/server/ServerHelper.java b/src/main/java/appeng/server/ServerHelper.java similarity index 95% rename from server/ServerHelper.java rename to src/main/java/appeng/server/ServerHelper.java index 84216f3c0..7b4db7bc3 100644 --- a/server/ServerHelper.java +++ b/src/main/java/appeng/server/ServerHelper.java @@ -1,162 +1,162 @@ -package appeng.server; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.world.World; -import appeng.api.parts.CableRenderMode; -import appeng.block.AEBaseBlock; -import appeng.client.EffectType; -import appeng.core.CommonHelper; -import appeng.core.sync.AppEngPacket; -import appeng.core.sync.network.NetworkHandler; -import appeng.items.tools.ToolNetworkTool; -import appeng.util.Platform; -import cpw.mods.fml.common.FMLCommonHandler; - -public class ServerHelper extends CommonHelper -{ - - @Override - public void doRenderItem(ItemStack sis, World tile) - { - - } - - @Override - public List getPlayers() - { - if ( !Platform.isClient() ) - { - MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); - - if ( server != null ) - return server.getConfigurationManager().playerEntityList; - } - - return new ArrayList(); - } - - @Override - public void sendToAllNearExcept(EntityPlayer p, double x, double y, double z, double dist, World w, AppEngPacket packet) - { - if ( Platform.isClient() ) - return; - - for (EntityPlayer o : getPlayers()) - { - EntityPlayerMP entityplayermp = (EntityPlayerMP) o; - - if ( entityplayermp != p && entityplayermp.worldObj == w ) - { - double dX = x - entityplayermp.posX; - double dY = y - entityplayermp.posY; - double dZ = z - entityplayermp.posZ; - - if ( dX * dX + dY * dY + dZ * dZ < dist * dist ) - { - NetworkHandler.instance.sendTo( packet, entityplayermp ); - } - } - } - } - - @Override - public void init() - { - - } - - @Override - public void postinit() - { - - } - - @Override - public World getWorld() - { - throw new RuntimeException( "This is a server..." ); - } - - @Override - public void bindTileEntitySpecialRenderer(Class tile, AEBaseBlock blk) - { - throw new RuntimeException( "This is a server..." ); - } - - @Override - public void spawnEffect(EffectType type, World worldObj, double posX, double posY, double posZ, Object o) - { - // :P - } - - @Override - public boolean shouldAddParticles(Random r) - { - return false; - } - - @Override - public MovingObjectPosition getMOP() - { - return null; - } - - @Override - public CableRenderMode getRenderMode() - { - if ( renderModeBased == null ) - return CableRenderMode.Standard; - - return renderModeForPlayer( renderModeBased ); - } - - private EntityPlayer renderModeBased; - - @Override - public void updateRenderMode(EntityPlayer player) - { - renderModeBased = player; - } - - protected CableRenderMode renderModeForPlayer(EntityPlayer player) - { - if ( player != null ) - { - for (int x = 0; x < InventoryPlayer.getHotbarSize(); x++) - { - ItemStack is = player.inventory.getStackInSlot( x ); - - if ( is != null && is.getItem() instanceof ToolNetworkTool ) - { - NBTTagCompound c = is.getTagCompound(); - if ( c != null && c.getBoolean( "hideFacades" ) ) - return CableRenderMode.CableView; - } - } - } - - return CableRenderMode.Standard; - } - - @Override - public void triggerUpdates() - { - - } - - @Override - public void missingCoreMod() - { - throw new RuntimeException( "Unable to Load Core Mod, please verify that AE2 is properly install in the mods folder, with a .jar extension." ); - } -} +package appeng.server; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import appeng.api.parts.CableRenderMode; +import appeng.block.AEBaseBlock; +import appeng.client.EffectType; +import appeng.core.CommonHelper; +import appeng.core.sync.AppEngPacket; +import appeng.core.sync.network.NetworkHandler; +import appeng.items.tools.ToolNetworkTool; +import appeng.util.Platform; +import cpw.mods.fml.common.FMLCommonHandler; + +public class ServerHelper extends CommonHelper +{ + + @Override + public void doRenderItem(ItemStack sis, World tile) + { + + } + + @Override + public List getPlayers() + { + if ( !Platform.isClient() ) + { + MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); + + if ( server != null ) + return server.getConfigurationManager().playerEntityList; + } + + return new ArrayList(); + } + + @Override + public void sendToAllNearExcept(EntityPlayer p, double x, double y, double z, double dist, World w, AppEngPacket packet) + { + if ( Platform.isClient() ) + return; + + for (EntityPlayer o : getPlayers()) + { + EntityPlayerMP entityplayermp = (EntityPlayerMP) o; + + if ( entityplayermp != p && entityplayermp.worldObj == w ) + { + double dX = x - entityplayermp.posX; + double dY = y - entityplayermp.posY; + double dZ = z - entityplayermp.posZ; + + if ( dX * dX + dY * dY + dZ * dZ < dist * dist ) + { + NetworkHandler.instance.sendTo( packet, entityplayermp ); + } + } + } + } + + @Override + public void init() + { + + } + + @Override + public void postinit() + { + + } + + @Override + public World getWorld() + { + throw new RuntimeException( "This is a server..." ); + } + + @Override + public void bindTileEntitySpecialRenderer(Class tile, AEBaseBlock blk) + { + throw new RuntimeException( "This is a server..." ); + } + + @Override + public void spawnEffect(EffectType type, World worldObj, double posX, double posY, double posZ, Object o) + { + // :P + } + + @Override + public boolean shouldAddParticles(Random r) + { + return false; + } + + @Override + public MovingObjectPosition getMOP() + { + return null; + } + + @Override + public CableRenderMode getRenderMode() + { + if ( renderModeBased == null ) + return CableRenderMode.Standard; + + return renderModeForPlayer( renderModeBased ); + } + + private EntityPlayer renderModeBased; + + @Override + public void updateRenderMode(EntityPlayer player) + { + renderModeBased = player; + } + + protected CableRenderMode renderModeForPlayer(EntityPlayer player) + { + if ( player != null ) + { + for (int x = 0; x < InventoryPlayer.getHotbarSize(); x++) + { + ItemStack is = player.inventory.getStackInSlot( x ); + + if ( is != null && is.getItem() instanceof ToolNetworkTool ) + { + NBTTagCompound c = is.getTagCompound(); + if ( c != null && c.getBoolean( "hideFacades" ) ) + return CableRenderMode.CableView; + } + } + } + + return CableRenderMode.Standard; + } + + @Override + public void triggerUpdates() + { + + } + + @Override + public void missingCoreMod() + { + throw new RuntimeException( "Unable to Load Core Mod, please verify that AE2 is properly install in the mods folder, with a .jar extension." ); + } +} diff --git a/server/subcommands/ChunkLogger.java b/src/main/java/appeng/server/subcommands/ChunkLogger.java similarity index 100% rename from server/subcommands/ChunkLogger.java rename to src/main/java/appeng/server/subcommands/ChunkLogger.java diff --git a/server/subcommands/Supporters.java b/src/main/java/appeng/server/subcommands/Supporters.java similarity index 100% rename from server/subcommands/Supporters.java rename to src/main/java/appeng/server/subcommands/Supporters.java diff --git a/services/CompassService.java b/src/main/java/appeng/services/CompassService.java similarity index 100% rename from services/CompassService.java rename to src/main/java/appeng/services/CompassService.java diff --git a/services/VersionChecker.java b/src/main/java/appeng/services/VersionChecker.java similarity index 96% rename from services/VersionChecker.java rename to src/main/java/appeng/services/VersionChecker.java index af64a29cc..9329685d2 100644 --- a/services/VersionChecker.java +++ b/src/main/java/appeng/services/VersionChecker.java @@ -1,131 +1,131 @@ -package appeng.services; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.Date; - -import net.minecraft.nbt.NBTTagCompound; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.core.AppEng; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import cpw.mods.fml.common.event.FMLInterModComms; - -public class VersionChecker implements Runnable -{ - - public static VersionChecker instance = null; - - private long delay = 0; - private boolean VersionChecker = true; - - public VersionChecker() - { - long now = (new Date()).getTime(); - delay = (1000 * 3600 * 5) - (now - AEConfig.instance.latestTimeStamp); - if ( delay < 1 ) - delay = 1; - } - - @Override - public void run() - { - try - { - sleep( delay ); - } - catch (InterruptedException e) - { - // :( - } - - while (true) - { - Thread.yield(); - - try - { - String MCVersion = cpw.mods.fml.common.Loader.instance().getMCVersionString().replace( "Minecraft ", "" ); - URL url = new URL( "http://feeds.ae-mod.info/latest.json?VersionMC=" + MCVersion + "&Channel=" + AEConfig.CHANNEL + "&CurrentVersion=" - + AEConfig.VERSION ); - - URLConnection yc = url.openConnection(); - yc.setRequestProperty( "User-Agent", "AE2/" + AEConfig.VERSION + " (Channel:" + AEConfig.CHANNEL + "," + MCVersion.replace( " ", ":" ) + ")" ); - BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream() ) ); - - String Version = ""; - String inputLine; - - while ((inputLine = in.readLine()) != null) - Version += inputLine; - - in.close(); - - if ( Version.length() > 2 ) - { - JsonElement element = (new JsonParser()).parse( Version ); - - int version = element.getAsJsonObject().get( "FormatVersion" ).getAsInt(); - if ( version == 1 ) - { - JsonObject Meta = element.getAsJsonObject().get( "Meta" ).getAsJsonObject(); - JsonArray Versions = element.getAsJsonObject().get( "Versions" ).getAsJsonArray(); - if ( Versions.size() > 0 ) - { - JsonObject Latest = Versions.get( 0 ).getAsJsonObject(); - - AEConfig.instance.latestVersion = Latest.get( "Version" ).getAsString(); - AEConfig.instance.latestTimeStamp = (new Date()).getTime(); - AEConfig.instance.save(); - - if ( VersionChecker && !AEConfig.VERSION.equals( AEConfig.instance.latestVersion ) ) - { - NBTTagCompound versionInf = new NBTTagCompound(); - versionInf.setString( "modDisplayName", "Applied Energistics 2" ); - versionInf.setString( "oldVersion", AEConfig.VERSION ); - versionInf.setString( "newVersion", AEConfig.instance.latestVersion ); - versionInf.setString( "updateUrl", Latest.get( "UserBuild" ).getAsString() ); - versionInf.setBoolean( "isDirectLink", true ); - - JsonElement changeLog = Latest.get( "ChangeLog" ); - if ( changeLog == null ) - versionInf.setString( "changeLog", "For full change log please see: " + Meta.get( "DownloadLink" ).getAsString() ); - else - versionInf.setString( "changeLog", changeLog.getAsString() ); - - versionInf.setString( "newFileName", "appliedenergistics2-" + AEConfig.instance.latestVersion + ".jar" ); - FMLInterModComms.sendRuntimeMessage( AppEng.instance, "VersionChecker", "addUpdate", versionInf ); - VersionChecker = false; - } - } - } - } - - sleep( 1000 * 3600 * 4 ); - } - catch (Exception e) - { - try - { - sleep( 1000 * 3600 * 4 ); - } - catch (InterruptedException e1) - { - AELog.error( e ); - } - } - } - } - - private void sleep(long i) throws InterruptedException - { - Thread.sleep( i ); - } -} +package appeng.services; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.Date; + +import net.minecraft.nbt.NBTTagCompound; +import appeng.core.AEConfig; +import appeng.core.AELog; +import appeng.core.AppEng; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import cpw.mods.fml.common.event.FMLInterModComms; + +public class VersionChecker implements Runnable +{ + + public static VersionChecker instance = null; + + private long delay = 0; + private boolean VersionChecker = true; + + public VersionChecker() + { + long now = (new Date()).getTime(); + delay = (1000 * 3600 * 5) - (now - AEConfig.instance.latestTimeStamp); + if ( delay < 1 ) + delay = 1; + } + + @Override + public void run() + { + try + { + sleep( delay ); + } + catch (InterruptedException e) + { + // :( + } + + while (true) + { + Thread.yield(); + + try + { + String MCVersion = cpw.mods.fml.common.Loader.instance().getMCVersionString().replace( "Minecraft ", "" ); + URL url = new URL( "http://feeds.ae-mod.info/latest.json?VersionMC=" + MCVersion + "&Channel=" + AEConfig.CHANNEL + "&CurrentVersion=" + + AEConfig.VERSION ); + + URLConnection yc = url.openConnection(); + yc.setRequestProperty( "User-Agent", "AE2/" + AEConfig.VERSION + " (Channel:" + AEConfig.CHANNEL + "," + MCVersion.replace( " ", ":" ) + ")" ); + BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream() ) ); + + String Version = ""; + String inputLine; + + while ((inputLine = in.readLine()) != null) + Version += inputLine; + + in.close(); + + if ( Version.length() > 2 ) + { + JsonElement element = (new JsonParser()).parse( Version ); + + int version = element.getAsJsonObject().get( "FormatVersion" ).getAsInt(); + if ( version == 1 ) + { + JsonObject Meta = element.getAsJsonObject().get( "Meta" ).getAsJsonObject(); + JsonArray Versions = element.getAsJsonObject().get( "Versions" ).getAsJsonArray(); + if ( Versions.size() > 0 ) + { + JsonObject Latest = Versions.get( 0 ).getAsJsonObject(); + + AEConfig.instance.latestVersion = Latest.get( "Version" ).getAsString(); + AEConfig.instance.latestTimeStamp = (new Date()).getTime(); + AEConfig.instance.save(); + + if ( VersionChecker && !AEConfig.VERSION.equals( AEConfig.instance.latestVersion ) ) + { + NBTTagCompound versionInf = new NBTTagCompound(); + versionInf.setString( "modDisplayName", "Applied Energistics 2" ); + versionInf.setString( "oldVersion", AEConfig.VERSION ); + versionInf.setString( "newVersion", AEConfig.instance.latestVersion ); + versionInf.setString( "updateUrl", Latest.get( "UserBuild" ).getAsString() ); + versionInf.setBoolean( "isDirectLink", true ); + + JsonElement changeLog = Latest.get( "ChangeLog" ); + if ( changeLog == null ) + versionInf.setString( "changeLog", "For full change log please see: " + Meta.get( "DownloadLink" ).getAsString() ); + else + versionInf.setString( "changeLog", changeLog.getAsString() ); + + versionInf.setString( "newFileName", "appliedenergistics2-" + AEConfig.instance.latestVersion + ".jar" ); + FMLInterModComms.sendRuntimeMessage( AppEng.instance, "VersionChecker", "addUpdate", versionInf ); + VersionChecker = false; + } + } + } + } + + sleep( 1000 * 3600 * 4 ); + } + catch (Exception e) + { + try + { + sleep( 1000 * 3600 * 4 ); + } + catch (InterruptedException e1) + { + AELog.error( e ); + } + } + } + } + + private void sleep(long i) throws InterruptedException + { + Thread.sleep( i ); + } +} diff --git a/services/helpers/CompassException.java b/src/main/java/appeng/services/helpers/CompassException.java similarity index 100% rename from services/helpers/CompassException.java rename to src/main/java/appeng/services/helpers/CompassException.java diff --git a/services/helpers/CompassReader.java b/src/main/java/appeng/services/helpers/CompassReader.java similarity index 100% rename from services/helpers/CompassReader.java rename to src/main/java/appeng/services/helpers/CompassReader.java diff --git a/services/helpers/CompassRegion.java b/src/main/java/appeng/services/helpers/CompassRegion.java similarity index 100% rename from services/helpers/CompassRegion.java rename to src/main/java/appeng/services/helpers/CompassRegion.java diff --git a/services/helpers/ICompassCallback.java b/src/main/java/appeng/services/helpers/ICompassCallback.java similarity index 100% rename from services/helpers/ICompassCallback.java rename to src/main/java/appeng/services/helpers/ICompassCallback.java diff --git a/spatial/BiomeGenStorage.java b/src/main/java/appeng/spatial/BiomeGenStorage.java similarity index 100% rename from spatial/BiomeGenStorage.java rename to src/main/java/appeng/spatial/BiomeGenStorage.java diff --git a/spatial/CachedPlane.java b/src/main/java/appeng/spatial/CachedPlane.java similarity index 100% rename from spatial/CachedPlane.java rename to src/main/java/appeng/spatial/CachedPlane.java diff --git a/spatial/DefaultSpatialHandler.java b/src/main/java/appeng/spatial/DefaultSpatialHandler.java similarity index 100% rename from spatial/DefaultSpatialHandler.java rename to src/main/java/appeng/spatial/DefaultSpatialHandler.java diff --git a/spatial/ISpatialVisitor.java b/src/main/java/appeng/spatial/ISpatialVisitor.java similarity index 100% rename from spatial/ISpatialVisitor.java rename to src/main/java/appeng/spatial/ISpatialVisitor.java diff --git a/spatial/StorageChunkProvider.java b/src/main/java/appeng/spatial/StorageChunkProvider.java similarity index 100% rename from spatial/StorageChunkProvider.java rename to src/main/java/appeng/spatial/StorageChunkProvider.java diff --git a/spatial/StorageHelper.java b/src/main/java/appeng/spatial/StorageHelper.java similarity index 100% rename from spatial/StorageHelper.java rename to src/main/java/appeng/spatial/StorageHelper.java diff --git a/spatial/StorageWorldProvider.java b/src/main/java/appeng/spatial/StorageWorldProvider.java similarity index 100% rename from spatial/StorageWorldProvider.java rename to src/main/java/appeng/spatial/StorageWorldProvider.java diff --git a/tile/AEBaseInvTile.java b/src/main/java/appeng/tile/AEBaseInvTile.java similarity index 96% rename from tile/AEBaseInvTile.java rename to src/main/java/appeng/tile/AEBaseInvTile.java index c3e00c7cb..a84b65ba9 100644 --- a/tile/AEBaseInvTile.java +++ b/src/main/java/appeng/tile/AEBaseInvTile.java @@ -1,154 +1,154 @@ -package appeng.tile; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.block.AEBaseBlock; -import appeng.tile.events.TileEventType; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; - -public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventory, IAEAppEngInventory -{ - - @TileEvent(TileEventType.WORLD_NBT_READ) - public void readFromNBT_AEBaseInvTile(net.minecraft.nbt.NBTTagCompound data) - { - IInventory inv = getInternalInventory(); - NBTTagCompound opt = data.getCompoundTag( "inv" ); - for (int x = 0; x < inv.getSizeInventory(); x++) - { - NBTTagCompound item = opt.getCompoundTag( "item" + x ); - inv.setInventorySlotContents( x, ItemStack.loadItemStackFromNBT( item ) ); - } - } - - @TileEvent(TileEventType.WORLD_NBT_WRITE) - public void writeToNBT_AEBaseInvTile(net.minecraft.nbt.NBTTagCompound data) - { - IInventory inv = getInternalInventory(); - NBTTagCompound opt = new NBTTagCompound(); - for (int x = 0; x < inv.getSizeInventory(); x++) - { - NBTTagCompound item = new NBTTagCompound(); - ItemStack is = getStackInSlot( x ); - if ( is != null ) - is.writeToNBT( item ); - opt.setTag( "item" + x, item ); - } - data.setTag( "inv", opt ); - } - - @Override - public int getSizeInventory() - { - return getInternalInventory().getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) - { - return getInternalInventory().getStackInSlot( i ); - } - - @Override - public ItemStack decrStackSize(int i, int j) - { - return getInternalInventory().decrStackSize( i, j ); - } - - @Override - public ItemStack getStackInSlotOnClosing(int i) - { - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) - { - getInternalInventory().setInventorySlotContents( i, itemstack ); - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { - } - - @Override - public int getInventoryStackLimit() - { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer p) - { - return this.worldObj.getTileEntity( this.xCoord, this.yCoord, this.zCoord ) != this ? false : p.getDistanceSq( (double) this.xCoord + 0.5D, - (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D ) <= 32.0D; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) - { - return true; - } - - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) - { - return isItemValidForSlot( i, itemstack ); - } - - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) - { - return true; - } - - public abstract IInventory getInternalInventory(); - - @Override - public abstract void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added); - - public abstract int[] getAccessibleSlotsBySide(ForgeDirection whichSide); - - @Override - final public int[] getAccessibleSlotsFromSide(int side) - { - Block blk = worldObj.getBlock( xCoord, yCoord, zCoord ); - if ( blk instanceof AEBaseBlock ) - { - ForgeDirection mySide = ForgeDirection.getOrientation( side ); - return getAccessibleSlotsBySide( ((AEBaseBlock) blk).mapRotation( this, mySide ) ); - } - return getAccessibleSlotsBySide( ForgeDirection.getOrientation( side ) ); - } - - /** - * Returns the name of the inventory - */ - @Override - public String getInventoryName() - { - return getCustomName(); - } - - /** - * Returns if the inventory is named - */ - @Override - public boolean hasCustomInventoryName() - { - return hasCustomName(); - } - -} +package appeng.tile; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.block.AEBaseBlock; +import appeng.tile.events.TileEventType; +import appeng.tile.inventory.IAEAppEngInventory; +import appeng.tile.inventory.InvOperation; + +public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventory, IAEAppEngInventory +{ + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void readFromNBT_AEBaseInvTile(net.minecraft.nbt.NBTTagCompound data) + { + IInventory inv = getInternalInventory(); + NBTTagCompound opt = data.getCompoundTag( "inv" ); + for (int x = 0; x < inv.getSizeInventory(); x++) + { + NBTTagCompound item = opt.getCompoundTag( "item" + x ); + inv.setInventorySlotContents( x, ItemStack.loadItemStackFromNBT( item ) ); + } + } + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void writeToNBT_AEBaseInvTile(net.minecraft.nbt.NBTTagCompound data) + { + IInventory inv = getInternalInventory(); + NBTTagCompound opt = new NBTTagCompound(); + for (int x = 0; x < inv.getSizeInventory(); x++) + { + NBTTagCompound item = new NBTTagCompound(); + ItemStack is = getStackInSlot( x ); + if ( is != null ) + is.writeToNBT( item ); + opt.setTag( "item" + x, item ); + } + data.setTag( "inv", opt ); + } + + @Override + public int getSizeInventory() + { + return getInternalInventory().getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(int i) + { + return getInternalInventory().getStackInSlot( i ); + } + + @Override + public ItemStack decrStackSize(int i, int j) + { + return getInternalInventory().decrStackSize( i, j ); + } + + @Override + public ItemStack getStackInSlotOnClosing(int i) + { + return null; + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) + { + getInternalInventory().setInventorySlotContents( i, itemstack ); + } + + @Override + public void openInventory() + { + } + + @Override + public void closeInventory() + { + } + + @Override + public int getInventoryStackLimit() + { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer p) + { + return this.worldObj.getTileEntity( this.xCoord, this.yCoord, this.zCoord ) != this ? false : p.getDistanceSq( (double) this.xCoord + 0.5D, + (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D ) <= 32.0D; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) + { + return true; + } + + @Override + public boolean canInsertItem(int i, ItemStack itemstack, int j) + { + return isItemValidForSlot( i, itemstack ); + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) + { + return true; + } + + public abstract IInventory getInternalInventory(); + + @Override + public abstract void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added); + + public abstract int[] getAccessibleSlotsBySide(ForgeDirection whichSide); + + @Override + final public int[] getAccessibleSlotsFromSide(int side) + { + Block blk = worldObj.getBlock( xCoord, yCoord, zCoord ); + if ( blk instanceof AEBaseBlock ) + { + ForgeDirection mySide = ForgeDirection.getOrientation( side ); + return getAccessibleSlotsBySide( ((AEBaseBlock) blk).mapRotation( this, mySide ) ); + } + return getAccessibleSlotsBySide( ForgeDirection.getOrientation( side ) ); + } + + /** + * Returns the name of the inventory + */ + @Override + public String getInventoryName() + { + return getCustomName(); + } + + /** + * Returns if the inventory is named + */ + @Override + public boolean hasCustomInventoryName() + { + return hasCustomName(); + } + +} diff --git a/tile/AEBaseTile.java b/src/main/java/appeng/tile/AEBaseTile.java similarity index 95% rename from tile/AEBaseTile.java rename to src/main/java/appeng/tile/AEBaseTile.java index 129093199..096f15e82 100644 --- a/tile/AEBaseTile.java +++ b/src/main/java/appeng/tile/AEBaseTile.java @@ -1,503 +1,503 @@ -package appeng.tile; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; - -import java.lang.ref.WeakReference; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S35PacketUpdateTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.implementations.tiles.ISegmentedInventory; -import appeng.api.util.ICommonTile; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigurableObject; -import appeng.api.util.IOrientable; -import appeng.core.AELog; -import appeng.core.features.ItemStackSrc; -import appeng.helpers.ICustomNameObject; -import appeng.helpers.IPriorityHost; -import appeng.tile.events.AETileEventHandler; -import appeng.tile.events.TileEventType; -import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.util.Platform; -import appeng.util.SettingsFrom; - -public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile, ICustomNameObject -{ - - static private final HashMap>> handlers = new HashMap>>(); - static private final HashMap myItem = new HashMap(); - - private ForgeDirection forward = ForgeDirection.UNKNOWN; - private ForgeDirection up = ForgeDirection.UNKNOWN; - - public static ThreadLocal> dropNoItems = new ThreadLocal(); - - public void disableDrops() - { - dropNoItems.set( new WeakReference( this ) ); - } - - public boolean dropItems() - { - WeakReference what = dropNoItems.get(); - return what == null || what.get() != this; - } - - public int renderFragment = 0; - public String customName; - - public boolean notLoaded() - { - return !worldObj.blockExists( xCoord, yCoord, zCoord ); - } - - public TileEntity getTile() - { - return this; - } - - static public void registerTileItem(Class c, ItemStackSrc wat) - { - myItem.put( c, wat ); - } - - protected ItemStack getItemFromTile(Object obj) - { - ItemStackSrc src = myItem.get( obj.getClass() ); - if ( src == null ) - return null; - return src.stack( 1 ); - } - - protected boolean hasHandlerFor(TileEventType type) - { - List list = getHandlerListFor( type ); - return list != null && !list.isEmpty(); - } - - protected List getHandlerListFor(TileEventType type) - { - Class clz = getClass(); - EnumMap> handlerSet = handlers.get( clz ); - - if ( handlerSet == null ) - { - handlers.put( clz, handlerSet = new EnumMap>( TileEventType.class ) ); - - for (Method m : clz.getMethods()) - { - TileEvent te = m.getAnnotation( TileEvent.class ); - if ( te != null ) - { - addHandler( handlerSet, te.value(), m ); - } - } - } - - List list = handlerSet.get( type ); - - if ( list == null ) - handlerSet.put( type, list = new LinkedList() ); - - return list; - } - - private void addHandler(EnumMap> handlerSet, TileEventType value, Method m) - { - List list = handlerSet.get( value ); - - if ( list == null ) - handlerSet.put( value, list = new ArrayList() ); - - list.add( new AETileEventHandler( m, value ) ); - } - - @Override - final public boolean canUpdate() - { - return hasHandlerFor( TileEventType.TICK ); - } - - final public void Tick() - { - - } - - @Override - final public void updateEntity() - { - for (AETileEventHandler h : getHandlerListFor( TileEventType.TICK )) - h.Tick( this ); - } - - @Override - public void onChunkUnload() - { - if ( !isInvalid() ) - invalidate(); - } - - /** - * for dormant chunk cache. - */ - public void onChunkLoad() - { - if ( isInvalid() ) - validate(); - } - - @Override - // NOTE: WAS FINAL, changed for Immibis - final public void writeToNBT(NBTTagCompound data) - { - super.writeToNBT( data ); - - if ( canBeRotated() ) - { - data.setString( "orientation_forward", forward.name() ); - data.setString( "orientation_up", up.name() ); - } - - if ( customName != null ) - data.setString( "customName", customName ); - - for (AETileEventHandler h : getHandlerListFor( TileEventType.WORLD_NBT_WRITE )) - h.writeToNBT( this, data ); - } - - @Override - // NOTE: WAS FINAL, changed for Immibis - final public void readFromNBT(NBTTagCompound data) - { - super.readFromNBT( data ); - - if ( data.hasKey( "customName" ) ) - customName = data.getString( "customName" ); - else - customName = null; - - try - { - if ( canBeRotated() ) - { - forward = ForgeDirection.valueOf( data.getString( "orientation_forward" ) ); - up = ForgeDirection.valueOf( data.getString( "orientation_up" ) ); - } - } - catch (IllegalArgumentException iae) - { - } - - for (AETileEventHandler h : getHandlerListFor( TileEventType.WORLD_NBT_READ )) - { - h.readFromNBT( this, data ); - } - } - - final public void writeToStream(ByteBuf data) - { - try - { - if ( canBeRotated() ) - { - byte orientation = (byte) ((up.ordinal() << 3) | forward.ordinal()); - data.writeByte( orientation ); - } - - for (AETileEventHandler h : getHandlerListFor( TileEventType.NETWORK_WRITE )) - h.writeToStream( this, data ); - } - catch (Throwable t) - { - AELog.error( t ); - } - } - - final public boolean readFromStream(ByteBuf data) - { - boolean output = false; - - try - { - - if ( canBeRotated() ) - { - ForgeDirection old_Forward = forward; - ForgeDirection old_Up = up; - - byte orientation = data.readByte(); - forward = ForgeDirection.getOrientation( orientation & 0x7 ); - up = ForgeDirection.getOrientation( orientation >> 3 ); - - output = !forward.equals( old_Forward ) || !up.equals( old_Up ); - } - - renderFragment = 100; - for (AETileEventHandler h : getHandlerListFor( TileEventType.NETWORK_READ )) - if ( h.readFromStream( this, data ) ) - output = true; - - if ( (renderFragment & 1) == 1 ) - output = true; - renderFragment = 0; - } - catch (Throwable t) - { - AELog.error( t ); - } - - return output; - } - - /** - * By default all blocks can have orientation, this handles saving, and loading, as well as synchronization. - * - * @return - */ - @Override - public boolean canBeRotated() - { - return true; - } - - @Override - public ForgeDirection getForward() - { - return forward; - } - - @Override - public ForgeDirection getUp() - { - return up; - } - - @Override - public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) - { - forward = inForward; - up = inUp; - markForUpdate(); - Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord ); - } - - public void onPlacement(ItemStack stack, EntityPlayer player, int side) - { - if ( stack.hasTagCompound() ) - { - uploadSettings( SettingsFrom.DISMANTLE_ITEM, stack.getTagCompound() ); - } - } - - @Override - public Packet getDescriptionPacket() - { - NBTTagCompound data = new NBTTagCompound(); - - ByteBuf stream = Unpooled.buffer(); - - try - { - writeToStream( stream ); - if ( stream.readableBytes() == 0 ) - return null; - } - catch (Throwable t) - { - AELog.error( t ); - } - - stream.capacity( stream.readableBytes() ); - data.setByteArray( "X", stream.array() ); - return new S35PacketUpdateTileEntity( xCoord, yCoord, zCoord, 64, data ); - } - - @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) - { - // / pkt.actionType - if ( pkt.func_148853_f() == 64 ) - { - ByteBuf stream = Unpooled.copiedBuffer( pkt.func_148857_g().getByteArray( "X" ) ); - if ( readFromStream( stream ) ) - markForUpdate(); - } - } - - public void markForUpdate() - { - if ( renderFragment > 0 ) - renderFragment = renderFragment | 1; - else - { - // TODO: Optimize Network Load - if ( worldObj != null ) - { - AELog.blockUpdate( xCoord, yCoord, zCoord, this ); - worldObj.markBlockForUpdate( xCoord, yCoord, zCoord ); - } - } - } - - /** - * returns the contents of the tile entity, into the world, defaults to dropping everything in the inventory. - * - * @param w - * @param x - * @param y - * @param z - * @param drops - */ - @Override - public void getDrops(World w, int x, int y, int z, ArrayList drops) - { - if ( this instanceof IInventory ) - { - IInventory inv = (IInventory) this; - - for (int l = 0; l < inv.getSizeInventory(); l++) - { - ItemStack is = inv.getStackInSlot( l ); - if ( is != null ) - drops.add( is ); - } - } - - } - - public void getNoDrops(World w, int x, int y, int z, ArrayList drops) - { - - } - - public void onReady() - { - - } - - /** - * depending on the from, different settings will be accepted, don't call this with null - * - * @param from - * @param compound - */ - public void uploadSettings(SettingsFrom from, NBTTagCompound compound) - { - if ( compound != null && this instanceof IConfigurableObject ) - { - IConfigManager cm = ((IConfigurableObject) this).getConfigManager(); - if ( cm != null ) - cm.readFromNBT( compound ); - } - - if ( this instanceof IPriorityHost ) - { - IPriorityHost pHost = (IPriorityHost) this; - pHost.setPriority( compound.getInteger( "priority" ) ); - } - - if ( this instanceof ISegmentedInventory ) - { - IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" ); - if ( inv != null && inv instanceof AppEngInternalAEInventory ) - { - AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv; - AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() ); - tmp.readFromNBT( compound, "config" ); - for (int x = 0; x < tmp.getSizeInventory(); x++) - target.setInventorySlotContents( x, tmp.getStackInSlot( x ) ); - } - } - } - - /** - * null means nothing to store... - * - * @param from - * @return - */ - public NBTTagCompound downloadSettings(SettingsFrom from) - { - NBTTagCompound output = new NBTTagCompound(); - - if ( hasCustomName() ) - { - NBTTagCompound dsp = new NBTTagCompound(); - dsp.setString( "Name", getCustomName() ); - output.setTag( "display", dsp ); - } - - if ( this instanceof IConfigurableObject ) - { - IConfigManager cm = ((IConfigurableObject) this).getConfigManager(); - if ( cm != null ) - cm.writeToNBT( output ); - } - - if ( this instanceof IPriorityHost ) - { - IPriorityHost pHost = (IPriorityHost) this; - output.setInteger( "priority", pHost.getPriority() ); - } - - if ( this instanceof ISegmentedInventory ) - { - IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" ); - if ( inv != null && inv instanceof AppEngInternalAEInventory ) - { - ((AppEngInternalAEInventory) inv).writeToNBT( output, "config" ); - } - } - - return output.hasNoTags() ? null : output; - } - - public void securityBreak() - { - worldObj.func_147480_a( xCoord, yCoord, zCoord, true ); - disableDrops(); - } - - public void saveChanges() - { - super.markDirty(); - } - - public boolean requiresTESR() - { - return false; - } - - public void setName(String name) - { - this.customName = name; - } - - @Override - public String getCustomName() - { - return hasCustomName() ? customName : getClass().getSimpleName(); - } - - @Override - public boolean hasCustomName() - { - return customName != null && customName.length() > 0; - } - -} +package appeng.tile; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import java.lang.ref.WeakReference; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.implementations.tiles.ISegmentedInventory; +import appeng.api.util.ICommonTile; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigurableObject; +import appeng.api.util.IOrientable; +import appeng.core.AELog; +import appeng.core.features.ItemStackSrc; +import appeng.helpers.ICustomNameObject; +import appeng.helpers.IPriorityHost; +import appeng.tile.events.AETileEventHandler; +import appeng.tile.events.TileEventType; +import appeng.tile.inventory.AppEngInternalAEInventory; +import appeng.util.Platform; +import appeng.util.SettingsFrom; + +public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile, ICustomNameObject +{ + + static private final HashMap>> handlers = new HashMap>>(); + static private final HashMap myItem = new HashMap(); + + private ForgeDirection forward = ForgeDirection.UNKNOWN; + private ForgeDirection up = ForgeDirection.UNKNOWN; + + public static ThreadLocal> dropNoItems = new ThreadLocal(); + + public void disableDrops() + { + dropNoItems.set( new WeakReference( this ) ); + } + + public boolean dropItems() + { + WeakReference what = dropNoItems.get(); + return what == null || what.get() != this; + } + + public int renderFragment = 0; + public String customName; + + public boolean notLoaded() + { + return !worldObj.blockExists( xCoord, yCoord, zCoord ); + } + + public TileEntity getTile() + { + return this; + } + + static public void registerTileItem(Class c, ItemStackSrc wat) + { + myItem.put( c, wat ); + } + + protected ItemStack getItemFromTile(Object obj) + { + ItemStackSrc src = myItem.get( obj.getClass() ); + if ( src == null ) + return null; + return src.stack( 1 ); + } + + protected boolean hasHandlerFor(TileEventType type) + { + List list = getHandlerListFor( type ); + return list != null && !list.isEmpty(); + } + + protected List getHandlerListFor(TileEventType type) + { + Class clz = getClass(); + EnumMap> handlerSet = handlers.get( clz ); + + if ( handlerSet == null ) + { + handlers.put( clz, handlerSet = new EnumMap>( TileEventType.class ) ); + + for (Method m : clz.getMethods()) + { + TileEvent te = m.getAnnotation( TileEvent.class ); + if ( te != null ) + { + addHandler( handlerSet, te.value(), m ); + } + } + } + + List list = handlerSet.get( type ); + + if ( list == null ) + handlerSet.put( type, list = new LinkedList() ); + + return list; + } + + private void addHandler(EnumMap> handlerSet, TileEventType value, Method m) + { + List list = handlerSet.get( value ); + + if ( list == null ) + handlerSet.put( value, list = new ArrayList() ); + + list.add( new AETileEventHandler( m, value ) ); + } + + @Override + final public boolean canUpdate() + { + return hasHandlerFor( TileEventType.TICK ); + } + + final public void Tick() + { + + } + + @Override + final public void updateEntity() + { + for (AETileEventHandler h : getHandlerListFor( TileEventType.TICK )) + h.Tick( this ); + } + + @Override + public void onChunkUnload() + { + if ( !isInvalid() ) + invalidate(); + } + + /** + * for dormant chunk cache. + */ + public void onChunkLoad() + { + if ( isInvalid() ) + validate(); + } + + @Override + // NOTE: WAS FINAL, changed for Immibis + final public void writeToNBT(NBTTagCompound data) + { + super.writeToNBT( data ); + + if ( canBeRotated() ) + { + data.setString( "orientation_forward", forward.name() ); + data.setString( "orientation_up", up.name() ); + } + + if ( customName != null ) + data.setString( "customName", customName ); + + for (AETileEventHandler h : getHandlerListFor( TileEventType.WORLD_NBT_WRITE )) + h.writeToNBT( this, data ); + } + + @Override + // NOTE: WAS FINAL, changed for Immibis + final public void readFromNBT(NBTTagCompound data) + { + super.readFromNBT( data ); + + if ( data.hasKey( "customName" ) ) + customName = data.getString( "customName" ); + else + customName = null; + + try + { + if ( canBeRotated() ) + { + forward = ForgeDirection.valueOf( data.getString( "orientation_forward" ) ); + up = ForgeDirection.valueOf( data.getString( "orientation_up" ) ); + } + } + catch (IllegalArgumentException iae) + { + } + + for (AETileEventHandler h : getHandlerListFor( TileEventType.WORLD_NBT_READ )) + { + h.readFromNBT( this, data ); + } + } + + final public void writeToStream(ByteBuf data) + { + try + { + if ( canBeRotated() ) + { + byte orientation = (byte) ((up.ordinal() << 3) | forward.ordinal()); + data.writeByte( orientation ); + } + + for (AETileEventHandler h : getHandlerListFor( TileEventType.NETWORK_WRITE )) + h.writeToStream( this, data ); + } + catch (Throwable t) + { + AELog.error( t ); + } + } + + final public boolean readFromStream(ByteBuf data) + { + boolean output = false; + + try + { + + if ( canBeRotated() ) + { + ForgeDirection old_Forward = forward; + ForgeDirection old_Up = up; + + byte orientation = data.readByte(); + forward = ForgeDirection.getOrientation( orientation & 0x7 ); + up = ForgeDirection.getOrientation( orientation >> 3 ); + + output = !forward.equals( old_Forward ) || !up.equals( old_Up ); + } + + renderFragment = 100; + for (AETileEventHandler h : getHandlerListFor( TileEventType.NETWORK_READ )) + if ( h.readFromStream( this, data ) ) + output = true; + + if ( (renderFragment & 1) == 1 ) + output = true; + renderFragment = 0; + } + catch (Throwable t) + { + AELog.error( t ); + } + + return output; + } + + /** + * By default all blocks can have orientation, this handles saving, and loading, as well as synchronization. + * + * @return + */ + @Override + public boolean canBeRotated() + { + return true; + } + + @Override + public ForgeDirection getForward() + { + return forward; + } + + @Override + public ForgeDirection getUp() + { + return up; + } + + @Override + public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) + { + forward = inForward; + up = inUp; + markForUpdate(); + Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord ); + } + + public void onPlacement(ItemStack stack, EntityPlayer player, int side) + { + if ( stack.hasTagCompound() ) + { + uploadSettings( SettingsFrom.DISMANTLE_ITEM, stack.getTagCompound() ); + } + } + + @Override + public Packet getDescriptionPacket() + { + NBTTagCompound data = new NBTTagCompound(); + + ByteBuf stream = Unpooled.buffer(); + + try + { + writeToStream( stream ); + if ( stream.readableBytes() == 0 ) + return null; + } + catch (Throwable t) + { + AELog.error( t ); + } + + stream.capacity( stream.readableBytes() ); + data.setByteArray( "X", stream.array() ); + return new S35PacketUpdateTileEntity( xCoord, yCoord, zCoord, 64, data ); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) + { + // / pkt.actionType + if ( pkt.func_148853_f() == 64 ) + { + ByteBuf stream = Unpooled.copiedBuffer( pkt.func_148857_g().getByteArray( "X" ) ); + if ( readFromStream( stream ) ) + markForUpdate(); + } + } + + public void markForUpdate() + { + if ( renderFragment > 0 ) + renderFragment = renderFragment | 1; + else + { + // TODO: Optimize Network Load + if ( worldObj != null ) + { + AELog.blockUpdate( xCoord, yCoord, zCoord, this ); + worldObj.markBlockForUpdate( xCoord, yCoord, zCoord ); + } + } + } + + /** + * returns the contents of the tile entity, into the world, defaults to dropping everything in the inventory. + * + * @param w + * @param x + * @param y + * @param z + * @param drops + */ + @Override + public void getDrops(World w, int x, int y, int z, ArrayList drops) + { + if ( this instanceof IInventory ) + { + IInventory inv = (IInventory) this; + + for (int l = 0; l < inv.getSizeInventory(); l++) + { + ItemStack is = inv.getStackInSlot( l ); + if ( is != null ) + drops.add( is ); + } + } + + } + + public void getNoDrops(World w, int x, int y, int z, ArrayList drops) + { + + } + + public void onReady() + { + + } + + /** + * depending on the from, different settings will be accepted, don't call this with null + * + * @param from + * @param compound + */ + public void uploadSettings(SettingsFrom from, NBTTagCompound compound) + { + if ( compound != null && this instanceof IConfigurableObject ) + { + IConfigManager cm = ((IConfigurableObject) this).getConfigManager(); + if ( cm != null ) + cm.readFromNBT( compound ); + } + + if ( this instanceof IPriorityHost ) + { + IPriorityHost pHost = (IPriorityHost) this; + pHost.setPriority( compound.getInteger( "priority" ) ); + } + + if ( this instanceof ISegmentedInventory ) + { + IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" ); + if ( inv != null && inv instanceof AppEngInternalAEInventory ) + { + AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv; + AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() ); + tmp.readFromNBT( compound, "config" ); + for (int x = 0; x < tmp.getSizeInventory(); x++) + target.setInventorySlotContents( x, tmp.getStackInSlot( x ) ); + } + } + } + + /** + * null means nothing to store... + * + * @param from + * @return + */ + public NBTTagCompound downloadSettings(SettingsFrom from) + { + NBTTagCompound output = new NBTTagCompound(); + + if ( hasCustomName() ) + { + NBTTagCompound dsp = new NBTTagCompound(); + dsp.setString( "Name", getCustomName() ); + output.setTag( "display", dsp ); + } + + if ( this instanceof IConfigurableObject ) + { + IConfigManager cm = ((IConfigurableObject) this).getConfigManager(); + if ( cm != null ) + cm.writeToNBT( output ); + } + + if ( this instanceof IPriorityHost ) + { + IPriorityHost pHost = (IPriorityHost) this; + output.setInteger( "priority", pHost.getPriority() ); + } + + if ( this instanceof ISegmentedInventory ) + { + IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" ); + if ( inv != null && inv instanceof AppEngInternalAEInventory ) + { + ((AppEngInternalAEInventory) inv).writeToNBT( output, "config" ); + } + } + + return output.hasNoTags() ? null : output; + } + + public void securityBreak() + { + worldObj.func_147480_a( xCoord, yCoord, zCoord, true ); + disableDrops(); + } + + public void saveChanges() + { + super.markDirty(); + } + + public boolean requiresTESR() + { + return false; + } + + public void setName(String name) + { + this.customName = name; + } + + @Override + public String getCustomName() + { + return hasCustomName() ? customName : getClass().getSimpleName(); + } + + @Override + public boolean hasCustomName() + { + return customName != null && customName.length() > 0; + } + +} diff --git a/tile/TileEvent.java b/src/main/java/appeng/tile/TileEvent.java similarity index 100% rename from tile/TileEvent.java rename to src/main/java/appeng/tile/TileEvent.java diff --git a/tile/crafting/TileCraftingMonitorTile.java b/src/main/java/appeng/tile/crafting/TileCraftingMonitorTile.java similarity index 100% rename from tile/crafting/TileCraftingMonitorTile.java rename to src/main/java/appeng/tile/crafting/TileCraftingMonitorTile.java diff --git a/tile/crafting/TileCraftingStorageTile.java b/src/main/java/appeng/tile/crafting/TileCraftingStorageTile.java similarity index 100% rename from tile/crafting/TileCraftingStorageTile.java rename to src/main/java/appeng/tile/crafting/TileCraftingStorageTile.java diff --git a/tile/crafting/TileCraftingTile.java b/src/main/java/appeng/tile/crafting/TileCraftingTile.java similarity index 100% rename from tile/crafting/TileCraftingTile.java rename to src/main/java/appeng/tile/crafting/TileCraftingTile.java diff --git a/tile/crafting/TileMolecularAssembler.java b/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java similarity index 100% rename from tile/crafting/TileMolecularAssembler.java rename to src/main/java/appeng/tile/crafting/TileMolecularAssembler.java diff --git a/tile/events/AETileEventHandler.java b/src/main/java/appeng/tile/events/AETileEventHandler.java similarity index 94% rename from tile/events/AETileEventHandler.java rename to src/main/java/appeng/tile/events/AETileEventHandler.java index e07c2717f..ac4186f9b 100644 --- a/tile/events/AETileEventHandler.java +++ b/src/main/java/appeng/tile/events/AETileEventHandler.java @@ -1,138 +1,138 @@ -package appeng.tile.events; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import net.minecraft.nbt.NBTTagCompound; -import appeng.tile.AEBaseTile; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class AETileEventHandler -{ - - private final Method method; - private final TileEventType type; - - public AETileEventHandler(Method m, TileEventType which) { - method = m; - type = which; - } - - // TICK - public void Tick(AEBaseTile tile) - { - try - { - method.invoke( tile ); - } - catch (IllegalAccessException e) - { - throw new RuntimeException( e ); - } - catch (IllegalArgumentException e) - { - throw new RuntimeException( e ); - } - catch (InvocationTargetException e) - { - throw new RuntimeException( e ); - } - } - - // WORLD_NBT - public void writeToNBT(AEBaseTile tile, NBTTagCompound data) - { - try - { - method.invoke( tile, data ); - } - catch (IllegalAccessException e) - { - throw new RuntimeException( e ); - } - catch (IllegalArgumentException e) - { - throw new RuntimeException( e ); - } - catch (InvocationTargetException e) - { - throw new RuntimeException( e ); - } - } - - // WORLD NBT - public void readFromNBT(AEBaseTile tile, NBTTagCompound data) - { - try - { - method.invoke( tile, data ); - } - catch (IllegalAccessException e) - { - throw new RuntimeException( e ); - } - catch (IllegalArgumentException e) - { - throw new RuntimeException( e ); - } - catch (InvocationTargetException e) - { - throw new RuntimeException( e ); - } - } - - // NETWORK - public void writeToStream(AEBaseTile tile, ByteBuf data) throws IOException - { - try - { - method.invoke( tile, data ); - } - catch (IllegalAccessException e) - { - throw new RuntimeException( e ); - } - catch (IllegalArgumentException e) - { - throw new RuntimeException( e ); - } - catch (InvocationTargetException e) - { - throw new RuntimeException( e ); - } - } - - // NETWORK - /** - * returning true from this method, will update the block's render - * - * @param data - * @return - * @throws IOException - */ - @SideOnly(Side.CLIENT) - public boolean readFromStream(AEBaseTile tile, ByteBuf data) throws IOException - { - try - { - return (Boolean) method.invoke( tile, data ); - } - catch (IllegalAccessException e) - { - throw new RuntimeException( e ); - } - catch (IllegalArgumentException e) - { - throw new RuntimeException( e ); - } - catch (InvocationTargetException e) - { - throw new RuntimeException( e ); - } - } - -} +package appeng.tile.events; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import net.minecraft.nbt.NBTTagCompound; +import appeng.tile.AEBaseTile; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class AETileEventHandler +{ + + private final Method method; + private final TileEventType type; + + public AETileEventHandler(Method m, TileEventType which) { + method = m; + type = which; + } + + // TICK + public void Tick(AEBaseTile tile) + { + try + { + method.invoke( tile ); + } + catch (IllegalAccessException e) + { + throw new RuntimeException( e ); + } + catch (IllegalArgumentException e) + { + throw new RuntimeException( e ); + } + catch (InvocationTargetException e) + { + throw new RuntimeException( e ); + } + } + + // WORLD_NBT + public void writeToNBT(AEBaseTile tile, NBTTagCompound data) + { + try + { + method.invoke( tile, data ); + } + catch (IllegalAccessException e) + { + throw new RuntimeException( e ); + } + catch (IllegalArgumentException e) + { + throw new RuntimeException( e ); + } + catch (InvocationTargetException e) + { + throw new RuntimeException( e ); + } + } + + // WORLD NBT + public void readFromNBT(AEBaseTile tile, NBTTagCompound data) + { + try + { + method.invoke( tile, data ); + } + catch (IllegalAccessException e) + { + throw new RuntimeException( e ); + } + catch (IllegalArgumentException e) + { + throw new RuntimeException( e ); + } + catch (InvocationTargetException e) + { + throw new RuntimeException( e ); + } + } + + // NETWORK + public void writeToStream(AEBaseTile tile, ByteBuf data) throws IOException + { + try + { + method.invoke( tile, data ); + } + catch (IllegalAccessException e) + { + throw new RuntimeException( e ); + } + catch (IllegalArgumentException e) + { + throw new RuntimeException( e ); + } + catch (InvocationTargetException e) + { + throw new RuntimeException( e ); + } + } + + // NETWORK + /** + * returning true from this method, will update the block's render + * + * @param data + * @return + * @throws IOException + */ + @SideOnly(Side.CLIENT) + public boolean readFromStream(AEBaseTile tile, ByteBuf data) throws IOException + { + try + { + return (Boolean) method.invoke( tile, data ); + } + catch (IllegalAccessException e) + { + throw new RuntimeException( e ); + } + catch (IllegalArgumentException e) + { + throw new RuntimeException( e ); + } + catch (InvocationTargetException e) + { + throw new RuntimeException( e ); + } + } + +} diff --git a/tile/events/TileEventType.java b/src/main/java/appeng/tile/events/TileEventType.java similarity index 92% rename from tile/events/TileEventType.java rename to src/main/java/appeng/tile/events/TileEventType.java index accf36b28..6c9c19eb9 100644 --- a/tile/events/TileEventType.java +++ b/src/main/java/appeng/tile/events/TileEventType.java @@ -1,10 +1,10 @@ -package appeng.tile.events; - -public enum TileEventType -{ - TICK, - - WORLD_NBT_READ, WORLD_NBT_WRITE, - - NETWORK_READ, NETWORK_WRITE -} +package appeng.tile.events; + +public enum TileEventType +{ + TICK, + + WORLD_NBT_READ, WORLD_NBT_WRITE, + + NETWORK_READ, NETWORK_WRITE +} diff --git a/tile/grid/AENetworkInvTile.java b/src/main/java/appeng/tile/grid/AENetworkInvTile.java similarity index 95% rename from tile/grid/AENetworkInvTile.java rename to src/main/java/appeng/tile/grid/AENetworkInvTile.java index e88cceefc..e4d84f367 100644 --- a/tile/grid/AENetworkInvTile.java +++ b/src/main/java/appeng/tile/grid/AENetworkInvTile.java @@ -1,81 +1,81 @@ -package appeng.tile.grid; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.IActionHost; -import appeng.me.helpers.AENetworkProxy; -import appeng.me.helpers.IGridProxyable; -import appeng.tile.AEBaseInvTile; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; - -public abstract class AENetworkInvTile extends AEBaseInvTile implements IActionHost, IGridProxyable -{ - - @TileEvent(TileEventType.WORLD_NBT_READ) - public void readFromNBT_AENetwork(NBTTagCompound data) - { - gridProxy.readFromNBT( data ); - } - - @TileEvent(TileEventType.WORLD_NBT_WRITE) - public void writeToNBT_AENetwork(NBTTagCompound data) - { - gridProxy.writeToNBT( data ); - } - - protected AENetworkProxy gridProxy = new AENetworkProxy( this, "proxy", getItemFromTile( this ), true ); - - @Override - public AENetworkProxy getProxy() - { - return gridProxy; - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) - { - return gridProxy.getNode(); - } - - @Override - public void onReady() - { - super.onReady(); - gridProxy.onReady(); - } - - @Override - public void onChunkUnload() - { - super.onChunkUnload(); - gridProxy.onChunkUnload(); - } - - @Override - public void validate() - { - super.validate(); - gridProxy.validate(); - } - - @Override - public void invalidate() - { - super.invalidate(); - gridProxy.invalidate(); - } - - @Override - public void gridChanged() - { - - } - - @Override - public IGridNode getActionableNode() - { - return gridProxy.getNode(); - } -} +package appeng.tile.grid; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.IGridNode; +import appeng.api.networking.security.IActionHost; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.helpers.IGridProxyable; +import appeng.tile.AEBaseInvTile; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; + +public abstract class AENetworkInvTile extends AEBaseInvTile implements IActionHost, IGridProxyable +{ + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void readFromNBT_AENetwork(NBTTagCompound data) + { + gridProxy.readFromNBT( data ); + } + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void writeToNBT_AENetwork(NBTTagCompound data) + { + gridProxy.writeToNBT( data ); + } + + protected AENetworkProxy gridProxy = new AENetworkProxy( this, "proxy", getItemFromTile( this ), true ); + + @Override + public AENetworkProxy getProxy() + { + return gridProxy; + } + + @Override + public IGridNode getGridNode(ForgeDirection dir) + { + return gridProxy.getNode(); + } + + @Override + public void onReady() + { + super.onReady(); + gridProxy.onReady(); + } + + @Override + public void onChunkUnload() + { + super.onChunkUnload(); + gridProxy.onChunkUnload(); + } + + @Override + public void validate() + { + super.validate(); + gridProxy.validate(); + } + + @Override + public void invalidate() + { + super.invalidate(); + gridProxy.invalidate(); + } + + @Override + public void gridChanged() + { + + } + + @Override + public IGridNode getActionableNode() + { + return gridProxy.getNode(); + } +} diff --git a/tile/grid/AENetworkPowerTile.java b/src/main/java/appeng/tile/grid/AENetworkPowerTile.java similarity index 95% rename from tile/grid/AENetworkPowerTile.java rename to src/main/java/appeng/tile/grid/AENetworkPowerTile.java index d2f0bc70c..079a8c366 100644 --- a/tile/grid/AENetworkPowerTile.java +++ b/src/main/java/appeng/tile/grid/AENetworkPowerTile.java @@ -1,95 +1,95 @@ -package appeng.tile.grid; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.IActionHost; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalCoord; -import appeng.me.helpers.AENetworkProxy; -import appeng.me.helpers.IGridProxyable; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.tile.powersink.AEBasePoweredTile; - -public abstract class AENetworkPowerTile extends AEBasePoweredTile implements IActionHost, IGridProxyable -{ - - @TileEvent(TileEventType.WORLD_NBT_READ) - public void readFromNBT_AENetwork(NBTTagCompound data) - { - gridProxy.readFromNBT( data ); - } - - @TileEvent(TileEventType.WORLD_NBT_WRITE) - public void writeToNBT_AENetwork(NBTTagCompound data) - { - gridProxy.writeToNBT( data ); - } - - protected AENetworkProxy gridProxy = new AENetworkProxy( this, "proxy", getItemFromTile( this ), true ); - - @Override - public AENetworkProxy getProxy() - { - return gridProxy; - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.SMART; - } - - @Override - public DimensionalCoord getLocation() - { - return new DimensionalCoord( this ); - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) - { - return gridProxy.getNode(); - } - - @Override - public void onReady() - { - super.onReady(); - gridProxy.onReady(); - } - - @Override - public void onChunkUnload() - { - super.onChunkUnload(); - gridProxy.onChunkUnload(); - } - - @Override - public void validate() - { - super.validate(); - gridProxy.validate(); - } - - @Override - public void invalidate() - { - super.invalidate(); - gridProxy.invalidate(); - } - - @Override - public void gridChanged() - { - - } - - @Override - public IGridNode getActionableNode() - { - return gridProxy.getNode(); - } -} +package appeng.tile.grid; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.IGridNode; +import appeng.api.networking.security.IActionHost; +import appeng.api.util.AECableType; +import appeng.api.util.DimensionalCoord; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.helpers.IGridProxyable; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.tile.powersink.AEBasePoweredTile; + +public abstract class AENetworkPowerTile extends AEBasePoweredTile implements IActionHost, IGridProxyable +{ + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void readFromNBT_AENetwork(NBTTagCompound data) + { + gridProxy.readFromNBT( data ); + } + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void writeToNBT_AENetwork(NBTTagCompound data) + { + gridProxy.writeToNBT( data ); + } + + protected AENetworkProxy gridProxy = new AENetworkProxy( this, "proxy", getItemFromTile( this ), true ); + + @Override + public AENetworkProxy getProxy() + { + return gridProxy; + } + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.SMART; + } + + @Override + public DimensionalCoord getLocation() + { + return new DimensionalCoord( this ); + } + + @Override + public IGridNode getGridNode(ForgeDirection dir) + { + return gridProxy.getNode(); + } + + @Override + public void onReady() + { + super.onReady(); + gridProxy.onReady(); + } + + @Override + public void onChunkUnload() + { + super.onChunkUnload(); + gridProxy.onChunkUnload(); + } + + @Override + public void validate() + { + super.validate(); + gridProxy.validate(); + } + + @Override + public void invalidate() + { + super.invalidate(); + gridProxy.invalidate(); + } + + @Override + public void gridChanged() + { + + } + + @Override + public IGridNode getActionableNode() + { + return gridProxy.getNode(); + } +} diff --git a/tile/grid/AENetworkTile.java b/src/main/java/appeng/tile/grid/AENetworkTile.java similarity index 94% rename from tile/grid/AENetworkTile.java rename to src/main/java/appeng/tile/grid/AENetworkTile.java index 863c181bc..2daadd242 100644 --- a/tile/grid/AENetworkTile.java +++ b/src/main/java/appeng/tile/grid/AENetworkTile.java @@ -1,100 +1,100 @@ -package appeng.tile.grid; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.IGridNode; -import appeng.api.networking.security.IActionHost; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalCoord; -import appeng.me.helpers.AENetworkProxy; -import appeng.me.helpers.IGridProxyable; -import appeng.tile.AEBaseTile; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; - -public class AENetworkTile extends AEBaseTile implements IActionHost, IGridProxyable -{ - - @TileEvent(TileEventType.WORLD_NBT_READ) - public void readFromNBT_AENetwork(NBTTagCompound data) - { - gridProxy.readFromNBT( data ); - } - - @TileEvent(TileEventType.WORLD_NBT_WRITE) - public void writeToNBT_AENetwork(NBTTagCompound data) - { - gridProxy.writeToNBT( data ); - } - - final protected AENetworkProxy gridProxy = createProxy(); - - protected AENetworkProxy createProxy() - { - return new AENetworkProxy( this, "proxy", getItemFromTile( this ), true ); - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) - { - return gridProxy.getNode(); - } - - @Override - public void onReady() - { - super.onReady(); - gridProxy.onReady(); - } - - @Override - public void onChunkUnload() - { - super.onChunkUnload(); - gridProxy.onChunkUnload(); - } - - @Override - public void validate() - { - super.validate(); - gridProxy.validate(); - } - - @Override - public void invalidate() - { - super.invalidate(); - gridProxy.invalidate(); - } - - @Override - public DimensionalCoord getLocation() - { - return new DimensionalCoord( this ); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.SMART; - } - - @Override - public void gridChanged() - { - - } - - @Override - public AENetworkProxy getProxy() - { - return gridProxy; - } - - @Override - public IGridNode getActionableNode() - { - return gridProxy.getNode(); - } -} +package appeng.tile.grid; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.IGridNode; +import appeng.api.networking.security.IActionHost; +import appeng.api.util.AECableType; +import appeng.api.util.DimensionalCoord; +import appeng.me.helpers.AENetworkProxy; +import appeng.me.helpers.IGridProxyable; +import appeng.tile.AEBaseTile; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; + +public class AENetworkTile extends AEBaseTile implements IActionHost, IGridProxyable +{ + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void readFromNBT_AENetwork(NBTTagCompound data) + { + gridProxy.readFromNBT( data ); + } + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void writeToNBT_AENetwork(NBTTagCompound data) + { + gridProxy.writeToNBT( data ); + } + + final protected AENetworkProxy gridProxy = createProxy(); + + protected AENetworkProxy createProxy() + { + return new AENetworkProxy( this, "proxy", getItemFromTile( this ), true ); + } + + @Override + public IGridNode getGridNode(ForgeDirection dir) + { + return gridProxy.getNode(); + } + + @Override + public void onReady() + { + super.onReady(); + gridProxy.onReady(); + } + + @Override + public void onChunkUnload() + { + super.onChunkUnload(); + gridProxy.onChunkUnload(); + } + + @Override + public void validate() + { + super.validate(); + gridProxy.validate(); + } + + @Override + public void invalidate() + { + super.invalidate(); + gridProxy.invalidate(); + } + + @Override + public DimensionalCoord getLocation() + { + return new DimensionalCoord( this ); + } + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.SMART; + } + + @Override + public void gridChanged() + { + + } + + @Override + public AENetworkProxy getProxy() + { + return gridProxy; + } + + @Override + public IGridNode getActionableNode() + { + return gridProxy.getNode(); + } +} diff --git a/tile/grindstone/TileCrank.java b/src/main/java/appeng/tile/grindstone/TileCrank.java similarity index 96% rename from tile/grindstone/TileCrank.java rename to src/main/java/appeng/tile/grindstone/TileCrank.java index 247d3219e..51f83f6cd 100644 --- a/tile/grindstone/TileCrank.java +++ b/src/main/java/appeng/tile/grindstone/TileCrank.java @@ -1,143 +1,143 @@ -package appeng.tile.grindstone; - -import io.netty.buffer.ByteBuf; - -import java.util.Arrays; -import java.util.List; - -import net.minecraft.entity.Entity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.implementations.tiles.ICrankable; -import appeng.helpers.ICustomCollision; -import appeng.tile.AEBaseTile; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.util.Platform; - -public class TileCrank extends AEBaseTile implements ICustomCollision -{ - - final int ticksPerRotation = 18; - - // sided values.. - public float visibleRotation = 0; - public int charge = 0; - - public int hits = 0; - public int rotation = 0; - - @TileEvent(TileEventType.TICK) - public void Tick_TileCrank() - { - if ( rotation > 0 ) - { - visibleRotation -= 360 / (ticksPerRotation); - charge++; - if ( charge >= ticksPerRotation ) - { - charge -= ticksPerRotation; - ICrankable g = getGrinder(); - if ( g != null ) - g.applyTurn(); - } - - rotation--; - } - } - - @TileEvent(TileEventType.NETWORK_READ) - public boolean readFromStream_TileCrank(ByteBuf data) throws java.io.IOException - { - rotation = data.readInt(); - return false; - } - - @TileEvent(TileEventType.NETWORK_WRITE) - public void writeToStream_TileCrank(ByteBuf data) throws java.io.IOException - { - data.writeInt( rotation ); - } - - public ICrankable getGrinder() - { - if ( Platform.isClient() ) - return null; - - ForgeDirection grinder = getUp().getOpposite(); - TileEntity te = worldObj.getTileEntity( xCoord + grinder.offsetX, yCoord + grinder.offsetY, zCoord + grinder.offsetZ ); - if ( te instanceof ICrankable ) - return (ICrankable) te; - return null; - } - - @Override - public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) - { - super.setOrientation( inForward, inUp ); - getBlockType().onNeighborBlockChange( worldObj, xCoord, yCoord, zCoord, Platform.air ); - } - - /** - * return true if this should count towards stats. - */ - public boolean power() - { - if ( Platform.isClient() ) - return false; - - if ( rotation < 3 ) - { - ICrankable g = getGrinder(); - if ( g != null ) - { - if ( g.canTurn() ) - { - hits = 0; - rotation += ticksPerRotation; - this.markForUpdate(); - return true; - } - else - { - hits++; - if ( hits > 10 ) - { - worldObj.func_147480_a( xCoord, yCoord, zCoord, false ); - // worldObj.destroyBlock( xCoord, yCoord, zCoord, false ); - } - } - } - } - - return false; - } - - @Override - public Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean isVisual) - { - double xOff = -0.15 * getUp().offsetX; - double yOff = -0.15 * getUp().offsetY; - double zOff = -0.15 * getUp().offsetZ; - return Arrays - .asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85 ) } ); - } - - @Override - public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) - { - double xOff = -0.15 * getUp().offsetX; - double yOff = -0.15 * getUp().offsetY; - double zOff = -0.15 * getUp().offsetZ; - out.add( AxisAlignedBB.getBoundingBox( xOff + (double) 0.15, yOff + (double) 0.15, zOff + (double) 0.15,// ahh - xOff + (double) 0.85, yOff + (double) 0.85, zOff + (double) 0.85 ) ); - } - - @Override - public boolean requiresTESR() - { - return true; - } -} +package appeng.tile.grindstone; + +import io.netty.buffer.ByteBuf; + +import java.util.Arrays; +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.implementations.tiles.ICrankable; +import appeng.helpers.ICustomCollision; +import appeng.tile.AEBaseTile; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.util.Platform; + +public class TileCrank extends AEBaseTile implements ICustomCollision +{ + + final int ticksPerRotation = 18; + + // sided values.. + public float visibleRotation = 0; + public int charge = 0; + + public int hits = 0; + public int rotation = 0; + + @TileEvent(TileEventType.TICK) + public void Tick_TileCrank() + { + if ( rotation > 0 ) + { + visibleRotation -= 360 / (ticksPerRotation); + charge++; + if ( charge >= ticksPerRotation ) + { + charge -= ticksPerRotation; + ICrankable g = getGrinder(); + if ( g != null ) + g.applyTurn(); + } + + rotation--; + } + } + + @TileEvent(TileEventType.NETWORK_READ) + public boolean readFromStream_TileCrank(ByteBuf data) throws java.io.IOException + { + rotation = data.readInt(); + return false; + } + + @TileEvent(TileEventType.NETWORK_WRITE) + public void writeToStream_TileCrank(ByteBuf data) throws java.io.IOException + { + data.writeInt( rotation ); + } + + public ICrankable getGrinder() + { + if ( Platform.isClient() ) + return null; + + ForgeDirection grinder = getUp().getOpposite(); + TileEntity te = worldObj.getTileEntity( xCoord + grinder.offsetX, yCoord + grinder.offsetY, zCoord + grinder.offsetZ ); + if ( te instanceof ICrankable ) + return (ICrankable) te; + return null; + } + + @Override + public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) + { + super.setOrientation( inForward, inUp ); + getBlockType().onNeighborBlockChange( worldObj, xCoord, yCoord, zCoord, Platform.air ); + } + + /** + * return true if this should count towards stats. + */ + public boolean power() + { + if ( Platform.isClient() ) + return false; + + if ( rotation < 3 ) + { + ICrankable g = getGrinder(); + if ( g != null ) + { + if ( g.canTurn() ) + { + hits = 0; + rotation += ticksPerRotation; + this.markForUpdate(); + return true; + } + else + { + hits++; + if ( hits > 10 ) + { + worldObj.func_147480_a( xCoord, yCoord, zCoord, false ); + // worldObj.destroyBlock( xCoord, yCoord, zCoord, false ); + } + } + } + } + + return false; + } + + @Override + public Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean isVisual) + { + double xOff = -0.15 * getUp().offsetX; + double yOff = -0.15 * getUp().offsetY; + double zOff = -0.15 * getUp().offsetZ; + return Arrays + .asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85 ) } ); + } + + @Override + public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) + { + double xOff = -0.15 * getUp().offsetX; + double yOff = -0.15 * getUp().offsetY; + double zOff = -0.15 * getUp().offsetZ; + out.add( AxisAlignedBB.getBoundingBox( xOff + (double) 0.15, yOff + (double) 0.15, zOff + (double) 0.15,// ahh + xOff + (double) 0.85, yOff + (double) 0.85, zOff + (double) 0.85 ) ); + } + + @Override + public boolean requiresTESR() + { + return true; + } +} diff --git a/tile/grindstone/TileGrinder.java b/src/main/java/appeng/tile/grindstone/TileGrinder.java similarity index 96% rename from tile/grindstone/TileGrinder.java rename to src/main/java/appeng/tile/grindstone/TileGrinder.java index 1702eb0f1..a47a1c034 100644 --- a/tile/grindstone/TileGrinder.java +++ b/src/main/java/appeng/tile/grindstone/TileGrinder.java @@ -1,164 +1,164 @@ -package appeng.tile.grindstone; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.features.IGrinderEntry; -import appeng.api.implementations.tiles.ICrankable; -import appeng.api.util.WorldCoord; -import appeng.tile.AEBaseInvTile; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.WrapperInventoryRange; - -public class TileGrinder extends AEBaseInvTile implements ICrankable -{ - - int points; - - final int inputs[] = new int[] { 0, 1, 2 }; - final int sides[] = new int[] { 0, 1, 2, 3, 4, 5 }; - AppEngInternalInventory inv = new AppEngInternalInventory( this, 7 ); - - @Override - public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) - { - super.setOrientation( inForward, inUp ); - getBlockType().onNeighborBlockChange( worldObj, xCoord, yCoord, zCoord, Platform.air ); - } - - private void addItem(InventoryAdaptor sia, ItemStack output) - { - if ( output == null ) - return; - - ItemStack notAdded = sia.addItems( output ); - if ( notAdded != null ) - { - WorldCoord wc = new WorldCoord( xCoord, yCoord, zCoord ); - - wc.add( getForward(), 1 ); - - List out = new ArrayList(); - out.add( notAdded ); - - Platform.spawnDrops( worldObj, wc.x, wc.y, wc.z, out ); - } - } - - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) - { - if ( AEApi.instance().registries().grinder().getRecipeForInput( itemstack ) == null ) - return false; - - return i >= 0 && i <= 2; - } - - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) - { - return i >= 3 && i <= 5; - } - - @Override - public IInventory getInternalInventory() - { - return inv; - } - - @Override - public int[] getAccessibleSlotsBySide(ForgeDirection side) - { - return sides; - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) - { - - } - - @Override - public boolean canTurn() - { - if ( Platform.isClient() ) - return false; - - if ( null == this.getStackInSlot( 6 ) ) // Add if there isn't one... - { - IInventory src = new WrapperInventoryRange( this, inputs, true ); - for (int x = 0; x < src.getSizeInventory(); x++) - { - ItemStack item = src.getStackInSlot( x ); - if ( item == null ) - continue; - - IGrinderEntry r = AEApi.instance().registries().grinder().getRecipeForInput( item ); - if ( r != null ) - { - if ( item.stackSize >= r.getInput().stackSize ) - { - item.stackSize -= r.getInput().stackSize; - ItemStack ais = item.copy(); - ais.stackSize = r.getInput().stackSize; - - if ( item.stackSize <= 0 ) - item = null; - - src.setInventorySlotContents( x, item ); - this.setInventorySlotContents( 6, ais ); - return true; - } - } - } - return false; - } - return true; - } - - @Override - public void applyTurn() - { - if ( Platform.isClient() ) - return; - - points++; - - ItemStack processing = this.getStackInSlot( 6 ); - IGrinderEntry r = AEApi.instance().registries().grinder().getRecipeForInput( processing ); - if ( r != null ) - { - if ( r.getEnergyCost() > points ) - return; - - points = 0; - InventoryAdaptor sia = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this, 3, 3, true ), ForgeDirection.EAST ); - - addItem( sia, r.getOutput() ); - - float chance = (Platform.getRandomInt() % 2000) / 2000.0f; - if ( chance <= r.getOptionalChance() ) - addItem( sia, r.getOptionalOutput() ); - - chance = (Platform.getRandomInt() % 2000) / 2000.0f; - if ( chance <= r.getSecondOptionalChance() ) - addItem( sia, r.getSecondOptionalOutput() ); - - this.setInventorySlotContents( 6, null ); - } - } - - @Override - public boolean canCrankAttach(ForgeDirection directionToCrank) - { - return getUp().equals( directionToCrank ); - } - -} +package appeng.tile.grindstone; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.features.IGrinderEntry; +import appeng.api.implementations.tiles.ICrankable; +import appeng.api.util.WorldCoord; +import appeng.tile.AEBaseInvTile; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.tile.inventory.InvOperation; +import appeng.util.InventoryAdaptor; +import appeng.util.Platform; +import appeng.util.inv.WrapperInventoryRange; + +public class TileGrinder extends AEBaseInvTile implements ICrankable +{ + + int points; + + final int inputs[] = new int[] { 0, 1, 2 }; + final int sides[] = new int[] { 0, 1, 2, 3, 4, 5 }; + AppEngInternalInventory inv = new AppEngInternalInventory( this, 7 ); + + @Override + public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) + { + super.setOrientation( inForward, inUp ); + getBlockType().onNeighborBlockChange( worldObj, xCoord, yCoord, zCoord, Platform.air ); + } + + private void addItem(InventoryAdaptor sia, ItemStack output) + { + if ( output == null ) + return; + + ItemStack notAdded = sia.addItems( output ); + if ( notAdded != null ) + { + WorldCoord wc = new WorldCoord( xCoord, yCoord, zCoord ); + + wc.add( getForward(), 1 ); + + List out = new ArrayList(); + out.add( notAdded ); + + Platform.spawnDrops( worldObj, wc.x, wc.y, wc.z, out ); + } + } + + @Override + public boolean canInsertItem(int i, ItemStack itemstack, int j) + { + if ( AEApi.instance().registries().grinder().getRecipeForInput( itemstack ) == null ) + return false; + + return i >= 0 && i <= 2; + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) + { + return i >= 3 && i <= 5; + } + + @Override + public IInventory getInternalInventory() + { + return inv; + } + + @Override + public int[] getAccessibleSlotsBySide(ForgeDirection side) + { + return sides; + } + + @Override + public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) + { + + } + + @Override + public boolean canTurn() + { + if ( Platform.isClient() ) + return false; + + if ( null == this.getStackInSlot( 6 ) ) // Add if there isn't one... + { + IInventory src = new WrapperInventoryRange( this, inputs, true ); + for (int x = 0; x < src.getSizeInventory(); x++) + { + ItemStack item = src.getStackInSlot( x ); + if ( item == null ) + continue; + + IGrinderEntry r = AEApi.instance().registries().grinder().getRecipeForInput( item ); + if ( r != null ) + { + if ( item.stackSize >= r.getInput().stackSize ) + { + item.stackSize -= r.getInput().stackSize; + ItemStack ais = item.copy(); + ais.stackSize = r.getInput().stackSize; + + if ( item.stackSize <= 0 ) + item = null; + + src.setInventorySlotContents( x, item ); + this.setInventorySlotContents( 6, ais ); + return true; + } + } + } + return false; + } + return true; + } + + @Override + public void applyTurn() + { + if ( Platform.isClient() ) + return; + + points++; + + ItemStack processing = this.getStackInSlot( 6 ); + IGrinderEntry r = AEApi.instance().registries().grinder().getRecipeForInput( processing ); + if ( r != null ) + { + if ( r.getEnergyCost() > points ) + return; + + points = 0; + InventoryAdaptor sia = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this, 3, 3, true ), ForgeDirection.EAST ); + + addItem( sia, r.getOutput() ); + + float chance = (Platform.getRandomInt() % 2000) / 2000.0f; + if ( chance <= r.getOptionalChance() ) + addItem( sia, r.getOptionalOutput() ); + + chance = (Platform.getRandomInt() % 2000) / 2000.0f; + if ( chance <= r.getSecondOptionalChance() ) + addItem( sia, r.getSecondOptionalOutput() ); + + this.setInventorySlotContents( 6, null ); + } + } + + @Override + public boolean canCrankAttach(ForgeDirection directionToCrank) + { + return getUp().equals( directionToCrank ); + } + +} diff --git a/tile/inventory/AppEngInternalAEInventory.java b/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java similarity index 100% rename from tile/inventory/AppEngInternalAEInventory.java rename to src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java diff --git a/tile/inventory/AppEngInternalInventory.java b/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java similarity index 94% rename from tile/inventory/AppEngInternalInventory.java rename to src/main/java/appeng/tile/inventory/AppEngInternalInventory.java index 0b41c4e37..8eb075ce5 100644 --- a/tile/inventory/AppEngInternalInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngInternalInventory.java @@ -1,256 +1,256 @@ -package appeng.tile.inventory; - -import java.util.Iterator; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import appeng.api.storage.IMEInventory; -import appeng.core.AELog; -import appeng.me.storage.MEIInventoryWrapper; -import appeng.util.Platform; -import appeng.util.iterators.InvIterator; - -public class AppEngInternalInventory implements IInventory, Iterable -{ - - protected IAEAppEngInventory te; - protected int size; - protected int maxStack; - - public boolean enableClientEvents = false; - protected ItemStack inv[]; - - public IMEInventory getIMEI() - { - return new MEIInventoryWrapper( this, null ); - } - - public boolean isEmpty() - { - for (int x = 0; x < getSizeInventory(); x++) - if ( getStackInSlot( x ) != null ) - return false; - return true; - } - - public AppEngInternalInventory(IAEAppEngInventory _te, int s) { - te = _te; - size = s; - maxStack = 64; - inv = new ItemStack[s]; - } - - protected boolean eventsEnabled() - { - return Platform.isServer() || enableClientEvents; - } - - public void setMaxStackSize(int s) - { - maxStack = s; - } - - @Override - public ItemStack getStackInSlot(int var1) - { - return inv[var1]; - } - - @Override - public ItemStack decrStackSize(int slot, int qty) - { - if ( inv[slot] != null ) - { - ItemStack split = getStackInSlot( slot ); - ItemStack ns = null; - - if ( qty >= split.stackSize ) - { - ns = inv[slot]; - inv[slot] = null; - } - else - ns = split.splitStack( qty ); - - if ( te != null && eventsEnabled() ) - { - te.onChangeInventory( this, slot, InvOperation.decrStackSize, ns, null ); - } - - markDirty(); - return ns; - } - - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int var1) - { - return null; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack newItemStack) - { - ItemStack oldStack = inv[slot]; - inv[slot] = newItemStack; - - if ( te != null && eventsEnabled() ) - { - ItemStack removed = oldStack; - ItemStack added = newItemStack; - - if ( oldStack != null && newItemStack != null && Platform.isSameItem( oldStack, newItemStack ) ) - { - if ( oldStack.stackSize > newItemStack.stackSize ) - { - removed = removed.copy(); - removed.stackSize -= newItemStack.stackSize; - added = null; - } - else if ( oldStack.stackSize < newItemStack.stackSize ) - { - added = added.copy(); - added.stackSize -= oldStack.stackSize; - removed = null; - } - else - { - removed = added = null; - } - } - - te.onChangeInventory( this, slot, InvOperation.setInventorySlotContents, removed, added ); - - markDirty(); - } - } - - @Override - public void markDirty() - { - if ( te != null && eventsEnabled() ) - { - te.onChangeInventory( this, -1, InvOperation.markDirty, null, null ); - } - } - - // for guis... - public void markDirty(int slotIndex) - { - if ( te != null && eventsEnabled() ) - { - te.onChangeInventory( this, slotIndex, InvOperation.markDirty, null, null ); - } - } - - @Override - public int getInventoryStackLimit() - { - return maxStack > 64 ? 64 : maxStack; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer var1) - { - return true; - } - - @Override - public void closeInventory() - { - } - - @Override - public void openInventory() - { - } - - public void writeToNBT(NBTTagCompound target) - { - for (int x = 0; x < size; x++) - { - try - { - NBTTagCompound c = new NBTTagCompound(); - - if ( inv[x] != null ) - { - inv[x].writeToNBT( c ); - } - - target.setTag( "#" + x, c ); - } - catch (Exception err) - { - } - } - } - - public void readFromNBT(NBTTagCompound target) - { - for (int x = 0; x < size; x++) - { - try - { - NBTTagCompound c = target.getCompoundTag( "#" + x ); - - if ( c != null ) - inv[x] = ItemStack.loadItemStackFromNBT( c ); - - } - catch (Exception e) - { - AELog.error( e ); - } - } - } - - public void writeToNBT(NBTTagCompound data, String name) - { - NBTTagCompound c = new NBTTagCompound(); - writeToNBT( c ); - data.setTag( name, c ); - } - - public void readFromNBT(NBTTagCompound data, String name) - { - NBTTagCompound c = data.getCompoundTag( name ); - if ( c != null ) - readFromNBT( c ); - } - - @Override - public int getSizeInventory() - { - return size; - } - - @Override - public String getInventoryName() - { - return "appeng-internal"; - } - - @Override - public boolean hasCustomInventoryName() - { - return false; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) - { - return true; - } - - @Override - public Iterator iterator() - { - return new InvIterator( this ); - } - -} +package appeng.tile.inventory; + +import java.util.Iterator; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import appeng.api.storage.IMEInventory; +import appeng.core.AELog; +import appeng.me.storage.MEIInventoryWrapper; +import appeng.util.Platform; +import appeng.util.iterators.InvIterator; + +public class AppEngInternalInventory implements IInventory, Iterable +{ + + protected IAEAppEngInventory te; + protected int size; + protected int maxStack; + + public boolean enableClientEvents = false; + protected ItemStack inv[]; + + public IMEInventory getIMEI() + { + return new MEIInventoryWrapper( this, null ); + } + + public boolean isEmpty() + { + for (int x = 0; x < getSizeInventory(); x++) + if ( getStackInSlot( x ) != null ) + return false; + return true; + } + + public AppEngInternalInventory(IAEAppEngInventory _te, int s) { + te = _te; + size = s; + maxStack = 64; + inv = new ItemStack[s]; + } + + protected boolean eventsEnabled() + { + return Platform.isServer() || enableClientEvents; + } + + public void setMaxStackSize(int s) + { + maxStack = s; + } + + @Override + public ItemStack getStackInSlot(int var1) + { + return inv[var1]; + } + + @Override + public ItemStack decrStackSize(int slot, int qty) + { + if ( inv[slot] != null ) + { + ItemStack split = getStackInSlot( slot ); + ItemStack ns = null; + + if ( qty >= split.stackSize ) + { + ns = inv[slot]; + inv[slot] = null; + } + else + ns = split.splitStack( qty ); + + if ( te != null && eventsEnabled() ) + { + te.onChangeInventory( this, slot, InvOperation.decrStackSize, ns, null ); + } + + markDirty(); + return ns; + } + + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(int var1) + { + return null; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack newItemStack) + { + ItemStack oldStack = inv[slot]; + inv[slot] = newItemStack; + + if ( te != null && eventsEnabled() ) + { + ItemStack removed = oldStack; + ItemStack added = newItemStack; + + if ( oldStack != null && newItemStack != null && Platform.isSameItem( oldStack, newItemStack ) ) + { + if ( oldStack.stackSize > newItemStack.stackSize ) + { + removed = removed.copy(); + removed.stackSize -= newItemStack.stackSize; + added = null; + } + else if ( oldStack.stackSize < newItemStack.stackSize ) + { + added = added.copy(); + added.stackSize -= oldStack.stackSize; + removed = null; + } + else + { + removed = added = null; + } + } + + te.onChangeInventory( this, slot, InvOperation.setInventorySlotContents, removed, added ); + + markDirty(); + } + } + + @Override + public void markDirty() + { + if ( te != null && eventsEnabled() ) + { + te.onChangeInventory( this, -1, InvOperation.markDirty, null, null ); + } + } + + // for guis... + public void markDirty(int slotIndex) + { + if ( te != null && eventsEnabled() ) + { + te.onChangeInventory( this, slotIndex, InvOperation.markDirty, null, null ); + } + } + + @Override + public int getInventoryStackLimit() + { + return maxStack > 64 ? 64 : maxStack; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer var1) + { + return true; + } + + @Override + public void closeInventory() + { + } + + @Override + public void openInventory() + { + } + + public void writeToNBT(NBTTagCompound target) + { + for (int x = 0; x < size; x++) + { + try + { + NBTTagCompound c = new NBTTagCompound(); + + if ( inv[x] != null ) + { + inv[x].writeToNBT( c ); + } + + target.setTag( "#" + x, c ); + } + catch (Exception err) + { + } + } + } + + public void readFromNBT(NBTTagCompound target) + { + for (int x = 0; x < size; x++) + { + try + { + NBTTagCompound c = target.getCompoundTag( "#" + x ); + + if ( c != null ) + inv[x] = ItemStack.loadItemStackFromNBT( c ); + + } + catch (Exception e) + { + AELog.error( e ); + } + } + } + + public void writeToNBT(NBTTagCompound data, String name) + { + NBTTagCompound c = new NBTTagCompound(); + writeToNBT( c ); + data.setTag( name, c ); + } + + public void readFromNBT(NBTTagCompound data, String name) + { + NBTTagCompound c = data.getCompoundTag( name ); + if ( c != null ) + readFromNBT( c ); + } + + @Override + public int getSizeInventory() + { + return size; + } + + @Override + public String getInventoryName() + { + return "appeng-internal"; + } + + @Override + public boolean hasCustomInventoryName() + { + return false; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) + { + return true; + } + + @Override + public Iterator iterator() + { + return new InvIterator( this ); + } + +} diff --git a/tile/inventory/AppEngNullInventory.java b/src/main/java/appeng/tile/inventory/AppEngNullInventory.java similarity index 93% rename from tile/inventory/AppEngNullInventory.java rename to src/main/java/appeng/tile/inventory/AppEngNullInventory.java index 8a4e539e1..41632842e 100644 --- a/tile/inventory/AppEngNullInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngNullInventory.java @@ -1,94 +1,94 @@ -package appeng.tile.inventory; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -public class AppEngNullInventory implements IInventory -{ - - public AppEngNullInventory() { - } - - @Override - public ItemStack getStackInSlot(int var1) - { - return null; - } - - @Override - public ItemStack decrStackSize(int slot, int qty) - { - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int var1) - { - return null; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack newItemStack) - { - - } - - @Override - public void markDirty() - { - - } - - @Override - public int getInventoryStackLimit() - { - return 0; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer var1) - { - return false; - } - - @Override - public void openInventory() - { - } - - @Override - public void closeInventory() - { - } - - public void writeToNBT(NBTTagCompound target) - { - } - - @Override - public int getSizeInventory() - { - return 0; - } - - @Override - public String getInventoryName() - { - return "appeng-internal"; - } - - @Override - public boolean hasCustomInventoryName() - { - return false; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) - { - return false; - } - -} +package appeng.tile.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class AppEngNullInventory implements IInventory +{ + + public AppEngNullInventory() { + } + + @Override + public ItemStack getStackInSlot(int var1) + { + return null; + } + + @Override + public ItemStack decrStackSize(int slot, int qty) + { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(int var1) + { + return null; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack newItemStack) + { + + } + + @Override + public void markDirty() + { + + } + + @Override + public int getInventoryStackLimit() + { + return 0; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer var1) + { + return false; + } + + @Override + public void openInventory() + { + } + + @Override + public void closeInventory() + { + } + + public void writeToNBT(NBTTagCompound target) + { + } + + @Override + public int getSizeInventory() + { + return 0; + } + + @Override + public String getInventoryName() + { + return "appeng-internal"; + } + + @Override + public boolean hasCustomInventoryName() + { + return false; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) + { + return false; + } + +} diff --git a/tile/inventory/IAEAppEngInventory.java b/src/main/java/appeng/tile/inventory/IAEAppEngInventory.java similarity index 95% rename from tile/inventory/IAEAppEngInventory.java rename to src/main/java/appeng/tile/inventory/IAEAppEngInventory.java index a0d9bc6ca..b76823ebd 100644 --- a/tile/inventory/IAEAppEngInventory.java +++ b/src/main/java/appeng/tile/inventory/IAEAppEngInventory.java @@ -1,13 +1,13 @@ -package appeng.tile.inventory; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public interface IAEAppEngInventory -{ - - void saveChanges(); - - void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack); - -} +package appeng.tile.inventory; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public interface IAEAppEngInventory +{ + + void saveChanges(); + + void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack); + +} diff --git a/tile/inventory/InvOperation.java b/src/main/java/appeng/tile/inventory/InvOperation.java similarity index 94% rename from tile/inventory/InvOperation.java rename to src/main/java/appeng/tile/inventory/InvOperation.java index 1b827e137..d417f1535 100644 --- a/tile/inventory/InvOperation.java +++ b/src/main/java/appeng/tile/inventory/InvOperation.java @@ -1,7 +1,7 @@ -package appeng.tile.inventory; - -public enum InvOperation -{ - decrStackSize, setInventorySlotContents, markDirty - -} +package appeng.tile.inventory; + +public enum InvOperation +{ + decrStackSize, setInventorySlotContents, markDirty + +} diff --git a/tile/misc/TileCellWorkbench.java b/src/main/java/appeng/tile/misc/TileCellWorkbench.java similarity index 100% rename from tile/misc/TileCellWorkbench.java rename to src/main/java/appeng/tile/misc/TileCellWorkbench.java diff --git a/tile/misc/TileCharger.java b/src/main/java/appeng/tile/misc/TileCharger.java similarity index 96% rename from tile/misc/TileCharger.java rename to src/main/java/appeng/tile/misc/TileCharger.java index 077c3f675..a01523751 100644 --- a/tile/misc/TileCharger.java +++ b/src/main/java/appeng/tile/misc/TileCharger.java @@ -1,245 +1,245 @@ -package appeng.tile.misc; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.PowerUnits; -import appeng.api.implementations.items.IAEItemPowerStorage; -import appeng.api.implementations.tiles.ICrankable; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalCoord; -import appeng.me.GridAccessException; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.tile.grid.AENetworkPowerTile; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.Platform; -import appeng.util.item.AEItemStack; - -public class TileCharger extends AENetworkPowerTile implements ICrankable -{ - - final int sides[] = new int[] { 0 }; - AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 ); - int tickTickTimer = 0; - - int lastUpdate = 0; - boolean requiresUpdate = false; - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.COVERED; - } - - @TileEvent(TileEventType.NETWORK_READ) - public boolean readFromStream_TileCharger(ByteBuf data) throws IOException - { - try - { - IAEItemStack item = AEItemStack.loadItemStackFromPacket( data ); - ItemStack is = item.getItemStack(); - inv.setInventorySlotContents( 0, is ); - } - catch (Throwable t) - { - inv.setInventorySlotContents( 0, null ); - } - return false; // TESR doesn't need updates! - } - - @TileEvent(TileEventType.NETWORK_WRITE) - public void writeToStream_TileCharger(ByteBuf data) throws IOException - { - AEItemStack is = AEItemStack.create( getStackInSlot( 0 ) ); - if ( is != null ) - is.writeToPacket( data ); - } - - @TileEvent(TileEventType.TICK) - public void Tick_TileCharger() - { - if ( lastUpdate > 60 && requiresUpdate ) - { - requiresUpdate = false; - markForUpdate(); - lastUpdate = 0; - } - lastUpdate++; - - tickTickTimer++; - if ( tickTickTimer < 20 ) - return; - tickTickTimer = 0; - - ItemStack myItem = getStackInSlot( 0 ); - - // charge from the network! - if ( internalCurrentPower < 1499 ) - { - try - { - injectExternalPower( PowerUnits.AE, - gridProxy.getEnergy().extractAEPower( Math.min( 150.0, 1500.0 - internalCurrentPower ), Actionable.MODULATE, PowerMultiplier.ONE ) ); - tickTickTimer = 20; // keep ticking... - } - catch (GridAccessException e) - { - // continue! - } - } - - if ( myItem == null ) - return; - - if ( internalCurrentPower > 149 && Platform.isChargeable( myItem ) ) - { - IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem(); - if ( ps.getAEMaxPower( myItem ) > ps.getAECurrentPower( myItem ) ) - { - double oldPower = internalCurrentPower; - - double adjustment = ps.injectAEPower( myItem, extractAEPower( 150.0, Actionable.MODULATE, PowerMultiplier.CONFIG ) ); - internalCurrentPower += adjustment; - if ( oldPower > internalCurrentPower ) - requiresUpdate = true; - tickTickTimer = 20; // keep ticking... - } - } - else if ( internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) ) - { - if ( Platform.getRandomFloat() > 0.8f ) // simulate wait - { - extractAEPower( internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500 - setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) ); - } - } - } - - public TileCharger() { - gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); - gridProxy.setFlags(); - internalMaxPower = 1500; - gridProxy.setIdlePowerUsage( 0 ); - } - - @Override - public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) - { - super.setOrientation( inForward, inUp ); - gridProxy.setValidSides( EnumSet.of( getUp(), getUp().getOpposite() ) ); - setPowerSides( EnumSet.of( getUp(), getUp().getOpposite() ) ); - } - - @Override - public boolean canTurn() - { - return internalCurrentPower < internalMaxPower; - } - - @Override - public void applyTurn() - { - injectExternalPower( PowerUnits.AE, 150 ); - - ItemStack myItem = getStackInSlot( 0 ); - if ( internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) ) - { - extractAEPower( internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500 - setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) ); - } - } - - @Override - public boolean canCrankAttach(ForgeDirection directionToCrank) - { - return getUp().equals( directionToCrank ) || getUp().getOpposite().equals( directionToCrank ); - } - - @Override - public IInventory getInternalInventory() - { - return inv; - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) - { - markForUpdate(); - } - - @Override - public int[] getAccessibleSlotsBySide(ForgeDirection whichSide) - { - return sides; - } - - @Override - public int getInventoryStackLimit() - { - return 1; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) - { - return Platform.isChargeable( itemstack ) || AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( itemstack ); - } - - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) - { - if ( Platform.isChargeable( itemstack ) ) - { - IAEItemPowerStorage ips = (IAEItemPowerStorage) itemstack.getItem(); - if ( ips.getAECurrentPower( itemstack ) >= ips.getAEMaxPower( itemstack ) ) - return true; - } - - return AEApi.instance().materials().materialCertusQuartzCrystalCharged.sameAsStack( itemstack ); - } - - public void activate(EntityPlayer player) - { - if ( !Platform.hasPermissions( new DimensionalCoord( this ), player ) ) - return; - - ItemStack myItem = getStackInSlot( 0 ); - if ( myItem == null ) - { - ItemStack held = player.inventory.getCurrentItem(); - if ( AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( held ) || Platform.isChargeable( held ) ) - { - held = player.inventory.decrStackSize( player.inventory.currentItem, 1 ); - setInventorySlotContents( 0, held ); - } - } - else - { - List drops = new ArrayList(); - drops.add( myItem ); - setInventorySlotContents( 0, null ); - Platform.spawnDrops( worldObj, xCoord + getForward().offsetX, yCoord + getForward().offsetY, zCoord + getForward().offsetZ, drops ); - } - } - - @Override - public boolean requiresTESR() - { - return true; - } - -} +package appeng.tile.misc; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.config.PowerUnits; +import appeng.api.implementations.items.IAEItemPowerStorage; +import appeng.api.implementations.tiles.ICrankable; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.util.AECableType; +import appeng.api.util.DimensionalCoord; +import appeng.me.GridAccessException; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.tile.grid.AENetworkPowerTile; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.tile.inventory.InvOperation; +import appeng.util.Platform; +import appeng.util.item.AEItemStack; + +public class TileCharger extends AENetworkPowerTile implements ICrankable +{ + + final int sides[] = new int[] { 0 }; + AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 ); + int tickTickTimer = 0; + + int lastUpdate = 0; + boolean requiresUpdate = false; + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.COVERED; + } + + @TileEvent(TileEventType.NETWORK_READ) + public boolean readFromStream_TileCharger(ByteBuf data) throws IOException + { + try + { + IAEItemStack item = AEItemStack.loadItemStackFromPacket( data ); + ItemStack is = item.getItemStack(); + inv.setInventorySlotContents( 0, is ); + } + catch (Throwable t) + { + inv.setInventorySlotContents( 0, null ); + } + return false; // TESR doesn't need updates! + } + + @TileEvent(TileEventType.NETWORK_WRITE) + public void writeToStream_TileCharger(ByteBuf data) throws IOException + { + AEItemStack is = AEItemStack.create( getStackInSlot( 0 ) ); + if ( is != null ) + is.writeToPacket( data ); + } + + @TileEvent(TileEventType.TICK) + public void Tick_TileCharger() + { + if ( lastUpdate > 60 && requiresUpdate ) + { + requiresUpdate = false; + markForUpdate(); + lastUpdate = 0; + } + lastUpdate++; + + tickTickTimer++; + if ( tickTickTimer < 20 ) + return; + tickTickTimer = 0; + + ItemStack myItem = getStackInSlot( 0 ); + + // charge from the network! + if ( internalCurrentPower < 1499 ) + { + try + { + injectExternalPower( PowerUnits.AE, + gridProxy.getEnergy().extractAEPower( Math.min( 150.0, 1500.0 - internalCurrentPower ), Actionable.MODULATE, PowerMultiplier.ONE ) ); + tickTickTimer = 20; // keep ticking... + } + catch (GridAccessException e) + { + // continue! + } + } + + if ( myItem == null ) + return; + + if ( internalCurrentPower > 149 && Platform.isChargeable( myItem ) ) + { + IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem(); + if ( ps.getAEMaxPower( myItem ) > ps.getAECurrentPower( myItem ) ) + { + double oldPower = internalCurrentPower; + + double adjustment = ps.injectAEPower( myItem, extractAEPower( 150.0, Actionable.MODULATE, PowerMultiplier.CONFIG ) ); + internalCurrentPower += adjustment; + if ( oldPower > internalCurrentPower ) + requiresUpdate = true; + tickTickTimer = 20; // keep ticking... + } + } + else if ( internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) ) + { + if ( Platform.getRandomFloat() > 0.8f ) // simulate wait + { + extractAEPower( internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500 + setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) ); + } + } + } + + public TileCharger() { + gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); + gridProxy.setFlags(); + internalMaxPower = 1500; + gridProxy.setIdlePowerUsage( 0 ); + } + + @Override + public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) + { + super.setOrientation( inForward, inUp ); + gridProxy.setValidSides( EnumSet.of( getUp(), getUp().getOpposite() ) ); + setPowerSides( EnumSet.of( getUp(), getUp().getOpposite() ) ); + } + + @Override + public boolean canTurn() + { + return internalCurrentPower < internalMaxPower; + } + + @Override + public void applyTurn() + { + injectExternalPower( PowerUnits.AE, 150 ); + + ItemStack myItem = getStackInSlot( 0 ); + if ( internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) ) + { + extractAEPower( internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500 + setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) ); + } + } + + @Override + public boolean canCrankAttach(ForgeDirection directionToCrank) + { + return getUp().equals( directionToCrank ) || getUp().getOpposite().equals( directionToCrank ); + } + + @Override + public IInventory getInternalInventory() + { + return inv; + } + + @Override + public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) + { + markForUpdate(); + } + + @Override + public int[] getAccessibleSlotsBySide(ForgeDirection whichSide) + { + return sides; + } + + @Override + public int getInventoryStackLimit() + { + return 1; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) + { + return Platform.isChargeable( itemstack ) || AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( itemstack ); + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) + { + if ( Platform.isChargeable( itemstack ) ) + { + IAEItemPowerStorage ips = (IAEItemPowerStorage) itemstack.getItem(); + if ( ips.getAECurrentPower( itemstack ) >= ips.getAEMaxPower( itemstack ) ) + return true; + } + + return AEApi.instance().materials().materialCertusQuartzCrystalCharged.sameAsStack( itemstack ); + } + + public void activate(EntityPlayer player) + { + if ( !Platform.hasPermissions( new DimensionalCoord( this ), player ) ) + return; + + ItemStack myItem = getStackInSlot( 0 ); + if ( myItem == null ) + { + ItemStack held = player.inventory.getCurrentItem(); + if ( AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( held ) || Platform.isChargeable( held ) ) + { + held = player.inventory.decrStackSize( player.inventory.currentItem, 1 ); + setInventorySlotContents( 0, held ); + } + } + else + { + List drops = new ArrayList(); + drops.add( myItem ); + setInventorySlotContents( 0, null ); + Platform.spawnDrops( worldObj, xCoord + getForward().offsetX, yCoord + getForward().offsetY, zCoord + getForward().offsetZ, drops ); + } + } + + @Override + public boolean requiresTESR() + { + return true; + } + +} diff --git a/tile/misc/TileCondenser.java b/src/main/java/appeng/tile/misc/TileCondenser.java similarity index 100% rename from tile/misc/TileCondenser.java rename to src/main/java/appeng/tile/misc/TileCondenser.java diff --git a/tile/misc/TileInscriber.java b/src/main/java/appeng/tile/misc/TileInscriber.java similarity index 96% rename from tile/misc/TileInscriber.java rename to src/main/java/appeng/tile/misc/TileInscriber.java index 6db431b13..2af259bce 100644 --- a/tile/misc/TileInscriber.java +++ b/src/main/java/appeng/tile/misc/TileInscriber.java @@ -1,400 +1,400 @@ -package appeng.tile.misc; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; -import java.util.EnumSet; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.energy.IEnergySource; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.util.AECableType; -import appeng.core.settings.TickRates; -import appeng.me.GridAccessException; -import appeng.recipes.handlers.Inscribe; -import appeng.recipes.handlers.Inscribe.InscriberRecipe; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.tile.grid.AENetworkPowerTile; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.inv.WrapperInventoryRange; -import appeng.util.item.AEItemStack; - -public class TileInscriber extends AENetworkPowerTile implements IGridTickable -{ - - final int top[] = new int[] { 0 }; - final int bottom[] = new int[] { 1 }; - final int sides[] = new int[] { 2, 3 }; - - AppEngInternalInventory inv = new AppEngInternalInventory( this, 4 ); - - public final int maxProcessingTime = 100; - public int processingTime = 0; - - // cycles from 0 - 16, at 8 it preforms the action, at 16 it re-enables the normal routine. - public boolean smash; - public int finalStep; - - public long clientStart; - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.COVERED; - } - - @TileEvent(TileEventType.WORLD_NBT_WRITE) - public void writeToNBT_TileInscriber(NBTTagCompound data) - { - inv.writeToNBT( data, "inscriberInv" ); - } - - @TileEvent(TileEventType.WORLD_NBT_READ) - public void readFromNBT_TileInscriber(NBTTagCompound data) - { - inv.readFromNBT( data, "inscriberInv" ); - } - - @TileEvent(TileEventType.NETWORK_READ) - public boolean readFromStream_TileInscriber(ByteBuf data) throws IOException - { - int slot = data.readByte(); - - boolean oldSmash = smash; - boolean newSmash = (slot & 64) == 64; - - if ( oldSmash != newSmash && newSmash ) - { - smash = true; - clientStart = System.currentTimeMillis(); - } - - for (int num = 0; num < inv.getSizeInventory(); num++) - { - if ( (slot & (1 << num)) > 0 ) - inv.setInventorySlotContents( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() ); - else - inv.setInventorySlotContents( num, null ); - } - - return false; - } - - @TileEvent(TileEventType.NETWORK_WRITE) - public void writeToStream_TileInscriber(ByteBuf data) throws IOException - { - int slot = smash ? 64 : 0; - - for (int num = 0; num < inv.getSizeInventory(); num++) - { - if ( inv.getStackInSlot( num ) != null ) - slot = slot | (1 << num); - } - - data.writeByte( slot ); - for (int num = 0; num < inv.getSizeInventory(); num++) - { - if ( (slot & (1 << num)) > 0 ) - { - AEItemStack st = AEItemStack.create( inv.getStackInSlot( num ) ); - st.writeToPacket( data ); - } - } - } - - @Override - public boolean requiresTESR() - { - return true; - } - - public TileInscriber() { - gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); - internalMaxPower = 1500; - gridProxy.setIdlePowerUsage( 0 ); - } - - @Override - public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) - { - super.setOrientation( inForward, inUp ); - gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( getForward() ) ) ); - setPowerSides( EnumSet.complementOf( EnumSet.of( getForward() ) ) ); - } - - @Override - public IInventory getInternalInventory() - { - return inv; - } - - @Override - public int[] getAccessibleSlotsBySide(ForgeDirection d) - { - if ( d == ForgeDirection.UP ) - return top; - - if ( d == ForgeDirection.DOWN ) - return bottom; - - return sides; - } - - @Override - public int getInventoryStackLimit() - { - return 1; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) - { - if ( smash ) - return false; - - if ( i == 0 || i == 1 ) - { - if ( AEApi.instance().materials().materialNamePress.sameAsStack( itemstack ) ) - return true; - - for (ItemStack s : Inscribe.plates) - if ( Platform.isSameItemPrecise( s, itemstack ) ) - return true; - } - - if ( i == 2 ) - { - return true; - // for (ItemStack s : Inscribe.inputs) - // if ( Platform.isSameItemPrecise( s, itemstack ) ) - // return true; - } - - return false; - } - - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) - { - if ( smash ) - return false; - - return i == 0 || i == 1 || i == 3; - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) - { - try - { - if ( mc != InvOperation.markDirty ) - { - if ( slot != 3 ) - processingTime = 0; - - if ( !smash ) - markForUpdate(); - - gridProxy.getTick().wakeDevice( gridProxy.getNode() ); - } - } - catch (GridAccessException e) - { - // :P - } - } - - public InscriberRecipe getTask() - { - ItemStack PlateA = getStackInSlot( 0 ); - ItemStack PlateB = getStackInSlot( 1 ); - ItemStack renamedItem = getStackInSlot( 2 ); - - if ( PlateA != null && PlateA.stackSize > 1 ) - return null; - - if ( PlateB != null && PlateB.stackSize > 1 ) - return null; - - if ( renamedItem != null && renamedItem.stackSize > 1 ) - return null; - - boolean isNameA = AEApi.instance().materials().materialNamePress.sameAsStack( PlateA ); - boolean isNameB = AEApi.instance().materials().materialNamePress.sameAsStack( PlateB ); - - if ( (isNameA || isNameB) && (isNameA || PlateA == null) && (isNameB || PlateB == null) ) - { - if ( renamedItem != null ) - { - String name = ""; - - if ( PlateA != null ) - { - NBTTagCompound tag = Platform.openNbtData( PlateA ); - name += tag.getString( "InscribeName" ); - } - - if ( PlateB != null ) - { - NBTTagCompound tag = Platform.openNbtData( PlateB ); - if ( name.length() > 0 ) - name += " "; - name += tag.getString( "InscribeName" ); - } - - ItemStack startingItem = renamedItem.copy(); - renamedItem = renamedItem.copy(); - NBTTagCompound tag = Platform.openNbtData( renamedItem ); - - NBTTagCompound display = tag.getCompoundTag( "display" ); - tag.setTag( "display", display ); - - if ( name.length() > 0 ) - display.setString( "Name", name ); - else - display.removeTag( "Name" ); - - return new InscriberRecipe( new ItemStack[] { startingItem }, PlateA, PlateB, renamedItem, false ); - } - } - - for (InscriberRecipe i : Inscribe.recipes) - { - - boolean matchA = (PlateA == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateA, i.plateA )) && // and... - (PlateB == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateB, i.plateB )); - - boolean matchB = (PlateB == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateB, i.plateA )) && // and... - (PlateA == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateA, i.plateB )); - - if ( matchA || matchB ) - { - for (ItemStack option : i.imprintable) - { - if ( Platform.isSameItemPrecise( option, getStackInSlot( 2 ) ) ) - return i; - } - } - - } - return null; - } - - private boolean hasWork() - { - if ( getTask() != null ) - return true; - - processingTime = 0; - return false || smash; - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) - { - return new TickingRequest( TickRates.Inscriber.min, TickRates.Inscriber.max, !hasWork(), false ); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) - { - if ( smash ) - { - finalStep++; - if ( finalStep == 8 ) - { - - InscriberRecipe out = getTask(); - if ( out != null ) - { - ItemStack is = out.output.copy(); - InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( inv, 3, 1, true ), ForgeDirection.UNKNOWN ); - - if ( ad.addItems( is ) == null ) - { - processingTime = 0; - if ( out.usePlates ) - { - setInventorySlotContents( 0, null ); - setInventorySlotContents( 1, null ); - } - setInventorySlotContents( 2, null ); - } - } - - markDirty(); - - } - else if ( finalStep == 16 ) - { - finalStep = 0; - smash = false; - markForUpdate(); - } - } - else - { - IEnergyGrid eg; - try - { - eg = gridProxy.getEnergy(); - IEnergySource src = this; - - double powerReq = extractAEPower( 10, Actionable.SIMULATE, PowerMultiplier.CONFIG ); - - if ( powerReq <= 9.99 ) - { - src = eg; - powerReq = eg.extractAEPower( 10, Actionable.SIMULATE, PowerMultiplier.CONFIG ); - } - - if ( powerReq > 9.99 ) - { - src.extractAEPower( 10, Actionable.MODULATE, PowerMultiplier.CONFIG ); - - if ( processingTime == 0 ) - processingTime++; - else - processingTime += TicksSinceLastCall; - } - } - catch (GridAccessException e) - { - // :P - } - - if ( processingTime > maxProcessingTime ) - { - processingTime = maxProcessingTime; - InscriberRecipe out = getTask(); - if ( out != null ) - { - ItemStack is = out.output.copy(); - InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( inv, 3, 1, true ), ForgeDirection.UNKNOWN ); - if ( ad.simulateAdd( is ) == null ) - { - smash = true; - finalStep = 0; - markForUpdate(); - } - } - } - } - - return hasWork() ? TickRateModulation.URGENT : TickRateModulation.SLEEP; - } -} +package appeng.tile.misc; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.util.EnumSet; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.energy.IEnergySource; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; +import appeng.api.util.AECableType; +import appeng.core.settings.TickRates; +import appeng.me.GridAccessException; +import appeng.recipes.handlers.Inscribe; +import appeng.recipes.handlers.Inscribe.InscriberRecipe; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.tile.grid.AENetworkPowerTile; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.tile.inventory.InvOperation; +import appeng.util.InventoryAdaptor; +import appeng.util.Platform; +import appeng.util.inv.WrapperInventoryRange; +import appeng.util.item.AEItemStack; + +public class TileInscriber extends AENetworkPowerTile implements IGridTickable +{ + + final int top[] = new int[] { 0 }; + final int bottom[] = new int[] { 1 }; + final int sides[] = new int[] { 2, 3 }; + + AppEngInternalInventory inv = new AppEngInternalInventory( this, 4 ); + + public final int maxProcessingTime = 100; + public int processingTime = 0; + + // cycles from 0 - 16, at 8 it preforms the action, at 16 it re-enables the normal routine. + public boolean smash; + public int finalStep; + + public long clientStart; + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.COVERED; + } + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void writeToNBT_TileInscriber(NBTTagCompound data) + { + inv.writeToNBT( data, "inscriberInv" ); + } + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void readFromNBT_TileInscriber(NBTTagCompound data) + { + inv.readFromNBT( data, "inscriberInv" ); + } + + @TileEvent(TileEventType.NETWORK_READ) + public boolean readFromStream_TileInscriber(ByteBuf data) throws IOException + { + int slot = data.readByte(); + + boolean oldSmash = smash; + boolean newSmash = (slot & 64) == 64; + + if ( oldSmash != newSmash && newSmash ) + { + smash = true; + clientStart = System.currentTimeMillis(); + } + + for (int num = 0; num < inv.getSizeInventory(); num++) + { + if ( (slot & (1 << num)) > 0 ) + inv.setInventorySlotContents( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() ); + else + inv.setInventorySlotContents( num, null ); + } + + return false; + } + + @TileEvent(TileEventType.NETWORK_WRITE) + public void writeToStream_TileInscriber(ByteBuf data) throws IOException + { + int slot = smash ? 64 : 0; + + for (int num = 0; num < inv.getSizeInventory(); num++) + { + if ( inv.getStackInSlot( num ) != null ) + slot = slot | (1 << num); + } + + data.writeByte( slot ); + for (int num = 0; num < inv.getSizeInventory(); num++) + { + if ( (slot & (1 << num)) > 0 ) + { + AEItemStack st = AEItemStack.create( inv.getStackInSlot( num ) ); + st.writeToPacket( data ); + } + } + } + + @Override + public boolean requiresTESR() + { + return true; + } + + public TileInscriber() { + gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); + internalMaxPower = 1500; + gridProxy.setIdlePowerUsage( 0 ); + } + + @Override + public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) + { + super.setOrientation( inForward, inUp ); + gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( getForward() ) ) ); + setPowerSides( EnumSet.complementOf( EnumSet.of( getForward() ) ) ); + } + + @Override + public IInventory getInternalInventory() + { + return inv; + } + + @Override + public int[] getAccessibleSlotsBySide(ForgeDirection d) + { + if ( d == ForgeDirection.UP ) + return top; + + if ( d == ForgeDirection.DOWN ) + return bottom; + + return sides; + } + + @Override + public int getInventoryStackLimit() + { + return 1; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) + { + if ( smash ) + return false; + + if ( i == 0 || i == 1 ) + { + if ( AEApi.instance().materials().materialNamePress.sameAsStack( itemstack ) ) + return true; + + for (ItemStack s : Inscribe.plates) + if ( Platform.isSameItemPrecise( s, itemstack ) ) + return true; + } + + if ( i == 2 ) + { + return true; + // for (ItemStack s : Inscribe.inputs) + // if ( Platform.isSameItemPrecise( s, itemstack ) ) + // return true; + } + + return false; + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) + { + if ( smash ) + return false; + + return i == 0 || i == 1 || i == 3; + } + + @Override + public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) + { + try + { + if ( mc != InvOperation.markDirty ) + { + if ( slot != 3 ) + processingTime = 0; + + if ( !smash ) + markForUpdate(); + + gridProxy.getTick().wakeDevice( gridProxy.getNode() ); + } + } + catch (GridAccessException e) + { + // :P + } + } + + public InscriberRecipe getTask() + { + ItemStack PlateA = getStackInSlot( 0 ); + ItemStack PlateB = getStackInSlot( 1 ); + ItemStack renamedItem = getStackInSlot( 2 ); + + if ( PlateA != null && PlateA.stackSize > 1 ) + return null; + + if ( PlateB != null && PlateB.stackSize > 1 ) + return null; + + if ( renamedItem != null && renamedItem.stackSize > 1 ) + return null; + + boolean isNameA = AEApi.instance().materials().materialNamePress.sameAsStack( PlateA ); + boolean isNameB = AEApi.instance().materials().materialNamePress.sameAsStack( PlateB ); + + if ( (isNameA || isNameB) && (isNameA || PlateA == null) && (isNameB || PlateB == null) ) + { + if ( renamedItem != null ) + { + String name = ""; + + if ( PlateA != null ) + { + NBTTagCompound tag = Platform.openNbtData( PlateA ); + name += tag.getString( "InscribeName" ); + } + + if ( PlateB != null ) + { + NBTTagCompound tag = Platform.openNbtData( PlateB ); + if ( name.length() > 0 ) + name += " "; + name += tag.getString( "InscribeName" ); + } + + ItemStack startingItem = renamedItem.copy(); + renamedItem = renamedItem.copy(); + NBTTagCompound tag = Platform.openNbtData( renamedItem ); + + NBTTagCompound display = tag.getCompoundTag( "display" ); + tag.setTag( "display", display ); + + if ( name.length() > 0 ) + display.setString( "Name", name ); + else + display.removeTag( "Name" ); + + return new InscriberRecipe( new ItemStack[] { startingItem }, PlateA, PlateB, renamedItem, false ); + } + } + + for (InscriberRecipe i : Inscribe.recipes) + { + + boolean matchA = (PlateA == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateA, i.plateA )) && // and... + (PlateB == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateB, i.plateB )); + + boolean matchB = (PlateB == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateB, i.plateA )) && // and... + (PlateA == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateA, i.plateB )); + + if ( matchA || matchB ) + { + for (ItemStack option : i.imprintable) + { + if ( Platform.isSameItemPrecise( option, getStackInSlot( 2 ) ) ) + return i; + } + } + + } + return null; + } + + private boolean hasWork() + { + if ( getTask() != null ) + return true; + + processingTime = 0; + return false || smash; + } + + @Override + public TickingRequest getTickingRequest(IGridNode node) + { + return new TickingRequest( TickRates.Inscriber.min, TickRates.Inscriber.max, !hasWork(), false ); + } + + @Override + public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + { + if ( smash ) + { + finalStep++; + if ( finalStep == 8 ) + { + + InscriberRecipe out = getTask(); + if ( out != null ) + { + ItemStack is = out.output.copy(); + InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( inv, 3, 1, true ), ForgeDirection.UNKNOWN ); + + if ( ad.addItems( is ) == null ) + { + processingTime = 0; + if ( out.usePlates ) + { + setInventorySlotContents( 0, null ); + setInventorySlotContents( 1, null ); + } + setInventorySlotContents( 2, null ); + } + } + + markDirty(); + + } + else if ( finalStep == 16 ) + { + finalStep = 0; + smash = false; + markForUpdate(); + } + } + else + { + IEnergyGrid eg; + try + { + eg = gridProxy.getEnergy(); + IEnergySource src = this; + + double powerReq = extractAEPower( 10, Actionable.SIMULATE, PowerMultiplier.CONFIG ); + + if ( powerReq <= 9.99 ) + { + src = eg; + powerReq = eg.extractAEPower( 10, Actionable.SIMULATE, PowerMultiplier.CONFIG ); + } + + if ( powerReq > 9.99 ) + { + src.extractAEPower( 10, Actionable.MODULATE, PowerMultiplier.CONFIG ); + + if ( processingTime == 0 ) + processingTime++; + else + processingTime += TicksSinceLastCall; + } + } + catch (GridAccessException e) + { + // :P + } + + if ( processingTime > maxProcessingTime ) + { + processingTime = maxProcessingTime; + InscriberRecipe out = getTask(); + if ( out != null ) + { + ItemStack is = out.output.copy(); + InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( inv, 3, 1, true ), ForgeDirection.UNKNOWN ); + if ( ad.simulateAdd( is ) == null ) + { + smash = true; + finalStep = 0; + markForUpdate(); + } + } + } + } + + return hasWork() ? TickRateModulation.URGENT : TickRateModulation.SLEEP; + } +} diff --git a/tile/misc/TileInterface.java b/src/main/java/appeng/tile/misc/TileInterface.java similarity index 100% rename from tile/misc/TileInterface.java rename to src/main/java/appeng/tile/misc/TileInterface.java diff --git a/tile/misc/TileLightDetector.java b/src/main/java/appeng/tile/misc/TileLightDetector.java similarity index 100% rename from tile/misc/TileLightDetector.java rename to src/main/java/appeng/tile/misc/TileLightDetector.java diff --git a/tile/misc/TilePaint.java b/src/main/java/appeng/tile/misc/TilePaint.java similarity index 100% rename from tile/misc/TilePaint.java rename to src/main/java/appeng/tile/misc/TilePaint.java diff --git a/tile/misc/TileQuartzGrowthAccelerator.java b/src/main/java/appeng/tile/misc/TileQuartzGrowthAccelerator.java similarity index 100% rename from tile/misc/TileQuartzGrowthAccelerator.java rename to src/main/java/appeng/tile/misc/TileQuartzGrowthAccelerator.java diff --git a/tile/misc/TileSecurity.java b/src/main/java/appeng/tile/misc/TileSecurity.java similarity index 100% rename from tile/misc/TileSecurity.java rename to src/main/java/appeng/tile/misc/TileSecurity.java diff --git a/tile/misc/TileSkyCompass.java b/src/main/java/appeng/tile/misc/TileSkyCompass.java similarity index 100% rename from tile/misc/TileSkyCompass.java rename to src/main/java/appeng/tile/misc/TileSkyCompass.java diff --git a/tile/misc/TileVibrationChamber.java b/src/main/java/appeng/tile/misc/TileVibrationChamber.java similarity index 95% rename from tile/misc/TileVibrationChamber.java rename to src/main/java/appeng/tile/misc/TileVibrationChamber.java index 8a350c7a6..65aba8281 100644 --- a/tile/misc/TileVibrationChamber.java +++ b/src/main/java/appeng/tile/misc/TileVibrationChamber.java @@ -1,253 +1,253 @@ -package appeng.tile.misc; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntityFurnace; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.Actionable; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.ticking.IGridTickable; -import appeng.api.networking.ticking.TickRateModulation; -import appeng.api.networking.ticking.TickingRequest; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalCoord; -import appeng.core.settings.TickRates; -import appeng.me.GridAccessException; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.tile.grid.AENetworkInvTile; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; - -public class TileVibrationChamber extends AENetworkInvTile implements IGridTickable -{ - - final double powerPerTick = 5; - - final int sides[] = new int[] { 0 }; - AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 ); - - public int burnSpeed = 100; - public double burnTime = 0; - public double maxBurnTime = 0; - - // client side.. - public boolean isOn; - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.COVERED; - } - - @TileEvent(TileEventType.NETWORK_READ) - public boolean readFromStream_TileVibrationChamber(ByteBuf data) throws IOException - { - boolean wasOn = isOn; - isOn = data.readBoolean(); - return wasOn != isOn; // TESR doesn't need updates! - } - - @TileEvent(TileEventType.NETWORK_WRITE) - public void writeToStream_TileVibrationChamber(ByteBuf data) throws IOException - { - data.writeBoolean( burnTime > 0 ); - } - - @TileEvent(TileEventType.WORLD_NBT_WRITE) - public void writeToNBT_TileVibrationChamber(NBTTagCompound data) - { - data.setDouble( "burnTime", burnTime ); - data.setDouble( "maxBurnTime", maxBurnTime ); - data.setInteger( "burnSpeed", burnSpeed ); - } - - @TileEvent(TileEventType.WORLD_NBT_READ) - public void readFromNBT_TileVibrationChamber(NBTTagCompound data) - { - burnTime = data.getDouble( "burnTime" ); - maxBurnTime = data.getDouble( "maxBurnTime" ); - burnSpeed = data.getInteger( "burnSpeed" ); - } - - public TileVibrationChamber() { - gridProxy.setIdlePowerUsage( 0 ); - gridProxy.setFlags(); - } - - @Override - public IInventory getInternalInventory() - { - return inv; - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) - { - if ( burnTime <= 0 ) - { - if ( canEatFuel() ) - { - try - { - gridProxy.getTick().wakeDevice( gridProxy.getNode() ); - } - catch (GridAccessException e) - { - // wake up! - } - } - } - } - - @Override - public int[] getAccessibleSlotsBySide(ForgeDirection side) - { - return sides; - } - - @Override - public int getInventoryStackLimit() - { - return 64; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) - { - return TileEntityFurnace.getItemBurnTime( itemstack ) > 0; - } - - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) - { - return false; - } - - @Override - public DimensionalCoord getLocation() - { - return new DimensionalCoord( this ); - } - - @Override - public TickingRequest getTickingRequest(IGridNode node) - { - if ( burnTime <= 0 ) - eatFuel(); - - return new TickingRequest( TickRates.VibrationChamber.min, TickRates.VibrationChamber.max, burnTime <= 0, false ); - } - - @Override - public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) - { - if ( burnTime <= 0 ) - { - eatFuel(); - - if ( burnTime > 0 ) - return TickRateModulation.URGENT; - - burnSpeed = 100; - return TickRateModulation.SLEEP; - } - - burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) ); - double dialiation = burnSpeed / 100.0; - - double timePassed = (double) TicksSinceLastCall * dialiation; - burnTime -= timePassed; - if ( burnTime < 0 ) - { - timePassed += burnTime; - burnTime = 0; - } - - try - { - IEnergyGrid grid = gridProxy.getEnergy(); - double newPower = timePassed * powerPerTick; - double overFlow = grid.injectPower( newPower, Actionable.SIMULATE ); - - // burn the over flow. - grid.injectPower( Math.max( 0.0, newPower - overFlow ), Actionable.MODULATE ); - - if ( overFlow > 0 ) - burnSpeed -= TicksSinceLastCall; - else - burnSpeed += TicksSinceLastCall; - - burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) ); - return overFlow > 0 ? TickRateModulation.SLOWER : TickRateModulation.FASTER; - } - catch (GridAccessException e) - { - burnSpeed -= TicksSinceLastCall; - burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) ); - return TickRateModulation.SLOWER; - } - } - - private boolean canEatFuel() - { - ItemStack is = getStackInSlot( 0 ); - if ( is != null ) - { - int newBurnTime = TileEntityFurnace.getItemBurnTime( is ); - if ( newBurnTime > 0 && is.stackSize > 0 ) - return true; - } - return false; - } - - private void eatFuel() - { - ItemStack is = getStackInSlot( 0 ); - if ( is != null ) - { - int newBurnTime = TileEntityFurnace.getItemBurnTime( is ); - if ( newBurnTime > 0 && is.stackSize > 0 ) - { - burnTime += newBurnTime; - maxBurnTime = burnTime; - is.stackSize--; - if ( is.stackSize <= 0 ) - { - ItemStack container = null; - - if ( is.getItem().hasContainerItem( is ) ) - container = is.getItem().getContainerItem( is ); - - setInventorySlotContents( 0, container ); - } - else - setInventorySlotContents( 0, is ); - } - } - - if ( burnTime > 0 ) - { - try - { - gridProxy.getTick().wakeDevice( gridProxy.getNode() ); - } - catch (GridAccessException e) - { - // gah! - } - } - - if ( (!isOn && burnTime > 0) || (isOn && burnTime <= 0) ) - { - isOn = burnTime > 0; - markForUpdate(); - } - } -} +package appeng.tile.misc; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.Actionable; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.ticking.IGridTickable; +import appeng.api.networking.ticking.TickRateModulation; +import appeng.api.networking.ticking.TickingRequest; +import appeng.api.util.AECableType; +import appeng.api.util.DimensionalCoord; +import appeng.core.settings.TickRates; +import appeng.me.GridAccessException; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.tile.grid.AENetworkInvTile; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.tile.inventory.InvOperation; + +public class TileVibrationChamber extends AENetworkInvTile implements IGridTickable +{ + + final double powerPerTick = 5; + + final int sides[] = new int[] { 0 }; + AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 ); + + public int burnSpeed = 100; + public double burnTime = 0; + public double maxBurnTime = 0; + + // client side.. + public boolean isOn; + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.COVERED; + } + + @TileEvent(TileEventType.NETWORK_READ) + public boolean readFromStream_TileVibrationChamber(ByteBuf data) throws IOException + { + boolean wasOn = isOn; + isOn = data.readBoolean(); + return wasOn != isOn; // TESR doesn't need updates! + } + + @TileEvent(TileEventType.NETWORK_WRITE) + public void writeToStream_TileVibrationChamber(ByteBuf data) throws IOException + { + data.writeBoolean( burnTime > 0 ); + } + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void writeToNBT_TileVibrationChamber(NBTTagCompound data) + { + data.setDouble( "burnTime", burnTime ); + data.setDouble( "maxBurnTime", maxBurnTime ); + data.setInteger( "burnSpeed", burnSpeed ); + } + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void readFromNBT_TileVibrationChamber(NBTTagCompound data) + { + burnTime = data.getDouble( "burnTime" ); + maxBurnTime = data.getDouble( "maxBurnTime" ); + burnSpeed = data.getInteger( "burnSpeed" ); + } + + public TileVibrationChamber() { + gridProxy.setIdlePowerUsage( 0 ); + gridProxy.setFlags(); + } + + @Override + public IInventory getInternalInventory() + { + return inv; + } + + @Override + public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) + { + if ( burnTime <= 0 ) + { + if ( canEatFuel() ) + { + try + { + gridProxy.getTick().wakeDevice( gridProxy.getNode() ); + } + catch (GridAccessException e) + { + // wake up! + } + } + } + } + + @Override + public int[] getAccessibleSlotsBySide(ForgeDirection side) + { + return sides; + } + + @Override + public int getInventoryStackLimit() + { + return 64; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) + { + return TileEntityFurnace.getItemBurnTime( itemstack ) > 0; + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) + { + return false; + } + + @Override + public DimensionalCoord getLocation() + { + return new DimensionalCoord( this ); + } + + @Override + public TickingRequest getTickingRequest(IGridNode node) + { + if ( burnTime <= 0 ) + eatFuel(); + + return new TickingRequest( TickRates.VibrationChamber.min, TickRates.VibrationChamber.max, burnTime <= 0, false ); + } + + @Override + public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) + { + if ( burnTime <= 0 ) + { + eatFuel(); + + if ( burnTime > 0 ) + return TickRateModulation.URGENT; + + burnSpeed = 100; + return TickRateModulation.SLEEP; + } + + burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) ); + double dialiation = burnSpeed / 100.0; + + double timePassed = (double) TicksSinceLastCall * dialiation; + burnTime -= timePassed; + if ( burnTime < 0 ) + { + timePassed += burnTime; + burnTime = 0; + } + + try + { + IEnergyGrid grid = gridProxy.getEnergy(); + double newPower = timePassed * powerPerTick; + double overFlow = grid.injectPower( newPower, Actionable.SIMULATE ); + + // burn the over flow. + grid.injectPower( Math.max( 0.0, newPower - overFlow ), Actionable.MODULATE ); + + if ( overFlow > 0 ) + burnSpeed -= TicksSinceLastCall; + else + burnSpeed += TicksSinceLastCall; + + burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) ); + return overFlow > 0 ? TickRateModulation.SLOWER : TickRateModulation.FASTER; + } + catch (GridAccessException e) + { + burnSpeed -= TicksSinceLastCall; + burnSpeed = Math.max( 20, Math.min( burnSpeed, 200 ) ); + return TickRateModulation.SLOWER; + } + } + + private boolean canEatFuel() + { + ItemStack is = getStackInSlot( 0 ); + if ( is != null ) + { + int newBurnTime = TileEntityFurnace.getItemBurnTime( is ); + if ( newBurnTime > 0 && is.stackSize > 0 ) + return true; + } + return false; + } + + private void eatFuel() + { + ItemStack is = getStackInSlot( 0 ); + if ( is != null ) + { + int newBurnTime = TileEntityFurnace.getItemBurnTime( is ); + if ( newBurnTime > 0 && is.stackSize > 0 ) + { + burnTime += newBurnTime; + maxBurnTime = burnTime; + is.stackSize--; + if ( is.stackSize <= 0 ) + { + ItemStack container = null; + + if ( is.getItem().hasContainerItem( is ) ) + container = is.getItem().getContainerItem( is ); + + setInventorySlotContents( 0, container ); + } + else + setInventorySlotContents( 0, is ); + } + } + + if ( burnTime > 0 ) + { + try + { + gridProxy.getTick().wakeDevice( gridProxy.getNode() ); + } + catch (GridAccessException e) + { + // gah! + } + } + + if ( (!isOn && burnTime > 0) || (isOn && burnTime <= 0) ) + { + isOn = burnTime > 0; + markForUpdate(); + } + } +} diff --git a/tile/networking/TileCableBus.java b/src/main/java/appeng/tile/networking/TileCableBus.java similarity index 95% rename from tile/networking/TileCableBus.java rename to src/main/java/appeng/tile/networking/TileCableBus.java index 21fa24797..64b0c0cc7 100644 --- a/tile/networking/TileCableBus.java +++ b/src/main/java/appeng/tile/networking/TileCableBus.java @@ -1,356 +1,356 @@ -package appeng.tile.networking; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.IGridNode; -import appeng.api.parts.IFacadeContainer; -import appeng.api.parts.IPart; -import appeng.api.parts.LayerFlags; -import appeng.api.parts.SelectedPart; -import appeng.api.util.AECableType; -import appeng.api.util.AEColor; -import appeng.api.util.DimensionalCoord; -import appeng.block.networking.BlockCableBus; -import appeng.core.AppEng; -import appeng.helpers.AEMultiTile; -import appeng.helpers.ICustomCollision; -import appeng.hooks.TickHandler; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.IImmibisMicroblocks; -import appeng.parts.CableBusContainer; -import appeng.tile.AEBaseTile; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.util.Platform; - -public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomCollision -{ - - public CableBusContainer cb = new CableBusContainer( this ); - private int oldLV = -1; // on re-calculate light when it changes - - @TileEvent(TileEventType.WORLD_NBT_READ) - public void readFromNBT_TileCableBus(NBTTagCompound data) - { - cb.readFromNBT( data ); - } - - @TileEvent(TileEventType.WORLD_NBT_WRITE) - public void writeToNBT_TileCableBus(NBTTagCompound data) - { - cb.writeToNBT( data ); - } - - @TileEvent(TileEventType.NETWORK_READ) - public boolean readFromStream_TileCableBus(ByteBuf data) throws IOException - { - boolean ret = cb.readFromStream( data ); - - int newLV = cb.getLightValue(); - if ( newLV != oldLV ) - { - oldLV = newLV; - worldObj.func_147451_t( xCoord, yCoord, zCoord ); - // worldObj.updateAllLightTypes( xCoord, yCoord, zCoord ); - } - - updateTileSetting(); - return ret; - } - - @TileEvent(TileEventType.NETWORK_WRITE) - public void writeToStream_TileCableBus(ByteBuf data) throws IOException - { - cb.writeToStream( data ); - } - - @Override - public boolean isInWorld() - { - return cb.isInWorld(); - } - - protected void updateTileSetting() - { - if ( cb.requiresDynamicRender ) - { - TileCableBus tcb; - try - { - tcb = (TileCableBus) BlockCableBus.tesrTile.newInstance(); - tcb.copyFrom( this ); - getWorldObj().setTileEntity( xCoord, yCoord, zCoord, tcb ); - } - catch (Throwable t) - { - - } - } - } - - protected void copyFrom(TileCableBus oldTile) - { - CableBusContainer tmpCB = cb; - cb = oldTile.cb; - oldLV = oldTile.oldLV; - oldTile.cb = tmpCB; - } - - @Override - public void onReady() - { - super.onReady(); - if ( cb.isEmpty() ) - { - if ( worldObj.getTileEntity( xCoord, yCoord, zCoord ) == this ) - worldObj.func_147480_a( xCoord, yCoord, zCoord, true ); - } - else - cb.addToWorld(); - } - - @Override - public void onChunkUnload() - { - super.onChunkUnload(); - cb.removeFromWorld(); - } - - @Override - public void validate() - { - super.validate(); - TickHandler.instance.addInit( this ); - } - - @Override - public void invalidate() - { - super.invalidate(); - cb.removeFromWorld(); - } - - @Override - public boolean canBeRotated() - { - return false; - } - - @Override - public double getMaxRenderDistanceSquared() - { - return 900.0; - } - - @Override - public void getDrops(World w, int x, int y, int z, ArrayList drops) - { - cb.getDrops( drops ); - } - - public void getNoDrops(World w, int x, int y, int z, ArrayList drops) - { - cb.getNoDrops( drops ); - } - - @Override - public IGridNode getGridNode(ForgeDirection dir) - { - return cb.getGridNode( dir ); - } - - @Override - public boolean canAddPart(ItemStack is, ForgeDirection side) - { - return cb.canAddPart( is, side ); - } - - @Override - public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer player) - { - return cb.addPart( is, side, player ); - } - - @Override - public void removePart(ForgeDirection side, boolean suppressUpdate) - { - cb.removePart( side, suppressUpdate ); - } - - @Override - public IPart getPart(ForgeDirection side) - { - return cb.getPart( side ); - } - - @Override - public DimensionalCoord getLocation() - { - return new DimensionalCoord( this ); - } - - @Override - public TileEntity getTile() - { - return this; - } - - @Override - public Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean visual) - { - return cb.getSelectedBoundingBoxsFromPool( false, true, e, visual ); - } - - @Override - public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) - { - for (AxisAlignedBB bx : getSelectedBoundingBoxesFromPool( w, x, y, z, e, false )) - out.add( AxisAlignedBB.getBoundingBox( bx.minX, bx.minY, bx.minZ, bx.maxX, bx.maxY, bx.maxZ ) ); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection side) - { - return cb.getCableConnectionType( side ); - } - - @Override - public AEColor getColor() - { - return cb.getColor(); - } - - @Override - public IFacadeContainer getFacadeContainer() - { - return cb.getFacadeContainer(); - } - - @Override - public void clearContainer() - { - cb = new CableBusContainer( this ); - } - - @Override - public boolean isBlocked(ForgeDirection side) - { - return !ImmibisMicroblocks_isSideOpen( side.ordinal() ); - } - - @Override - public void markForUpdate() - { - if ( worldObj == null ) - return; - - int newLV = cb.getLightValue(); - if ( newLV != oldLV ) - { - oldLV = newLV; - worldObj.func_147451_t( xCoord, yCoord, zCoord ); - // worldObj.updateAllLightTypes( xCoord, yCoord, zCoord ); - } - - super.markForUpdate(); - } - - @Override - public SelectedPart selectPart(Vec3 pos) - { - return cb.selectPart( pos ); - } - - @Override - public void partChanged() - { - notifyNeighbors(); - } - - @Override - public void notifyNeighbors() - { - if ( worldObj != null && worldObj.blockExists( xCoord, yCoord, zCoord ) && !CableBusContainer.isLoading() ) - Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord ); - } - - @Override - public void markForSave() - { - super.markDirty(); - } - - @Override - public boolean hasRedstone(ForgeDirection side) - { - return cb.hasRedstone( side ); - } - - @Override - public boolean isEmpty() - { - return cb.isEmpty(); - } - - @Override - public boolean requiresTESR() - { - return cb.requiresDynamicRender; - } - - @Override - public Set getLayerFlags() - { - return cb.getLayerFlags(); - } - - @Override - public void cleanup() - { - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.ImmibisMicroblocks ) ) - { - IImmibisMicroblocks imb = (IImmibisMicroblocks) AppEng.instance.getIntegration( IntegrationType.ImmibisMicroblocks ); - if ( imb != null && imb.leaveParts( this ) ) - return; - } - - getWorldObj().setBlock( xCoord, yCoord, zCoord, Platform.air ); - } - - /** - * Immibis MB Support - */ - - boolean ImmibisMicroblocks_TransformableTileEntityMarker = true; - - public boolean ImmibisMicroblocks_isSideOpen(int side) - { - return true; - } - - public void ImmibisMicroblocks_onMicroblocksChanged() - { - cb.updateConnections(); - } - - @Override - public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) - { - return cb.recolourBlock( side, colour, who ); - } - -} +package appeng.tile.networking; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.IGridNode; +import appeng.api.parts.IFacadeContainer; +import appeng.api.parts.IPart; +import appeng.api.parts.LayerFlags; +import appeng.api.parts.SelectedPart; +import appeng.api.util.AECableType; +import appeng.api.util.AEColor; +import appeng.api.util.DimensionalCoord; +import appeng.block.networking.BlockCableBus; +import appeng.core.AppEng; +import appeng.helpers.AEMultiTile; +import appeng.helpers.ICustomCollision; +import appeng.hooks.TickHandler; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.IImmibisMicroblocks; +import appeng.parts.CableBusContainer; +import appeng.tile.AEBaseTile; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.util.Platform; + +public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomCollision +{ + + public CableBusContainer cb = new CableBusContainer( this ); + private int oldLV = -1; // on re-calculate light when it changes + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void readFromNBT_TileCableBus(NBTTagCompound data) + { + cb.readFromNBT( data ); + } + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void writeToNBT_TileCableBus(NBTTagCompound data) + { + cb.writeToNBT( data ); + } + + @TileEvent(TileEventType.NETWORK_READ) + public boolean readFromStream_TileCableBus(ByteBuf data) throws IOException + { + boolean ret = cb.readFromStream( data ); + + int newLV = cb.getLightValue(); + if ( newLV != oldLV ) + { + oldLV = newLV; + worldObj.func_147451_t( xCoord, yCoord, zCoord ); + // worldObj.updateAllLightTypes( xCoord, yCoord, zCoord ); + } + + updateTileSetting(); + return ret; + } + + @TileEvent(TileEventType.NETWORK_WRITE) + public void writeToStream_TileCableBus(ByteBuf data) throws IOException + { + cb.writeToStream( data ); + } + + @Override + public boolean isInWorld() + { + return cb.isInWorld(); + } + + protected void updateTileSetting() + { + if ( cb.requiresDynamicRender ) + { + TileCableBus tcb; + try + { + tcb = (TileCableBus) BlockCableBus.tesrTile.newInstance(); + tcb.copyFrom( this ); + getWorldObj().setTileEntity( xCoord, yCoord, zCoord, tcb ); + } + catch (Throwable t) + { + + } + } + } + + protected void copyFrom(TileCableBus oldTile) + { + CableBusContainer tmpCB = cb; + cb = oldTile.cb; + oldLV = oldTile.oldLV; + oldTile.cb = tmpCB; + } + + @Override + public void onReady() + { + super.onReady(); + if ( cb.isEmpty() ) + { + if ( worldObj.getTileEntity( xCoord, yCoord, zCoord ) == this ) + worldObj.func_147480_a( xCoord, yCoord, zCoord, true ); + } + else + cb.addToWorld(); + } + + @Override + public void onChunkUnload() + { + super.onChunkUnload(); + cb.removeFromWorld(); + } + + @Override + public void validate() + { + super.validate(); + TickHandler.instance.addInit( this ); + } + + @Override + public void invalidate() + { + super.invalidate(); + cb.removeFromWorld(); + } + + @Override + public boolean canBeRotated() + { + return false; + } + + @Override + public double getMaxRenderDistanceSquared() + { + return 900.0; + } + + @Override + public void getDrops(World w, int x, int y, int z, ArrayList drops) + { + cb.getDrops( drops ); + } + + public void getNoDrops(World w, int x, int y, int z, ArrayList drops) + { + cb.getNoDrops( drops ); + } + + @Override + public IGridNode getGridNode(ForgeDirection dir) + { + return cb.getGridNode( dir ); + } + + @Override + public boolean canAddPart(ItemStack is, ForgeDirection side) + { + return cb.canAddPart( is, side ); + } + + @Override + public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer player) + { + return cb.addPart( is, side, player ); + } + + @Override + public void removePart(ForgeDirection side, boolean suppressUpdate) + { + cb.removePart( side, suppressUpdate ); + } + + @Override + public IPart getPart(ForgeDirection side) + { + return cb.getPart( side ); + } + + @Override + public DimensionalCoord getLocation() + { + return new DimensionalCoord( this ); + } + + @Override + public TileEntity getTile() + { + return this; + } + + @Override + public Iterable getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity e, boolean visual) + { + return cb.getSelectedBoundingBoxsFromPool( false, true, e, visual ); + } + + @Override + public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e) + { + for (AxisAlignedBB bx : getSelectedBoundingBoxesFromPool( w, x, y, z, e, false )) + out.add( AxisAlignedBB.getBoundingBox( bx.minX, bx.minY, bx.minZ, bx.maxX, bx.maxY, bx.maxZ ) ); + } + + @Override + public AECableType getCableConnectionType(ForgeDirection side) + { + return cb.getCableConnectionType( side ); + } + + @Override + public AEColor getColor() + { + return cb.getColor(); + } + + @Override + public IFacadeContainer getFacadeContainer() + { + return cb.getFacadeContainer(); + } + + @Override + public void clearContainer() + { + cb = new CableBusContainer( this ); + } + + @Override + public boolean isBlocked(ForgeDirection side) + { + return !ImmibisMicroblocks_isSideOpen( side.ordinal() ); + } + + @Override + public void markForUpdate() + { + if ( worldObj == null ) + return; + + int newLV = cb.getLightValue(); + if ( newLV != oldLV ) + { + oldLV = newLV; + worldObj.func_147451_t( xCoord, yCoord, zCoord ); + // worldObj.updateAllLightTypes( xCoord, yCoord, zCoord ); + } + + super.markForUpdate(); + } + + @Override + public SelectedPart selectPart(Vec3 pos) + { + return cb.selectPart( pos ); + } + + @Override + public void partChanged() + { + notifyNeighbors(); + } + + @Override + public void notifyNeighbors() + { + if ( worldObj != null && worldObj.blockExists( xCoord, yCoord, zCoord ) && !CableBusContainer.isLoading() ) + Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord ); + } + + @Override + public void markForSave() + { + super.markDirty(); + } + + @Override + public boolean hasRedstone(ForgeDirection side) + { + return cb.hasRedstone( side ); + } + + @Override + public boolean isEmpty() + { + return cb.isEmpty(); + } + + @Override + public boolean requiresTESR() + { + return cb.requiresDynamicRender; + } + + @Override + public Set getLayerFlags() + { + return cb.getLayerFlags(); + } + + @Override + public void cleanup() + { + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.ImmibisMicroblocks ) ) + { + IImmibisMicroblocks imb = (IImmibisMicroblocks) AppEng.instance.getIntegration( IntegrationType.ImmibisMicroblocks ); + if ( imb != null && imb.leaveParts( this ) ) + return; + } + + getWorldObj().setBlock( xCoord, yCoord, zCoord, Platform.air ); + } + + /** + * Immibis MB Support + */ + + boolean ImmibisMicroblocks_TransformableTileEntityMarker = true; + + public boolean ImmibisMicroblocks_isSideOpen(int side) + { + return true; + } + + public void ImmibisMicroblocks_onMicroblocksChanged() + { + cb.updateConnections(); + } + + @Override + public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who) + { + return cb.recolourBlock( side, colour, who ); + } + +} diff --git a/tile/networking/TileCableBusTESR.java b/src/main/java/appeng/tile/networking/TileCableBusTESR.java similarity index 100% rename from tile/networking/TileCableBusTESR.java rename to src/main/java/appeng/tile/networking/TileCableBusTESR.java diff --git a/tile/networking/TileController.java b/src/main/java/appeng/tile/networking/TileController.java similarity index 100% rename from tile/networking/TileController.java rename to src/main/java/appeng/tile/networking/TileController.java diff --git a/tile/networking/TileCreativeEnergyCell.java b/src/main/java/appeng/tile/networking/TileCreativeEnergyCell.java similarity index 95% rename from tile/networking/TileCreativeEnergyCell.java rename to src/main/java/appeng/tile/networking/TileCreativeEnergyCell.java index 839f7b28f..06d9967f3 100644 --- a/tile/networking/TileCreativeEnergyCell.java +++ b/src/main/java/appeng/tile/networking/TileCreativeEnergyCell.java @@ -1,60 +1,60 @@ -package appeng.tile.networking; - -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.networking.energy.IAEPowerStorage; -import appeng.api.util.AECableType; -import appeng.tile.grid.AENetworkTile; - -public class TileCreativeEnergyCell extends AENetworkTile implements IAEPowerStorage -{ - - public TileCreativeEnergyCell() { - gridProxy.setIdlePowerUsage( 0 ); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.COVERED; - } - - @Override - public double injectAEPower(double amt, Actionable mode) - { - return 0; - } - - @Override - public double extractAEPower(double amt, Actionable mode, PowerMultiplier pm) - { - return amt; - } - - @Override - public double getAEMaxPower() - { - return Long.MAX_VALUE / 10000; - } - - @Override - public double getAECurrentPower() - { - return Long.MAX_VALUE / 10000; - } - - @Override - public boolean isAEPublicPowerStorage() - { - return true; - } - - @Override - public AccessRestriction getPowerFlow() - { - return AccessRestriction.READ_WRITE; - } - -} +package appeng.tile.networking; + +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.AccessRestriction; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.networking.energy.IAEPowerStorage; +import appeng.api.util.AECableType; +import appeng.tile.grid.AENetworkTile; + +public class TileCreativeEnergyCell extends AENetworkTile implements IAEPowerStorage +{ + + public TileCreativeEnergyCell() { + gridProxy.setIdlePowerUsage( 0 ); + } + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.COVERED; + } + + @Override + public double injectAEPower(double amt, Actionable mode) + { + return 0; + } + + @Override + public double extractAEPower(double amt, Actionable mode, PowerMultiplier pm) + { + return amt; + } + + @Override + public double getAEMaxPower() + { + return Long.MAX_VALUE / 10000; + } + + @Override + public double getAECurrentPower() + { + return Long.MAX_VALUE / 10000; + } + + @Override + public boolean isAEPublicPowerStorage() + { + return true; + } + + @Override + public AccessRestriction getPowerFlow() + { + return AccessRestriction.READ_WRITE; + } + +} diff --git a/tile/networking/TileDenseEnergyCell.java b/src/main/java/appeng/tile/networking/TileDenseEnergyCell.java similarity index 94% rename from tile/networking/TileDenseEnergyCell.java rename to src/main/java/appeng/tile/networking/TileDenseEnergyCell.java index 3442f7abc..26f09bcbc 100644 --- a/tile/networking/TileDenseEnergyCell.java +++ b/src/main/java/appeng/tile/networking/TileDenseEnergyCell.java @@ -1,10 +1,10 @@ -package appeng.tile.networking; - -public class TileDenseEnergyCell extends TileEnergyCell -{ - - public TileDenseEnergyCell() { - internalMaxPower = 200000 * 8; - } - -} +package appeng.tile.networking; + +public class TileDenseEnergyCell extends TileEnergyCell +{ + + public TileDenseEnergyCell() { + internalMaxPower = 200000 * 8; + } + +} diff --git a/tile/networking/TileEnergyAcceptor.java b/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java similarity index 100% rename from tile/networking/TileEnergyAcceptor.java rename to src/main/java/appeng/tile/networking/TileEnergyAcceptor.java diff --git a/tile/networking/TileEnergyCell.java b/src/main/java/appeng/tile/networking/TileEnergyCell.java similarity index 100% rename from tile/networking/TileEnergyCell.java rename to src/main/java/appeng/tile/networking/TileEnergyCell.java diff --git a/tile/networking/TileWireless.java b/src/main/java/appeng/tile/networking/TileWireless.java similarity index 95% rename from tile/networking/TileWireless.java rename to src/main/java/appeng/tile/networking/TileWireless.java index 501343ea9..ea33fc646 100644 --- a/tile/networking/TileWireless.java +++ b/src/main/java/appeng/tile/networking/TileWireless.java @@ -1,182 +1,182 @@ -package appeng.tile.networking; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; -import java.util.EnumSet; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.implementations.IPowerChannelState; -import appeng.api.implementations.tiles.IWirelessAccessPoint; -import appeng.api.networking.GridFlags; -import appeng.api.networking.IGrid; -import appeng.api.networking.events.MENetworkChannelsChanged; -import appeng.api.networking.events.MENetworkEventSubscribe; -import appeng.api.networking.events.MENetworkPowerStatusChange; -import appeng.api.util.AECableType; -import appeng.api.util.DimensionalCoord; -import appeng.core.AEConfig; -import appeng.me.GridAccessException; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.tile.grid.AENetworkInvTile; -import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; -import appeng.util.Platform; - -public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoint, IPowerChannelState -{ - - public static final int POWERED_FLAG = 1; - public static final int CHANNEL_FLAG = 2; - - final int sides[] = new int[] { 0 }; - AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 ); - - public int clientFlags = 0; - - public TileWireless() { - gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL ); - gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); - } - - @Override - public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) - { - super.setOrientation( inForward, inUp ); - gridProxy.setValidSides( EnumSet.of( getForward().getOpposite() ) ); - } - - @MENetworkEventSubscribe - public void chanRender(MENetworkChannelsChanged c) - { - markForUpdate(); - } - - @MENetworkEventSubscribe - public void powerRender(MENetworkPowerStatusChange c) - { - markForUpdate(); - } - - @TileEvent(TileEventType.NETWORK_READ) - public boolean readFromStream_TileWireless(ByteBuf data) throws IOException - { - int old = clientFlags; - clientFlags = data.readByte(); - - return old != clientFlags; - } - - @TileEvent(TileEventType.NETWORK_WRITE) - public void writeToStream_TileWireless(ByteBuf data) throws IOException - { - clientFlags = 0; - - try - { - if ( gridProxy.getEnergy().isNetworkPowered() ) - clientFlags |= POWERED_FLAG; - - if ( gridProxy.getNode().meetsChannelRequirements() ) - clientFlags |= CHANNEL_FLAG; - } - catch (GridAccessException e) - { - // meh - } - - data.writeByte( (byte) clientFlags ); - } - - @Override - public AECableType getCableConnectionType(ForgeDirection dir) - { - return AECableType.SMART; - } - - @Override - public DimensionalCoord getLocation() - { - return new DimensionalCoord( this ); - } - - @Override - public IInventory getInternalInventory() - { - return inv; - } - - @Override - public void onReady() - { - updatePower(); - super.onReady(); - } - - @Override - public void markDirty() - { - updatePower(); - } - - private void updatePower() - { - gridProxy.setIdlePowerUsage( AEConfig.instance.wireless_getPowerDrain( getBoosters() ) ); - } - - @Override - public int[] getAccessibleSlotsBySide(ForgeDirection side) - { - return sides; - } - - @Override - public double getRange() - { - return AEConfig.instance.wireless_getMaxRange( getBoosters() ); - } - - @Override - public boolean isActive() - { - if ( Platform.isClient() ) - return isPowered() && (CHANNEL_FLAG == (clientFlags & CHANNEL_FLAG)); - - return gridProxy.isActive(); - } - - @Override - public IGrid getGrid() - { - try - { - return gridProxy.getGrid(); - } - catch (GridAccessException e) - { - return null; - } - } - - private int getBoosters() - { - ItemStack boosters = inv.getStackInSlot( 0 ); - return boosters == null ? 0 : boosters.stackSize; - } - - @Override - public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) - { - // :P - } - - @Override - public boolean isPowered() - { - return POWERED_FLAG == (clientFlags & POWERED_FLAG); - } - -} +package appeng.tile.networking; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.util.EnumSet; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.implementations.IPowerChannelState; +import appeng.api.implementations.tiles.IWirelessAccessPoint; +import appeng.api.networking.GridFlags; +import appeng.api.networking.IGrid; +import appeng.api.networking.events.MENetworkChannelsChanged; +import appeng.api.networking.events.MENetworkEventSubscribe; +import appeng.api.networking.events.MENetworkPowerStatusChange; +import appeng.api.util.AECableType; +import appeng.api.util.DimensionalCoord; +import appeng.core.AEConfig; +import appeng.me.GridAccessException; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.tile.grid.AENetworkInvTile; +import appeng.tile.inventory.AppEngInternalInventory; +import appeng.tile.inventory.InvOperation; +import appeng.util.Platform; + +public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoint, IPowerChannelState +{ + + public static final int POWERED_FLAG = 1; + public static final int CHANNEL_FLAG = 2; + + final int sides[] = new int[] { 0 }; + AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 ); + + public int clientFlags = 0; + + public TileWireless() { + gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL ); + gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) ); + } + + @Override + public void setOrientation(ForgeDirection inForward, ForgeDirection inUp) + { + super.setOrientation( inForward, inUp ); + gridProxy.setValidSides( EnumSet.of( getForward().getOpposite() ) ); + } + + @MENetworkEventSubscribe + public void chanRender(MENetworkChannelsChanged c) + { + markForUpdate(); + } + + @MENetworkEventSubscribe + public void powerRender(MENetworkPowerStatusChange c) + { + markForUpdate(); + } + + @TileEvent(TileEventType.NETWORK_READ) + public boolean readFromStream_TileWireless(ByteBuf data) throws IOException + { + int old = clientFlags; + clientFlags = data.readByte(); + + return old != clientFlags; + } + + @TileEvent(TileEventType.NETWORK_WRITE) + public void writeToStream_TileWireless(ByteBuf data) throws IOException + { + clientFlags = 0; + + try + { + if ( gridProxy.getEnergy().isNetworkPowered() ) + clientFlags |= POWERED_FLAG; + + if ( gridProxy.getNode().meetsChannelRequirements() ) + clientFlags |= CHANNEL_FLAG; + } + catch (GridAccessException e) + { + // meh + } + + data.writeByte( (byte) clientFlags ); + } + + @Override + public AECableType getCableConnectionType(ForgeDirection dir) + { + return AECableType.SMART; + } + + @Override + public DimensionalCoord getLocation() + { + return new DimensionalCoord( this ); + } + + @Override + public IInventory getInternalInventory() + { + return inv; + } + + @Override + public void onReady() + { + updatePower(); + super.onReady(); + } + + @Override + public void markDirty() + { + updatePower(); + } + + private void updatePower() + { + gridProxy.setIdlePowerUsage( AEConfig.instance.wireless_getPowerDrain( getBoosters() ) ); + } + + @Override + public int[] getAccessibleSlotsBySide(ForgeDirection side) + { + return sides; + } + + @Override + public double getRange() + { + return AEConfig.instance.wireless_getMaxRange( getBoosters() ); + } + + @Override + public boolean isActive() + { + if ( Platform.isClient() ) + return isPowered() && (CHANNEL_FLAG == (clientFlags & CHANNEL_FLAG)); + + return gridProxy.isActive(); + } + + @Override + public IGrid getGrid() + { + try + { + return gridProxy.getGrid(); + } + catch (GridAccessException e) + { + return null; + } + } + + private int getBoosters() + { + ItemStack boosters = inv.getStackInSlot( 0 ); + return boosters == null ? 0 : boosters.stackSize; + } + + @Override + public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) + { + // :P + } + + @Override + public boolean isPowered() + { + return POWERED_FLAG == (clientFlags & POWERED_FLAG); + } + +} diff --git a/tile/powersink/AEBasePoweredTile.java b/src/main/java/appeng/tile/powersink/AEBasePoweredTile.java similarity index 94% rename from tile/powersink/AEBasePoweredTile.java rename to src/main/java/appeng/tile/powersink/AEBasePoweredTile.java index 407398040..35a44b9eb 100644 --- a/tile/powersink/AEBasePoweredTile.java +++ b/src/main/java/appeng/tile/powersink/AEBasePoweredTile.java @@ -1,6 +1,6 @@ -package appeng.tile.powersink; - -public abstract class AEBasePoweredTile extends MekJoules -{ - -} +package appeng.tile.powersink; + +public abstract class AEBasePoweredTile extends MekJoules +{ + +} diff --git a/tile/powersink/AERootPoweredTile.java b/src/main/java/appeng/tile/powersink/AERootPoweredTile.java similarity index 96% rename from tile/powersink/AERootPoweredTile.java rename to src/main/java/appeng/tile/powersink/AERootPoweredTile.java index 6d7333ed1..e8149210f 100644 --- a/tile/powersink/AERootPoweredTile.java +++ b/src/main/java/appeng/tile/powersink/AERootPoweredTile.java @@ -1,167 +1,167 @@ -package appeng.tile.powersink; - -import java.util.EnumSet; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.AccessRestriction; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.PowerUnits; -import appeng.api.networking.energy.IAEPowerStorage; -import appeng.api.networking.events.MENetworkPowerStorage.PowerEventType; -import appeng.tile.AEBaseInvTile; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; - -public abstract class AERootPoweredTile extends AEBaseInvTile implements IAEPowerStorage -{ - - // values that determine general function, are set by inheriting classes if - // needed. These should generally remain static. - protected double internalMaxPower = 10000; - protected boolean internalCanAcceptPower = true; - protected boolean internalPublicPowerStorage = false; - private EnumSet internalPowerSides = EnumSet.allOf( ForgeDirection.class ); - - protected AccessRestriction internalPowerFlow = AccessRestriction.READ_WRITE; - - // the current power buffer. - protected double internalCurrentPower = 0; - - protected void setPowerSides(EnumSet sides) - { - internalPowerSides = sides; - // trigger re-calc! - } - - protected EnumSet getPowerSides() - { - return internalPowerSides.clone(); - } - - @TileEvent(TileEventType.WORLD_NBT_WRITE) - public void writeToNBT_AERootPoweredTile(NBTTagCompound data) - { - data.setDouble( "internalCurrentPower", internalCurrentPower ); - } - - @TileEvent(TileEventType.WORLD_NBT_READ) - public void readFromNBT_AERootPoweredTile(NBTTagCompound data) - { - internalCurrentPower = data.getDouble( "internalCurrentPower" ); - } - - final protected double getExternalPowerDemand(PowerUnits externalUnit, double maxPowerRequired) - { - return PowerUnits.AE.convertTo( externalUnit, Math.max( 0.0, getFunnelPowerDemand( externalUnit.convertTo( PowerUnits.AE, maxPowerRequired ) ) ) ); - } - - protected double getFunnelPowerDemand(double maxRequired) - { - return internalMaxPower - internalCurrentPower; - } - - final public double injectExternalPower(PowerUnits input, double amt) - { - return PowerUnits.AE.convertTo( input, funnelPowerIntoStorage( input.convertTo( PowerUnits.AE, amt ), Actionable.MODULATE ) ); - } - - protected double funnelPowerIntoStorage(double AEUnits, Actionable mode) - { - return injectAEPower( AEUnits, mode ); - } - - @Override - final public double injectAEPower(double amt, Actionable mode) - { - if ( amt < 0.000001 ) - return 0; - - if ( mode == Actionable.SIMULATE ) - { - double fakeBattery = internalCurrentPower + amt; - - if ( fakeBattery > internalMaxPower ) - return fakeBattery - internalMaxPower; - - return 0; - } - else - { - if ( internalCurrentPower < 0.01 && amt > 0.01 ) - PowerEvent( PowerEventType.PROVIDE_POWER ); - - internalCurrentPower += amt; - if ( internalCurrentPower > internalMaxPower ) - { - amt = internalCurrentPower - internalMaxPower; - internalCurrentPower = internalMaxPower; - return amt; - } - - return 0; - } - } - - protected void PowerEvent(PowerEventType x) - { - // nothing. - } - - protected double extractAEPower(double amt, Actionable mode) - { - if ( mode == Actionable.SIMULATE ) - { - if ( internalCurrentPower > amt ) - return amt; - return internalCurrentPower; - } - - boolean wasFull = internalCurrentPower >= internalMaxPower - 0.001; - if ( wasFull && amt > 0.001 ) - { - PowerEvent( PowerEventType.REQUEST_POWER ); - } - - if ( internalCurrentPower > amt ) - { - internalCurrentPower -= amt; - return amt; - } - - amt = internalCurrentPower; - internalCurrentPower = 0; - return amt; - } - - @Override - final public double extractAEPower(double amt, Actionable mode, PowerMultiplier multiplier) - { - return multiplier.divide( extractAEPower( multiplier.multiply( amt ), mode ) ); - } - - @Override - final public double getAEMaxPower() - { - return internalMaxPower; - } - - @Override - final public double getAECurrentPower() - { - return internalCurrentPower; - } - - @Override - final public boolean isAEPublicPowerStorage() - { - return internalPublicPowerStorage; - } - - @Override - final public AccessRestriction getPowerFlow() - { - return internalPowerFlow; - } -} +package appeng.tile.powersink; + +import java.util.EnumSet; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.AccessRestriction; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.config.PowerUnits; +import appeng.api.networking.energy.IAEPowerStorage; +import appeng.api.networking.events.MENetworkPowerStorage.PowerEventType; +import appeng.tile.AEBaseInvTile; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; + +public abstract class AERootPoweredTile extends AEBaseInvTile implements IAEPowerStorage +{ + + // values that determine general function, are set by inheriting classes if + // needed. These should generally remain static. + protected double internalMaxPower = 10000; + protected boolean internalCanAcceptPower = true; + protected boolean internalPublicPowerStorage = false; + private EnumSet internalPowerSides = EnumSet.allOf( ForgeDirection.class ); + + protected AccessRestriction internalPowerFlow = AccessRestriction.READ_WRITE; + + // the current power buffer. + protected double internalCurrentPower = 0; + + protected void setPowerSides(EnumSet sides) + { + internalPowerSides = sides; + // trigger re-calc! + } + + protected EnumSet getPowerSides() + { + return internalPowerSides.clone(); + } + + @TileEvent(TileEventType.WORLD_NBT_WRITE) + public void writeToNBT_AERootPoweredTile(NBTTagCompound data) + { + data.setDouble( "internalCurrentPower", internalCurrentPower ); + } + + @TileEvent(TileEventType.WORLD_NBT_READ) + public void readFromNBT_AERootPoweredTile(NBTTagCompound data) + { + internalCurrentPower = data.getDouble( "internalCurrentPower" ); + } + + final protected double getExternalPowerDemand(PowerUnits externalUnit, double maxPowerRequired) + { + return PowerUnits.AE.convertTo( externalUnit, Math.max( 0.0, getFunnelPowerDemand( externalUnit.convertTo( PowerUnits.AE, maxPowerRequired ) ) ) ); + } + + protected double getFunnelPowerDemand(double maxRequired) + { + return internalMaxPower - internalCurrentPower; + } + + final public double injectExternalPower(PowerUnits input, double amt) + { + return PowerUnits.AE.convertTo( input, funnelPowerIntoStorage( input.convertTo( PowerUnits.AE, amt ), Actionable.MODULATE ) ); + } + + protected double funnelPowerIntoStorage(double AEUnits, Actionable mode) + { + return injectAEPower( AEUnits, mode ); + } + + @Override + final public double injectAEPower(double amt, Actionable mode) + { + if ( amt < 0.000001 ) + return 0; + + if ( mode == Actionable.SIMULATE ) + { + double fakeBattery = internalCurrentPower + amt; + + if ( fakeBattery > internalMaxPower ) + return fakeBattery - internalMaxPower; + + return 0; + } + else + { + if ( internalCurrentPower < 0.01 && amt > 0.01 ) + PowerEvent( PowerEventType.PROVIDE_POWER ); + + internalCurrentPower += amt; + if ( internalCurrentPower > internalMaxPower ) + { + amt = internalCurrentPower - internalMaxPower; + internalCurrentPower = internalMaxPower; + return amt; + } + + return 0; + } + } + + protected void PowerEvent(PowerEventType x) + { + // nothing. + } + + protected double extractAEPower(double amt, Actionable mode) + { + if ( mode == Actionable.SIMULATE ) + { + if ( internalCurrentPower > amt ) + return amt; + return internalCurrentPower; + } + + boolean wasFull = internalCurrentPower >= internalMaxPower - 0.001; + if ( wasFull && amt > 0.001 ) + { + PowerEvent( PowerEventType.REQUEST_POWER ); + } + + if ( internalCurrentPower > amt ) + { + internalCurrentPower -= amt; + return amt; + } + + amt = internalCurrentPower; + internalCurrentPower = 0; + return amt; + } + + @Override + final public double extractAEPower(double amt, Actionable mode, PowerMultiplier multiplier) + { + return multiplier.divide( extractAEPower( multiplier.multiply( amt ), mode ) ); + } + + @Override + final public double getAEMaxPower() + { + return internalMaxPower; + } + + @Override + final public double getAECurrentPower() + { + return internalCurrentPower; + } + + @Override + final public boolean isAEPublicPowerStorage() + { + return internalPublicPowerStorage; + } + + @Override + final public AccessRestriction getPowerFlow() + { + return internalPowerFlow; + } +} diff --git a/tile/powersink/IC2.java b/src/main/java/appeng/tile/powersink/IC2.java similarity index 95% rename from tile/powersink/IC2.java rename to src/main/java/appeng/tile/powersink/IC2.java index 3a3ae89fa..aa22c212a 100644 --- a/tile/powersink/IC2.java +++ b/src/main/java/appeng/tile/powersink/IC2.java @@ -1,105 +1,105 @@ -package appeng.tile.powersink; - -import ic2.api.energy.tile.IEnergySink; - -import java.util.EnumSet; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.config.PowerUnits; -import appeng.core.AppEng; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.IIC2; -import appeng.transformer.annotations.integration.Interface; -import appeng.util.Platform; - -@Interface(iname = "IC2", iface = "ic2.api.energy.tile.IEnergySink") -public abstract class IC2 extends MinecraftJoules6 implements IEnergySink -{ - - boolean isInIC2 = false; - - @Override - final public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) - { - return internalCanAcceptPower && getPowerSides().contains( direction ); - } - - @Override - final public double getDemandedEnergy() - { - return getExternalPowerDemand( PowerUnits.EU, Double.MAX_VALUE ); - } - - @Override - final public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) - { - // just store the excess in the current block, if I return the waste, - // IC2 will just disintegrate it - Oct 20th 2013 - double overflow = PowerUnits.EU.convertTo( PowerUnits.AE, injectExternalPower( PowerUnits.EU, amount ) ); - internalCurrentPower += overflow; - return 0; // see above comment. - } - - @Override - final public int getSinkTier() - { - return Integer.MAX_VALUE; - } - - @Override - public void invalidate() - { - super.invalidate(); - removeFromENet(); - } - - @Override - public void onChunkUnload() - { - super.onChunkUnload(); - removeFromENet(); - } - - @Override - public void onReady() - { - super.onReady(); - addToENet(); - } - - @Override - protected void setPowerSides(EnumSet sides) - { - super.setPowerSides( sides ); - removeFromENet(); - addToENet(); - } - - final private void addToENet() - { - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) ) - { - IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 ); - if ( !isInIC2 && Platform.isServer() && ic2Integration != null ) - { - ic2Integration.addToEnergyNet( this ); - isInIC2 = true; - } - } - } - - final private void removeFromENet() - { - if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) ) - { - IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 ); - if ( isInIC2 && Platform.isServer() && ic2Integration != null ) - { - ic2Integration.removeFromEnergyNet( this ); - isInIC2 = false; - } - } - } - -} +package appeng.tile.powersink; + +import ic2.api.energy.tile.IEnergySink; + +import java.util.EnumSet; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.config.PowerUnits; +import appeng.core.AppEng; +import appeng.integration.IntegrationType; +import appeng.integration.abstraction.IIC2; +import appeng.transformer.annotations.integration.Interface; +import appeng.util.Platform; + +@Interface(iname = "IC2", iface = "ic2.api.energy.tile.IEnergySink") +public abstract class IC2 extends MinecraftJoules6 implements IEnergySink +{ + + boolean isInIC2 = false; + + @Override + final public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) + { + return internalCanAcceptPower && getPowerSides().contains( direction ); + } + + @Override + final public double getDemandedEnergy() + { + return getExternalPowerDemand( PowerUnits.EU, Double.MAX_VALUE ); + } + + @Override + final public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) + { + // just store the excess in the current block, if I return the waste, + // IC2 will just disintegrate it - Oct 20th 2013 + double overflow = PowerUnits.EU.convertTo( PowerUnits.AE, injectExternalPower( PowerUnits.EU, amount ) ); + internalCurrentPower += overflow; + return 0; // see above comment. + } + + @Override + final public int getSinkTier() + { + return Integer.MAX_VALUE; + } + + @Override + public void invalidate() + { + super.invalidate(); + removeFromENet(); + } + + @Override + public void onChunkUnload() + { + super.onChunkUnload(); + removeFromENet(); + } + + @Override + public void onReady() + { + super.onReady(); + addToENet(); + } + + @Override + protected void setPowerSides(EnumSet sides) + { + super.setPowerSides( sides ); + removeFromENet(); + addToENet(); + } + + final private void addToENet() + { + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) ) + { + IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 ); + if ( !isInIC2 && Platform.isServer() && ic2Integration != null ) + { + ic2Integration.addToEnergyNet( this ); + isInIC2 = true; + } + } + } + + final private void removeFromENet() + { + if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) ) + { + IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 ); + if ( isInIC2 && Platform.isServer() && ic2Integration != null ) + { + ic2Integration.removeFromEnergyNet( this ); + isInIC2 = false; + } + } + } + +} diff --git a/tile/powersink/MekJoules.java b/src/main/java/appeng/tile/powersink/MekJoules.java similarity index 100% rename from tile/powersink/MekJoules.java rename to src/main/java/appeng/tile/powersink/MekJoules.java diff --git a/tile/powersink/MinecraftJoules5.java b/src/main/java/appeng/tile/powersink/MinecraftJoules5.java similarity index 100% rename from tile/powersink/MinecraftJoules5.java rename to src/main/java/appeng/tile/powersink/MinecraftJoules5.java diff --git a/tile/powersink/MinecraftJoules6.java b/src/main/java/appeng/tile/powersink/MinecraftJoules6.java similarity index 100% rename from tile/powersink/MinecraftJoules6.java rename to src/main/java/appeng/tile/powersink/MinecraftJoules6.java diff --git a/tile/powersink/RedstoneFlux.java b/src/main/java/appeng/tile/powersink/RedstoneFlux.java similarity index 100% rename from tile/powersink/RedstoneFlux.java rename to src/main/java/appeng/tile/powersink/RedstoneFlux.java diff --git a/tile/powersink/RotaryCraft.java b/src/main/java/appeng/tile/powersink/RotaryCraft.java similarity index 94% rename from tile/powersink/RotaryCraft.java rename to src/main/java/appeng/tile/powersink/RotaryCraft.java index b206723ad..ef54b34c4 100644 --- a/tile/powersink/RotaryCraft.java +++ b/src/main/java/appeng/tile/powersink/RotaryCraft.java @@ -1,148 +1,148 @@ -package appeng.tile.powersink; - -import net.minecraftforge.common.util.ForgeDirection; -import Reika.RotaryCraft.API.ShaftPowerReceiver; -import appeng.api.config.PowerUnits; -import appeng.tile.TileEvent; -import appeng.tile.events.TileEventType; -import appeng.transformer.annotations.integration.Interface; -import appeng.transformer.annotations.integration.Method; -import appeng.util.Platform; - -@Interface(iname = "RotaryCraft", iface = "Reika.RotaryCraft.API.ShaftPowerReceiver") -public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver -{ - - private int omega = 0; - private int torque = 0; - private long power = 0; - private int alpha = 0; - - @TileEvent(TileEventType.TICK) - @Method(iname = "RotaryCraft") - public void Tick_RotaryCraft() - { - if ( worldObj != null && !worldObj.isRemote && power > 0 ) - injectExternalPower( PowerUnits.WA, power ); - } - - @Override - final public int getOmega() - { - return omega; - } - - @Override - final public int getTorque() - { - return torque; - } - - @Override - final public long getPower() - { - return power; - } - - @Override - final public String getName() - { - return "AE"; - } - - @Override - final public int getIORenderAlpha() - { - return alpha; - } - - @Override - final public void setIORenderAlpha(int io) - { - alpha = io; - } - - - final public int getMachineX() - { - return xCoord; - } - - final public int getMachineY() - { - return yCoord; - } - - final public int getMachineZ() - { - return zCoord; - } - - @Override - final public void setOmega(int o) - { - omega = o; - } - - @Override - final public void setTorque(int t) - { - torque = t; - } - - @Override - final public void setPower(long p) - { - if ( Platform.isClient() ) - return; - - power = p; - } - - final public boolean canReadFromBlock(int x, int y, int z) - { - ForgeDirection side = ForgeDirection.UNKNOWN; - - if ( x == xCoord - 1 ) - side = ForgeDirection.WEST; - else if ( x == xCoord + 1 ) - side = ForgeDirection.EAST; - else if ( z == zCoord - 1 ) - side = ForgeDirection.NORTH; - else if ( z == zCoord + 1 ) - side = ForgeDirection.SOUTH; - else if ( y == yCoord - 1 ) - side = ForgeDirection.DOWN; - else if ( y == yCoord + 1 ) - side = ForgeDirection.UP; - - return internalCanAcceptPower && getPowerSides().contains( side ); - } - - @Override - final public boolean isReceiving() - { - return true; - } - - @Override - final public void noInputMachine() - { - power = 0; - torque = 0; - omega = 0; - } - - @Override - final public boolean canReadFrom(ForgeDirection side) - { - return internalCanAcceptPower && getPowerSides().contains( side ); - } - - @Override - final public int getMinTorque(int available) - { - return 0; - } - -} +package appeng.tile.powersink; + +import net.minecraftforge.common.util.ForgeDirection; +import Reika.RotaryCraft.API.ShaftPowerReceiver; +import appeng.api.config.PowerUnits; +import appeng.tile.TileEvent; +import appeng.tile.events.TileEventType; +import appeng.transformer.annotations.integration.Interface; +import appeng.transformer.annotations.integration.Method; +import appeng.util.Platform; + +@Interface(iname = "RotaryCraft", iface = "Reika.RotaryCraft.API.ShaftPowerReceiver") +public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver +{ + + private int omega = 0; + private int torque = 0; + private long power = 0; + private int alpha = 0; + + @TileEvent(TileEventType.TICK) + @Method(iname = "RotaryCraft") + public void Tick_RotaryCraft() + { + if ( worldObj != null && !worldObj.isRemote && power > 0 ) + injectExternalPower( PowerUnits.WA, power ); + } + + @Override + final public int getOmega() + { + return omega; + } + + @Override + final public int getTorque() + { + return torque; + } + + @Override + final public long getPower() + { + return power; + } + + @Override + final public String getName() + { + return "AE"; + } + + @Override + final public int getIORenderAlpha() + { + return alpha; + } + + @Override + final public void setIORenderAlpha(int io) + { + alpha = io; + } + + + final public int getMachineX() + { + return xCoord; + } + + final public int getMachineY() + { + return yCoord; + } + + final public int getMachineZ() + { + return zCoord; + } + + @Override + final public void setOmega(int o) + { + omega = o; + } + + @Override + final public void setTorque(int t) + { + torque = t; + } + + @Override + final public void setPower(long p) + { + if ( Platform.isClient() ) + return; + + power = p; + } + + final public boolean canReadFromBlock(int x, int y, int z) + { + ForgeDirection side = ForgeDirection.UNKNOWN; + + if ( x == xCoord - 1 ) + side = ForgeDirection.WEST; + else if ( x == xCoord + 1 ) + side = ForgeDirection.EAST; + else if ( z == zCoord - 1 ) + side = ForgeDirection.NORTH; + else if ( z == zCoord + 1 ) + side = ForgeDirection.SOUTH; + else if ( y == yCoord - 1 ) + side = ForgeDirection.DOWN; + else if ( y == yCoord + 1 ) + side = ForgeDirection.UP; + + return internalCanAcceptPower && getPowerSides().contains( side ); + } + + @Override + final public boolean isReceiving() + { + return true; + } + + @Override + final public void noInputMachine() + { + power = 0; + torque = 0; + omega = 0; + } + + @Override + final public boolean canReadFrom(ForgeDirection side) + { + return internalCanAcceptPower && getPowerSides().contains( side ); + } + + @Override + final public int getMinTorque(int available) + { + return 0; + } + +} diff --git a/tile/powersink/UniversalElectricity.java b/src/main/java/appeng/tile/powersink/UniversalElectricity.java similarity index 95% rename from tile/powersink/UniversalElectricity.java rename to src/main/java/appeng/tile/powersink/UniversalElectricity.java index cd1a271ee..f93f60d56 100644 --- a/tile/powersink/UniversalElectricity.java +++ b/src/main/java/appeng/tile/powersink/UniversalElectricity.java @@ -1,65 +1,65 @@ -package appeng.tile.powersink; - -/* -import net.minecraftforge.common.util.ForgeDirection; -import universalelectricity.core.block.IElectrical; -import universalelectricity.core.electricity.ElectricityPack; -import appeng.api.config.PowerUnits; - -public abstract class UniversalElectricity extends ThermalExpansion implements IElectrical -{ - - @Override - final public boolean canConnect(ForgeDirection direction) - { - return internalCanAcceptPower && getPowerSides().contains( direction ); - } - - @Override - final public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive) - { - float accepted = 0; - double receivedPower = receive.getWatts(); - - if ( doReceive ) - { - accepted = (float) (receivedPower - injectExternalPower( PowerUnits.KJ, receivedPower )); - } - else - { - double whatIWant = getExternalPowerDemand( PowerUnits.KJ ); - if ( whatIWant > receivedPower ) - accepted = (float) receivedPower; - else - accepted = (float) whatIWant; - } - - return accepted; - } - - @Override - final public float getRequest(ForgeDirection direction) - { - return (float) getExternalPowerDemand( PowerUnits.KJ ); - } - - @Override - final public float getVoltage() - { - return 120; - } - - @Override - final public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide) - { - return null; // cannot be dis-charged - } - - @Override - final public float getProvide(ForgeDirection direction) - { - return 0; - } - -} +package appeng.tile.powersink; + +/* +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IElectrical; +import universalelectricity.core.electricity.ElectricityPack; +import appeng.api.config.PowerUnits; + +public abstract class UniversalElectricity extends ThermalExpansion implements IElectrical +{ + + @Override + final public boolean canConnect(ForgeDirection direction) + { + return internalCanAcceptPower && getPowerSides().contains( direction ); + } + + @Override + final public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive) + { + float accepted = 0; + double receivedPower = receive.getWatts(); + + if ( doReceive ) + { + accepted = (float) (receivedPower - injectExternalPower( PowerUnits.KJ, receivedPower )); + } + else + { + double whatIWant = getExternalPowerDemand( PowerUnits.KJ ); + if ( whatIWant > receivedPower ) + accepted = (float) receivedPower; + else + accepted = (float) whatIWant; + } + + return accepted; + } + + @Override + final public float getRequest(ForgeDirection direction) + { + return (float) getExternalPowerDemand( PowerUnits.KJ ); + } + + @Override + final public float getVoltage() + { + return 120; + } + + @Override + final public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide) + { + return null; // cannot be dis-charged + } + + @Override + final public float getProvide(ForgeDirection direction) + { + return 0; + } + +} */ \ No newline at end of file diff --git a/tile/qnb/TileQuantumBridge.java b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java similarity index 100% rename from tile/qnb/TileQuantumBridge.java rename to src/main/java/appeng/tile/qnb/TileQuantumBridge.java diff --git a/tile/spatial/TileSpatialIOPort.java b/src/main/java/appeng/tile/spatial/TileSpatialIOPort.java similarity index 100% rename from tile/spatial/TileSpatialIOPort.java rename to src/main/java/appeng/tile/spatial/TileSpatialIOPort.java diff --git a/tile/spatial/TileSpatialPylon.java b/src/main/java/appeng/tile/spatial/TileSpatialPylon.java similarity index 100% rename from tile/spatial/TileSpatialPylon.java rename to src/main/java/appeng/tile/spatial/TileSpatialPylon.java diff --git a/tile/storage/TileChest.java b/src/main/java/appeng/tile/storage/TileChest.java similarity index 100% rename from tile/storage/TileChest.java rename to src/main/java/appeng/tile/storage/TileChest.java diff --git a/tile/storage/TileDrive.java b/src/main/java/appeng/tile/storage/TileDrive.java similarity index 100% rename from tile/storage/TileDrive.java rename to src/main/java/appeng/tile/storage/TileDrive.java diff --git a/tile/storage/TileIOPort.java b/src/main/java/appeng/tile/storage/TileIOPort.java similarity index 100% rename from tile/storage/TileIOPort.java rename to src/main/java/appeng/tile/storage/TileIOPort.java diff --git a/tile/storage/TileSkyChest.java b/src/main/java/appeng/tile/storage/TileSkyChest.java similarity index 100% rename from tile/storage/TileSkyChest.java rename to src/main/java/appeng/tile/storage/TileSkyChest.java diff --git a/transformer/AppEngCore.java b/src/main/java/appeng/transformer/AppEngCore.java similarity index 100% rename from transformer/AppEngCore.java rename to src/main/java/appeng/transformer/AppEngCore.java diff --git a/transformer/MissingCoreMod.java b/src/main/java/appeng/transformer/MissingCoreMod.java similarity index 100% rename from transformer/MissingCoreMod.java rename to src/main/java/appeng/transformer/MissingCoreMod.java diff --git a/transformer/annotations/integration.java b/src/main/java/appeng/transformer/annotations/integration.java similarity index 100% rename from transformer/annotations/integration.java rename to src/main/java/appeng/transformer/annotations/integration.java diff --git a/transformer/asm/ASMIntegration.java b/src/main/java/appeng/transformer/asm/ASMIntegration.java similarity index 100% rename from transformer/asm/ASMIntegration.java rename to src/main/java/appeng/transformer/asm/ASMIntegration.java diff --git a/transformer/asm/ASMTweaker.java b/src/main/java/appeng/transformer/asm/ASMTweaker.java similarity index 100% rename from transformer/asm/ASMTweaker.java rename to src/main/java/appeng/transformer/asm/ASMTweaker.java diff --git a/util/BlockUpdate.java b/src/main/java/appeng/util/BlockUpdate.java similarity index 100% rename from util/BlockUpdate.java rename to src/main/java/appeng/util/BlockUpdate.java diff --git a/util/ConfigManager.java b/src/main/java/appeng/util/ConfigManager.java similarity index 100% rename from util/ConfigManager.java rename to src/main/java/appeng/util/ConfigManager.java diff --git a/util/IConfigManagerHost.java b/src/main/java/appeng/util/IConfigManagerHost.java similarity index 94% rename from util/IConfigManagerHost.java rename to src/main/java/appeng/util/IConfigManagerHost.java index 5681bad92..004677fe0 100644 --- a/util/IConfigManagerHost.java +++ b/src/main/java/appeng/util/IConfigManagerHost.java @@ -1,10 +1,10 @@ -package appeng.util; - -import appeng.api.util.IConfigManager; - -public interface IConfigManagerHost -{ - - void updateSetting(IConfigManager manager, Enum settingName, Enum newValue); - -} +package appeng.util; + +import appeng.api.util.IConfigManager; + +public interface IConfigManagerHost +{ + + void updateSetting(IConfigManager manager, Enum settingName, Enum newValue); + +} diff --git a/util/InWorldToolOperationResult.java b/src/main/java/appeng/util/InWorldToolOperationResult.java similarity index 100% rename from util/InWorldToolOperationResult.java rename to src/main/java/appeng/util/InWorldToolOperationResult.java diff --git a/util/InventoryAdaptor.java b/src/main/java/appeng/util/InventoryAdaptor.java similarity index 100% rename from util/InventoryAdaptor.java rename to src/main/java/appeng/util/InventoryAdaptor.java diff --git a/util/ItemSorters.java b/src/main/java/appeng/util/ItemSorters.java similarity index 100% rename from util/ItemSorters.java rename to src/main/java/appeng/util/ItemSorters.java diff --git a/util/LookDirection.java b/src/main/java/appeng/util/LookDirection.java similarity index 93% rename from util/LookDirection.java rename to src/main/java/appeng/util/LookDirection.java index e496261d5..bb5ac4f68 100644 --- a/util/LookDirection.java +++ b/src/main/java/appeng/util/LookDirection.java @@ -1,15 +1,15 @@ -package appeng.util; - -import net.minecraft.util.Vec3; - -public class LookDirection -{ - - public final Vec3 a; - public final Vec3 b; - - public LookDirection(Vec3 a, Vec3 b) { - this.a = a; - this.b = b; - } -} +package appeng.util; + +import net.minecraft.util.Vec3; + +public class LookDirection +{ + + public final Vec3 a; + public final Vec3 b; + + public LookDirection(Vec3 a, Vec3 b) { + this.a = a; + this.b = b; + } +} diff --git a/util/Platform.java b/src/main/java/appeng/util/Platform.java similarity index 100% rename from util/Platform.java rename to src/main/java/appeng/util/Platform.java diff --git a/util/ReadOnlyCollection.java b/src/main/java/appeng/util/ReadOnlyCollection.java similarity index 93% rename from util/ReadOnlyCollection.java rename to src/main/java/appeng/util/ReadOnlyCollection.java index 739dc541f..2410147ef 100644 --- a/util/ReadOnlyCollection.java +++ b/src/main/java/appeng/util/ReadOnlyCollection.java @@ -1,41 +1,41 @@ -package appeng.util; - -import java.util.Collection; -import java.util.Iterator; - -import appeng.api.util.IReadOnlyCollection; - -public class ReadOnlyCollection implements IReadOnlyCollection -{ - - private final Collection c; - - public ReadOnlyCollection(Collection in) { - c = in; - } - - @Override - public Iterator iterator() - { - return c.iterator(); - } - - @Override - public int size() - { - return c.size(); - } - - @Override - public boolean isEmpty() - { - return c.isEmpty(); - } - - @Override - public boolean contains(Object node) - { - return c.contains( node ); - } - -} +package appeng.util; + +import java.util.Collection; +import java.util.Iterator; + +import appeng.api.util.IReadOnlyCollection; + +public class ReadOnlyCollection implements IReadOnlyCollection +{ + + private final Collection c; + + public ReadOnlyCollection(Collection in) { + c = in; + } + + @Override + public Iterator iterator() + { + return c.iterator(); + } + + @Override + public int size() + { + return c.size(); + } + + @Override + public boolean isEmpty() + { + return c.isEmpty(); + } + + @Override + public boolean contains(Object node) + { + return c.contains( node ); + } + +} diff --git a/util/SettingsFrom.java b/src/main/java/appeng/util/SettingsFrom.java similarity index 93% rename from util/SettingsFrom.java rename to src/main/java/appeng/util/SettingsFrom.java index 0bd4e79fe..341724b1c 100644 --- a/util/SettingsFrom.java +++ b/src/main/java/appeng/util/SettingsFrom.java @@ -1,10 +1,10 @@ -package appeng.util; - -public enum SettingsFrom -{ - // moved the item, and replaced it. - DISMANTLE_ITEM, - - // used memory card? - MEMORY_CARD -} +package appeng.util; + +public enum SettingsFrom +{ + // moved the item, and replaced it. + DISMANTLE_ITEM, + + // used memory card? + MEMORY_CARD +} diff --git a/util/SortedList.java b/src/main/java/appeng/util/SortedList.java similarity index 94% rename from util/SortedList.java rename to src/main/java/appeng/util/SortedList.java index 531e2736f..52778043e 100644 --- a/util/SortedList.java +++ b/src/main/java/appeng/util/SortedList.java @@ -1,195 +1,195 @@ -package appeng.util; - -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; - -public class SortedList implements Iterable, List, Cloneable { - - private boolean sorted = true; - private final Comparator comp; - private final LinkedList storage = new LinkedList(); - - private void makeSorted() { - if (!sorted) { - sorted = true; - Collections.sort(storage, comp); - } - } - - public SortedList(Comparator comp) { - this.comp = comp; - } - - @Override - public boolean add(T input) { - sorted = false; - return storage.add(input); - } - - @Override - public boolean addAll(Collection input) { - if (!input.isEmpty()) - sorted = false; - return storage.addAll(input); - } - - @Override - public void clear() { - sorted = true; - storage.clear(); - } - - @Override - public boolean contains(Object input) { - return storage.contains(input); - } - - @Override - public boolean containsAll(Collection input) { - return storage.containsAll(input); - } - - @Override - public boolean isEmpty() { - return isEmpty(); - } - - @Override - public Iterator iterator() { - makeSorted(); - return storage.iterator(); - } - - public Iterator reverseIterator() { - makeSorted(); - final ListIterator listIterator = listIterator(size()); - - return new Iterator() { - - public boolean hasNext() { - return listIterator.hasPrevious(); - } - - public T next() { - return listIterator.previous(); - } - - public void remove() { - listIterator.remove(); - } - - }; - } - - @Override - public boolean remove(Object input) { - return storage.remove(input); - } - - @Override - public boolean removeAll(Collection input) { - return storage.removeAll(input); - } - - @Override - public boolean retainAll(Collection input) { - return storage.retainAll(input); - } - - @Override - public int size() { - return storage.size(); - } - - @Override - public Object[] toArray() { - return storage.toArray(); - } - - @Override - public X[] toArray(X[] input) { - return storage.toArray(input); - } - - public Comparator comparator() { - return comp; - } - - public T first() { - makeSorted(); - return storage.peekFirst(); - } - - public T last() { - makeSorted(); - return storage.peekLast(); - } - - @Override - public void add(int index, T element) { - makeSorted(); - sorted = false; - add(index, element); - } - - @Override - public boolean addAll(int index, Collection c) { - sorted = false; - return addAll(index, c); - } - - @Override - public T get(int index) { - makeSorted(); - return get(index); - } - - @Override - public int indexOf(Object o) { - makeSorted(); - return indexOf(o); - } - - @Override - public int lastIndexOf(Object o) { - makeSorted(); - return lastIndexOf(o); - } - - @Override - public ListIterator listIterator() { - makeSorted(); - return listIterator(); - } - - @Override - public ListIterator listIterator(int index) { - makeSorted(); - return listIterator(index); - } - - @Override - public T remove(int index) { - makeSorted(); - return remove(index); - } - - @Override - public T set(int index, T element) { - makeSorted(); - sorted = false; - return set(index, element); - } - - @Override - public List subList(int fromIndex, int toIndex) { - makeSorted(); - return storage.subList(fromIndex, toIndex); - } - -} +package appeng.util; + +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; + +public class SortedList implements Iterable, List, Cloneable { + + private boolean sorted = true; + private final Comparator comp; + private final LinkedList storage = new LinkedList(); + + private void makeSorted() { + if (!sorted) { + sorted = true; + Collections.sort(storage, comp); + } + } + + public SortedList(Comparator comp) { + this.comp = comp; + } + + @Override + public boolean add(T input) { + sorted = false; + return storage.add(input); + } + + @Override + public boolean addAll(Collection input) { + if (!input.isEmpty()) + sorted = false; + return storage.addAll(input); + } + + @Override + public void clear() { + sorted = true; + storage.clear(); + } + + @Override + public boolean contains(Object input) { + return storage.contains(input); + } + + @Override + public boolean containsAll(Collection input) { + return storage.containsAll(input); + } + + @Override + public boolean isEmpty() { + return isEmpty(); + } + + @Override + public Iterator iterator() { + makeSorted(); + return storage.iterator(); + } + + public Iterator reverseIterator() { + makeSorted(); + final ListIterator listIterator = listIterator(size()); + + return new Iterator() { + + public boolean hasNext() { + return listIterator.hasPrevious(); + } + + public T next() { + return listIterator.previous(); + } + + public void remove() { + listIterator.remove(); + } + + }; + } + + @Override + public boolean remove(Object input) { + return storage.remove(input); + } + + @Override + public boolean removeAll(Collection input) { + return storage.removeAll(input); + } + + @Override + public boolean retainAll(Collection input) { + return storage.retainAll(input); + } + + @Override + public int size() { + return storage.size(); + } + + @Override + public Object[] toArray() { + return storage.toArray(); + } + + @Override + public X[] toArray(X[] input) { + return storage.toArray(input); + } + + public Comparator comparator() { + return comp; + } + + public T first() { + makeSorted(); + return storage.peekFirst(); + } + + public T last() { + makeSorted(); + return storage.peekLast(); + } + + @Override + public void add(int index, T element) { + makeSorted(); + sorted = false; + add(index, element); + } + + @Override + public boolean addAll(int index, Collection c) { + sorted = false; + return addAll(index, c); + } + + @Override + public T get(int index) { + makeSorted(); + return get(index); + } + + @Override + public int indexOf(Object o) { + makeSorted(); + return indexOf(o); + } + + @Override + public int lastIndexOf(Object o) { + makeSorted(); + return lastIndexOf(o); + } + + @Override + public ListIterator listIterator() { + makeSorted(); + return listIterator(); + } + + @Override + public ListIterator listIterator(int index) { + makeSorted(); + return listIterator(index); + } + + @Override + public T remove(int index) { + makeSorted(); + return remove(index); + } + + @Override + public T set(int index, T element) { + makeSorted(); + sorted = false; + return set(index, element); + } + + @Override + public List subList(int fromIndex, int toIndex) { + makeSorted(); + return storage.subList(fromIndex, toIndex); + } + +} diff --git a/util/inv/AdaptorBCPipe.java b/src/main/java/appeng/util/inv/AdaptorBCPipe.java similarity index 100% rename from util/inv/AdaptorBCPipe.java rename to src/main/java/appeng/util/inv/AdaptorBCPipe.java diff --git a/util/inv/AdaptorIInventory.java b/src/main/java/appeng/util/inv/AdaptorIInventory.java similarity index 100% rename from util/inv/AdaptorIInventory.java rename to src/main/java/appeng/util/inv/AdaptorIInventory.java diff --git a/util/inv/AdaptorISpecialInventory.java b/src/main/java/appeng/util/inv/AdaptorISpecialInventory.java similarity index 100% rename from util/inv/AdaptorISpecialInventory.java rename to src/main/java/appeng/util/inv/AdaptorISpecialInventory.java diff --git a/util/inv/AdaptorList.java b/src/main/java/appeng/util/inv/AdaptorList.java similarity index 100% rename from util/inv/AdaptorList.java rename to src/main/java/appeng/util/inv/AdaptorList.java diff --git a/util/inv/AdaptorPlayerHand.java b/src/main/java/appeng/util/inv/AdaptorPlayerHand.java similarity index 100% rename from util/inv/AdaptorPlayerHand.java rename to src/main/java/appeng/util/inv/AdaptorPlayerHand.java diff --git a/util/inv/AdaptorPlayerInventory.java b/src/main/java/appeng/util/inv/AdaptorPlayerInventory.java similarity index 100% rename from util/inv/AdaptorPlayerInventory.java rename to src/main/java/appeng/util/inv/AdaptorPlayerInventory.java diff --git a/util/inv/IInventoryDestination.java b/src/main/java/appeng/util/inv/IInventoryDestination.java similarity index 100% rename from util/inv/IInventoryDestination.java rename to src/main/java/appeng/util/inv/IInventoryDestination.java diff --git a/util/inv/IInventoryWrapper.java b/src/main/java/appeng/util/inv/IInventoryWrapper.java similarity index 100% rename from util/inv/IInventoryWrapper.java rename to src/main/java/appeng/util/inv/IInventoryWrapper.java diff --git a/util/inv/IMEAdaptor.java b/src/main/java/appeng/util/inv/IMEAdaptor.java similarity index 100% rename from util/inv/IMEAdaptor.java rename to src/main/java/appeng/util/inv/IMEAdaptor.java diff --git a/util/inv/IMEAdaptorIterator.java b/src/main/java/appeng/util/inv/IMEAdaptorIterator.java similarity index 100% rename from util/inv/IMEAdaptorIterator.java rename to src/main/java/appeng/util/inv/IMEAdaptorIterator.java diff --git a/util/inv/IMEInventoryDestination.java b/src/main/java/appeng/util/inv/IMEInventoryDestination.java similarity index 100% rename from util/inv/IMEInventoryDestination.java rename to src/main/java/appeng/util/inv/IMEInventoryDestination.java diff --git a/util/inv/ItemListIgnoreCrafting.java b/src/main/java/appeng/util/inv/ItemListIgnoreCrafting.java similarity index 93% rename from util/inv/ItemListIgnoreCrafting.java rename to src/main/java/appeng/util/inv/ItemListIgnoreCrafting.java index 266437b2b..5977ae2d1 100644 --- a/util/inv/ItemListIgnoreCrafting.java +++ b/src/main/java/appeng/util/inv/ItemListIgnoreCrafting.java @@ -1,90 +1,90 @@ -package appeng.util.inv; - -import java.util.Collection; -import java.util.Iterator; - -import appeng.api.config.FuzzyMode; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; - -public class ItemListIgnoreCrafting implements IItemList -{ - - final IItemList target; - - public ItemListIgnoreCrafting(IItemList cla) { - target = cla; - } - - @Override - public void add(T option) - { - if ( option != null && option.isCraftable() ) - { - option = (T) option.copy(); - option.setCraftable( false ); - } - - target.add( option ); - } - - @Override - public void addCrafting(T option) - { - // nothing. - } - - @Override - public T findPrecise(T i) - { - return target.findPrecise( i ); - } - - @Override - public Collection findFuzzy(T input, FuzzyMode fuzzy) - { - return target.findFuzzy( input, fuzzy ); - } - - @Override - public boolean isEmpty() - { - return target.isEmpty(); - } - - @Override - public void addStorage(T option) - { - target.addStorage( option ); - } - - @Override - public void addRequestable(T option) - { - target.addRequestable( option ); - } - - @Override - public T getFirstItem() - { - return target.getFirstItem(); - } - - @Override - public int size() - { - return target.size(); - } - - @Override - public Iterator iterator() - { - return target.iterator(); - } - - @Override - public void resetStatus() - { - target.resetStatus(); - } -} +package appeng.util.inv; + +import java.util.Collection; +import java.util.Iterator; + +import appeng.api.config.FuzzyMode; +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; + +public class ItemListIgnoreCrafting implements IItemList +{ + + final IItemList target; + + public ItemListIgnoreCrafting(IItemList cla) { + target = cla; + } + + @Override + public void add(T option) + { + if ( option != null && option.isCraftable() ) + { + option = (T) option.copy(); + option.setCraftable( false ); + } + + target.add( option ); + } + + @Override + public void addCrafting(T option) + { + // nothing. + } + + @Override + public T findPrecise(T i) + { + return target.findPrecise( i ); + } + + @Override + public Collection findFuzzy(T input, FuzzyMode fuzzy) + { + return target.findFuzzy( input, fuzzy ); + } + + @Override + public boolean isEmpty() + { + return target.isEmpty(); + } + + @Override + public void addStorage(T option) + { + target.addStorage( option ); + } + + @Override + public void addRequestable(T option) + { + target.addRequestable( option ); + } + + @Override + public T getFirstItem() + { + return target.getFirstItem(); + } + + @Override + public int size() + { + return target.size(); + } + + @Override + public Iterator iterator() + { + return target.iterator(); + } + + @Override + public void resetStatus() + { + target.resetStatus(); + } +} diff --git a/util/inv/ItemSlot.java b/src/main/java/appeng/util/inv/ItemSlot.java similarity index 95% rename from util/inv/ItemSlot.java rename to src/main/java/appeng/util/inv/ItemSlot.java index ba7604a33..e319aa1b1 100644 --- a/util/inv/ItemSlot.java +++ b/src/main/java/appeng/util/inv/ItemSlot.java @@ -1,40 +1,40 @@ -package appeng.util.inv; - -import net.minecraft.item.ItemStack; -import appeng.api.storage.data.IAEItemStack; -import appeng.util.item.AEItemStack; - -public class ItemSlot -{ - - public int slot; - - // one or the other.. - private IAEItemStack aeitemstack; - private ItemStack itemStack; - - public boolean isExtractable; - - public void setItemStack(ItemStack is) - { - aeitemstack = null; - itemStack = is; - } - - public void setAEItemStack(IAEItemStack is) - { - aeitemstack = is; - itemStack = null; - } - - public ItemStack getItemStack() - { - return itemStack == null ? (aeitemstack == null ? null : (itemStack = aeitemstack.getItemStack())) : itemStack; - } - - public IAEItemStack getAEItemStack() - { - return aeitemstack == null ? (itemStack == null ? null : (aeitemstack = AEItemStack.create( itemStack ))) : aeitemstack; - } - -} +package appeng.util.inv; + +import net.minecraft.item.ItemStack; +import appeng.api.storage.data.IAEItemStack; +import appeng.util.item.AEItemStack; + +public class ItemSlot +{ + + public int slot; + + // one or the other.. + private IAEItemStack aeitemstack; + private ItemStack itemStack; + + public boolean isExtractable; + + public void setItemStack(ItemStack is) + { + aeitemstack = null; + itemStack = is; + } + + public void setAEItemStack(IAEItemStack is) + { + aeitemstack = is; + itemStack = null; + } + + public ItemStack getItemStack() + { + return itemStack == null ? (aeitemstack == null ? null : (itemStack = aeitemstack.getItemStack())) : itemStack; + } + + public IAEItemStack getAEItemStack() + { + return aeitemstack == null ? (itemStack == null ? null : (aeitemstack = AEItemStack.create( itemStack ))) : aeitemstack; + } + +} diff --git a/util/inv/WrapperBCPipe.java b/src/main/java/appeng/util/inv/WrapperBCPipe.java similarity index 100% rename from util/inv/WrapperBCPipe.java rename to src/main/java/appeng/util/inv/WrapperBCPipe.java diff --git a/util/inv/WrapperChainedInventory.java b/src/main/java/appeng/util/inv/WrapperChainedInventory.java similarity index 100% rename from util/inv/WrapperChainedInventory.java rename to src/main/java/appeng/util/inv/WrapperChainedInventory.java diff --git a/util/inv/WrapperInvSlot.java b/src/main/java/appeng/util/inv/WrapperInvSlot.java similarity index 100% rename from util/inv/WrapperInvSlot.java rename to src/main/java/appeng/util/inv/WrapperInvSlot.java diff --git a/util/inv/WrapperInventoryRange.java b/src/main/java/appeng/util/inv/WrapperInventoryRange.java similarity index 100% rename from util/inv/WrapperInventoryRange.java rename to src/main/java/appeng/util/inv/WrapperInventoryRange.java diff --git a/util/inv/WrapperMCISidedInventory.java b/src/main/java/appeng/util/inv/WrapperMCISidedInventory.java similarity index 100% rename from util/inv/WrapperMCISidedInventory.java rename to src/main/java/appeng/util/inv/WrapperMCISidedInventory.java diff --git a/util/inv/WrapperTEPipe.java b/src/main/java/appeng/util/inv/WrapperTEPipe.java similarity index 100% rename from util/inv/WrapperTEPipe.java rename to src/main/java/appeng/util/inv/WrapperTEPipe.java diff --git a/util/item/AEFluidStack.java b/src/main/java/appeng/util/item/AEFluidStack.java similarity index 100% rename from util/item/AEFluidStack.java rename to src/main/java/appeng/util/item/AEFluidStack.java diff --git a/util/item/AEItemDef.java b/src/main/java/appeng/util/item/AEItemDef.java similarity index 95% rename from util/item/AEItemDef.java rename to src/main/java/appeng/util/item/AEItemDef.java index d87a98b6a..6d32bfb66 100644 --- a/util/item/AEItemDef.java +++ b/src/main/java/appeng/util/item/AEItemDef.java @@ -1,96 +1,96 @@ -package appeng.util.item; - -import java.util.List; - -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import appeng.util.Platform; -import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class AEItemDef -{ - - public int myHash; - - public int def; - - private int itemID; - public Item item; - public int damageValue; - - public int dspDamage; - public int maxDamage; - - public AESharedNBT tagCompound; - - @SideOnly(Side.CLIENT) - public String displayName; - - @SideOnly(Side.CLIENT) - public List tooltip; - - @SideOnly(Side.CLIENT) - public UniqueIdentifier uniqueID; - - public OreReference isOre; - - static AESharedNBT lowTag = new AESharedNBT( Integer.MIN_VALUE ); - static AESharedNBT highTag = new AESharedNBT( Integer.MAX_VALUE ); - - public AEItemDef(Item it) { - item = it; - itemID = System.identityHashCode( item ); - } - - public AEItemDef copy() - { - AEItemDef t = new AEItemDef( item ); - t.def = def; - t.damageValue = damageValue; - t.dspDamage = dspDamage; - t.maxDamage = maxDamage; - t.tagCompound = tagCompound; - t.isOre = isOre; - return t; - } - - @Override - public boolean equals(Object obj) - { - AEItemDef def = (AEItemDef) obj; - return def.damageValue == damageValue && def.item == item && tagCompound == def.tagCompound; - } - - public int getDamageValueHack(ItemStack is) - { - return Items.blaze_rod.getDamage( is ); - } - - public boolean isItem(ItemStack otherStack) - { - // hackery! - int dmg = getDamageValueHack( otherStack ); - - if ( item == otherStack.getItem() && dmg == damageValue ) - { - if ( (tagCompound != null) == otherStack.hasTagCompound() ) - return true; - - if ( tagCompound != null && otherStack.hasTagCompound() ) - return Platform.NBTEqualityTest( (NBTBase) tagCompound, otherStack.getTagCompound() ); - - return true; - } - return false; - } - - public void reHash() - { - def = itemID << Platform.DEF_OFFSET | damageValue; - myHash = def ^ (tagCompound == null ? 0 : System.identityHashCode( tagCompound )); - } -} +package appeng.util.item; + +import java.util.List; + +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import appeng.util.Platform; +import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class AEItemDef +{ + + public int myHash; + + public int def; + + private int itemID; + public Item item; + public int damageValue; + + public int dspDamage; + public int maxDamage; + + public AESharedNBT tagCompound; + + @SideOnly(Side.CLIENT) + public String displayName; + + @SideOnly(Side.CLIENT) + public List tooltip; + + @SideOnly(Side.CLIENT) + public UniqueIdentifier uniqueID; + + public OreReference isOre; + + static AESharedNBT lowTag = new AESharedNBT( Integer.MIN_VALUE ); + static AESharedNBT highTag = new AESharedNBT( Integer.MAX_VALUE ); + + public AEItemDef(Item it) { + item = it; + itemID = System.identityHashCode( item ); + } + + public AEItemDef copy() + { + AEItemDef t = new AEItemDef( item ); + t.def = def; + t.damageValue = damageValue; + t.dspDamage = dspDamage; + t.maxDamage = maxDamage; + t.tagCompound = tagCompound; + t.isOre = isOre; + return t; + } + + @Override + public boolean equals(Object obj) + { + AEItemDef def = (AEItemDef) obj; + return def.damageValue == damageValue && def.item == item && tagCompound == def.tagCompound; + } + + public int getDamageValueHack(ItemStack is) + { + return Items.blaze_rod.getDamage( is ); + } + + public boolean isItem(ItemStack otherStack) + { + // hackery! + int dmg = getDamageValueHack( otherStack ); + + if ( item == otherStack.getItem() && dmg == damageValue ) + { + if ( (tagCompound != null) == otherStack.hasTagCompound() ) + return true; + + if ( tagCompound != null && otherStack.hasTagCompound() ) + return Platform.NBTEqualityTest( (NBTBase) tagCompound, otherStack.getTagCompound() ); + + return true; + } + return false; + } + + public void reHash() + { + def = itemID << Platform.DEF_OFFSET | damageValue; + myHash = def ^ (tagCompound == null ? 0 : System.identityHashCode( tagCompound )); + } +} diff --git a/util/item/AEItemStack.java b/src/main/java/appeng/util/item/AEItemStack.java similarity index 100% rename from util/item/AEItemStack.java rename to src/main/java/appeng/util/item/AEItemStack.java diff --git a/util/item/AESharedNBT.java b/src/main/java/appeng/util/item/AESharedNBT.java similarity index 100% rename from util/item/AESharedNBT.java rename to src/main/java/appeng/util/item/AESharedNBT.java diff --git a/util/item/AEStack.java b/src/main/java/appeng/util/item/AEStack.java similarity index 94% rename from util/item/AEStack.java rename to src/main/java/appeng/util/item/AEStack.java index 405250559..ee26520a3 100644 --- a/util/item/AEStack.java +++ b/src/main/java/appeng/util/item/AEStack.java @@ -1,165 +1,165 @@ -package appeng.util.item; - -import io.netty.buffer.ByteBuf; - -import java.io.IOException; - -import appeng.api.storage.data.IAEStack; - -public abstract class AEStack implements IAEStack -{ - - protected boolean isCraftable; - protected long stackSize; - protected long countRequestable; - - @Override - public boolean isMeaningful() - { - return stackSize != 0 || getCountRequestable() > 0 || isCraftable(); - } - - @Override - public StackType reset() - { - stackSize = 0; - // priority = Integer.MIN_VALUE; - setCountRequestable( 0 ); - setCraftable( false ); - return (StackType) this; - } - - @Override - public long getStackSize() - { - return stackSize; - } - - @Override - public StackType setStackSize(long ss) - { - stackSize = ss; - return (StackType) this; - } - - @Override - public long getCountRequestable() - { - return countRequestable; - } - - @Override - public StackType setCountRequestable(long countRequestable) - { - this.countRequestable = countRequestable; - return (StackType) this; - } - - @Override - public boolean isCraftable() - { - return isCraftable; - } - - @Override - public StackType setCraftable(boolean isCraftable) - { - this.isCraftable = isCraftable; - return (StackType) this; - } - - @Override - public void decStackSize(long i) - { - stackSize -= i; - } - - @Override - public void incStackSize(long i) - { - stackSize += i; - } - - @Override - public void decCountRequestable(long i) - { - countRequestable -= i; - } - - @Override - public void incCountRequestable(long i) - { - countRequestable += i; - } - - void putPacketValue(ByteBuf tag, long num) throws IOException - { - if ( num <= 255 ) - tag.writeByte( (byte) (num + (long) Byte.MIN_VALUE) ); - else if ( num <= 65535 ) - tag.writeShort( (short) (num + (long) Short.MIN_VALUE) ); - else if ( num <= 4294967295L ) - tag.writeInt( (int) (num + (long) Integer.MIN_VALUE) ); - else - tag.writeLong( num ); - } - - static long getPacketValue(byte type, ByteBuf tag) throws IOException - { - if ( type == 0 ) - { - long l = tag.readByte(); - l -= (long) Byte.MIN_VALUE; - return l; - } - else if ( type == 1 ) - { - long l = tag.readShort(); - l -= (long) Short.MIN_VALUE; - return l; - } - else if ( type == 2 ) - { - long l = tag.readInt(); - l -= (long) Integer.MIN_VALUE; - return l; - } - - return tag.readLong(); - } - - byte getType(long num) - { - if ( num <= 255 ) - return 0; - else if ( num <= 65535 ) - return 1; - else if ( num <= 4294967295L ) - return 2; - else - return 3; - } - - abstract void writeIdentity(ByteBuf i) throws IOException; - - abstract void readNBT(ByteBuf i) throws IOException; - - abstract boolean hasTagCompound(); - - @Override - public void writeToPacket(ByteBuf i) throws IOException - { - byte mask = (byte) (getType( 0 ) | (getType( stackSize ) << 2) | (getType( getCountRequestable() ) << 4) | ((byte) (isCraftable ? 1 : 0) << 6) | (hasTagCompound() ? 1 - : 0) << 7); - - i.writeByte( mask ); - writeIdentity( i ); - - readNBT( i ); - - // putPacketValue( i, priority ); - putPacketValue( i, stackSize ); - putPacketValue( i, getCountRequestable() ); - } - -} +package appeng.util.item; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; + +import appeng.api.storage.data.IAEStack; + +public abstract class AEStack implements IAEStack +{ + + protected boolean isCraftable; + protected long stackSize; + protected long countRequestable; + + @Override + public boolean isMeaningful() + { + return stackSize != 0 || getCountRequestable() > 0 || isCraftable(); + } + + @Override + public StackType reset() + { + stackSize = 0; + // priority = Integer.MIN_VALUE; + setCountRequestable( 0 ); + setCraftable( false ); + return (StackType) this; + } + + @Override + public long getStackSize() + { + return stackSize; + } + + @Override + public StackType setStackSize(long ss) + { + stackSize = ss; + return (StackType) this; + } + + @Override + public long getCountRequestable() + { + return countRequestable; + } + + @Override + public StackType setCountRequestable(long countRequestable) + { + this.countRequestable = countRequestable; + return (StackType) this; + } + + @Override + public boolean isCraftable() + { + return isCraftable; + } + + @Override + public StackType setCraftable(boolean isCraftable) + { + this.isCraftable = isCraftable; + return (StackType) this; + } + + @Override + public void decStackSize(long i) + { + stackSize -= i; + } + + @Override + public void incStackSize(long i) + { + stackSize += i; + } + + @Override + public void decCountRequestable(long i) + { + countRequestable -= i; + } + + @Override + public void incCountRequestable(long i) + { + countRequestable += i; + } + + void putPacketValue(ByteBuf tag, long num) throws IOException + { + if ( num <= 255 ) + tag.writeByte( (byte) (num + (long) Byte.MIN_VALUE) ); + else if ( num <= 65535 ) + tag.writeShort( (short) (num + (long) Short.MIN_VALUE) ); + else if ( num <= 4294967295L ) + tag.writeInt( (int) (num + (long) Integer.MIN_VALUE) ); + else + tag.writeLong( num ); + } + + static long getPacketValue(byte type, ByteBuf tag) throws IOException + { + if ( type == 0 ) + { + long l = tag.readByte(); + l -= (long) Byte.MIN_VALUE; + return l; + } + else if ( type == 1 ) + { + long l = tag.readShort(); + l -= (long) Short.MIN_VALUE; + return l; + } + else if ( type == 2 ) + { + long l = tag.readInt(); + l -= (long) Integer.MIN_VALUE; + return l; + } + + return tag.readLong(); + } + + byte getType(long num) + { + if ( num <= 255 ) + return 0; + else if ( num <= 65535 ) + return 1; + else if ( num <= 4294967295L ) + return 2; + else + return 3; + } + + abstract void writeIdentity(ByteBuf i) throws IOException; + + abstract void readNBT(ByteBuf i) throws IOException; + + abstract boolean hasTagCompound(); + + @Override + public void writeToPacket(ByteBuf i) throws IOException + { + byte mask = (byte) (getType( 0 ) | (getType( stackSize ) << 2) | (getType( getCountRequestable() ) << 4) | ((byte) (isCraftable ? 1 : 0) << 6) | (hasTagCompound() ? 1 + : 0) << 7); + + i.writeByte( mask ); + writeIdentity( i ); + + readNBT( i ); + + // putPacketValue( i, priority ); + putPacketValue( i, stackSize ); + putPacketValue( i, getCountRequestable() ); + } + +} diff --git a/util/item/ItemList.java b/src/main/java/appeng/util/item/ItemList.java similarity index 100% rename from util/item/ItemList.java rename to src/main/java/appeng/util/item/ItemList.java diff --git a/util/item/ItemModList.java b/src/main/java/appeng/util/item/ItemModList.java similarity index 100% rename from util/item/ItemModList.java rename to src/main/java/appeng/util/item/ItemModList.java diff --git a/util/item/MeaningfulIterator.java b/src/main/java/appeng/util/item/MeaningfulIterator.java similarity index 100% rename from util/item/MeaningfulIterator.java rename to src/main/java/appeng/util/item/MeaningfulIterator.java diff --git a/util/item/OreHelper.java b/src/main/java/appeng/util/item/OreHelper.java similarity index 94% rename from util/item/OreHelper.java rename to src/main/java/appeng/util/item/OreHelper.java index 50d476605..673c76f6e 100644 --- a/util/item/OreHelper.java +++ b/src/main/java/appeng/util/item/OreHelper.java @@ -1,154 +1,154 @@ -package appeng.util.item; - -import java.util.Collection; -import java.util.HashMap; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; -import appeng.api.storage.data.IAEItemStack; - -public class OreHelper -{ - - public static OreHelper instance = new OreHelper(); - - class ItemRef - { - - ItemRef(ItemStack stack) { - ref = stack.getItem(); - - if ( stack.getItem().isDamageable() ) - damage = 0; // IGNORED - else - damage = stack.getItemDamage(); // might be important... - - hash = ref.hashCode() ^ damage; - } - - Item ref; - int damage; - int hash; - - @Override - public boolean equals(Object o) - { - ItemRef obj = (ItemRef) o; - return damage == obj.damage && ref == obj.ref; - } - - @Override - public int hashCode() - { - return hash; - } - - }; - - class OreResult - { - - public OreReference oreValue = null; - - }; - - HashMap references = new HashMap(); - - public OreReference isOre(ItemStack ItemStack) - { - ItemRef ir = new ItemRef( ItemStack ); - OreResult or = references.get( ir ); - - if ( or == null ) - { - or = new OreResult(); - references.put( ir, or ); - - OreReference ref = new OreReference(); - Collection ores = ref.getOres(); - Collection set = ref.getEquivalents(); - - for (String ore : OreDictionary.getOreNames()) - { - boolean add = false; - - for (ItemStack oreItem : OreDictionary.getOres( ore )) - { - if ( OreDictionary.itemMatches( oreItem, ItemStack, false ) ) - { - add = true; - break; - } - } - - if ( add ) - { - for (ItemStack oreItem : OreDictionary.getOres( ore )) - set.add( oreItem.copy() ); - - ores.add( OreDictionary.getOreID( ore ) ); - } - } - - if ( !set.isEmpty() ) - or.oreValue = ref; - } - - return or.oreValue; - } - - public boolean sameOre(AEItemStack aeItemStack, IAEItemStack is) - { - OreReference a = aeItemStack.def.isOre; - OreReference b = ((AEItemStack) aeItemStack).def.isOre; - - if ( a == b ) - return true; - - if ( a == null || b == null ) - return false; - - Collection bOres = b.getOres(); - for (Integer ore : a.getOres()) - { - if ( bOres.contains( ore ) ) - return true; - } - - return false; - } - - public boolean sameOre(OreReference a, OreReference b) - { - if ( a == null || b == null ) - return false; - - if ( a == b ) - return true; - - Collection bOres = b.getOres(); - for (Integer ore : a.getOres()) - { - if ( bOres.contains( ore ) ) - return true; - } - - return false; - } - - public boolean sameOre(AEItemStack aeItemStack, ItemStack o) - { - OreReference a = aeItemStack.def.isOre; - if ( a == null ) - return false; - - for (ItemStack oreItem : a.getEquivalents()) - { - if ( OreDictionary.itemMatches( oreItem, o, false ) ) - return true; - } - - return false; - } +package appeng.util.item; + +import java.util.Collection; +import java.util.HashMap; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; +import appeng.api.storage.data.IAEItemStack; + +public class OreHelper +{ + + public static OreHelper instance = new OreHelper(); + + class ItemRef + { + + ItemRef(ItemStack stack) { + ref = stack.getItem(); + + if ( stack.getItem().isDamageable() ) + damage = 0; // IGNORED + else + damage = stack.getItemDamage(); // might be important... + + hash = ref.hashCode() ^ damage; + } + + Item ref; + int damage; + int hash; + + @Override + public boolean equals(Object o) + { + ItemRef obj = (ItemRef) o; + return damage == obj.damage && ref == obj.ref; + } + + @Override + public int hashCode() + { + return hash; + } + + }; + + class OreResult + { + + public OreReference oreValue = null; + + }; + + HashMap references = new HashMap(); + + public OreReference isOre(ItemStack ItemStack) + { + ItemRef ir = new ItemRef( ItemStack ); + OreResult or = references.get( ir ); + + if ( or == null ) + { + or = new OreResult(); + references.put( ir, or ); + + OreReference ref = new OreReference(); + Collection ores = ref.getOres(); + Collection set = ref.getEquivalents(); + + for (String ore : OreDictionary.getOreNames()) + { + boolean add = false; + + for (ItemStack oreItem : OreDictionary.getOres( ore )) + { + if ( OreDictionary.itemMatches( oreItem, ItemStack, false ) ) + { + add = true; + break; + } + } + + if ( add ) + { + for (ItemStack oreItem : OreDictionary.getOres( ore )) + set.add( oreItem.copy() ); + + ores.add( OreDictionary.getOreID( ore ) ); + } + } + + if ( !set.isEmpty() ) + or.oreValue = ref; + } + + return or.oreValue; + } + + public boolean sameOre(AEItemStack aeItemStack, IAEItemStack is) + { + OreReference a = aeItemStack.def.isOre; + OreReference b = ((AEItemStack) aeItemStack).def.isOre; + + if ( a == b ) + return true; + + if ( a == null || b == null ) + return false; + + Collection bOres = b.getOres(); + for (Integer ore : a.getOres()) + { + if ( bOres.contains( ore ) ) + return true; + } + + return false; + } + + public boolean sameOre(OreReference a, OreReference b) + { + if ( a == null || b == null ) + return false; + + if ( a == b ) + return true; + + Collection bOres = b.getOres(); + for (Integer ore : a.getOres()) + { + if ( bOres.contains( ore ) ) + return true; + } + + return false; + } + + public boolean sameOre(AEItemStack aeItemStack, ItemStack o) + { + OreReference a = aeItemStack.def.isOre; + if ( a == null ) + return false; + + for (ItemStack oreItem : a.getEquivalents()) + { + if ( OreDictionary.itemMatches( oreItem, o, false ) ) + return true; + } + + return false; + } } \ No newline at end of file diff --git a/util/item/OreReference.java b/src/main/java/appeng/util/item/OreReference.java similarity index 100% rename from util/item/OreReference.java rename to src/main/java/appeng/util/item/OreReference.java diff --git a/util/item/SharedSearchObject.java b/src/main/java/appeng/util/item/SharedSearchObject.java similarity index 100% rename from util/item/SharedSearchObject.java rename to src/main/java/appeng/util/item/SharedSearchObject.java diff --git a/util/iterators/AEInvIterator.java b/src/main/java/appeng/util/iterators/AEInvIterator.java similarity index 100% rename from util/iterators/AEInvIterator.java rename to src/main/java/appeng/util/iterators/AEInvIterator.java diff --git a/util/iterators/ChainedIterator.java b/src/main/java/appeng/util/iterators/ChainedIterator.java similarity index 92% rename from util/iterators/ChainedIterator.java rename to src/main/java/appeng/util/iterators/ChainedIterator.java index c97e67081..e0ff2f535 100644 --- a/util/iterators/ChainedIterator.java +++ b/src/main/java/appeng/util/iterators/ChainedIterator.java @@ -1,33 +1,33 @@ -package appeng.util.iterators; - -import java.util.Iterator; - -public class ChainedIterator implements Iterator -{ - - int offset = 0; - T[] list; - - public ChainedIterator(T... list) { - this.list = list; - } - - @Override - public boolean hasNext() - { - return offset < list.length; - } - - @Override - public T next() - { - return list[offset++]; - } - - @Override - public void remove() - { - throw new RuntimeException( "Not implemented." ); - } - -} +package appeng.util.iterators; + +import java.util.Iterator; + +public class ChainedIterator implements Iterator +{ + + int offset = 0; + T[] list; + + public ChainedIterator(T... list) { + this.list = list; + } + + @Override + public boolean hasNext() + { + return offset < list.length; + } + + @Override + public T next() + { + return list[offset++]; + } + + @Override + public void remove() + { + throw new RuntimeException( "Not implemented." ); + } + +} diff --git a/util/iterators/InvIterator.java b/src/main/java/appeng/util/iterators/InvIterator.java similarity index 100% rename from util/iterators/InvIterator.java rename to src/main/java/appeng/util/iterators/InvIterator.java diff --git a/util/iterators/NullIterator.java b/src/main/java/appeng/util/iterators/NullIterator.java similarity index 91% rename from util/iterators/NullIterator.java rename to src/main/java/appeng/util/iterators/NullIterator.java index 3f05975c8..ad2eed75d 100644 --- a/util/iterators/NullIterator.java +++ b/src/main/java/appeng/util/iterators/NullIterator.java @@ -1,26 +1,26 @@ -package appeng.util.iterators; - -import java.util.Iterator; - -public class NullIterator implements Iterator -{ - - @Override - public boolean hasNext() - { - return false; - } - - @Override - public T next() - { - return null; - } - - @Override - public void remove() - { - - } - -} +package appeng.util.iterators; + +import java.util.Iterator; + +public class NullIterator implements Iterator +{ + + @Override + public boolean hasNext() + { + return false; + } + + @Override + public T next() + { + return null; + } + + @Override + public void remove() + { + + } + +} diff --git a/util/iterators/ProxyNodeIterator.java b/src/main/java/appeng/util/iterators/ProxyNodeIterator.java similarity index 94% rename from util/iterators/ProxyNodeIterator.java rename to src/main/java/appeng/util/iterators/ProxyNodeIterator.java index f597ba179..522c6f97f 100644 --- a/util/iterators/ProxyNodeIterator.java +++ b/src/main/java/appeng/util/iterators/ProxyNodeIterator.java @@ -1,37 +1,37 @@ -package appeng.util.iterators; - -import java.util.Iterator; - -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; - -public class ProxyNodeIterator implements Iterator -{ - - Iterator hosts; - - public ProxyNodeIterator(Iterator hosts) { - this.hosts = hosts; - } - - @Override - public boolean hasNext() - { - return hosts.hasNext(); - } - - @Override - public IGridNode next() - { - IGridHost host = hosts.next(); - return host.getGridNode( ForgeDirection.UNKNOWN ); - } - - @Override - public void remove() - { - throw new RuntimeException( "Not implemented." ); - } - -} +package appeng.util.iterators; + +import java.util.Iterator; + +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; + +public class ProxyNodeIterator implements Iterator +{ + + Iterator hosts; + + public ProxyNodeIterator(Iterator hosts) { + this.hosts = hosts; + } + + @Override + public boolean hasNext() + { + return hosts.hasNext(); + } + + @Override + public IGridNode next() + { + IGridHost host = hosts.next(); + return host.getGridNode( ForgeDirection.UNKNOWN ); + } + + @Override + public void remove() + { + throw new RuntimeException( "Not implemented." ); + } + +} diff --git a/util/iterators/StackToSlotIterator.java b/src/main/java/appeng/util/iterators/StackToSlotIterator.java similarity index 93% rename from util/iterators/StackToSlotIterator.java rename to src/main/java/appeng/util/iterators/StackToSlotIterator.java index 587d669fc..9bd445bc5 100644 --- a/util/iterators/StackToSlotIterator.java +++ b/src/main/java/appeng/util/iterators/StackToSlotIterator.java @@ -1,39 +1,39 @@ -package appeng.util.iterators; - -import java.util.Iterator; - -import net.minecraft.item.ItemStack; -import appeng.util.inv.ItemSlot; - -public class StackToSlotIterator implements Iterator -{ - - int x = 0; - final ItemSlot iss = new ItemSlot(); - final Iterator is; - - public StackToSlotIterator(Iterator is) { - this.is = is; - } - - @Override - public boolean hasNext() - { - return is.hasNext(); - } - - @Override - public ItemSlot next() - { - iss.slot = x++; - iss.setItemStack( is.next() ); - return iss; - } - - @Override - public void remove() - { - // uhh no. - } - -} +package appeng.util.iterators; + +import java.util.Iterator; + +import net.minecraft.item.ItemStack; +import appeng.util.inv.ItemSlot; + +public class StackToSlotIterator implements Iterator +{ + + int x = 0; + final ItemSlot iss = new ItemSlot(); + final Iterator is; + + public StackToSlotIterator(Iterator is) { + this.is = is; + } + + @Override + public boolean hasNext() + { + return is.hasNext(); + } + + @Override + public ItemSlot next() + { + iss.slot = x++; + iss.setItemStack( is.next() ); + return iss; + } + + @Override + public void remove() + { + // uhh no. + } + +} diff --git a/util/prioitylist/DefaultPriorityList.java b/src/main/java/appeng/util/prioitylist/DefaultPriorityList.java similarity index 93% rename from util/prioitylist/DefaultPriorityList.java rename to src/main/java/appeng/util/prioitylist/DefaultPriorityList.java index 87dc68f80..67bdd79e4 100644 --- a/util/prioitylist/DefaultPriorityList.java +++ b/src/main/java/appeng/util/prioitylist/DefaultPriorityList.java @@ -1,30 +1,30 @@ -package appeng.util.prioitylist; - -import java.util.ArrayList; -import java.util.List; - -import appeng.api.storage.data.IAEStack; - -public class DefaultPriorityList> implements IPartitionList -{ - - final static List nullList = new ArrayList(); - - public boolean isListed(T input) - { - return false; - } - - @Override - public boolean isEmpty() - { - return true; - } - - @Override - public Iterable getItems() - { - return (Iterable) nullList; - } - -} +package appeng.util.prioitylist; + +import java.util.ArrayList; +import java.util.List; + +import appeng.api.storage.data.IAEStack; + +public class DefaultPriorityList> implements IPartitionList +{ + + final static List nullList = new ArrayList(); + + public boolean isListed(T input) + { + return false; + } + + @Override + public boolean isEmpty() + { + return true; + } + + @Override + public Iterable getItems() + { + return (Iterable) nullList; + } + +} diff --git a/util/prioitylist/FuzzyPriorityList.java b/src/main/java/appeng/util/prioitylist/FuzzyPriorityList.java similarity index 94% rename from util/prioitylist/FuzzyPriorityList.java rename to src/main/java/appeng/util/prioitylist/FuzzyPriorityList.java index 96da3782d..967d1f7d5 100644 --- a/util/prioitylist/FuzzyPriorityList.java +++ b/src/main/java/appeng/util/prioitylist/FuzzyPriorityList.java @@ -1,38 +1,38 @@ -package appeng.util.prioitylist; - -import java.util.Collection; - -import appeng.api.config.FuzzyMode; -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; - -public class FuzzyPriorityList> implements IPartitionList -{ - - final IItemList list; - final FuzzyMode mode; - - public FuzzyPriorityList(IItemList in, FuzzyMode mode) { - list = in; - this.mode = mode; - } - - public boolean isListed(T input) - { - Collection out = list.findFuzzy( input, mode ); - return out != null && !out.isEmpty(); - } - - @Override - public boolean isEmpty() - { - return list.isEmpty(); - } - - @Override - public Iterable getItems() - { - return list; - } - -} +package appeng.util.prioitylist; + +import java.util.Collection; + +import appeng.api.config.FuzzyMode; +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; + +public class FuzzyPriorityList> implements IPartitionList +{ + + final IItemList list; + final FuzzyMode mode; + + public FuzzyPriorityList(IItemList in, FuzzyMode mode) { + list = in; + this.mode = mode; + } + + public boolean isListed(T input) + { + Collection out = list.findFuzzy( input, mode ); + return out != null && !out.isEmpty(); + } + + @Override + public boolean isEmpty() + { + return list.isEmpty(); + } + + @Override + public Iterable getItems() + { + return list; + } + +} diff --git a/util/prioitylist/IPartitionList.java b/src/main/java/appeng/util/prioitylist/IPartitionList.java similarity index 93% rename from util/prioitylist/IPartitionList.java rename to src/main/java/appeng/util/prioitylist/IPartitionList.java index d5e5b4c90..3c947f2db 100644 --- a/util/prioitylist/IPartitionList.java +++ b/src/main/java/appeng/util/prioitylist/IPartitionList.java @@ -1,14 +1,14 @@ -package appeng.util.prioitylist; - -import appeng.api.storage.data.IAEStack; - -public interface IPartitionList> -{ - - boolean isListed(T input); - - boolean isEmpty(); - - Iterable getItems(); - -} +package appeng.util.prioitylist; + +import appeng.api.storage.data.IAEStack; + +public interface IPartitionList> +{ + + boolean isListed(T input); + + boolean isEmpty(); + + Iterable getItems(); + +} diff --git a/util/prioitylist/MergedPriorityList.java b/src/main/java/appeng/util/prioitylist/MergedPriorityList.java similarity index 100% rename from util/prioitylist/MergedPriorityList.java rename to src/main/java/appeng/util/prioitylist/MergedPriorityList.java diff --git a/util/prioitylist/PrecisePriorityList.java b/src/main/java/appeng/util/prioitylist/PrecisePriorityList.java similarity index 94% rename from util/prioitylist/PrecisePriorityList.java rename to src/main/java/appeng/util/prioitylist/PrecisePriorityList.java index 03086f9d6..102ee012e 100644 --- a/util/prioitylist/PrecisePriorityList.java +++ b/src/main/java/appeng/util/prioitylist/PrecisePriorityList.java @@ -1,32 +1,32 @@ -package appeng.util.prioitylist; - -import appeng.api.storage.data.IAEStack; -import appeng.api.storage.data.IItemList; - -public class PrecisePriorityList> implements IPartitionList -{ - - final IItemList list; - - public PrecisePriorityList(IItemList in) { - list = in; - } - - public boolean isListed(T input) - { - return list.findPrecise( input ) != null; - } - - @Override - public boolean isEmpty() - { - return list.isEmpty(); - } - - @Override - public Iterable getItems() - { - return list; - } - -} +package appeng.util.prioitylist; + +import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; + +public class PrecisePriorityList> implements IPartitionList +{ + + final IItemList list; + + public PrecisePriorityList(IItemList in) { + list = in; + } + + public boolean isListed(T input) + { + return list.findPrecise( input ) != null; + } + + @Override + public boolean isEmpty() + { + return list.isEmpty(); + } + + @Override + public Iterable getItems() + { + return list; + } + +}