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

import net.minecraft.core.NonNullList
import net.minecraft.data.recipes.RecipeOutput
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.crafting.Ingredient
import net.minecraft.world.item.crafting.ShapedRecipePattern
import net.neoforged.neoforge.common.Tags
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.datagen.modLocation
import ru.dbotthepony.mc.otm.recipe.MatterEntanglerRecipe
import ru.dbotthepony.mc.otm.registry.MItemTags
import ru.dbotthepony.mc.otm.registry.game.MItems
import java.util.*

private fun pattern(
	c00: Ingredient, c10: Ingredient, c20: Ingredient,
	c01: Ingredient, c11: Ingredient, c21: Ingredient,
	c02: Ingredient, c12: Ingredient, c22: Ingredient,
): ShapedRecipePattern {
	val patternMap = linkedMapOf(
		'A' to c00, 'B' to c10, 'C' to c20,
		'D' to c01, 'E' to c11, 'F' to c21,
		'G' to c02, 'K' to c12, 'M' to c22,
	)

	val pattern = listOf(
		"ABC",
		"DEF",
		"GKM",
	)

	return ShapedRecipePattern(
		3, 3,
		NonNullList.copyOf(patternMap.values),
		Optional.of(ShapedRecipePattern.Data(patternMap, pattern))
	)
}

fun addMatterEntanglerRecipes(consumer: RecipeOutput) {
	consumer.accept(
		modLocation("quantum_capacitor"),
		MatterEntanglerRecipe(
			pattern(
				Ingredient.of(MItems.ELECTRIC_PARTS), Ingredient.of(MItemTags.GOLD_WIRES), Ingredient.of(MItems.ELECTRIC_PARTS),
				Ingredient.of(MItems.BATTERY_CAPACITOR), Ingredient.of(MItems.QUANTUM_TRANSCEIVER), Ingredient.of(MItems.BATTERY_CAPACITOR),
				Ingredient.of(MItemTags.TRITANIUM_PLATES), Ingredient.of(MItemTags.TRITANIUM_PLATES), Ingredient.of(MItemTags.TRITANIUM_PLATES),
			),
			Decimal(40),
			400.0,
			ItemStack(MItems.QUANTUM_CAPACITOR, 2),
			experience = 15f
		).energetic()
	)

	consumer.accept(
		modLocation("quantum_battery"),
		MatterEntanglerRecipe(
			pattern(
				Ingredient.of(Tags.Items.STORAGE_BLOCKS_REDSTONE), Ingredient.of(MItemTags.GOLD_WIRES), Ingredient.of(Tags.Items.STORAGE_BLOCKS_REDSTONE),
				Ingredient.of(MItems.BATTERY_DENSE), Ingredient.of(MItems.QUANTUM_TRANSCEIVER), Ingredient.of(MItems.BATTERY_DENSE),
				Ingredient.of(MItemTags.TRITANIUM_PLATES), Ingredient.of(MItemTags.TRITANIUM_PLATES), Ingredient.of(MItemTags.TRITANIUM_PLATES),
			),
			Decimal(120),
			600.0,
			ItemStack(MItems.QUANTUM_BATTERY, 2),
			experience = 20f
		).energetic()
	)

	consumer.accept(
		modLocation("antimatter_transform_matrix"),
		MatterEntanglerRecipe(
			ingredients = pattern(
				Ingredient.of(Tags.Items.ENDER_PEARLS), Ingredient.of(MItemTags.DILITHIUM_GEMS), Ingredient.of(Tags.Items.ENDER_PEARLS),
				Ingredient.of(Tags.Items.DUSTS_REDSTONE), Ingredient.of(MItems.MATTER_TRANSFORM_MATRIX), Ingredient.of(Tags.Items.DUSTS_REDSTONE),
				Ingredient.of(Tags.Items.DUSTS_GLOWSTONE), Ingredient.of(MItemTags.DILITHIUM_GEMS), Ingredient.of(Tags.Items.DUSTS_GLOWSTONE),
			),
			matter = Decimal(600),
			ticks = 2000.0,
			result = ItemStack(MItems.ANTIMATTER_TRANSFORM_MATRIX, 1),
			experience = 20f
		).energetic()
	)
}
