package JAKJ . RedstoneInMotion ;

public class CarriageTranslocatorLabelRecipe extends Recipe
{
	@Override
	public net . minecraft . item . ItemStack Process ( net . minecraft . inventory . InventoryCrafting Inventory )
	{
		net . minecraft . item . ItemStack Drive = null ;

		boolean [ ] DyesToAdd = new boolean [ Vanilla . DyeTypes . values ( ) . length ] ;

		boolean DyeFound = false ;

		boolean ComparatorPresent = false ;

		int InventorySize = Inventory . getSizeInventory ( ) ;

		for ( int Index = 0 ; Index < InventorySize ; Index ++ )
		{
			net . minecraft . item . ItemStack Item = Inventory . getStackInSlot ( Index ) ;

			if ( Item == null )
			{
				continue ;
			}

			if ( Item . itemID == Blocks . CarriageDrive . blockID )
			{
				if ( BlockItem . GetBlockType ( Item ) == CarriageDrive . Types . Translocator . ordinal ( ) )
				{
					if ( Drive != null )
					{
						return ( null ) ;
					}

					Drive = Item ;

					continue ;
				}
			}
			else if ( Item . itemID == net . minecraft . item . Item . dyePowder . itemID )
			{
				if ( DyesToAdd [ Item . itemDamage ] )
				{
					return ( null ) ;
				}

				DyesToAdd [ Item . itemDamage ] = true ;

				DyeFound = true ;

				continue ;
			}
			else if ( Item . itemID == net . minecraft . item . Item . comparator . itemID )
			{
				if ( ComparatorPresent == true )
				{
					return ( null ) ;
				}

				ComparatorPresent = true ;

				continue ;
			}

			return ( null ) ;
		}

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

		if ( ( ! ComparatorPresent ) && ( ! DyeFound ) )
		{
			return ( CarriageDriveItem . Stack ( CarriageDrive . Types . Translocator . ordinal ( ) ) ) ;
		}

		boolean Private = CarriageDriveItem . GetPrivateFlag ( Drive ) ;

		int Label = CarriageDriveItem . GetLabel ( Drive ) ;

		if ( ComparatorPresent )
		{
			if ( Private )
			{
				return ( null ) ;
			}

			Private = true ;
		}

		for ( Vanilla . DyeTypes DyeType : Vanilla . DyeTypes . values ( ) )
		{
			if ( DyesToAdd [ DyeType . ordinal ( ) ] )
			{
				if ( CarriageDriveItem . LabelHasDye ( Label , DyeType ) )
				{
					return ( null ) ;
				}

				Label = CarriageDriveItem . AddDyeToLabel ( Label , DyeType ) ;
			}
		}

		if ( ! CarriageDriveItem . LabelWillResultInValidItemStack ( Label ) )
		{
			Debug . Emit ( "Failed to label carriage translocator: Dye combination " + Label + " too large to store in ItemStack." ) ;

			return ( null ) ;
		}

		return ( CarriageDriveItem . Stack ( CarriageDrive . Types . Translocator . ordinal ( ) , Private , Label ) ) ;
	}
}
