diff --git a/.gitignore b/.gitignore index 456c8b297..109ec4206 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ LICENSE /src/minecraft/basiccomponents/* /src/minecraft/buildcraft/* /src/minecraft/EUIClient/* -/src/minecraft/BasicPipes/* /src/common/cpw/* /src/common/net/* /src/common/org/* @@ -31,16 +30,6 @@ LICENSE /src/common/universalelectricity/* /src/common/basiccomponents/* /src/common/buildcraft/* -/src/common/BasicPipes/BasicPipesMain.java -/src/common/BasicPipes/PipeProxy.java -/src/common/BasicPipes/pipes/BlockPipe.java -/src/common/BasicPipes/pipes/BlockPump.java -/src/common/BasicPipes/pipes/ItemGuage.java -/src/common/BasicPipes/pipes/ItemParts.java -/src/common/BasicPipes/pipes/ItemPipe.java -/src/common/BasicPipes/pipes/TileEntityCondenser.java -/src/common/BasicPipes/pipes/TileEntityPipe.java -/src/common/BasicPipes/pipes/TileEntityPump.java /bin/ /conf/ /docs/ diff --git a/src/common/basicpipes/BasicPipesMain.java b/src/common/basicpipes/BasicPipesMain.java new file mode 100644 index 000000000..4e78f3ed1 --- /dev/null +++ b/src/common/basicpipes/BasicPipesMain.java @@ -0,0 +1,126 @@ +package basicpipes; +import java.io.File; + +import basicpipes.pipes.BlockPipe; +import basicpipes.pipes.BlockPump; +import basicpipes.pipes.ItemGuage; +import basicpipes.pipes.ItemParts; +import basicpipes.pipes.ItemPipe; +import basicpipes.pipes.TileEntityPump; + +import net.minecraft.client.Minecraft; +import net.minecraft.src.Block; +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; +import net.minecraftforge.common.Configuration; +import universalelectricity.basiccomponents.BasicComponents; +import universalelectricity.network.PacketManager; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.Init; +import cpw.mods.fml.common.Mod.Instance; +import cpw.mods.fml.common.Mod.PostInit; +import cpw.mods.fml.common.Mod.PreInit; +import cpw.mods.fml.common.SidedProxy; +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.network.NetworkMod; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.common.registry.LanguageRegistry; +@Mod(modid = "basicPipes", name = "Basic Pipes", version = "V4") +@NetworkMod(channels = { "Pipes" }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class) + +public class BasicPipesMain{ + @Instance + public static BasicPipesMain instance; + + @SidedProxy(clientSide = "BasicPipes.PipeClientProxy", serverSide = "BasicPipes.PipeProxy") + public static PipeProxy proxy; + static Configuration config = new Configuration((new File(cpw.mods.fml.common.Loader.instance().getConfigDir(), "/EUIndustry/BasicPipes.cfg"))); + public static int pipeID = configurationProperties(); + private static int partID; + private static int ppipeID; + private static int machineID; + public static Block pipe = new BlockPipe(pipeID).setBlockName("pipe"); + public static Block machine = new BlockPump(machineID).setBlockName("pump"); + public static Item parts = new ItemParts(partID); + public static Item itemPipes = new ItemPipe(ppipeID); + public static Item gauge = new ItemGuage(ppipeID+1); + + public static String channel = "Pipes"; + + public static int configurationProperties() + { + config.load(); + pipeID = Integer.parseInt(config.getOrCreateIntProperty("PipeBlock", Configuration.CATEGORY_BLOCK, 155).value); + machineID = Integer.parseInt(config.getOrCreateIntProperty("machineBlock", Configuration.CATEGORY_BLOCK, 156).value); + partID = Integer.parseInt(config.getOrCreateIntProperty("parts", Configuration.CATEGORY_ITEM, 23022).value); + ppipeID = Integer.parseInt(config.getOrCreateIntProperty("pipes", Configuration.CATEGORY_ITEM, 23023).value); + config.save(); + return pipeID; + } + @PreInit + public void preInit(FMLPreInitializationEvent event) + { + proxy.preInit(); + GameRegistry.registerBlock(pipe); + GameRegistry.registerBlock(machine); + } + @Init + public void load(FMLInitializationEvent evt) + { + //register + proxy.init(); + GameRegistry.registerTileEntity(TileEntityPump.class, "pump"); + //Names + LanguageRegistry.addName((new ItemStack(gauge, 1, 0)), "guage"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 0)), "SteamPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 1)), "WaterPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 2)), "LavaPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 3)), "OilPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 4)), "FuelPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 5)), "AirPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 6)), "MethainPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 7)), "BioFuelPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 8)), "coolentPipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 9)), "NukeWastePipe"); + LanguageRegistry.addName((new ItemStack(itemPipes, 1, 10)), "Pipe"); + LanguageRegistry.addName((new ItemStack(parts, 1, 0)), "BronzeTube"); + LanguageRegistry.addName((new ItemStack(parts, 1, 1)), "IronTube"); + LanguageRegistry.addName((new ItemStack(parts, 1, 2)), "ObsidianTube"); + LanguageRegistry.addName((new ItemStack(parts, 1, 3)), "NetherTube"); + LanguageRegistry.addName((new ItemStack(parts, 1, 4)), "LeatherSeal"); + LanguageRegistry.addName((new ItemStack(parts, 1, 5)), "SlimeSeal"); + LanguageRegistry.addName((new ItemStack(parts, 1, 6)), "BronzeTank"); + LanguageRegistry.addName((new ItemStack(parts, 1, 7)), "Valve"); + //crafting parts + } + @PostInit + public void postInit(FMLPostInitializationEvent event) + { + proxy.postInit(); + GameRegistry.addRecipe(new ItemStack(parts, 2,0), new Object[] { "@@@", '@',BasicComponents.itemBronzeIngot});//bronze tube + GameRegistry.addRecipe(new ItemStack(parts, 2,1), new Object[] { "@@@", '@',Item.ingotIron});//iron tube + GameRegistry.addRecipe(new ItemStack(parts, 2,2), new Object[] { "@@@", '@',Block.obsidian});//obby Tube + GameRegistry.addRecipe(new ItemStack(parts, 2,3), new Object[] { "N@N", 'N',Block.netherrack,'@',new ItemStack(parts, 2,2)});//nether tube + GameRegistry.addRecipe(new ItemStack(parts, 2,4), new Object[] { "@@","@@", '@',Item.leather});//seal + GameRegistry.addShapelessRecipe(new ItemStack(parts, 1,5), new Object[] { new ItemStack(parts, 1,4),new ItemStack(Item.slimeBall, 1)});//stick seal + GameRegistry.addRecipe(new ItemStack(parts, 1,6), new Object[] { " @ ","@ @"," @ ", '@',BasicComponents.itemBronzeIngot});//tank + GameRegistry.addRecipe(new ItemStack(parts, 1,7), new Object[] { "T@T", 'T',new ItemStack(parts,1,0),'@',Block.lever});//valve + //crafting pipes + //{"black", "red", "green", "brown", "blue", "purple", "cyan", + //"silver", "gray", "pink", "lime", "yellow", "lightBlue", "magenta", "orange", "white"}; + //steam + GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1,0), new Object[] { new ItemStack(parts, 1,0),new ItemStack(parts, 1,4)}); + //water + GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1,1), new Object[] { new ItemStack(parts, 1,1),new ItemStack(parts, 1,4),new ItemStack(Item.dyePowder, 1,4)}); + //lava TODO change to use obby pipe and nether items + GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1,2), new Object[] { new ItemStack(parts, 1,2),new ItemStack(Item.dyePowder, 1,1)}); + //oil + GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1,3), new Object[] { new ItemStack(parts, 1,1),new ItemStack(parts, 1,4),new ItemStack(Item.dyePowder, 1,0)}); + //fuel + GameRegistry.addShapelessRecipe(new ItemStack(itemPipes, 1,4), new Object[] { new ItemStack(parts, 1,1),new ItemStack(parts, 1,4),new ItemStack(Item.dyePowder, 1,11)}); + + } + +} diff --git a/src/common/basicpipes/PipeProxy.java b/src/common/basicpipes/PipeProxy.java new file mode 100644 index 000000000..617aa6778 --- /dev/null +++ b/src/common/basicpipes/PipeProxy.java @@ -0,0 +1,54 @@ +package basicpipes; + +import basicpipes.pipes.TileEntityPipe; +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.TileEntity; +import net.minecraft.src.World; +import cpw.mods.fml.common.network.IGuiHandler; +import cpw.mods.fml.common.registry.GameRegistry; + +public class PipeProxy implements IGuiHandler +{ + + public void preInit() + { + + } + public void init() + { + GameRegistry.registerTileEntity(TileEntityPipe.class, "pipe"); + } + public void postInit() + { + + } + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity != null) + { + switch(ID) + { + } + } + + return null; + } + + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity != null) + { + switch(ID) + { + } + } + + return null; + } +} diff --git a/src/common/basicpipes/pipes/BlockPipe.java b/src/common/basicpipes/pipes/BlockPipe.java new file mode 100644 index 000000000..6f7106e78 --- /dev/null +++ b/src/common/basicpipes/pipes/BlockPipe.java @@ -0,0 +1,147 @@ +package basicpipes.pipes; + +import java.util.Random; + +import basicpipes.pipes.api.ILiquidConsumer; +import basicpipes.pipes.api.ILiquidProducer; + +import net.minecraft.src.BlockContainer; +import net.minecraft.src.Material; +import net.minecraft.src.TileEntity; +import net.minecraft.src.World; +import net.minecraftforge.common.ForgeDirection; + +public class BlockPipe extends BlockContainer +{ + + public BlockPipe(int id) + { + super(id, Material.iron); + this.setBlockName("Pipe"); + this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F); + } + + /** + * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two + * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. + */ + public boolean isOpaqueCube() + { + return false; + } + + /** + * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) + */ + public boolean renderAsNormalBlock() + { + return false; + } + + /** + * The type of render function that is called for this block + */ + public int getRenderType() + { + return -1; + } + + /** + * Returns the ID of the items to drop on destruction. + */ + public int idDropped(int par1, Random par2Random, int par3) + { + return 0; + } + //Per tick + public int conductorCapacity() + { + return 5; + } + + + /** + * Called whenever the block is added into the world. Args: world, x, y, z + */ + @Override + public void onBlockAdded(World world, int x, int y, int z) + { + super.onBlockAdded(world, x, y, z); + + this.updateConductorTileEntity(world, x, y, z); + } + public static TileEntity getUEUnit(World world, int x, int y, int z, byte side,int type) + { + switch(side) + { + case 0: y -= 1; break; + case 1: y += 1; break; + case 2: z += 1; break; + case 3: z -= 1; break; + case 4: x += 1; break; + case 5: x -= 1; break; + } + + //Check if the designated block is a UE Unit - producer, consumer or a conductor + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + TileEntity returnValue = null; + + if(tileEntity instanceof ILiquidConsumer) + { + if(((ILiquidConsumer)tileEntity).canRecieveLiquid(type,ForgeDirection.getOrientation(side))) + { + returnValue = tileEntity; + } + } + + if (tileEntity instanceof ILiquidProducer) + { + if(((ILiquidProducer)tileEntity).canProduceLiquid(type,ForgeDirection.getOrientation(side))) + { + returnValue = tileEntity; + } + } + + return returnValue; + } + /** + * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are + * their own) Args: x, y, z, neighbor blockID + */ + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, int blockID) + { + super.onNeighborBlockChange(world, x, y, z, blockID); + this.updateConductorTileEntity(world, x, y, z); + } + @Override + public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) + { + int var5 = par1World.getBlockId(par2, par3, par4); + return var5 == 0 || blocksList[var5].blockMaterial.isGroundCover(); + } + @Override + public boolean canPlaceBlockOnSide(World par1World, int par2, int par3, int par4, int par5) + { + return true; + } + public static void updateConductorTileEntity(World world, int x, int y, int z) + { + + for(byte i = 0; i < 6; i++) + { + //Update the tile entity on neighboring blocks + TileEntityPipe conductorTileEntity = (TileEntityPipe)world.getBlockTileEntity(x, y, z); + int type = conductorTileEntity.getType(); + conductorTileEntity.addConnection(getUEUnit(world, x, y, z, i, type), ForgeDirection.getOrientation(i));; + } + } + + @Override + public TileEntity createNewTileEntity(World var1) { + // TODO Auto-generated method stub + return new TileEntityPipe(); + } + } + + diff --git a/src/common/basicpipes/pipes/BlockPump.java b/src/common/basicpipes/pipes/BlockPump.java new file mode 100644 index 000000000..78eddc4cb --- /dev/null +++ b/src/common/basicpipes/pipes/BlockPump.java @@ -0,0 +1,155 @@ +package basicpipes.pipes; + +import java.util.ArrayList; +import net.minecraft.src.*; + +import java.util.Random; + +public class BlockPump extends BlockContainer +{ + + public BlockPump(int id) + { + super(id, Material.iron); + this.setBlockName("Pump"); + } + + /** + * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two + * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. + */ + public boolean isOpaqueCube() + { + return false; + } + @Override + public int getBlockTexture(IBlockAccess par1iBlockAccess, int x, int y, int z, int side) + { + int metadata = par1iBlockAccess.getBlockMetadata(x, y, z); + + if (side == 1) + { + switch(metadata) + { + case 0: return 1; + case 1: return 3; + case 2: return 18; + case 3: return 5; + } + } + + + + switch(metadata) + { + case 1: return 4; + case 2: return 16; + case 3: return 2; + } + return 0; + + + } + @Override + public int getBlockTextureFromSideAndMetadata(int side, int metadata) + { + if (side == 1) + { + switch(metadata) + { + case 0: return 1; + case 1: return 3; + case 2: return 18; + case 3: return 5; + } + } + else + { + //If it is the front side + if(side == 3) + { + switch(metadata) + { + case 0: return 19; + case 1: return 6; + case 2: return 17; + case 3: return 3; + } + } + //If it is the back side + else if(side == 2) + { + switch(metadata) + { + case 0: return this.blockIndexInTexture + 2; + case 1: return this.blockIndexInTexture + 3; + case 2: return this.blockIndexInTexture + 2; + } + } + + switch(metadata) + { + case 1: return 4; + case 2: return 16; + case 3: return 2; + } + } + return 0; + } + /** + * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) + */ + public boolean renderAsNormalBlock() + { + return false; + } + + /** + * The type of render function that is called for this block + */ + public int getRenderType() + { + return 0; + } + + /** + * Returns the ID of the items to drop on destruction. + */ + public int idDropped(int par1, Random par2Random, int par3) + { + return 0; + } + @Override + public String getTextureFile() { + // TODO Auto-generated method stub + return "/eui/blocks.png"; + } + //Per tick + public int conductorCapacity() + { + return 10; + } + public void addCreativeItems(ArrayList itemList) + { + + itemList.add(new ItemStack(this, 1,0)); + } + + @Override + public TileEntity createNewTileEntity(World var1,int meta) { + // TODO Auto-generated method stub + switch(meta) + { + case 0: return new TileEntityPump(); + } + return null; + } + + @Override + public TileEntity createNewTileEntity(World var1) { + // TODO Auto-generated method stub + return null; + } + } + + diff --git a/src/common/basicpipes/pipes/ItemGuage.java b/src/common/basicpipes/pipes/ItemGuage.java new file mode 100644 index 000000000..bbaeb43f2 --- /dev/null +++ b/src/common/basicpipes/pipes/ItemGuage.java @@ -0,0 +1,78 @@ +package basicpipes.pipes; + +import java.util.ArrayList; +import net.minecraft.src.*; + +public class ItemGuage extends Item +{ + private int spawnID; + + public ItemGuage(int id) + { + super(id); + this.setMaxDamage(0); + this.setHasSubtypes(true); + this.setIconIndex(10); + this.setItemName("guage"); + } + @Override + public int getIconFromDamage(int par1) + { + switch(par1) + { + case 0: return 11; + } + return this.iconIndex; + } + @Override + public String getItemName() + { + return "guage"; + } + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7) + { + + TileEntity blockEntity = par3World.getBlockTileEntity(par4, par5, par6); + if(blockEntity instanceof TileEntityPipe) + { + TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity; + int steam = pipeEntity.getStoredLiquid(0); + int type = pipeEntity.getType(); + String typeName = getType(type); + par2EntityPlayer.addChatMessage(typeName +" " + steam); + return true; + } + + + + + return false; + } + public String getType(int type) + { + switch(type) + { + case 0: return "Steam"; + case 1: return "Water"; + case 2: return "Lava"; + case 3: return "Oil"; + case 4: return "Fuel"; + case 5: return "Air"; + default: return "unknow"; + } + } + public String getItemNameIS(ItemStack par1ItemStack) + { + int var3 = par1ItemStack.getItemDamage(); + switch(var3) + { + case 1: return "PipeGuage"; + } + return this.getItemName(); + } + @Override + public String getTextureFile() { + return "/eui/Items.png"; + } + +} diff --git a/src/common/basicpipes/pipes/ItemParts.java b/src/common/basicpipes/pipes/ItemParts.java new file mode 100644 index 000000000..41f5ebb0e --- /dev/null +++ b/src/common/basicpipes/pipes/ItemParts.java @@ -0,0 +1,58 @@ +package basicpipes.pipes; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.src.CreativeTabs; +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; + +public class ItemParts extends Item{ + String[] names = new String[]{"BronzeTube","IronTube","ObbyTube","NetherTube","Seal","StickSeal","BronzeTank","Valve",}; + int[] iconID = new int[] {0 ,1 ,2 ,3 ,16 ,17 ,18 ,19};//TODO check these + public ItemParts(int par1) + { + super(par1); + this.setItemName("Parts"); + this.setHasSubtypes(true); + this.setMaxDamage(0); + this.setMaxStackSize(64); + this.setTabToDisplayOn(CreativeTabs.tabMaterials); + } + @Override + public int getIconFromDamage(int par1) + { + if(par1 < iconID.length) + { + return iconID[par1]; + } + return par1; + } + @Override + public String getItemNameIS(ItemStack itemstack) + { + return names[itemstack.getItemDamage()]; + } + @Override + public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) + { + for(int i = 0; i < names.length; i++) + { + par3List.add(new ItemStack(this, 1, i)); + } + } + public String getTextureFile() { + return "/EUIClient/Textures/Items.png"; + } + @Override + public String getItemName() + { + return "parts"; + } +} + + + + + + diff --git a/src/common/basicpipes/pipes/ItemPipe.java b/src/common/basicpipes/pipes/ItemPipe.java new file mode 100644 index 000000000..c9d23a7e0 --- /dev/null +++ b/src/common/basicpipes/pipes/ItemPipe.java @@ -0,0 +1,129 @@ +package basicpipes.pipes; + +import java.util.List; + +import basicpipes.BasicPipesMain; + +import net.minecraft.src.Block; +import net.minecraft.src.CreativeTabs; +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; +import net.minecraft.src.TileEntity; +import net.minecraft.src.World; + +public class ItemPipe extends Item +{ + int index = 32;//32 + 4 rows alloted to pipes + String[] names = new String[]{"Steam","Water","Lava","Oil","Fuel","Air","Methain","BioFuel","coolent","NukeWaste"}; + private int spawnID; + + public ItemPipe(int id) + { + super(id); + this.setMaxDamage(0); + this.setHasSubtypes(true); + this.setIconIndex(10); + this.setItemName("pipe"); + this.setTabToDisplayOn(CreativeTabs.tabRedstone); + } + @Override + public int getIconFromDamage(int par1) + { + + return par1+index; + } + @Override + public String getItemNameIS(ItemStack itemstack) + { + return itemstack.getItemDamage() < names.length ? names[itemstack.getItemDamage()] +" Pipe2" : "EmptyPipe"; + } + @Override + public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) + { + for(int i = 0; i < names.length; i++) + { + par3List.add(new ItemStack(this, 1, i)); + } + } + public String getTextureFile() { + return "/EUIClient/Textures/Items.png"; + } + @Override + public String getItemName() + { + return "Pipes"; + } + @Override + public boolean tryPlaceIntoWorld(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) + { + int blockID = par3World.getBlockId(par4, par5, par6); + spawnID = BasicPipesMain.pipeID; + if (blockID == Block.snow.blockID) + { + par7 = 1; + } + else if (blockID != Block.vine.blockID && blockID != Block.tallGrass.blockID && blockID != Block.deadBush.blockID) + { + if (par7 == 0) + { + --par5; + } + + if (par7 == 1) + { + ++par5; + } + + if (par7 == 2) + { + --par6; + } + + if (par7 == 3) + { + ++par6; + } + + if (par7 == 4) + { + --par4; + } + + if (par7 == 5) + { + ++par4; + } + } + + if (BasicPipesMain.pipe.canPlaceBlockAt(par3World,par4,par5,par6)) + { + Block var9 = Block.blocksList[this.spawnID]; + par3World.editingBlocks = true; + if (par3World.setBlockWithNotify(par4, par5, par6, var9.blockID)) + { + if (par3World.getBlockId(par4, par5, par6) == var9.blockID) + { + + Block.blocksList[this.spawnID].onBlockAdded(par3World, par4, par5, par6); + Block.blocksList[this.spawnID].onBlockPlacedBy(par3World, par4, par5, par6, par2EntityPlayer); + TileEntity blockEntity = par3World.getBlockTileEntity(par4, par5, par6); + if(blockEntity instanceof TileEntityPipe) + { + TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity; + int dm = par1ItemStack.getItemDamage(); + pipeEntity.setType(dm); + } + } + + --par1ItemStack.stackSize; + par3World.editingBlocks = false; + return true; + } + } + par3World.editingBlocks = false; + return false; + } + + +} \ No newline at end of file diff --git a/src/common/basicpipes/pipes/TileEntityCondenser.java b/src/common/basicpipes/pipes/TileEntityCondenser.java new file mode 100644 index 000000000..25ebd4a0c --- /dev/null +++ b/src/common/basicpipes/pipes/TileEntityCondenser.java @@ -0,0 +1,98 @@ +package basicpipes.pipes; + +import basicpipes.pipes.api.ILiquidProducer; +import net.minecraft.src.NBTTagCompound; +import net.minecraft.src.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.extend.IElectricUnit; + +public class TileEntityCondenser extends TileEntity implements ILiquidProducer, IElectricUnit { + int tickCount = 0; + int waterStored = 0; + int energyStored = 0; + @Override + public int onProduceLiquid(int type,int maxVol, ForgeDirection side) { + if(type == 1) + { + int tradeW = Math.min(maxVol, waterStored); + waterStored -= tradeW; + return tradeW; + } + return 0; + } + public void writeToNBT(NBTTagCompound par1NBTTagCompound) + { + super.writeToNBT(par1NBTTagCompound); + par1NBTTagCompound.setInteger("energyStored", (int)this.energyStored); + par1NBTTagCompound.setInteger("waterStored", (int)this.waterStored); + } + + public void readFromNBT(NBTTagCompound par1NBTTagCompound) + { + super.readFromNBT(par1NBTTagCompound); + this.energyStored = par1NBTTagCompound.getInteger("energyStored"); + this.waterStored = par1NBTTagCompound.getInteger("waterStored"); + } + public void updateEntity() + { + if(energyStored > 100 && tickCount > 200 && waterStored < 10) + { + energyStored -= 100; + waterStored += 1; + tickCount = 0; + } + tickCount++; + } + @Override + public boolean canProduceLiquid(int type, ForgeDirection side) { + if(type == 1) + { + return true; + } + return false; + } + @Override + public void onDisable(int duration) { + // TODO Auto-generated method stub + + } + @Override + public boolean isDisabled() { + // TODO Auto-generated method stub + return false; + } + @Override + public void onUpdate(float amps, float voltage, ForgeDirection side) { + // TODO Auto-generated method stub + + } + @Override + public float electricityRequest() { + // TODO Auto-generated method stub + return 0; + } + @Override + public boolean canConnect(ForgeDirection side) { + // TODO Auto-generated method stub + return false; + } + @Override + public boolean canReceiveFromSide(ForgeDirection side) { + // TODO Auto-generated method stub + return false; + } + @Override + public float getVoltage() { + // TODO Auto-generated method stub + return 0; + } + @Override + public int getTickInterval() { + // TODO Auto-generated method stub + return 0; + } + + + + +} diff --git a/src/common/basicpipes/pipes/TileEntityPipe.java b/src/common/basicpipes/pipes/TileEntityPipe.java new file mode 100644 index 000000000..cc0da15d2 --- /dev/null +++ b/src/common/basicpipes/pipes/TileEntityPipe.java @@ -0,0 +1,266 @@ +package basicpipes.pipes; +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.NBTTagCompound; +import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.Vector3; +import universalelectricity.network.IPacketReceiver; +import universalelectricity.network.PacketManager; +import basicpipes.pipes.api.ILiquidConsumer; +import basicpipes.pipes.api.ILiquidProducer; + +import com.google.common.io.ByteArrayDataInput; +public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacketReceiver +{ + //The amount stored in the conductor + protected int liquidStored = 0; + //the current set type of the pipe 0-5 + protected int type = 0; + //The maximum amount of electricity this conductor can take + protected int capacity = 5; + private int count = 0; + private boolean intiUpdate = true; + //Stores information on all connected blocks around this tile entity + public TileEntity[] connectedBlocks = {null, null, null, null, null, null}; + + //Checks if this is the first the tile entity updates + protected boolean firstUpdate = true; + /** + * This function adds a connection between this pipe and other blocks + * @param tileEntity - Must be either a producer, consumer or a conductor + * @param side - side in which the connection is coming from + */ + public void addConnection(TileEntity tileEntity, ForgeDirection side) + { + int sideN = getNumSide(side); + this.connectedBlocks[sideN] = null; + if(tileEntity instanceof ILiquidConsumer) + { + if(((ILiquidConsumer)tileEntity).canRecieveLiquid(this.type, side)) + { + this.connectedBlocks[sideN] = tileEntity; + } + } + if(tileEntity instanceof ILiquidProducer) + { + if(((ILiquidProducer)tileEntity).canProduceLiquid(this.type, side)) + { + this.connectedBlocks[sideN] = tileEntity; + } + } + } + + + + private int getNumSide(ForgeDirection side) { + +if(side == ForgeDirection.DOWN) +{ + return 0; +} +if(side == ForgeDirection.UP) +{ + return 1; +} +if(side == ForgeDirection.NORTH) +{ + return 2; +} +if(side == ForgeDirection.SOUTH) +{ + return 3; +} +if(side == ForgeDirection.WEST) +{ + return 4; +} +if(side == ForgeDirection.EAST) +{ + return 5; +} + + + return 0; + } + + + + /** + * onRecieveLiquid is called whenever a something sends a volume to the pipe (which is this block). + * @param vols - The amount of vol source is trying to give to this pipe + * @param side - The side of the block in which the liquid came from + * @return vol - The amount of rejected liquid that can't enter the pipe + */ + @Override + public int onReceiveLiquid(int type,int vol, ForgeDirection side) + { + if(type == this.type) + { + int rejectedVolume = Math.max((this.getStoredLiquid(type) + vol) - this.capacity, 0); + this.liquidStored += vol - rejectedVolume; + return rejectedVolume; + } + return vol; + } + @Override + public void updateEntity() + { + //cause the block to update itself every tick needs to be change to .5 seconds to reduce load + BlockPipe.updateConductorTileEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord); + count++; + if(count >= 30 || intiUpdate) + { + PacketManager.sendTileEntityPacket(this, "Pipes", new Object[]{this.type}); + count = 0; + intiUpdate = false; + } + if(!this.worldObj.isRemote) + { + byte connectedUnits = 0; + byte connectedConductors = 1; + int averageVolume = this.liquidStored; + + Vector3 currentPosition = new Vector3(this.xCoord, this.yCoord, this.zCoord); + + for(byte i = 0; i < 6; i++) + { + if(connectedBlocks[i] != null) + { + if(connectedBlocks[i] instanceof ILiquidConsumer || connectedBlocks[i] instanceof ILiquidProducer) + { + connectedUnits ++; + + if(connectedBlocks[i] instanceof TileEntityPipe) + { + averageVolume += ((TileEntityPipe)connectedBlocks[i]).liquidStored; + + connectedConductors ++; + } + } + } + } + //average volume used to control volume spread to pipes. Prevent one pipe getting all liquid when another is empty + averageVolume = Math.max(averageVolume/connectedConductors,0); + if(connectedUnits > 0) + { + for(byte i = 0; i < 6; i++) + { + if(connectedBlocks[i] != null) + { + //Spread the liquid among the different blocks + if(connectedBlocks[i] instanceof ILiquidConsumer && this.liquidStored > 0) + { + if(((ILiquidConsumer)connectedBlocks[i]).canRecieveLiquid(this.type,ForgeDirection.getOrientation(i))) + { + int transferVolumeAmount = 0; //amount to be moved + ILiquidConsumer connectedConsumer = ((ILiquidConsumer)connectedBlocks[i]); + + if(connectedBlocks[i] instanceof TileEntityPipe && this.liquidStored > ((TileEntityPipe)connectedConsumer).liquidStored) + { + transferVolumeAmount = Math.max(Math.min(averageVolume - ((TileEntityPipe)connectedConsumer).liquidStored, this.liquidStored), 0); + } + else if(!(connectedConsumer instanceof TileEntityPipe)) + { + transferVolumeAmount = this.liquidStored; + } + + int rejectedVolume = connectedConsumer.onReceiveLiquid(this.type,transferVolumeAmount, ForgeDirection.getOrientation(i)); + this.liquidStored = Math.max(Math.min(this.liquidStored - transferVolumeAmount + rejectedVolume, 5), 0); + } + } + + if(connectedBlocks[i] instanceof ILiquidProducer && this.liquidStored < this.getLiquidCapacity(type)) + { + if(((ILiquidProducer)connectedBlocks[i]).canProduceLiquid(this.type,ForgeDirection.getOrientation(i))) + { + int gainedVolume = ((ILiquidProducer)connectedBlocks[i]).onProduceLiquid(this.type,5-this.liquidStored, ForgeDirection.getOrientation(i)); + this.onReceiveLiquid(this.type, gainedVolume, ForgeDirection.getOrientation(i)); + } + } + } + } + } + } + } + + /** + * @return Return the stored volume in this pipe. + */ + @Override + public int getStoredLiquid(int type) + { + return this.liquidStored; + } + + + @Override + public int getLiquidCapacity(int type) + { + return 5; + } + + /** + * Reads a tile entity from NBT. + */ + public void readFromNBT(NBTTagCompound par1NBTTagCompound) + { + super.readFromNBT(par1NBTTagCompound); + this.liquidStored = par1NBTTagCompound.getInteger("liquid"); + this.type = par1NBTTagCompound.getInteger("type"); + } + + /** + * Writes a tile entity to NBT. + */ + public void writeToNBT(NBTTagCompound par1NBTTagCompound) + { + super.writeToNBT(par1NBTTagCompound); + par1NBTTagCompound.setInteger("liquid", this.liquidStored); + par1NBTTagCompound.setInteger("type", this.type); + } +//find wether or not this side of X block can recieve X liquid type. Also use to determine connection of a pipe + @Override + public boolean canRecieveLiquid(int type, ForgeDirection side) { + if(type == this.type) + { + return true; + } + return false; + } + //returns liquid type + public int getType() { + return this.type; + } + + //used by the item to set the liquid type on spawn + public void setType(int rType) { + this.type = rType; + + } + + + + @Override + public void handlePacketData(NetworkManager network, + Packet250CustomPayload packet, EntityPlayer player, + ByteArrayDataInput data) { + try + { + int type = data.readInt(); + if(worldObj.isRemote) + { + this.type = type; + } + } + catch(Exception e) + { + e.printStackTrace(); + } + + + } + +} + diff --git a/src/common/basicpipes/pipes/TileEntityPump.java b/src/common/basicpipes/pipes/TileEntityPump.java new file mode 100644 index 000000000..1d39cc0cb --- /dev/null +++ b/src/common/basicpipes/pipes/TileEntityPump.java @@ -0,0 +1,89 @@ +package basicpipes.pipes; + +import basicpipes.pipes.api.ILiquidProducer; +import net.minecraft.src.Block; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.electricity.TileEntityElectricUnit; +import universalelectricity.extend.IElectricUnit; + +public class TileEntityPump extends TileEntityElectricUnit implements ILiquidProducer,IElectricUnit { + int dCount = 0; + float eStored = 0; + float eMax = 2000; + int wStored = 0; + int wMax = 10; + @Override + public void onDisable(int duration) { + dCount = duration; + } + + @Override + public boolean isDisabled() { + if(dCount <= 0) + { + return false; + } + return true; + } + + @Override + public void onUpdate(float watts, float voltage, ForgeDirection side) { + super.onUpdate(watts, voltage, side); + if (electricityRequest() > 0 && canConnect(side)) + { + float rejectedElectricity = (float) Math.max((this.eStored + watts) - this.eMax, 0.0); + this.eStored = (float) Math.max(this.eStored + watts - rejectedElectricity, 0.0); + } + int bBlock = worldObj.getBlockId(xCoord, yCoord -1, zCoord); + if(bBlock == Block.waterStill.blockID && this.eStored > 1000 && this.wStored < this.wMax) + { + eStored -= 1000; + wStored += 1; + worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord-1, zCoord, 0, 0); + } + + } + + @Override + public float electricityRequest() { + return Math.max(eMax - eStored,0); + } + @Override + public boolean canReceiveFromSide(ForgeDirection side) { + if(side != ForgeDirection.DOWN) + { + return true; + } + return false; + } + + @Override + public float getVoltage() { + return 240; + } + + @Override + public int getTickInterval() { + return 40; + } + + @Override + public int onProduceLiquid(int type, int maxVol, ForgeDirection side) { + if(type == 1 && wStored > 0) + { + int tradeW = Math.min(maxVol, wStored); + wStored -= tradeW; + return tradeW; + } + return 0; + } + + @Override + public boolean canProduceLiquid(int type, ForgeDirection side) { + if(type == 1 && side != ForgeDirection.DOWN) + { + return true; + } + return false; + } +} diff --git a/src/minecraft/basicpipes/ModelPipe.java b/src/minecraft/basicpipes/ModelPipe.java new file mode 100644 index 000000000..e1a21d368 --- /dev/null +++ b/src/minecraft/basicpipes/ModelPipe.java @@ -0,0 +1,98 @@ +package basicpipes; + +import net.minecraft.src.*; + +public class ModelPipe extends ModelBase +{ + //fields + ModelRenderer Middle; + ModelRenderer Right; + ModelRenderer Left; + ModelRenderer Back; + ModelRenderer Front; + ModelRenderer Top; + ModelRenderer Bottom; + + public ModelPipe() + { + textureWidth = 64; + textureHeight = 32; + + Middle = new ModelRenderer(this, 0, 0); + Middle.addBox(-1F, -1F, -1F, 4, 4, 4); + Middle.setRotationPoint(-1F, 15F, -1F); + Middle.setTextureSize(64, 32); + Middle.mirror = true; + setRotation(Middle, 0F, 0F, 0F); + Right = new ModelRenderer(this, 21, 0); + Right.addBox(0F, 0F, 0F, 6, 4, 4); + Right.setRotationPoint(2F, 14F, -2F); + Right.setTextureSize(64, 32); + Right.mirror = true; + setRotation(Right, 0F, 0F, 0F); + Left = new ModelRenderer(this, 21, 0); + Left.addBox(0F, 0F, 0F, 6, 4, 4); + Left.setRotationPoint(-8F, 14F, -2F); + Left.setTextureSize(64, 32); + Left.mirror = true; + setRotation(Left, 0F, 0F, 0F); + Back = new ModelRenderer(this, 0, 11); + Back.addBox(0F, 0F, 0F, 4, 4, 6); + Back.setRotationPoint(-2F, 14F, 2F); + Back.setTextureSize(64, 32); + Back.mirror = true; + setRotation(Back, 0F, 0F, 0F); + Front = new ModelRenderer(this, 0, 11); + Front.addBox(0F, 0F, 0F, 4, 4, 6); + Front.setRotationPoint(-2F, 14F, -8F); + Front.setTextureSize(64, 32); + Front.mirror = true; + setRotation(Front, 0F, 0F, 0F); + Top = new ModelRenderer(this, 21, 11); + Top.addBox(0F, 0F, 0F, 4, 6, 4); + Top.setRotationPoint(-2F, 8F, -2F); + Top.setTextureSize(64, 32); + Top.mirror = true; + setRotation(Top, 0F, 0F, 0F); + Bottom = new ModelRenderer(this, 21, 11); + Bottom.addBox(0F, 0F, 0F, 4, 6, 4); + Bottom.setRotationPoint(-2F, 18F, -2F); + Bottom.setTextureSize(64, 32); + Bottom.mirror = true; + setRotation(Bottom, 0F, 0F, 0F); + } + + public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) + { + super.render(entity, f, f1, f2, f3, f4, f5); + setRotationAngles(f, f1, f2, f3, f4, f5); + this.renderMiddle(); + this.renderBottom(); + this.renderTop(); + this.renderLeft(); + this.renderRight(); + this.renderBack(); + this.renderFront(); + } + + public void renderMiddle() { Middle.render(0.0625F); } + public void renderBottom() { Bottom.render(0.0625F); } + public void renderTop() { Top.render(0.0625F); } + public void renderLeft() { Left.render(0.0625F); } + public void renderRight() { Right.render(0.0625F); } + public void renderBack() { Back.render(0.0625F); } + public void renderFront() { Front.render(0.0625F);} + + private void setRotation(ModelRenderer model, float x, float y, float z) + { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } + + public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5) + { + super.setRotationAngles(f, f1, f2, f3, f4, f5); + } + +} diff --git a/src/minecraft/basicpipes/PipeClientProxy.java b/src/minecraft/basicpipes/PipeClientProxy.java new file mode 100644 index 000000000..eb707d7dd --- /dev/null +++ b/src/minecraft/basicpipes/PipeClientProxy.java @@ -0,0 +1,23 @@ +package basicpipes; + +import basicpipes.PipeProxy; +import basicpipes.pipes.TileEntityPipe; +import net.minecraftforge.client.MinecraftForgeClient; +import cpw.mods.fml.client.registry.ClientRegistry; + +public class PipeClientProxy extends PipeProxy +{ + @Override + public void preInit() + { + //Preload textures + MinecraftForgeClient.preloadTexture("/EUIClient/Textures/Items.png"); + MinecraftForgeClient.preloadTexture("/EUIClient/Textures/blocks.png"); + } + + @Override + public void init() + { + ClientRegistry.registerTileEntity(TileEntityPipe.class, "pipe", new RenderPipe()); + } +} diff --git a/src/minecraft/basicpipes/RenderPipe.java b/src/minecraft/basicpipes/RenderPipe.java new file mode 100644 index 000000000..972851509 --- /dev/null +++ b/src/minecraft/basicpipes/RenderPipe.java @@ -0,0 +1,58 @@ +package basicpipes; + +import net.minecraft.src.TileEntity; +import net.minecraft.src.TileEntitySpecialRenderer; + +import org.lwjgl.opengl.GL11; + +import basicpipes.pipes.TileEntityPipe; + + +public class RenderPipe extends TileEntitySpecialRenderer +{ + int type = 0; + private ModelPipe model; + + public RenderPipe() + { + model = new ModelPipe(); + } + + public void renderAModelAt(TileEntityPipe tileEntity, double d, double d1, double d2, float f) + { + //Texture file + + type = tileEntity.getType(); + switch(type) + { + case 0: bindTextureByName("/EUIClient/Textures/SteamPipe.png");break; + case 1: bindTextureByName("/EUIClient/Textures/WaterPipe.png");break; + //case 2: bindTextureByName("/eui/lavaPipe.png");break; + //case 3: bindTextureByName("/eui/oilPipe.png");break; + //case 4: bindTextureByName("/eui/fuelPipe.png");break; + //case 5: bindTextureByName("/eui/airPipe.png");break; + default:bindTextureByName("/EUIClient/Textures/DefaultPipe.png"); break; + } + + GL11.glPushMatrix(); + GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F); + GL11.glScalef(1.0F, -1F, -1F); + + if(tileEntity.connectedBlocks[0] != null) model.renderBottom(); + if(tileEntity.connectedBlocks[1] != null) model.renderTop(); + if(tileEntity.connectedBlocks[2] != null) model.renderFront(); + if(tileEntity.connectedBlocks[3] != null) model.renderBack(); + if(tileEntity.connectedBlocks[4] != null) model.renderRight(); + if(tileEntity.connectedBlocks[5] != null) model.renderLeft(); + + model.renderMiddle(); + GL11.glPopMatrix(); + + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) { + this.renderAModelAt((TileEntityPipe)tileEntity, var2, var4, var6, var8); + } + +} \ No newline at end of file