package JAKJ . RedstoneInMotion ;

public class CarriageDrive extends Block
{
	public CarriageDrive ( )
	{
		super ( Configuration . BlockIds . CarriageDrive , blockIron , CarriageDriveItem . class , HarvestToolTypes . Pickaxe ) ;

		{
			RegisterTileEntity ( CarriageEngineEntity . class ) ;

			RegisterTileEntity ( CarriageMotorEntity . class ) ;

			RegisterTileEntity ( CarriageTranslocatorEntity . class ) ;

			if ( ModInteraction . CarriageControllerClass != null )
			{
				RegisterTileEntity ( ModInteraction . CarriageControllerClass ) ;
			}
		}
	}

	public enum Types
	{
		Engine ,
		Motor ,
		Controller ,
		Translocator ;

		public net . minecraft . util . Icon NormalIcon ;

		public net . minecraft . util . Icon ContinuousIcon ;

		public net . minecraft . util . Icon NormalActiveIcon ;

		public net . minecraft . util . Icon ContinuousActiveIcon ;
	}

	public net . minecraft . util . Icon InactiveIcon ;

	@Override
	public void AddShowcaseStacks ( java . util . List Showcase )
	{
		for ( Types Type : Types . values ( ) )
		{
			if ( ( Type == Types . Controller ) && ( ModInteraction . CarriageControllerClass == null ) )
			{
				continue ;
			}

			Showcase . add ( Stack . New ( this , Type . ordinal ( ) ) ) ;
		}
	}

	@Override
	public boolean hasTileEntity ( int Meta )
	{
		return ( true ) ;
	}

	@Override
	public net . minecraft . tileentity . TileEntity createTileEntity ( net . minecraft . world . World World , int Meta )
	{
		try
		{
			switch ( Types . values ( ) [ Meta ] )
			{
				case Engine :

					return ( new CarriageEngineEntity ( ) ) ;

				case Motor :

					return ( new CarriageMotorEntity ( ) ) ;

				case Translocator :

					return ( new CarriageTranslocatorEntity ( ) ) ;

				case Controller :

					return ( ( TileEntity ) ModInteraction . CarriageControllerClass . newInstance ( ) ) ;
			}
		}
		catch ( Throwable Throwable )
		{
			Throwable . printStackTrace ( ) ;
		}

		return ( null ) ;
	}

	@Override
	public void registerIcons ( net . minecraft . client . renderer . texture . IconRegister IconRegister )
	{
		for ( Types Type : Types . values ( ) )
		{
			if ( Type == Types . Controller )
			{
				if ( ModInteraction . CarriageControllerClass == null )
				{
					continue ;
				}
			}
			else
			{
				Type . ContinuousIcon = Registry . RegisterIcon ( IconRegister , "Carriage" + Type . name ( ) + "_Continuous" ) ;

				Type . ContinuousActiveIcon = Registry . RegisterIcon ( IconRegister , "Carriage" + Type . name ( ) + "_Continuous_Active" ) ;
			}

			Type . NormalIcon = Registry . RegisterIcon ( IconRegister , "Carriage" + Type . name ( ) ) ;

			Type . NormalActiveIcon = Registry . RegisterIcon ( IconRegister , "Carriage" + Type . name ( ) + "_Active" ) ;
		}

		InactiveIcon = Registry . RegisterIcon ( IconRegister , "CarriageDriveInactive" ) ;
	}

	@Override
	public net . minecraft . util . Icon getIcon ( int Side , int Meta )
	{
		try
		{
			return ( Types . values ( ) [ Meta & 0xF ] . NormalIcon ) ;
		}
		catch ( Throwable Throwable )
		{
			Throwable . printStackTrace ( ) ;

			return ( null ) ;
		}
	}

	@Override
	public net . minecraft . util . Icon getBlockTexture ( net . minecraft . world . IBlockAccess World , int X , int Y , int Z , int Side )
	{
		try
		{
			CarriageDriveEntity Drive = ( CarriageDriveEntity ) World . getBlockTileEntity ( X , Y , Z ) ;

			if ( Drive . SideClosed [ Side ] )
			{
				return ( InactiveIcon ) ;
			}

			Types Type = Types . values ( ) [ World . getBlockMetadata ( X , Y , Z ) ] ;

			if ( Drive . Continuous )
			{
				return ( Drive . Active ? Type . ContinuousActiveIcon : Type . ContinuousIcon ) ;
			}

			return ( Drive . Active ? Type . NormalActiveIcon : Type . NormalIcon ) ;
		}
		catch ( Throwable Throwable )
		{
			Throwable . printStackTrace ( ) ;

			return ( super . getBlockTexture ( World , X , Y , Z , Side ) ) ;
		}
	}

	@Override
	public boolean onBlockActivated ( net . minecraft . world . World World , int X , int Y , int Z , net . minecraft . entity . player . EntityPlayer Player , int Side , float HitX , float HitY , float HitZ )
	{
		if ( World . isRemote )
		{
			return ( false ) ;
		}

		if ( ! ToolItemSet . IsScrewdriverOrEquivalent ( Player . inventory . getCurrentItem ( ) ) )
		{
			return ( false ) ;
		}

		try
		{
			( ( CarriageDriveEntity ) World . getBlockTileEntity ( X , Y , Z ) ) . HandleToolUsage ( Side , Player . isSneaking ( ) ) ;
		}
		catch ( Throwable Throwable )
		{
			Throwable . printStackTrace ( ) ;
		}

		return ( true ) ;
	}

	@Override
	public void onNeighborBlockChange ( net . minecraft . world . World World , int X , int Y , int Z , int Id )
	{
		try
		{
			( ( CarriageDriveEntity ) World . getBlockTileEntity ( X , Y , Z ) ) . HandleNeighbourBlockChange ( ) ;
		}
		catch ( Throwable Throwable )
		{
			Throwable . printStackTrace ( ) ;
		}
	}
}
