package moe.hazu.tinkeringabnormally.data;

import com.teamabnormals.caverns_and_chasms.core.registry.CCBlocks;
import com.teamabnormals.caverns_and_chasms.core.registry.CCItems;
import moe.hazu.tinkeringabnormally.TinkeringAbnormally;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.crafting.ConditionalRecipe;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.mantle.recipe.data.ICommonRecipeHelper;
import slimeknights.tconstruct.fluids.TinkerFluids;
import slimeknights.tconstruct.library.data.recipe.ISmelteryRecipeHelper;
import slimeknights.tconstruct.library.recipe.FluidValues;
import slimeknights.tconstruct.library.recipe.alloying.AlloyRecipeBuilder;
import slimeknights.tconstruct.library.recipe.casting.ItemCastingRecipeBuilder;
import slimeknights.tconstruct.library.recipe.melting.MeltingRecipeBuilder;
import slimeknights.tconstruct.smeltery.data.Byproduct;

import java.util.function.Consumer;


public class SmelteryRecipeProvider extends RecipeProvider implements ISmelteryRecipeHelper, ICommonRecipeHelper {
    public SmelteryRecipeProvider(DataGenerator generator) {
        super(generator);
    }

    @Override
    public String getName() {
        return "Tinkering Abnormally Smeltery Recipes";
    }

    @Override
    public String getModId() {
        return TinkeringAbnormally.MODID;
    }

    @Override
    protected void buildCraftingRecipes(Consumer<FinishedRecipe> consumer) {
        String castingFolder = "smeltery/casting/";
        this.gemCasting(consumer, TinkeringAbnormally.moltenSpinel, CCItems.SPINEL.get(), castingFolder + "spinel/gem");
        ItemCastingRecipeBuilder.basinRecipe(CCBlocks.SPINEL_BLOCK.get())
                .setFluidAndTime(TinkeringAbnormally.moltenSpinel, FluidValues.LARGE_GEM_BLOCK)
                .save(consumer, location(castingFolder + "spinel/block"));
        this.metalCasting(consumer, TinkeringAbnormally.moltenNecromium, CCBlocks.NECROMIUM_BLOCK.get(), CCItems.NECROMIUM_INGOT.get(), CCItems.NECROMIUM_NUGGET.get(), castingFolder, "necromium");
        ItemCastingRecipeBuilder.tableRecipe(CCItems.BEJEWELED_APPLE.get())
                .setFluidAndTime(TinkeringAbnormally.moltenSpinel, FluidValues.GEM * 4)
                .setCast(Items.GOLDEN_APPLE, true)
                .save(consumer, location(castingFolder + "spinel/apple"));

        String meltingFolder = "smeltery/melting/";
        gemMelting(consumer, TinkeringAbnormally.moltenSpinel.get(), "spinel", true, 9, meltingFolder, false);
        metalMelting(consumer, TinkeringAbnormally.moltenNecromium.get(), "necromium", false, meltingFolder, false);
        int[] necromiumSizes = {FluidValues.NUGGET, FluidValues.GEM_SHARD};
        MeltingRecipeBuilder.melting(Ingredient.of(CCItems.NECROMIUM_HELMET.get()), TinkeringAbnormally.moltenNecromium.get(), FluidValues.INGOT)
                .setDamagable(necromiumSizes)
                .addByproduct(new FluidStack(TinkerFluids.moltenDiamond.get(), FluidValues.GEM * 5))
                .save(consumer, location(meltingFolder + "necromium/helmet"));
        MeltingRecipeBuilder.melting(Ingredient.of(CCItems.NECROMIUM_CHESTPLATE.get()), TinkeringAbnormally.moltenNecromium.get(), FluidValues.INGOT)
                .setDamagable(necromiumSizes)
                .addByproduct(new FluidStack(TinkerFluids.moltenDiamond.get(), FluidValues.GEM * 8))
                .save(consumer, location(meltingFolder + "necromium/chestplate"));
        MeltingRecipeBuilder.melting(Ingredient.of(CCItems.NECROMIUM_LEGGINGS.get()), TinkeringAbnormally.moltenNecromium.get(), FluidValues.INGOT)
                .setDamagable(necromiumSizes)
                .addByproduct(new FluidStack(TinkerFluids.moltenDiamond.get(), FluidValues.GEM * 7))
                .save(consumer, location(meltingFolder + "necromium/leggings"));
        MeltingRecipeBuilder.melting(Ingredient.of(CCItems.NECROMIUM_BOOTS.get()), TinkeringAbnormally.moltenNecromium.get(), FluidValues.INGOT)
                .setDamagable(necromiumSizes)
                .addByproduct(new FluidStack(TinkerFluids.moltenDiamond.get(), FluidValues.GEM * 4))
                .save(consumer, location(meltingFolder + "necromium/boots"));
        MeltingRecipeBuilder.melting(Ingredient.of(CCItems.NECROMIUM_AXE.get(), CCItems.NECROMIUM_PICKAXE.get()), TinkeringAbnormally.moltenNecromium.get(), FluidValues.INGOT)
                .setDamagable(necromiumSizes)
                .addByproduct(new FluidStack(TinkerFluids.moltenDiamond.get(), FluidValues.GEM * 3))
                .save(consumer, location(meltingFolder + "necromium/axes"));
        MeltingRecipeBuilder.melting(Ingredient.of(CCItems.NECROMIUM_SWORD.get(), CCItems.NECROMIUM_HOE.get()), TinkeringAbnormally.moltenNecromium.get(), FluidValues.INGOT)
                .setDamagable(necromiumSizes)
                .addByproduct(new FluidStack(TinkerFluids.moltenDiamond.get(), FluidValues.GEM * 2))
                .save(consumer, location(meltingFolder + "necromium/weapon"));
        MeltingRecipeBuilder.melting(Ingredient.of(CCItems.NECROMIUM_SHOVEL.get()), TinkeringAbnormally.moltenNecromium.get(), FluidValues.INGOT)
                .setDamagable(necromiumSizes)
                .addByproduct(new FluidStack(TinkerFluids.moltenDiamond.get(), FluidValues.GEM))
                .save(consumer, location(meltingFolder + "necromium/shovel"));
        MeltingRecipeBuilder.melting(Ingredient.of(CCItems.SILVER_HORSE_ARMOR.get()), TinkerFluids.moltenSilver.get(), FluidValues.INGOT * 7)
                .save(consumer, location(meltingFolder + "silver/horse_armor"));

        String alloyFolder = "smeltery/alloys/";
        AlloyRecipeBuilder.alloy(TinkeringAbnormally.moltenNecromium.get(), FluidValues.NUGGET)
                .addInput(TinkerFluids.moltenDebris.getLocalTag(), FluidValues.NUGGET * 4)
                .addInput(TinkerFluids.moltenSilver.getForgeTag(), FluidValues.NUGGET * 2)
                .save(consumer, prefix(TinkeringAbnormally.moltenNecromium, alloyFolder));
    }
}
