package squeek.spiceoflife.helpers;

import java.lang.reflect.Field;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.util.FoodStats;
import net.minecraft.world.World;
import squeek.spiceoflife.proxy.ProxyAgriculture;
import squeek.spiceoflife.proxy.ProxyHungerOverhaul;
import squeek.spiceoflife.proxy.ProxyMariculture;

public class FoodHelper
{
	public static final Field foodExhaustion = ReflectionHelper.findField(FoodStats.class, "foodExhaustionLevel", "field_75126_c", "c");
	static
	{
		foodExhaustion.setAccessible(true);
	}
	
	public static boolean isFood(ItemStack itemStack)
	{
		return itemStack.getItem() instanceof ItemFood || ProxyAgriculture.isFood(itemStack) || ProxyMariculture.isFood(itemStack) || itemStack.getItem() == Item.cake;
	}

	public static float getExhaustionLevel(FoodStats foodStats)
	{
		try
		{
			return foodExhaustion.getFloat(foodStats);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return 0f;
		}
	}
	
	public static void setExhaustionLevel(FoodStats foodStats, float val)
	{
		try
		{
			foodExhaustion.setFloat(foodStats, val);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static float getMaxExhaustionLevel(World world)
	{
		if (ProxyHungerOverhaul.initialized)
			return ProxyHungerOverhaul.getMaxExhaustionLevel(world);
		else
			return 4f;
	}
}

@@ -111,16 +111,54 @@
 Helper;%0A
+import net.minecraft.item.EnumAction;%0A
 import n
@@ -756,16 +756,17 @@
 %09return 
+(
 itemStac
@@ -796,16 +796,40 @@
 ItemFood
+ && isEdible(itemStack))
  %7C%7C Prox
@@ -938,16 +938,221 @@
 ke;%0A%09%7D%0A%0A
+%09public static boolean isEdible(ItemStack itemStack)%0A%09%7B%0A%09%09EnumAction useAction = itemStack.getItem().getItemUseAction(itemStack);%0A%09%09return useAction == EnumAction.eat %7C%7C useAction == EnumAction.drink;%0A%09%7D%0A%0A
 %09public 

Add support for marking things as inedible using getItemUseAction * If getItemUseAction does not return eat || drink, it is presumed inedible