package techreborn.compat.recipes;

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 forestry.api.arboriculture.EnumWoodType;
import forestry.api.arboriculture.TreeManager;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.GeneratorFuel;
import forestry.core.config.Version;
import ic2.api.item.IC2Items;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import techreborn.api.fuel.FluidPowerManager;
import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.machines.IndustrialSawmillRecipe;
import techreborn.compat.CompatManager;
import techreborn.compat.ICompatModule;
import techreborn.config.ConfigTechReborn;

import java.util.Iterator;
import java.util.Map;

public class RecipesForestry implements ICompatModule {
    @Override
    public void preInit(FMLPreInitializationEvent event) {
            System.out.println(Version.VERSION);
        System.out.println();
        if(!Version.VERSION.split(".")[0].equals("4")){
            CompatManager.INSTANCE.compatModules.remove(this);
        }
    }

    @Override
    public void init(FMLInitializationEvent event) {

    }

    @Override
    public void postInit(FMLPostInitializationEvent event) {
        if (ConfigTechReborn.AllowForestryRecipes) {
            ItemStack pulpStack = OreDictionary.getOres("pulpWood").get(0);
            for (EnumWoodType woodType : EnumWoodType.VALUES) {
                ItemStack log = TreeManager.woodItemAccess.getLog(woodType, true);
                log.stackSize = 1;
                ItemStack plank = TreeManager.woodItemAccess.getPlanks(woodType, true);
                plank.stackSize = 6;
                System.out.println(log.getDisplayName() + ":" + plank.getDisplayName());
                RecipeHandler.addRecipe(new IndustrialSawmillRecipe(log, null, new FluidStack(FluidRegistry.WATER, 1000), plank, pulpStack, null, 200, 30, false));
                RecipeHandler.addRecipe(new IndustrialSawmillRecipe(log, IC2Items.getItem("waterCell"), null, plank, pulpStack, IC2Items.getItem("cell"), 200, 30, false));
                RecipeHandler.addRecipe(new IndustrialSawmillRecipe(log, new ItemStack(Items.water_bucket), null, plank, pulpStack, new ItemStack(Items.bucket), 200, 30, false));

                log = TreeManager.woodItemAccess.getLog(woodType, false);
                log.stackSize = 1;
                plank = TreeManager.woodItemAccess.getPlanks(woodType, false);
                plank.stackSize = 6;
                System.out.println(log.getDisplayName() + ":" + plank.getDisplayName());
                RecipeHandler.addRecipe(new IndustrialSawmillRecipe(log, null, new FluidStack(FluidRegistry.WATER, 1000), plank, pulpStack, null, 200, 30, false));
                RecipeHandler.addRecipe(new IndustrialSawmillRecipe(log, IC2Items.getItem("waterCell"), null, plank, pulpStack, IC2Items.getItem("cell"), 200, 30, false));
                RecipeHandler.addRecipe(new IndustrialSawmillRecipe(log, new ItemStack(Items.water_bucket), null, plank, pulpStack, new ItemStack(Items.bucket), 200, 30, false));
            }
        }

        Iterator entries = FuelManager.generatorFuel.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry thisEntry = (Map.Entry) entries.next();
            Fluid fluid = (Fluid) thisEntry.getKey();
            GeneratorFuel generatorFuel = (GeneratorFuel) thisEntry.getValue();
            FluidPowerManager.fluidPowerValues.put(fluid, (double) (generatorFuel.eu / generatorFuel.rate));
        }
    }

    @Override
    public void serverStarting(FMLServerStartingEvent event) {

    }
}


@@ -1033,16 +1033,50 @@
 hReborn;
+%0Aimport techreborn.util.LogHelper;
 %0A%0Aimport
@@ -1252,87 +1252,8 @@
 ) %7B%0A
-            System.out.println(Version.VERSION);%0A        System.out.println();%0A
     
@@ -1367,16 +1367,124 @@
 (this);%0A
+            LogHelper.error(%22Disabled forestry integration because you are not using forestry version 4!%22);%0A
         

Clean up forestry version checker