package org.cyclops.commoncapabilities.modcompat.forestry.capability;

import forestry.core.config.Constants;
import forestry.core.tiles.TileEngine;
import forestry.energy.tiles.TileEngineBiogas;
import forestry.energy.tiles.TileEngineClockwork;
import forestry.energy.tiles.TileEngineElectric;
import forestry.energy.tiles.TileEnginePeat;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.cyclops.commoncapabilities.CommonCapabilities;
import org.cyclops.commoncapabilities.Reference;
import org.cyclops.commoncapabilities.api.capability.temperature.ITemperature;
import org.cyclops.commoncapabilities.capability.temperature.TemperatureConfig;
import org.cyclops.commoncapabilities.modcompat.forestry.capability.temperature.TileEngineTemperature;
import org.cyclops.cyclopscore.modcompat.IModCompat;
import org.cyclops.cyclopscore.modcompat.capabilities.CapabilityConstructorRegistry;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.cyclopscore.modcompat.capabilities.SimpleCapabilityConstructor;

import javax.annotation.Nullable;

/**
 * Capabilities for EnderIO.
 * @author rubensworks
 */
public class ForestryModCompat implements IModCompat {
    @Override
    public String getModID() {
        return Reference.MOD_FORESTRY;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public String getComment() {
        return "Worker and Temperature capabilities for Forestry machines.";
    }

    @Override
    public void onInit(Step initStep) {
        if(initStep == Step.INIT) {
            CapabilityConstructorRegistry registry = CommonCapabilities._instance.getCapabilityConstructorRegistry();
            // Temperature
            registerEngineTemperature(registry, TileEngineBiogas.class, ITemperature.ZERO_CELCIUS + Constants.ENGINE_BRONZE_HEAT_MAX);
            registerEngineTemperature(registry, TileEngineClockwork.class, ITemperature.ZERO_CELCIUS + 300000);
            registerEngineTemperature(registry, TileEngineElectric.class, ITemperature.ZERO_CELCIUS + Constants.ENGINE_ELECTRIC_HEAT_MAX);
            registerEngineTemperature(registry, TileEnginePeat.class, ITemperature.ZERO_CELCIUS + Constants.ENGINE_COPPER_HEAT_MAX);
        }
    }

    protected static <T extends TileEngine> void registerEngineTemperature(
            CapabilityConstructorRegistry registry, Class<T> clazz, final double maximumTemperature) {
        registry.registerTile(clazz,
                new SimpleCapabilityConstructor<ITemperature, T>() {
                    @Override
                    public Capability<ITemperature> getCapability() {
                        return TemperatureConfig.CAPABILITY;
                    }

                    @Nullable
                    @Override
                    public ICapabilityProvider createProvider(T host) {
                        return new DefaultCapabilityProvider<>(TemperatureConfig.CAPABILITY,
                                new TileEngineTemperature(host, maximumTemperature,
                                        ITemperature.ZERO_CELCIUS, ITemperature.ZERO_CELCIUS));
                    }
                });
    }
}

@@ -103,16 +103,55 @@
 stants;%0A
+import forestry.core.items.ItemWrench;%0A
 import f
@@ -181,16 +181,16 @@
 Engine;%0A
-
 import f
@@ -368,24 +368,61 @@
 EnginePeat;%0A
+import net.minecraft.item.ItemStack;%0A
 import net.m
@@ -712,32 +712,176 @@
 e.ITemperature;%0A
+import org.cyclops.commoncapabilities.api.capability.wrench.DefaultWrench;%0Aimport org.cyclops.commoncapabilities.api.capability.wrench.IWrench;%0A
 import org.cyclo
@@ -944,16 +944,86 @@
 Config;%0A
+import org.cyclops.commoncapabilities.capability.wrench.WrenchConfig;%0A
 import o
@@ -1328,32 +1328,110 @@
 bilityProvider;%0A
+import org.cyclops.cyclopscore.modcompat.capabilities.ICapabilityConstructor;%0A
 import org.cyclo
@@ -2558,32 +2558,32 @@
 TRIC_HEAT_MAX);%0A
-
             regi
@@ -2690,32 +2690,723 @@
 OPPER_HEAT_MAX);
+%0A%0A            // Wrench%0A            registry.registerItem(ItemWrench.class,%0A                    new ICapabilityConstructor%3CIWrench, ItemWrench, ItemStack%3E() %7B%0A                        @Override%0A                        public Capability%3CIWrench%3E getCapability() %7B%0A                            return WrenchConfig.CAPABILITY;%0A                        %7D%0A%0A                        @Nullable%0A                        @Override%0A                        public ICapabilityProvider createProvider(ItemWrench hostType, final ItemStack host) %7B%0A                            return new DefaultCapabilityProvider%3C%3E(WrenchConfig.CAPABILITY, new DefaultWrench());%0A                        %7D%0A                    %7D);
 %0A        %7D%0A    %7D

Add Forestry Wrench capability