package com.r3944realms.modernlifepatch.datagen.provider;

import com.r3944realms.modernlifepatch.content.item.ModItems;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.*;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.Tags;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;

public class ModRecipeProvider extends RecipeProvider {
    public ModRecipeProvider(PackOutput pOutput) {
        super(pOutput);
    }

    @Override
    protected void buildRecipes(@NotNull Consumer<FinishedRecipe> pWriter) {
        ShapelessRecipeBuilder.shapeless(RecipeCategory.DECORATIONS, ModItems.MIRROR_ITEM.get(), 1)
                .requires(Tags.Items.GLASS_PANES)
                .requires(Items.IRON_INGOT)
                .requires(ItemTags.WOODEN_SLABS)
                .unlockedBy("has_item_glass_pane", has(Tags.Items.GLASS_PANES))
                .save(pWriter);
        ShapedRecipeBuilder.shaped(RecipeCategory.DECORATIONS, ModItems.TALL_MIRROR_ITEM.get(), 1)
                .define('@', ModItems.MIRROR_ITEM.get())
                .pattern("@")
                .pattern("@")
                .unlockedBy("has_item_mirror", has(ModItems.MIRROR_ITEM.get()))
                .save(pWriter);
        ShapedRecipeBuilder.shaped(RecipeCategory.DECORATIONS, ModItems.LARGE_MIRROR_ITEM.get(), 1)
                .define('@', ModItems.MIRROR_ITEM.get())
                .pattern("@@")
                .pattern("@@")
                .unlockedBy("has_item_mirror", has(ModItems.MIRROR_ITEM.get()))
                .save(pWriter);
        ShapedRecipeBuilder.shaped(RecipeCategory.DECORATIONS, ModItems.MASSIVE_MIRROR_ITEM.get(), 1)
                .define('@', ModItems.MIRROR_ITEM.get())
                .pattern("@@@")
                .pattern("@@@")
                .unlockedBy("has_item_mirror", has(ModItems.MIRROR_ITEM.get()))
                .save(pWriter);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.LIGHT_GRAY_CONCRETE_BARRIER_ITEM.get(), Items.LIGHT_GRAY_CONCRETE,2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.WHITE_CONCRETE_BARRIER_ITEM.get(), Items.WHITE_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.ORANGE_CONCRETE_BARRIER_ITEM.get(), Items.ORANGE_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.MAGENTA_CONCRETE_BARRIER_ITEM.get(), Items.MAGENTA_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.LIGHT_BLUE_CONCRETE_BARRIER_ITEM.get(), Items.LIGHT_BLUE_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.YELLOW_CONCRETE_BARRIER_ITEM.get(), Items.YELLOW_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.LIME_CONCRETE_BARRIER_ITEM.get(), Items.LIME_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.PINK_CONCRETE_BARRIER_ITEM.get(), Items.PINK_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.GRAY_CONCRETE_BARRIER_ITEM.get(), Items.GRAY_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.CYAN_CONCRETE_BARRIER_ITEM.get(), Items.CYAN_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.PURPLE_CONCRETE_BARRIER_ITEM.get(), Items.PURPLE_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.BLUE_CONCRETE_BARRIER_ITEM.get(), Items.BLUE_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.BROWN_CONCRETE_BARRIER_ITEM.get(), Items.BROWN_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.GREEN_CONCRETE_BARRIER_ITEM.get(), Items.GREEN_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.RED_CONCRETE_BARRIER_ITEM.get(), Items.RED_CONCRETE, 2);
        stonecutterResultFromBase(pWriter,  RecipeCategory.DECORATIONS,  ModItems.BLACK_CONCRETE_BARRIER_ITEM.get(), Items.BLACK_CONCRETE, 2);
        ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), 2)
                .define('#', Items.WHITE_DYE)
                .define('$', Items.RED_DYE)
                .define('@', Ingredient.of(Items.STONE, Items.GRANITE, Items.DIORITE, Items.ANDESITE, Items.DEEPSLATE, Items.CALCITE, Items.TUFF))
                .pattern("#$#")
                .pattern("$@$")
                .pattern("#$#")
                .unlockedBy("has_red_dye",has(Items.RED_DYE))
                .save(pWriter);

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.NULL_BLOCK_ITEM.get())
                .unlockedBy("has_null_block", has(ModItems.NULL_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_null");

// 其他数字方块还原为 NULL_BLOCK
        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.ZERO_BLOCK_ITEM.get())
                .unlockedBy("has_zero_block", has(ModItems.ZERO_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_zero");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.ONE_BLOCK_ITEM.get())
                .unlockedBy("has_one_block", has(ModItems.ONE_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_one");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.TWO_BLOCK_ITEM.get())
                .unlockedBy("has_two_block", has(ModItems.TWO_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_two");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.THREE_BLOCK_ITEM.get())
                .unlockedBy("has_three_block", has(ModItems.THREE_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_three");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.FOUR_BLOCK_ITEM.get())
                .unlockedBy("has_four_block", has(ModItems.FOUR_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_four");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.FIVE_BLOCK_ITEM.get())
                .unlockedBy("has_five_block", has(ModItems.FIVE_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_five");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.SIX_BLOCK_ITEM.get())
                .unlockedBy("has_six_block", has(ModItems.SIX_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_six");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.SEVEN_BLOCK_ITEM.get())
                .unlockedBy("has_seven_block", has(ModItems.SEVEN_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_seven");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.EIGHT_BLOCK_ITEM.get())
                .unlockedBy("has_eight_block", has(ModItems.EIGHT_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_eight");

        ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get())
                .requires(ModItems.NINE_BLOCK_ITEM.get())
                .unlockedBy("has_nine_block", has(ModItems.NINE_BLOCK_ITEM.get()))
                .save(pWriter, "null_block_from_nine");

// 切石机支持双向转换
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.ZERO_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.ZERO_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.ONE_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.ONE_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.TWO_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.TWO_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.THREE_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.THREE_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.FOUR_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.FOUR_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.FIVE_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.FIVE_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.SIX_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.SIX_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.SEVEN_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.SEVEN_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.EIGHT_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.EIGHT_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());

        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NULL_BLOCK_ITEM.get(), ModItems.NINE_BLOCK_ITEM.get());
        stonecutterResultFromBase(pWriter, RecipeCategory.MISC, ModItems.NINE_BLOCK_ITEM.get(), ModItems.NULL_BLOCK_ITEM.get());
    }
}
