package techreborn;

import java.io.File;

import org.apache.commons.lang3.time.StopWatch;

import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import erogenousbeef.coreTR.multiblock.MultiblockEventHandler;
import erogenousbeef.coreTR.multiblock.MultiblockServerTickHandler;
import net.minecraftforge.common.MinecraftForge;
import techreborn.achievement.TRAchievements;
import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.recipeConfig.RecipeConfigManager;
import techreborn.client.GuiHandler;
import techreborn.command.TechRebornDevCommand;
import techreborn.compat.CompatManager;
import techreborn.compat.ICompatModule;
import techreborn.config.ConfigTechReborn;
import techreborn.events.TRTickHandler;
import techreborn.init.ModBlocks;
import techreborn.init.ModFluids;
import techreborn.init.ModItems;
import techreborn.init.ModParts;
import techreborn.init.ModRecipes;
import techreborn.lib.ModInfo;
import techreborn.packets.PacketHandler;
import techreborn.packets.PacketPipeline;
import techreborn.proxies.CommonProxy;
import techreborn.tiles.idsu.IDSUManager;
import techreborn.util.LogHelper;
import techreborn.util.VersionChecker;
import techreborn.world.TROreGen;

@Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.MOD_VERSION, dependencies = ModInfo.MOD_DEPENDENCUIES, guiFactory = ModInfo.GUI_FACTORY_CLASS)
public class Core {
    public static ConfigTechReborn config;

    @SidedProxy(clientSide = ModInfo.CLIENT_PROXY_CLASS, serverSide = ModInfo.SERVER_PROXY_CLASS)
    public static CommonProxy proxy;

    @Mod.Instance
    public static Core INSTANCE;

    public static final PacketPipeline packetPipeline = new PacketPipeline();

    public VersionChecker versionChecker;

    @Mod.EventHandler
    public void preinit(FMLPreInitializationEvent event) {
        event.getModMetadata().version = ModInfo.MOD_VERSION;
        INSTANCE = this;
        String path = event.getSuggestedConfigurationFile().getAbsolutePath()
                .replace(ModInfo.MOD_ID, "TechReborn");

        config = ConfigTechReborn.initialize(new File(path));

        for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
            compatModule.preInit(event);
        }

        RecipeConfigManager.load(event.getModConfigurationDirectory());
        versionChecker = new VersionChecker("TechReborn");
        versionChecker.checkVersionThreaded();
        LogHelper.info("PreInitialization Complete");
    }

    @Mod.EventHandler
    public void init(FMLInitializationEvent event) {
        // Register ModBlocks
        ModBlocks.init();
        // Register Fluids
        ModFluids.init();
        // Register ModItems
        ModItems.init();
        //Multiparts
        ModParts.init();
        // Recipes
        StopWatch watch = new StopWatch();
        watch.start();
        ModRecipes.init();
        LogHelper.all(watch + " : main recipes");
        watch.stop();
        //Client only init, needs to be done before parts system
        proxy.init();
        // Compat
        for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
            compatModule.init(event);
        }
        // WorldGen
        GameRegistry.registerWorldGenerator(new TROreGen(), 0);
//		DungeonLoot.init();
        // Register Gui Handler
        NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());
        // packets
        PacketHandler.setChannels(NetworkRegistry.INSTANCE.newChannel(
                ModInfo.MOD_ID + "_packets", new PacketHandler()));
        // Achievements
        TRAchievements.init();
        // Multiblock events
        MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler());
        // IDSU manager
        IDSUManager.INSTANCE = new IDSUManager();
        MinecraftForge.EVENT_BUS.register(IDSUManager.INSTANCE);
        FMLCommonHandler.instance().bus().register(new MultiblockServerTickHandler());
        FMLCommonHandler.instance().bus().register(new TRTickHandler());
        packetPipeline.initalise();
        LogHelper.info("Initialization Complete");
    }

    @Mod.EventHandler
    public void postinit(FMLPostInitializationEvent event) throws Exception {
        // Has to be done here as Buildcraft registers there recipes late
        for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
            compatModule.postInit(event);
        }
        packetPipeline.postInitialise();
        LogHelper.info(RecipeHandler.recipeList.size() + " recipes loaded");

//        RecipeHandler.scanForDupeRecipes();

        //RecipeConfigManager.save();
    }

    @Mod.EventHandler
    public void serverStarting(FMLServerStartingEvent event) {
        event.registerServerCommand(new TechRebornDevCommand());
        for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
            compatModule.serverStarting(event);
        }
    }

    @SubscribeEvent
    public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent cfgChange) {
        if (cfgChange.modID.equals("TechReborn")) {
            ConfigTechReborn.Configs();
        }
    }
}

@@ -18,79 +18,8 @@
 n;%0A%0A
-import java.io.File;%0A%0Aimport org.apache.commons.lang3.time.StopWatch;%0A%0A
 impo
@@ -63,24 +63,24 @@
 angedEvent;%0A
+
 import cpw.m
@@ -478,110 +478,8 @@
 nt;%0A
-import cpw.mods.fml.common.gameevent.TickEvent;%0Aimport cpw.mods.fml.common.gameevent.TickEvent.Phase;%0A
 impo
@@ -580,45 +580,8 @@
 ry;%0A
-import cpw.mods.fml.relauncher.Side;%0A
 impo
@@ -756,16 +756,64 @@
 tForge;%0A
+import org.apache.commons.lang3.time.StopWatch;%0A
 import t
@@ -1232,152 +1232,9 @@
 nit.
-ModBlocks;%0Aimport techreborn.init.ModFluids;%0Aimport techreborn.init.ModItems;%0Aimport techreborn.init.ModParts;%0Aimport techreborn.init.ModRecipes
+*
 ;%0Aim
@@ -1495,24 +1495,24 @@
 ionChecker;%0A
-
 import techr
@@ -1534,16 +1534,38 @@
 reGen;%0A%0A
+import java.io.File;%0A%0A
 @Mod(mod

Clean up import