package squeek.veganoption.content.registry;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import squeek.veganoption.helpers.MiscHelper;

public class CompostRegistry
{
	public static List<ItemStack> browns = new ArrayList<ItemStack>();
	public static List<ItemStack> greens = new ArrayList<ItemStack>();
	public static List<FoodSpecifier> uncompostableFoods = new ArrayList<FoodSpecifier>();

	public static void registerAllFoods()
	{
		// TODO: Check for/handle metadata-based sub items
		for (Object obj : Item.itemRegistry)
		{
			ItemStack itemStack = new ItemStack((Item) obj);
			if (isCompostableFood(itemStack))
			{
				addGreen(itemStack);
			}
		}
	}

	public abstract static class FoodSpecifier
	{
		public abstract boolean matches(ItemStack itemStack);
	}

	public static boolean isCompostable(ItemStack itemStack)
	{
		return isGreen(itemStack) || isBrown(itemStack);
	}

	public static boolean isBrown(ItemStack itemStack)
	{
		return MiscHelper.isItemStackInList(browns, itemStack);
	}

	public static boolean isGreen(ItemStack itemStack)
	{
		return MiscHelper.isItemStackInList(greens, itemStack);
	}

	public static boolean isCompostableFood(ItemStack itemStack)
	{
		// TODO: optionally use AppleCore's method?
		if (itemStack != null && itemStack.getItem() instanceof ItemFood)
		{
			for (FoodSpecifier uncompostableFood : uncompostableFoods)
			{
				if (uncompostableFood.matches(itemStack))
					return false;
			}
			return true;
		}
		return false;
	}

	public static void addBrown(Item item)
	{
		addBrown(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE));
	}

	public static void addBrown(Block block)
	{
		addBrown(new ItemStack(block, 1, OreDictionary.WILDCARD_VALUE));
	}

	public static void addBrown(ItemStack itemStack)
	{
		browns.add(itemStack);
	}

	public static void addBrown(String oredictName)
	{
		browns.addAll(OreDictionary.getOres(oredictName));
	}

	public static void addGreen(Item item)
	{
		addGreen(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE));
	}

	public static void addGreen(Block block)
	{
		addGreen(new ItemStack(block, 1, OreDictionary.WILDCARD_VALUE));
	}

	public static void addGreen(ItemStack itemStack)
	{
		greens.add(itemStack);
	}

	public static void addGreen(String oredictName)
	{
		greens.addAll(OreDictionary.getOres(oredictName));
	}

	public static void blacklist(FoodSpecifier foodSpecifier)
	{
		uncompostableFoods.add(foodSpecifier);
	}
}

@@ -120,24 +120,71 @@
 lock.Block;%0A
+import net.minecraft.creativetab.CreativeTabs;%0A
 import net.m
@@ -676,154 +676,399 @@
 %7B%0A%09%09
-// TODO: Check for/handle metadata-based sub items%0A%09%09for (Object obj : Item.itemRegistry)%0A%09%09%7B%0A%09%09%09ItemStack itemStack
+List%3CItemStack%3E stackList = new ArrayList%3CItemStack%3E();%0A%0A%09%09for (Object obj : Item.itemRegistry)%0A%09%09%7B%0A%09%09%09Item item = ((Item) obj);%0A%0A%09%09%09if (item == null)%0A%09%09%09%09continue;%0A%0A%09%09%09for (CreativeTabs itemTab : item.getCreativeTabs())%0A%09%09%09%7B%0A%09%09%09%09if (itemTab
  =
+=
  n
-ew ItemStack((Item) obj);%0A
+ull)%0A%09%09%09%09%09continue;%0A%0A%09%09%09%09stackList.clear();%0A%09%09%09%09item.getSubItems(item, itemTab, stackList);%0A%09%09%09%7D%0A%0A%09%09%09for (ItemStack itemStack : stackList)%0A%09%09%09%7B%0A%09
 %09%09%09i
@@ -1099,26 +1099,28 @@
 mStack))%0A%09%09%09
+%09
 %7B%0A
+%09
 %09%09%09%09addGreen
@@ -1132,16 +1132,22 @@
 Stack);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Add subitem support to CompostRegistry food discovery