content: package thebetweenlands.common.block.structure;
  
  import java.util.Random;
  
  import net.minecraft.block.BlockDirectional;
  import net.minecraft.block.ITileEntityProvider;
  import net.minecraft.block.SoundType;
  import net.minecraft.block.material.Material;
  import net.minecraft.block.properties.IProperty;
  import net.minecraft.block.state.BlockStateContainer;
  import net.minecraft.block.state.IBlockState;
  import net.minecraft.entity.EntityLivingBase;
  import net.minecraft.tileentity.TileEntity;
  import net.minecraft.util.BlockRenderLayer;
  import net.minecraft.util.EnumBlockRenderType;
  import net.minecraft.util.EnumFacing;
  import net.minecraft.util.Mirror;
  import net.minecraft.util.Rotation;
  import net.minecraft.util.math.BlockPos;
  import net.minecraft.util.math.MathHelper;
  import net.minecraft.world.World;
  import net.minecraftforge.fml.relauncher.Side;
  import net.minecraftforge.fml.relauncher.SideOnly;
  import thebetweenlands.client.tab.BLCreativeTabs;
  import thebetweenlands.common.tile.TileEntitySpikeTrap;
  
  public class BlockSpikeTrap extends BlockDirectional implements ITileEntityProvider {
  
  	public BlockSpikeTrap() {
  		super(Material.ROCK);
  		setDefaultState(this.getBlockState().getBaseState().withProperty(FACING, EnumFacing.UP));
  		setSoundType(SoundType.STONE);
  		setHardness(10F);
  		setResistance(2000.0F);
  		setCreativeTab(BLCreativeTabs.BLOCKS);
  	}
  
  	@Override
  	public TileEntity createNewTileEntity(World world, int meta) {
  		return new TileEntitySpikeTrap();
  	}
  
  	@Override
      public EnumBlockRenderType getRenderType(IBlockState state) {
          return EnumBlockRenderType.MODEL;
      }
  
  	@Override
  	@SideOnly(Side.CLIENT)
  	public BlockRenderLayer getRenderLayer() {
  		return BlockRenderLayer.CUTOUT;
  	}
  
  	@Override
  	public int quantityDropped(Random random) {
  		return 0;
  	}
  
  	@Override
  	public IBlockState getStateFromMeta(int meta) {
  		return getDefaultState().withProperty(FACING, EnumFacing.byIndex(meta));
  	}
  
  	@Override
  	public int getMetaFromState(IBlockState state) {
  		int meta = 0;
  		meta = meta | ((EnumFacing) state.getValue(FACING)).getIndex();
  
  		return meta;
  	}
  
  	@Override
  	 public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  		return this.getDefaultState().withProperty(FACING, getFacingFromEntity(pos, placer));
  	}
  
  	public static EnumFacing getFacingFromEntity(BlockPos pos, EntityLivingBase entity) {
  		if (MathHelper.abs((float) entity.posX - (float) pos.getX()) < 2.0F && MathHelper.abs((float) entity.posZ - (float) pos.getZ()) < 2.0F) {
  			double eyeHeight = entity.posY + (double) entity.getEyeHeight();
  			if (eyeHeight - (double) pos.getY() > 2.0D)
  				return EnumFacing.UP;
  			if ((double) pos.getY() - eyeHeight > 0.0D)
  				return EnumFacing.DOWN;
  		}
  		return entity.getHorizontalFacing().getOpposite();
  	}
  
  	@Override
  	public IBlockState withRotation(IBlockState state, Rotation rot) {
  		return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
  	}
  
  	@Override
  	public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
  		return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING)));
  	}
  
  	@Override
  	protected BlockStateContainer createBlockState() {
  		return new BlockStateContainer(this, new IProperty[] { FACING });
  	}
  }