package JAKJ . RedstoneInMotion ;

public class Carriage extends Block
{
	public Carriage ( )
	{
		super ( Configuration . BlockIds . Carriage , wood , CarriageItem . class , HarvestToolTypes . Hatchet ) ;

		RegisterTileEntity ( FrameCarriageEntity . class ) ;

		RegisterTileEntity ( PlatformCarriageEntity . class ) ;

		RegisterTileEntity ( StructureCarriageEntity . class ) ;

		RegisterTileEntity ( SupportCarriageEntity . class ) ;

		RegisterTileEntity ( TemplateCarriageEntity . class ) ;
	}

	public enum Types
	{
		Frame ,
		Platform ,
		Structure ,
		Support ,
		Template ;

		public net . minecraft . util . Icon OpenIcon ;
		public net . minecraft . util . Icon ClosedIcon ;
	}

	@Override
	public void AddShowcaseStacks ( java . util . List Showcase )
	{
		for ( Types Type : Types . values ( ) )
		{
			Showcase . add ( Stack . New ( this , Type ) ) ;
		}
	}

	@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 Frame :

					return ( new FrameCarriageEntity ( ) ) ;

				case Platform :

					return ( new PlatformCarriageEntity ( ) ) ;

				case Structure :

					return ( new StructureCarriageEntity ( ) ) ;

				case Support :

					return ( new SupportCarriageEntity ( ) ) ;

				case Template :

					return ( new TemplateCarriageEntity ( ) ) ;
			}
		}
		catch ( Throwable Throwable )
		{
			Throwable . printStackTrace ( ) ;
		}

		return ( null ) ;
	}

	@Override
	public void registerIcons ( net . minecraft . client . renderer . texture . IconRegister IconRegister )
	{
		for ( Types Type : Types . values ( ) )
		{
			Type . ClosedIcon = Registry . RegisterIcon ( IconRegister , Type . name ( ) + "Carriage_Closed" ) ;

			Type . OpenIcon = Registry . RegisterIcon ( IconRegister , Type . name ( ) + "Carriage_Open" ) ;
		}

		TemplateCarriageEntity . PlaceholderIcon = Registry . RegisterIcon ( IconRegister , "CarriagePlaceholder" ) ;
	}

	@Override
	public net . minecraft . util . Icon getIcon ( int Side , int Meta )
	{
		if ( Side != Directions . PosY . ordinal ( ) )
		{
			int DecorationId = Meta >> 8 ;

			if ( DecorationId != 0 )
			{
				int DecorationMeta = ( Meta >> 4 ) & 0xF ;

				try
				{
					return ( Block . Get ( DecorationId ) . getIcon ( Side , DecorationMeta ) ) ;
				}
				catch ( Throwable Throwable )
				{
					Throwable . printStackTrace ( ) ;
				}
			}
		}

		return ( Types . values ( ) [ Meta & 0xF ] . OpenIcon ) ;
	}

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

			if ( ( Carriage . DecorationId != 0 ) && ( Carriage . SideClosed [ Side ] ) )
			{
				return ( net . minecraft . block . Block . blocksList [ Carriage . DecorationId ] . getIcon ( Side , Carriage . DecorationMeta ) ) ;
			}

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

			return ( Carriage . SideClosed [ Side ] ? Type . ClosedIcon : Type . OpenIcon ) ;
		}
		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 ) ;
		}

		( ( CarriageEntity ) World . getBlockTileEntity ( X , Y , Z ) ) . ToggleSide ( Side , Player . isSneaking ( ) ) ;

		return ( true ) ;
	}

	@Override
	public boolean isOpaqueCube ( )
	{
		return ( false ) ;
	}
}
