Started work on valve

should have this done this weekend and it will be a basic valve that
denies connection of pipes when off. Version one will be by hand and
version two by redstone. Both are start in the same block.
This commit is contained in:
Rseifert 2012-09-23 07:29:19 -04:00
parent f16047c2ad
commit d41c646249
8 changed files with 442 additions and 7 deletions

View file

@ -7,6 +7,7 @@ import basicpipes.pipes.ItemParts;
import basicpipes.pipes.ItemPipe;
import basicpipes.pipes.api.Liquid;
import basicpipes.pumps.BlockMachine;
import basicpipes.pumps.BlockValve;
import basicpipes.pumps.TileEntityPump;
import net.minecraft.client.Minecraft;
@ -43,20 +44,25 @@ public class BasicPipesMain{
private static int ppipeID;
public static int machineID;
private static int toolID;
public static int valveID;
public static Block pipe = new BlockPipe(pipeID).setBlockName("pipe");
public static Block machine = new BlockMachine(machineID).setBlockName("pump");
public static Block valve = new BlockValve(valveID).setBlockName("valve");
public static Item parts = new ItemParts(partID);
public static Item itemPipes = new ItemPipe(ppipeID);
public static Item gauge = new ItemGuage(toolID);
public static String channel = "Pipes";
public static String textureFile = "/textures";
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);
valveID = Integer.parseInt(config.getOrCreateIntProperty("machineBlock", Configuration.CATEGORY_BLOCK, 157).value);
partID = Integer.parseInt(config.getOrCreateIntProperty("parts", Configuration.CATEGORY_ITEM, 23022).value);
ppipeID = Integer.parseInt(config.getOrCreateIntProperty("pipes", Configuration.CATEGORY_ITEM, 23023).value);
toolID = Integer.parseInt(config.getOrCreateIntProperty("ToolID", Configuration.CATEGORY_ITEM, 23024).value);

View file

@ -1,7 +1,5 @@
package basicpipes;
package basicpipes.pipes.api;
import basicpipes.pipes.api.ILiquidConsumer;
import basicpipes.pipes.api.Liquid;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;

View file

@ -26,8 +26,7 @@ public class BlockMachine extends BlockContainer
public boolean renderAsNormalBlock()
{
//TODO change later when custom models are added
return true;
return false;
}
/**
@ -43,6 +42,18 @@ public class BlockMachine extends BlockContainer
*/
public int idDropped(int par1, Random par2Random, int par3)
{
return this.blockID;
}
protected int damageDropped(int meta)
{
if(meta < 4)
{
return 0;
}
if(meta > 3 && meta < 8)
{
return 4;
}
return 0;
}
//Per tick
@ -60,6 +71,10 @@ public class BlockMachine extends BlockContainer
if(meta > 3 && meta < 8)
{
return new TileEntityCondenser();
}
if(meta > 7 && meta < 12)
{
return new TileEntityValve();
}
return null;
}

View file

@ -0,0 +1,179 @@
package basicpipes.pumps;
import java.util.ArrayList;
import net.minecraft.src.*;
import java.util.Random;
import universalelectricity.UniversalElectricity;
import basicpipes.BasicPipesMain;
public class BlockValve extends universalelectricity.extend.BlockMachine
{
public BlockValve(int id)
{
super("Valve", id, Material.iron);
this.setBlockName("Valve");
this.setCreativeTab(CreativeTabs.tabRedstone);
this.setRequiresSelfNotify();
this.blockIndexInTexture = 26;
}
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player)
{
TileEntity te = world.getBlockTileEntity(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(te instanceof TileEntityValve)
{
TileEntityValve valve = (TileEntityValve) te;
if(meta < 8)
{
if(!valve.on){
valve.on = true;
}else{
valve.on = false;
}
}
}
return false;
}
//rotation valve around y axis
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer player)
{
int meta = world.getBlockMetadata(x, y, z);
if(meta < 4)
{
if(meta == 3)
{
world.setBlockMetadataWithNotify(x, y, z, 0);
}
else
{
world.setBlockMetadataWithNotify(x, y, z, meta+1);
}
return true;
}
if(meta > 3 && meta < 8)
{
if(meta == 7)
{
world.setBlockMetadataWithNotify(x, y, z, 4);
}
else
{
world.setBlockMetadataWithNotify(x, y, z, meta+1);
}
return true;
}
if(meta > 7 && meta < 12)
{
if(meta == 11)
{
world.setBlockMetadataWithNotify(x, y, z, 8);
}
else
{
world.setBlockMetadataWithNotify(x, y, z, meta+1);
}
return true;
}
if(meta > 11 && meta < 16)
{
if(meta == 15)
{
world.setBlockMetadataWithNotify(x, y, z, 12);
}
else
{
world.setBlockMetadataWithNotify(x, y, z, meta+1);
}
return true;
}
return false;
}
//one shift click inverts pipe to face up
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer player)
{
int meta = world.getBlockMetadata(x, y, z);
if(meta < 4)
{
world.setBlockMetadataWithNotify(x, y, z, meta+4);
return true;
}
if(meta > 3 && meta < 8)
{
world.setBlockMetadataWithNotify(x, y, z, meta-4);
return true;
}
if(meta > 7 && meta < 12)
{
world.setBlockMetadataWithNotify(x, y, z, meta+4);
return true;
}
if(meta > 11 && meta < 16)
{
world.setBlockMetadataWithNotify(x, y, z, meta-4);
return true;
}
return false;
}
public boolean isOpaqueCube()
{
return false;
}
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 this.blockID;
}
protected int damageDropped(int meta)
{
if(meta < 8)
{
return 0;
}
if(meta < 16 && meta > 7)
{
return 4;
}
return 0;
}
//Per tick
public int conductorCapacity()
{
return 1;
}
@Override
public TileEntity createNewTileEntity(World var1) {
// TODO Auto-generated method stub
return new TileEntityValve();
}
@Override
public String getTextureFile() {
return BasicPipesMain.textureFile+"/Items.png";
}
}

