package ru.dbotthepony.mc.otm.datagen.recipes

import net.minecraft.data.recipes.FinishedRecipe
import net.minecraft.data.recipes.RecipeCategory
import net.minecraft.data.recipes.ShapelessRecipeBuilder
import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraft.world.item.crafting.Ingredient
import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.datagen.modLocation
import ru.dbotthepony.mc.otm.registry.MItemTags
import ru.dbotthepony.mc.otm.registry.MItems
import ru.dbotthepony.mc.otm.registry.MRegistry
import java.util.function.Consumer

fun addShapelessRecipes(consumer: Consumer<FinishedRecipe>) {
	for (color in DyeColor.values()) {
		ShapelessRecipeBuilder(RecipeCategory.TRANSPORTATION, MItems.CARGO_CRATE_MINECARTS[color]!!, 1)
			.requires(Items.MINECART)
			.requires(MRegistry.CARGO_CRATES.items[color]!!)
			.unlockedBy(Items.MINECART)
			.unlockedBy(MRegistry.CARGO_CRATES.items[color]!!)
			.save(consumer)

		ShapelessRecipeBuilder(RecipeCategory.TRANSPORTATION, MItems.CARGO_CRATE_MINECARTS[color]!!, 1)
			.requires(Ingredient.of(MItems.CARGO_CRATE_MINECARTS.entries.stream().filter { it.key != color }.map { ItemStack(it.value) }))
			.requires(color.tag)
			.unlockedBy(MItems.CARGO_CRATE_MINECARTS.entries.stream().filter { it.key != color }.map { it.value })
			.save(consumer, modLocation(MItems.CARGO_CRATE_MINECARTS[color]!!.registryName!!.path + "_alt"))
	}

	ShapelessRecipeBuilder(RecipeCategory.TRANSPORTATION, MItems.CARGO_CRATE_MINECARTS[null]!!, 1)
		.requires(Items.MINECART)
		.requires(MRegistry.CARGO_CRATES.item)
		.unlockedBy(Items.MINECART)
		.unlockedBy(MRegistry.CARGO_CRATES.item)
		.save(consumer)
}
