package com.mcmoddev.nethermetals.integration.plugins;

import com.mcmoddev.nethermetals.NetherMetals;
import com.mcmoddev.lib.data.Names;
import com.mcmoddev.lib.init.Materials;
import com.mcmoddev.lib.integration.IIntegration;
import com.mcmoddev.lib.integration.IntegrationInitEvent;
import com.mcmoddev.lib.integration.MMDPlugin;
import com.mcmoddev.lib.material.MMDMaterial;
import com.mcmoddev.lib.util.ConfigBase.Options;
import com.mcmoddev.lib.util.Oredicts;
import com.mcmoddev.lib.integration.plugins.TinkersConstructBase;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import slimeknights.tconstruct.library.TinkerRegistry;
import slimeknights.tconstruct.library.smeltery.MeltingRecipe;
import slimeknights.mantle.util.RecipeMatch;

/**
 *
 * @author Jasmine Iwanek
 *
 */
@MMDPlugin(addonId = NetherMetals.MODID,
pluginId = TinkersConstruct.PLUGIN_MODID,
versions = TinkersConstruct.PLUGIN_MODID + "@[1.12.2-2.7.4.0,);")
public final class TinkersConstruct extends TinkersConstructBase implements IIntegration {

	@Override
	public void init() {
		if (!Options.isModEnabled(TinkersConstruct.PLUGIN_MODID)) {
			return;
		}

		MinecraftForge.EVENT_BUS.register(this);
	}

	private boolean registered = false;

	/**
	 *
	 * @param event The Event.
	 */
	@SubscribeEvent
	public void registerExtraMeltings(final IntegrationInitEvent event) {
		if (registered) {
			return;
		}
		Materials.getAllMaterials().stream()
		.filter(this::isMaterialEmpty)
		.filter(this::hasOre)
		.filter(this::hasFluid)
		.forEach(material -> {
			final RecipeMatch input = RecipeMatch.of(Oredicts.ORE_NETHER + material.getCapitalizedName(), 576);
			final MeltingRecipe recipe = new MeltingRecipe(input, FluidRegistry.getFluid(material.getName()));
			TinkerRegistry.registerMelting(recipe);
		});
		registered = true;
	}

	private boolean hasFluid(final MMDMaterial material) {
		return FluidRegistry.getFluid(material.getName()) != null;
	}

	private boolean hasOre(final MMDMaterial material) {
		return material.hasBlock(Names.NETHERORE);
	}

	private boolean isMaterialEmpty(final MMDMaterial mat) {
		return !mat.isEmpty();
	}
}

@@ -526,16 +526,102 @@
 uctBase;
+%0Aimport com.mcmoddev.lib.integration.plugins.tinkers.events.TinkersExtraMeltingsEvent;
 %0A%0Aimport
@@ -1170,96 +1170,235 @@
 uct 
-extends TinkersConstructBase implements IIntegration %7B%0A%0A%09@Override%0A%09public void init() %7B
+implements IIntegration %7B%0A%0A%09public static final String PLUGIN_MODID = TinkersConstructBase.PLUGIN_MODID;%0A%0A%09public TinkersConstruct() %7B%0A%09%09// do nothing%0A%09%7D%0A%0A%09@Override%0A%09public void init() %7B%0A%09%09TinkersConstructBase.INSTANCE.init();
 %0A%09%09i
@@ -1637,21 +1637,16 @@
 register
-Extra
 Meltings
@@ -1650,37 +1650,36 @@
 ngs(
-final IntegrationInit
+TinkersExtraMeltings
 Event ev
 ent)
@@ -1674,19 +1674,16 @@
 Event ev
-ent
 ) %7B%0A%09%09if

fix TiCon plugin to latest setup