package JAKJ . RedstoneInMotion ;

import java . util . List ;
import java . util . Random ;
import net . minecraft . creativetab . CreativeTabs ;
import net . minecraft . entity . EntityLiving ;
import net . minecraft . entity . player . EntityPlayer ;
import net . minecraft . item . ItemStack ;
import net . minecraft . util . Icon ;
import net . minecraft . world . IBlockAccess ;
import net . minecraft . world . World ;

public abstract class Block extends net . minecraft . block . Block
{
	public static net . minecraft . block . Block Get ( int Id )
	{
		return ( net . minecraft . block . Block . blocksList [ Id ] ) ;
	}

	public static int Count ( )
	{
		return ( net . minecraft . block . Block . blocksList . length ) ;
	}

	public String DefaultHandle ( )
	{
		return ( getClass ( ) . getSimpleName ( ) ) ;
	}

	public abstract Class < ? extends BlockItem > BlockItemClass ( ) ;

	public int SubTypeCount ( )
	{
		return ( 1 ) ;
	}

	public abstract Class < ? extends TileEntity > TileEntityClass ( int Index ) ;

	public Block ( int Id , net . minecraft . block . Block Template , String ToolType )
	{
		super ( Id , new Material ( Template ) ) ;

		setHardness ( Template . blockHardness ) ;

		setStepSound ( Template . stepSound ) ;

		setUnlocalizedName ( Core . Handle + "_" + DefaultHandle ( ) ) ;

		setCreativeTab ( CreativeTab . Instance ) ;

		Registry . RegisterBlock ( this , BlockItemClass ( ) ) ;

		{
			int SubTypeCount = SubTypeCount ( ) ;

			for ( int Index = 0 ; Index < SubTypeCount ; Index ++ )
			{
				Class < ? extends TileEntity > TileEntityClass = TileEntityClass ( Index ) ;

				if ( TileEntityClass == null )
				{
					continue ;
				}

				Registry . RegisterTileEntity ( TileEntityClass ) ;
			}
		}

		Registry . RegisterHarvestLevel ( this , ToolType ) ;
	}

	public int GetId ( )
	{
		return ( blockID ) ;
	}

	@Override
	public boolean hasTileEntity ( int Meta )
	{
		try
		{
			return ( TileEntityClass ( Meta ) != null ) ;
		}
		catch ( Throwable Throwable )
		{
			Throwable . printStackTrace ( ) ;

			return ( false ) ;
		}
	}

	@Override
	public TileEntity createTileEntity ( World World , int Meta )
	{
		try
		{
			return ( TileEntityClass ( Meta ) . newInstance ( ) ) ;
		}
		catch ( Throwable Throwable )
		{
			throw ( new RuntimeException ( Throwable ) ) ;
		}
	}

	public List ShowcaseStackList ;

	public void RegisterShowcaseStack ( Stack Stack )
	{
		ShowcaseStackList . add ( Stack . Stack ) ;
	}

	public void RegisterShowcaseStacks ( )
	{
	}

	@Override
	public void getSubBlocks ( int Id , CreativeTabs Tab , List List )
	{
		ShowcaseStackList = List ;

		RegisterShowcaseStacks ( ) ;

		ShowcaseStackList = null ;
	}

	public void RegisterIcons ( IconRegister Register )
	{
	}

	@Override
	public void registerIcons ( net . minecraft . client . renderer . texture . IconRegister Register )
	{
		RegisterIcons ( new IconRegister ( Register ) ) ;
	}

	public abstract IconHolder GetIcon ( int Side , int Meta ) ;

	@Override
	public Icon getIcon ( int Side , int Meta )
	{
		return ( GetIcon ( Side , Meta ) . Icon ) ;
	}

	@Override
	public Icon getBlockTexture ( IBlockAccess World , int X , int Y , int Z , int Side )
	{
		TileEntity TileEntity = ( TileEntity ) World . getBlockTileEntity ( X , Y , Z ) ;

		int Meta = World . getBlockMetadata ( X , Y , Z ) ;

		IconHolder Icon = null ;

		if ( TileEntity != null )
		{
			Icon = TileEntity . GetIcon ( Side , Meta ) ;
		}

		if ( Icon == null )
		{
			return ( getIcon ( Side , Meta ) ) ;
		}

		return ( Icon . Icon ) ;
	}

	@Override
	public boolean onBlockActivated ( World World , int X , int Y , int Z , EntityPlayer Player , int Side , float HitX , float HitY , float HitZ )
	{
		TileEntity Entity = ( TileEntity ) World . getBlockTileEntity ( X , Y , Z ) ;

		if ( Entity == null )
		{
			return ( false ) ;
		}

		return ( Entity . HandleBlockActivation ( World . isRemote , Player . isSneaking ( ) ) ) ;
	}

	@Override
	public int quantityDropped ( int Meta , int Fortune , java . util . Random Random )
	{
		return ( 0 ) ;
	}

	@Override
	public void onBlockPlacedBy ( World World , int X , int Y , int Z , EntityLiving Entity , ItemStack Stack )
	{
		TileEntity TileEntity = ( TileEntity ) World . getBlockTileEntity ( X , Y , Z ) ;

		TileEntity . Initialize ( new Stack ( Stack ) , Entity . rotationYaw ) ;
	}

	public void GenerateDrop ( net . minecraft . world . World World , int X , int Y , int Z , Stack Drop )
	{
		dropBlockAsItem_do ( World , X , Y , Z , Drop . Stack ) ;
	}

	public void GenerateDrops ( int Meta )
	{
	}

	@Override
	public boolean removeBlockByPlayer ( net . minecraft . world . World World , net . minecraft . entity . player . EntityPlayer Player , int X , int Y , int Z )
	{
		if ( ! World . isRemote )
		{
			if ( ! Player . capabilities . isCreativeMode )
			{
				TileEntity TileEntity = ( TileEntity ) World . getBlockTileEntity ( X , Y , Z ) ;

				int Meta = World . getBlockMetadata ( X , Y , Z ) ;

				if ( TileEntity != null )
				{
					TileEntity . GenerateDrops ( this , Meta ) ;
				}
				else
				{
					GenerateDrops ( Meta ) ;
				}
			}
		}

		return ( super . removeBlockByPlayer ( World , Player , X , Y , Z ) ) ;
	}

	public static boolean IsScrewdriverEquivalent ( net . minecraft . item . ItemStack Item )
	{
		if ( Item == null )
		{
			return ( false ) ;
		}

		if ( Item . itemID == Items . ToolItemSet . GetId ( ) )
		{
			if ( Item . getItemDamage ( ) == ToolItemSet . Types . Screwdriver . ordinal ( ) )
			{
				return ( true ) ;
			}
		}

		try
		{
			if ( Class . forName ( "omnitools.item.ItemWrench" ) . isInstance ( Item . getItem ( ) ) )
			{
				return ( true ) ;
			}
		}
		catch ( Throwable Throwable )
		{
		}

		return ( false ) ;
	}
}