View file

@ -37,13 +37,14 @@ public class ItemMachine extends ItemBlock
@Override
public String getItemNameIS(ItemStack itemstack)
{
return itemstack.getItemDamage() == 0 ? "Pump" :"Condenser";
return itemstack.getItemDamage() == 0 ? "Pump" :"Conderser";//itemstack.getItemDamage() == 4 ? "Condenser":"Unknown";
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(this, 1, 0));
par3List.add(new ItemStack(this, 1, 4));
}
public String getTextureFile() {

View file

@ -0,0 +1,126 @@
package basicpipes.pumps;
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.ItemBlock;
import net.minecraft.src.ItemStack;
import net.minecraft.src.MathHelper;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
public class ItemValve extends ItemBlock
{
int index = 26;
private int spawnID;
public ItemValve(int id)
{
super(id);
this.setMaxDamage(0);
this.setHasSubtypes(true);
this.setIconIndex(10);
this.setItemName("Machine");
this.setTabToDisplayOn(CreativeTabs.tabRedstone);
}
@Override
public int getIconFromDamage(int par1)
{
return par1+index;
}
@Override
public String getItemNameIS(ItemStack itemstack)
{
return itemstack.getItemDamage() == 0 ? "Pump" :"Conderser";//itemstack.getItemDamage() == 4 ? "Condenser":"Unknown";
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(this, 1, 0));
par3List.add(new ItemStack(this, 1, 4));
}
public String getTextureFile() {
return BasicPipesMain.textureFile+"/Items.png";
}
@Override
public String getItemName()
{
return "Machines";
}
@Override
public boolean tryPlaceIntoWorld(ItemStack itemStack, EntityPlayer player, 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.valveID;
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;
int angle = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
if (par3World.setBlockAndMetadataWithNotify(par4, par5, par6, var9.blockID,angle+itemStack.getItemDamage()))
{
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, player);
TileEntity blockEntity = par3World.getBlockTileEntity(par4, par5, par6);
}
--itemStack.stackSize;
par3World.editingBlocks = false;
return true;
}
}
par3World.editingBlocks = false;
return false;
}
}

View file

@ -1,8 +1,8 @@
package basicpipes.pumps;
import basicpipes.TradeHelper;
import basicpipes.pipes.api.ILiquidProducer;
import basicpipes.pipes.api.Liquid;
import basicpipes.pipes.api.TradeHelper;
import net.minecraft.src.Block;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;

View file

@ -0,0 +1,110 @@
package basicpipes.pumps;
import universalelectricity.Vector3;
import basicpipes.pipes.api.ILiquidConsumer;
import basicpipes.pipes.api.Liquid;
import basicpipes.pipes.api.TradeHelper;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import basicpipes.pipes.TileEntityPipe;
public class TileEntityValve extends TileEntity implements ILiquidConsumer {
Liquid type = Liquid.DEFUALT;
int liquidStored = 0;
int lMax = 1;
int tickCount = 0;
TileEntity[] connected = {null,null,null,null,null,null};
boolean on = false;
@Override
public void updateEntity()
{
tickCount++;
if(tickCount >= 10)
{
int deltaX = 0;
int deltaZ = 0;
int deltaY = 0;
int facing = 0;
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if(meta == 0 && meta == 8)
{
facing = 2;
}
if(meta == 1 && meta == 9)
{
facing = 5;
}
if(meta == 2 && meta == 10)
{
facing = 3;
}
if(meta == 3 && meta == 11)
{
facing = 4;
}
if((meta > 3 && meta < 8)&&(meta> 11 && meta < 16))
{
facing = 0;
}
switch(facing)
{
case 0: deltaY++;break;
case 1: deltaY--;break;
case 2: deltaZ--;break;
case 5: deltaZ++;break;
case 3: deltaX--;break;
case 4: deltaX++;break;
}
connected = TradeHelper.getSourounding(this);
for(int i = 0;i<6;i++)
{
if(!(connected[i] instanceof TileEntityPipe))
{
connected[i] = null;
}
}
if(!worldObj.isRemote)
{
//TODO send packet
}
tickCount = 0;
}
}
@Override
public int onReceiveLiquid(Liquid type, int vol, ForgeDirection side) {
if(this.type == Liquid.DEFUALT)
{
this.type = type;
}
return vol;
}
@Override
public boolean canRecieveLiquid(Liquid type, ForgeDirection forgeDirection) {
if(type == this.type)
{
return true;
}
return false;
}
@Override
public int getStoredLiquid(Liquid type) {
if(type == this.type)
{
return liquidStored;
}
return 0;
}
@Override
public int getLiquidCapacity(Liquid type) {
if(type == this.type)
{
return lMax;
}
return 0;
}
}