package frogcraftrebirth.common.block;

import javax.annotation.Nullable;

import frogcraftrebirth.FrogCraftRebirth;
import frogcraftrebirth.common.lib.block.BlockFrogWrenchable;
import frogcraftrebirth.common.lib.tile.TileFrog;
import frogcraftrebirth.common.tile.TileCondenseTower;
import frogcraftrebirth.common.tile.TileCondenseTowerStructure;
import frogcraftrebirth.common.tile.TileFluidOutputHatch;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class BlockCondenseTower extends BlockFrogWrenchable implements ITileEntityProvider {
	
	public static final PropertyEnum<Part> TYPE = PropertyEnum.<Part>create("part", Part.class);

	public BlockCondenseTower() {
		super(MACHINE, "condense_tower", false, 0, 1, 2);
		setUnlocalizedName("condenseTower");
		setHardness(15.0F);
		setResistance(20.0f);
	}
	
	@Override
	protected IProperty<?>[] getPropertyArray() {
		return new IProperty[] { TYPE, FACING_HORIZONTAL };
	}

	@Override
	public TileEntity createNewTileEntity(World world, int meta) {
		switch (meta) {
		case 0:
			return new TileCondenseTower();
		case 1:
			return new TileCondenseTowerStructure();
		case 2:
			return new TileFluidOutputHatch();
		}
		
		return null;
	}
	
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
		if (worldIn.isRemote)
			return false;
		else {
			if (worldIn.getTileEntity(pos) instanceof TileFrog) {
				playerIn.openGui(FrogCraftRebirth.instance, 2, worldIn, pos.getX(), pos.getY(), pos.getZ());
				return true;
			}
		}
		return false;
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		int facing = state.getValue(FACING_HORIZONTAL).getIndex();
		return facing << 2 + state.getValue(TYPE).ordinal() - 2;
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		int facing = meta >> 2, type = meta & 0b11;
		return this.getDefaultState().withProperty(FACING_HORIZONTAL, EnumFacing.getFront(facing)).withProperty(TYPE, Part.values()[type]);
	}
	
	public static enum Part implements IStringSerializable {
		CORE, CYLINDER, OUTPUT;

		@Override
		public String getName() {
			return this.name().toLowerCase();
		}
	}

}

@@ -1499,16 +1499,17 @@
 %7B%0A%09%09
+%09
 case 0:%0A
 %09%09%09r
@@ -1504,16 +1504,17 @@
 case 0:%0A
+%09
 %09%09%09retur
@@ -1546,16 +1546,17 @@
 ;%0A%09%09
+%09
 case 1:%0A
 %09%09%09r
@@ -1551,16 +1551,17 @@
 case 1:%0A
+%09
 %09%09%09retur
@@ -1602,16 +1602,17 @@
 ;%0A%09%09
+%09
 case 2:%0A
 %09%09%09r
@@ -1607,16 +1607,17 @@
 case 2:%0A
+%09
 %09%09%09retur
@@ -1650,28 +1650,143 @@
 ();%0A
+%09%09%09default:%0A%09%09%09%09return null;%0A
 %09%09%7D%0A%09
+%7D%0A
 %09%0A%09
-%09return null
+@Override%0A%09public int damageDropped(IBlockState state) %7B%0A%09%09return state.getValue(TYPE).ordinal()
 ;%0A%09%7D
@@ -2433,12 +2433,8 @@
 al()
- - 2
 ;%0A%09%7D
@@ -2605,16 +2605,17 @@
 IZONTAL,
+ 
  EnumFac
@@ -2625,13 +2625,18 @@
 .get
-Fr
+Horiz
 ont
+al
 (fac

Fix weird crash caused by metadata