package net.teamio.taam.content.piping;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.teamio.taam.Log;
import net.teamio.taam.Taam;
import net.teamio.taam.content.BaseBlock;
import net.teamio.taam.content.MaterialMachinesTransparent;

public class BlockPipeMachines extends BaseBlock {

	public static final PropertyEnum<Taam.BLOCK_PIPEMACHINES_META> VARIANT = PropertyEnum.create("variant", Taam.BLOCK_PIPEMACHINES_META.class);
	
	public BlockPipeMachines() {
		super(MaterialMachinesTransparent.INSTANCE);
		this.setHardness(3.5f);
		this.setStepSound(Block.soundTypeMetal);
		this.setHarvestLevel("pickaxe", 1);
	}
	
	@Override
	protected BlockState createBlockState() {
		return new BlockState(this, VARIANT);
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		Taam.BLOCK_PIPEMACHINES_META meta = (Taam.BLOCK_PIPEMACHINES_META)state.getValue(VARIANT);
		return meta.ordinal();
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		Taam.BLOCK_PIPEMACHINES_META[] values = Taam.BLOCK_PIPEMACHINES_META.values();
		if(meta < 0 || meta > values.length) {
			return getDefaultState();
		}
		return getDefaultState().withProperty(VARIANT, values[meta]);
	}
	
	public String getUnlocalizedName(ItemStack itemStack) {
		int i = itemStack.getItemDamage();
		Enum<?>[] values = Taam.BLOCK_PIPEMACHINES_META.values();

		if (i < 0 || i >= values.length) {
			i = 0;
		}

		return super.getUnlocalizedName() + "." + values[i].name();
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public void getSubBlocks(Item item, CreativeTabs creativeTab, List<ItemStack> list) {
		Enum<?>[] values = Taam.BLOCK_PIPEMACHINES_META.values();
		for (int i = 0; i < values.length; i++) {
			list.add(new ItemStack(item, 1, i));
		}
	}
	
	@Override
	public TileEntity createTileEntity(World world, IBlockState state) {
		Taam.BLOCK_PIPEMACHINES_META variant = (Taam.BLOCK_PIPEMACHINES_META)state.getValue(VARIANT);
		switch(variant) {
		case tank:
			return new TileEntityTank();
		case creativewell:
			return new TileEntityCreativeWell();
		}
		Log.error("Was not able to create a TileEntity for " + getClass().getName());
		return null;
	}
	
	@Override
	public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
		return true;
	}

}

@@ -431,16 +431,63 @@
 ockPos;%0A
+import net.minecraft.util.EnumWorldBlockLayer;%0A
 import n
@@ -512,16 +512,16 @@
 .World;%0A
-
 import n
@@ -964,18 +964,17 @@
 class);%0A
-%09
 %0A
+
 %09public 
@@ -1148,26 +1148,25 @@
 xe%22, 1);%0A%09%7D%0A
-%09
 %0A
+
 %09@Override%0A%09
@@ -1246,26 +1246,25 @@
 ARIANT);%0A%09%7D%0A
-%09
 %0A
+
 %09@Override%0A%09
@@ -1372,32 +1372,33 @@
 PEMACHINES_META)
+ 
 state.getValue(V
@@ -1430,26 +1430,25 @@
 dinal();%0A%09%7D%0A
-%09
 %0A
+
 %09@Override%0A%09
@@ -1580,16 +1580,17 @@
 ();%0A%09%09if
+ 
 (meta %3C 
@@ -1718,17 +1718,127 @@
 a%5D);%0A%09%7D%0A
-%09
+%0A%09@SideOnly(Side.CLIENT)%0A%09public EnumWorldBlockLayer getBlockLayer() %7B%0A%09%09return EnumWorldBlockLayer.CUTOUT;%0A%09%7D%0A
 %0A%09public
@@ -2098,26 +2098,25 @@
 .name();%0A%09%7D%0A
-%09
 %0A
+
 %09@Override%0A%09
@@ -2372,26 +2372,25 @@
 i));%0A%09%09%7D%0A%09%7D%0A
-%09
 %0A
+
 %09@Override%0A%09
@@ -2529,16 +2529,17 @@
 ES_META)
+ 
 state.ge
@@ -2563,16 +2563,17 @@
 %09%09switch
+ 
 (variant
@@ -2784,17 +2784,16 @@
 ull;%0A%09%7D%0A
-%09
 %0A%09@Overr

Fix alpha rendering in tanks / pipe blocks