package JAKJ . RedstoneInMotion ;

public abstract class CarriageEntity extends TileEntity
{
	public Stack Decoration ;

	@Override
	public void Initialize ( Stack Stack , double PlacementYaw )
	{
		if ( Stack . HasTag ( ) )
		{
			Decoration = Stack . GetStack ( "Decoration" ) ;
		}
	}

	@Override
	public void GenerateDrops ( Block Block , int Meta )
	{
		Stack Drop = new Stack ( Block , Meta ) ;

		if ( Decoration != null )
		{
			Drop . AddTag ( ) ;

			Drop . SetStack ( "Decoration" , Decoration ) ;
		}

		Block . GenerateDrop ( worldObj , xCoord , yCoord , zCoord , Drop ) ;
	}

	public boolean [ ] SideClosed = new boolean [ Directions . values ( ) . length ] ;

	@Override
	public IconHolder GetIcon ( int Side , int Meta )
	{
		if ( SideClosed [ Side ] )
		{
			if ( Decoration != null )
			{
				try
				{
					net . minecraft . item . ItemBlock BlockItem = ( net . minecraft . item . ItemBlock ) Decoration . Stack . getItem ( ) ;

					return ( IconHolder . Wrap ( RenderEngine . GetBlockIcon ( Decoration . GetId ( ) , Side , BlockItem . getMetadata ( Decoration . GetDamage ( ) ) ) ) ) ;
				}
				catch ( Throwable Throwable )
				{
					Throwable . printStackTrace ( ) ;
				}
			}

			return ( Carriage . Types . values ( ) [ Meta ] . ClosedIcon ) ;
		}

		return ( Carriage . Types . values ( ) [ Meta ] . OpenIcon ) ;
	}

	public void ToggleSide ( int Side )
	{
		SideClosed [ Side ] = ! SideClosed [ Side ] ;

		Propagate ( ) ;
	}

	@Override
	public void ReadFromNbt ( NbtCompound TagCompound , boolean FromServer )
	{
		for ( int Index = 0 ; Index < SideClosed . length ; Index ++ )
		{
			SideClosed [ Index ] = TagCompound . getBoolean ( "SideClosed" + Index ) ;
		}

		Decoration = TagCompound . GetStack ( "Decoration" ) ;
	}

	@Override
	public void WriteToNbt ( NbtCompound TagCompound , boolean ToClient )
	{
		for ( int Index = 0 ; Index < SideClosed . length ; Index ++ )
		{
			TagCompound . setBoolean ( "SideClosed" + Index , SideClosed [ Index ] ) ;
		}

		if ( Decoration != null )
		{
			TagCompound . PutStack ( "Decoration" , Decoration ) ;
		}
	}
/*
	public CarriagePackage BeginCarriagePackage ( CarriageDriveEntity Drive , Directions MotionDirection )
	{
		CarriagePackage CarriagePackage = new CarriagePackage ( this , Drive , MotionDirection ) ;

		if ( ! LoadCarriagePackage ( CarriagePackage , MotionDirection ) )
		{
			return ( null ) ;
		}

		return ( CarriagePackage ) ;
	}

	public abstract boolean LoadCarriagePackage ( CarriagePackage CarriagePackage , Directions MotionDirection ) ;

	public CarriagePackage CarriageBodyInclusive ( CarriageDriveEntity Drive , Directions MotionDirection , int IncludedX , int IncludedY , int IncludedZ )
	{
		CarriagePackage CarriagePackage = BeginCarriagePackage ( Drive , MotionDirection ) ;

		if ( CarriagePackage == null )
		{
			return ( null ) ;
		}

		if ( CarriagePackage . BlocksChecked . contains ( new BlockRecord ( IncludedX , IncludedY , IncludedZ ) ) )
		{
			return ( CarriagePackage . CarriageBody ( ) ) ;
		}

		return ( null ) ;
	}

	public CarriagePackage CarriageBodyExclusive ( CarriageDriveEntity Drive , Directions MotionDirection , int ExcludedX , int ExcludedY , int ExcludedZ )
	{
		CarriagePackage CarriagePackage = BeginCarriagePackage ( Drive , MotionDirection ) ;

		if ( CarriagePackage == null )
		{
			return ( null ) ;
		}

		if ( CarriagePackage . BlocksChecked . contains ( new BlockRecord ( ExcludedX , ExcludedY , ExcludedZ ) ) )
		{
			return ( null ) ;
		}

		return ( CarriagePackage . CarriageBody ( ) ) ;
	}

	public CarriagePackage CarriageBody ( CarriageDriveEntity Drive , Directions MotionDirection )
	{
		CarriagePackage CarriagePackage = BeginCarriagePackage ( Drive , MotionDirection ) ;

		if ( CarriagePackage == null )
		{
			return ( null ) ;
		}

		return ( CarriagePackage . CarriageBody ( ) ) ;
	}
	*/

	public abstract void FillPackage ( CarriagePackage Package ) throws CarriageMotionException ;
}
