package squeek.spiceoflife;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.*;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import squeek.spiceoflife.foodtracker.FoodModifier;
import squeek.spiceoflife.foodtracker.FoodTracker;
import squeek.spiceoflife.foodtracker.commands.CommandResetHistory;
import squeek.spiceoflife.foodtracker.foodgroups.FoodGroupConfig;
import squeek.spiceoflife.foodtracker.foodgroups.FoodGroupRegistry;
import squeek.spiceoflife.gui.TooltipHandler;
import squeek.spiceoflife.helpers.GuiHelper;
import squeek.spiceoflife.helpers.MovementHelper;
import squeek.spiceoflife.network.PacketHandler;

import java.io.File;

@Mod(modid = ModInfo.MODID, version = ModInfo.VERSION, dependencies = "required-after:AppleCore")
public class ModSpiceOfLife
{
	public static final Logger Log = LogManager.getLogger(ModInfo.MODID);

	@Instance(ModInfo.MODID)
	public static ModSpiceOfLife instance;
	public File sourceFile;

	@EventHandler
	public void preInit(FMLPreInitializationEvent event)
	{
		sourceFile = event.getSourceFile();
		ModConfig.init(event.getSuggestedConfigurationFile());
		ModContent.registerItems();
		ModContent.registerRecipes();
	}

	@EventHandler
	public void init(FMLInitializationEvent event)
	{
		GuiHelper.init();
		MovementHelper.init();
		FoodTracker foodTracker = new FoodTracker();
		MinecraftForge.EVENT_BUS.register(foodTracker);
		MinecraftForge.EVENT_BUS.register(new FoodModifier());

		if (event.getSide() == Side.CLIENT)
		{
			MinecraftForge.EVENT_BUS.register(new TooltipHandler());
		}

		// need to make sure that the packet types get registered before packets are received
		PacketHandler.PacketType.values();
	}

	@EventHandler
	public void postInit(FMLPostInitializationEvent event)
	{
		FoodGroupConfig.load();
		FMLInterModComms.sendRuntimeMessage(ModInfo.MODID, "VersionChecker", "addVersionCheck", "http://www.ryanliptak.com/minecraft/versionchecker/squeek502/SpiceOfLife");
	}

	@EventHandler
	public void serverStarting(FMLServerStartingEvent event)
	{
		FoodGroupRegistry.setInStone();
		event.registerServerCommand(new CommandResetHistory());
	}
}

@@ -46,35 +46,271 @@
 raft
-forge.common.MinecraftForge
+.nbt.NBTBase;%0Aimport net.minecraft.nbt.NBTTagCompound;%0Aimport net.minecraft.util.EnumFacing;%0Aimport net.minecraftforge.common.MinecraftForge;%0Aimport net.minecraftforge.common.capabilities.Capability;%0Aimport net.minecraftforge.common.capabilities.CapabilityManager
 ;%0Aim
@@ -628,24 +628,75 @@
 g4j.Logger;%0A
+import squeek.spiceoflife.foodtracker.FoodHistory;%0A
 import squee
@@ -782,24 +782,87 @@
 oodTracker;%0A
+import squeek.spiceoflife.foodtracker.capability.IFoodHistory;%0A
 import squee
@@ -1262,16 +1262,54 @@
 io.File;
+%0Aimport java.util.concurrent.Callable;
 %0A%0A@Mod(m
@@ -1787,24 +1787,24 @@
 terItems();%0A
-
 %09%09ModContent
@@ -1819,24 +1819,621 @@
 rRecipes();%0A
+%09%09CapabilityManager.INSTANCE.register(IFoodHistory.class, new Capability.IStorage%3CIFoodHistory%3E()%0A%09%09%7B%0A%09%09%09@Override%0A%09%09%09public NBTBase writeNBT(Capability%3CIFoodHistory%3E capability, IFoodHistory instance, EnumFacing side)%0A%09%09%09%7B%0A%09%09%09%09return instance.serializeNBT();%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public void readNBT(Capability%3CIFoodHistory%3E capability, IFoodHistory instance, EnumFacing side, NBTBase nbt)%0A%09%09%09%7B%0A%09%09%09%09instance.deserializeNBT((NBTTagCompound) nbt);%0A%09%09%09%7D%0A%09%09%7D, new Callable%3CIFoodHistory%3E()%0A%09%09%7B%0A%09%09%09@Override%0A%09%09%09public IFoodHistory call() throws Exception%0A%09%09%09%7B%0A%09%09%09%09return new FoodHistory();%0A%09%09%09%7D%0A%09%09%7D);%0A
 %09%7D%0A%0A%09@EventH

Fix conflicts due to incorrect capability implementation (IFoodHistory capability wasn't being registered) - Fixes #91