content: package thebetweenlands.common.block.container;
  
  import java.util.Random;
  
  import net.minecraft.block.BlockContainer;
  import net.minecraft.block.BlockHorizontal;
  import net.minecraft.block.SoundType;
  import net.minecraft.block.material.Material;
  import net.minecraft.block.properties.IProperty;
  import net.minecraft.block.properties.PropertyDirection;
  import net.minecraft.block.state.BlockFaceShape;
  import net.minecraft.block.state.BlockStateContainer;
  import net.minecraft.block.state.IBlockState;
  import net.minecraft.entity.EntityLivingBase;
  import net.minecraft.entity.player.EntityPlayer;
  import net.minecraft.init.SoundEvents;
  import net.minecraft.inventory.Container;
  import net.minecraft.inventory.InventoryHelper;
  import net.minecraft.item.Item;
  import net.minecraft.item.ItemBlock;
  import net.minecraft.item.ItemStack;
  import net.minecraft.tileentity.TileEntity;
  import net.minecraft.util.BlockRenderLayer;
  import net.minecraft.util.EnumBlockRenderType;
  import net.minecraft.util.EnumFacing;
  import net.minecraft.util.EnumHand;
  import net.minecraft.util.EnumParticleTypes;
  import net.minecraft.util.Mirror;
  import net.minecraft.util.Rotation;
  import net.minecraft.util.SoundCategory;
  import net.minecraft.util.math.BlockPos;
  import net.minecraft.world.IBlockAccess;
  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.TheBetweenlands;
  import thebetweenlands.common.proxy.CommonProxy;
  import thebetweenlands.common.registries.BlockRegistry;
  import thebetweenlands.common.registries.BlockRegistry.ICustomItemBlock;
  import thebetweenlands.common.tile.TileEntityBLFurnace;
  
  public class BlockBLFurnace extends BlockContainer implements ICustomItemBlock {
  
  	private final boolean isBurning;
  	private static boolean keepInventory;
      public static final PropertyDirection FACING = BlockHorizontal.FACING;
  
      public BlockBLFurnace(boolean isBurning) {
          super(Material.ROCK);
          this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
          this.isBurning = isBurning;
          setHardness(3.5F);
          setSoundType(SoundType.STONE);
          if(!isBurning)
          	setCreativeTab(BLCreativeTabs.BLOCKS);
      }
  
  	@Override
      public Item getItemDropped(IBlockState state, Random rand, int fortune) {
          return Item.getItemFromBlock(BlockRegistry.SULFUR_FURNACE);
      }
  
  	@Override
  	@SideOnly(Side.CLIENT)
  	public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
  		return true;
  	}
  
  	@Override
      public EnumBlockRenderType getRenderType(IBlockState state) {
          return EnumBlockRenderType.MODEL;
      }
  
  	@Override
  	@SideOnly(Side.CLIENT)
  	public BlockRenderLayer getRenderLayer() {
  		return BlockRenderLayer.CUTOUT;
  	}
  
  	@Override
  	public boolean isOpaqueCube(IBlockState state) {
  		return false;
  	}
  
  	@Override
  	public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
          setDefaultFacing(worldIn, pos, state);
      }
  
      private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) {
          if (!worldIn.isRemote) {
              IBlockState iblockstate = worldIn.getBlockState(pos.north());
              IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
              IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
              IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
              EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
  
              if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
                  enumfacing = EnumFacing.SOUTH;
  
              else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
                  enumfacing = EnumFacing.NORTH;
  
              else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
                  enumfacing = EnumFacing.EAST;
  
              else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
                  enumfacing = EnumFacing.WEST;
  
              worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
          }
      }
  
  	@Override
  	public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
  		if (world.isRemote)
  			return true;
  		else {
  			TileEntityBLFurnace tileentityfurnace = (TileEntityBLFurnace)world.getTileEntity(pos);
              if (tileentityfurnace != null)
              	player.openGui(TheBetweenlands.instance, CommonProxy.GUI_BL_FURNACE, world, pos.getX(), pos.getY(), pos.getZ());
              return true;
  		}
  	}
  
  	public static void setState(boolean active, World world, BlockPos pos) {
  		IBlockState iblockstate = world.getBlockState(pos);
  		TileEntity tileentity = world.getTileEntity(pos);
  		keepInventory = true;
  
  		if (active)
  			world.setBlockState(pos, BlockRegistry.SULFUR_FURNACE_ACTIVE.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
  		else
  			world.setBlockState(pos, BlockRegistry.SULFUR_FURNACE.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
  
  		keepInventory = false;
  
  		if (tileentity != null) {
  			tileentity.validate();
  			world.setTileEntity(pos, tileentity);
  		}
  	}
  
  	@Override
  	public TileEntity createNewTileEntity(World world, int meta) {
          return new TileEntityBLFurnace();
      }
  
  	public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  		return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  	}
  
  	@Override
  	public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
  		world.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  
  		if (stack.hasDisplayName())
  			((TileEntityBLFurnace)world.getTileEntity(pos)).setStackDisplayName(stack.getDisplayName());
  	}
  
  	@Override
      public void breakBlock(World world, BlockPos pos, IBlockState state) {
  		 if (!keepInventory) {
              TileEntity tileentity = world.getTileEntity(pos);
  
              if (tileentity instanceof TileEntityBLFurnace) {
                  InventoryHelper.dropInventoryItems(world, pos, (TileEntityBLFurnace)tileentity);
                  world.updateComparatorOutputLevel(pos, this);
              }
          }
          super.breakBlock(world, pos, state);
      }
  
  	@SideOnly(Side.CLIENT)
  	@Override
  	public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
  		if (this.isBurning) {
  			EnumFacing enumfacing = (EnumFacing) stateIn.getValue(FACING);
  			double d0 = (double) pos.getX() + 0.5D;
  			double d1 = (double) pos.getY() + 0.25D + rand.nextDouble() * 6.0D / 16.0D;
  			double d2 = (double) pos.getZ() + 0.5D;
  			double d4 = rand.nextDouble() * 0.6D - 0.3D;
  
  			if (rand.nextDouble() < 0.1D) {
  				worldIn.playSound((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
  			}
  
  			switch (enumfacing) {
  			case WEST:
  				worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  				worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  				break;
  			case EAST:
  				worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  				worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  				break;
  			case NORTH:
  				worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D, new int[0]);
  				worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D, new int[0]);
  				break;
  			case SOUTH:
  				worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D, new int[0]);
  				worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D, new int[0]);
  			}
  		}
  	}
  
  	@Override
  	public boolean hasComparatorInputOverride(IBlockState state) {
  		return true;
  	}
  
  	@Override
  	public int getComparatorInputOverride(IBlockState blockState, World world, BlockPos pos) {
  		return Container.calcRedstone(world.getTileEntity(pos));
  	}
  
  	@Override
  	public ItemStack getItem(World world, BlockPos pos, IBlockState state) {
  		return new ItemStack(BlockRegistry.SULFUR_FURNACE);
  	}
  
  	@Override
  	public IBlockState getStateFromMeta(int meta) {
  		EnumFacing enumfacing = EnumFacing.byIndex(meta);
  
  		if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
  			enumfacing = EnumFacing.NORTH;
  		}
  
  		return getDefaultState().withProperty(FACING, enumfacing);
  	}
  
  	@Override
  	public int getMetaFromState(IBlockState state) {
  		return ((EnumFacing) state.getValue(FACING)).getIndex();
  	}
  
  	@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 });
  	}
  
  	@Override
      public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) {
      	return face == EnumFacing.UP ? BlockFaceShape.CENTER_SMALL : face == EnumFacing.DOWN ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED;
      }
  	
  	@Override
  	public boolean isSideSolid(IBlockState base_state, IBlockAccess world, BlockPos pos, EnumFacing side) {
  		return side == EnumFacing.DOWN;
  	}
  	
  	@Override
  	public ItemBlock getItemBlock() {
  		if(this.isBurning) {
  			return null;
  		}
  		return ICustomItemBlock.getDefaultItemBlock(this);
  	}
  }