package squeek.tictooltips.helpers;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import tconstruct.tools.items.Pattern;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.CustomMaterial;

public class PatternHelper
{

	public static boolean isBowstringPattern(Item item, int meta)
	{
		return getPatternName(item, meta).equals("bowstring");
	}

	public static boolean isFletchingPattern(Item item, int meta)
	{
		return getPatternName(item, meta).equals("fletching");
	}

	public static String getPatternName(Item item, int meta)
	{
		if (item instanceof Pattern)
		{
			return ((Pattern) item).unlocalizedNames[meta];
		}
		return "";
	}

	public static List<String> getValidCustomMaterialsOfType(Class<? extends CustomMaterial> matClass)
	{
		List<String> validMats = new ArrayList<String>();
		for (CustomMaterial customMat : TConstructRegistry.customMaterials)
		{
			customMat = TConstructRegistry.getCustomMaterial(customMat.materialID, matClass);
			if (customMat != null)
			{
				if (customMat.input != null && !validMats.contains(customMat.input.getDisplayName()))
					validMats.add(customMat.input.getDisplayName());
				else if (customMat.input == null && customMat.oredict != null)
				{
					List<ItemStack> items = OreDictionary.getOres(customMat.oredict);
					for (ItemStack item : items)
					{
						if (!validMats.contains(item.getDisplayName()))
							validMats.add(item.getDisplayName());
					}
				}
			}
		}
		return validMats;
	}

}

@@ -1427,105 +1427,449 @@
 %09%09%09%09
-for (ItemStack item : items)%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09if (!validMats.contains(item.getDisplayName()))
+if (items != null && !items.isEmpty())%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09ItemStack itemStackToGetNameOf = items.get(0);%0A%09%09%09%09%09%09if (itemStackToGetNameOf.getItemDamage() == OreDictionary.WILDCARD_VALUE)%0A%09%09%09%09%09%09%7B%0A%09%09%09%09%09%09%09itemStackToGetNameOf = itemStackToGetNameOf.copy();%0A%09%09%09%09%09%09%09itemStackToGetNameOf.setItemDamage(0);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09String name = itemStackToGetNameOf.getDisplayName();%0A%09%09%09%09%09%09String line = String.format(%22%25s (%25s)%22, name, customMat.oredict);
 %0A%09%09%09%09%09%09
-%09
+if (!
 vali
@@ -1878,33 +1878,49 @@
 ats.
-add(item.getDisplayName()
+contains(line))%0A%09%09%09%09%09%09%09validMats.add(line
 );%0A%09

Fix and consolidate the valid materials tooltip of Patterns * Ore dictionary materials no longer list every OreDictionaried item, but rather "First Item's Name (oredictName)" * Fixes #30