package squeek.applecore.example;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import squeek.applecore.api.food.FoodValues;
import squeek.applecore.api.food.IEdible;
import squeek.applecore.api.food.ItemFoodProxy;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Optional;

@Optional.Interface(iface = "squeek.applecore.api.food.IEdible", modid = "AppleCore")
public class ItemNonStandardFood extends Item implements IEdible
{
	public ItemNonStandardFood()
	{
	}

	@Optional.Method(modid = "AppleCore")
	@Override
	public FoodValues getFoodValues(ItemStack itemStack)
	{
		return new FoodValues(1, 1f);
	}

	@Override
	public ItemStack onEaten(ItemStack itemStack, World world, EntityPlayer player)
	{
		--itemStack.stackSize;

		if (Loader.isModLoaded("AppleCore"))
		{
			// one possible compatible method
			player.getFoodStats().func_151686_a(new ItemFoodProxy(this), itemStack);

			// another possible compatible method:
			// new ItemFoodProxy(this).onEaten(itemStack, player);
		}
		else
		{
			// this method is not compatible with AppleCore
			player.getFoodStats().addStats(1, 1f);
		}

		world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
		return itemStack;
	}

	@Override
	public EnumAction getItemUseAction(ItemStack itemStack)
	{
		return EnumAction.eat;
	}

	@Override
	public int getMaxItemUseDuration(ItemStack itemStack)
	{
		return 32;
	}

	@Override
	public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
	{
		if (player.canEat(true))
		{
			player.setItemInUse(itemStack, getMaxItemUseDuration(itemStack));
		}

		return itemStack;
	}
}

@@ -764,43 +764,198 @@
 %7D%0A%0A%09
-@Override%0A%09public ItemStack onEaten
+// This needs to be abstracted into an Optional method,%0A%09// otherwise the ItemFoodProxy reference will cause problems%0A%09@Optional.Method(modid = %22AppleCore%22)%0A%09public void onEatenCompatibility
 (Ite
@@ -967,37 +967,24 @@
 k itemStack,
- World world,
  EntityPlaye
@@ -1000,78 +1000,8 @@
 %0A%09%7B%0A
-%09%09--itemStack.stackSize;%0A%0A%09%09if (Loader.isModLoaded(%22AppleCore%22))%0A%09%09%7B%0A%09
 %09%09//
@@ -1032,17 +1032,16 @@
  method%0A
-%09
 %09%09player
@@ -1110,17 +1110,16 @@
 ck);%0A%0A%09%09
-%09
 // anoth
@@ -1151,17 +1151,16 @@
 thod:%0A%09%09
-%09
 // new I
@@ -1206,16 +1206,228 @@
 layer);%0A
+%09%7D%0A%0A%09@Override%0A%09public ItemStack onEaten(ItemStack itemStack, World world, EntityPlayer player)%0A%09%7B%0A%09%09--itemStack.stackSize;%0A%0A%09%09if (Loader.isModLoaded(%22AppleCore%22))%0A%09%09%7B%0A%09%09%09onEatenCompatibility(itemStack, player);%0A
 %09%09%7D%0A%09%09el

Fix non-standard food example implementation * Old example implementation would cause a crash on startup if AppleCore wasn't installed due to the ItemFoodProxy reference in a non-Optional method