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

import net.minecraft.core.component.DataComponents
import net.minecraft.data.recipes.RecipeCategory
import net.minecraft.data.recipes.RecipeOutput
import net.minecraft.data.recipes.ShapelessRecipeBuilder
import net.minecraft.tags.ItemTags
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraft.world.item.crafting.Ingredient
import net.neoforged.neoforge.common.Tags
import net.neoforged.neoforge.common.conditions.NotCondition
import net.neoforged.neoforge.common.conditions.TagEmptyCondition
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
import ru.dbotthepony.mc.otm.config.CablesConfig
import ru.dbotthepony.mc.otm.core.ResourceLocation
import ru.dbotthepony.mc.otm.registry.game.MBlocks
import ru.dbotthepony.mc.otm.registry.MItemTags
import ru.dbotthepony.mc.otm.registry.game.MItems
import ru.dbotthepony.mc.otm.registry.MRegistry
import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.datagen.modLocation
import ru.dbotthepony.mc.otm.recipe.UpgradeRecipe

fun addCraftingTableRecipes(consumer: RecipeOutput) {
	val machinesCategory = RecipeCategory.DECORATIONS

	MatteryRecipe(MRegistry.CARGO_CRATES.item, category = RecipeCategory.DECORATIONS)
		.row(MItemTags.TRITANIUM_PLATES, multiIngredient(Tags.Items.CHESTS_WOODEN, Tags.Items.BARRELS_WOODEN), MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItemTags.TRITANIUM_PLATES)
		.unlockedBy(Tags.Items.CHESTS)
		.build(consumer)

	for ((dye, crate) in MRegistry.CARGO_CRATES.blocks) {
		ShapelessRecipeBuilder(RecipeCategory.DECORATIONS, crate, 1)
			.requires(Ingredient.of(MRegistry.CARGO_CRATES.allItems.entries.stream().filter { it.key != dye }.map { ItemStack(it.value) }))
			.requires(dye.tag)
			.unlockedBy(MRegistry.CARGO_CRATES.allItems.entries.stream().filter { it.key != dye }.map { it.value })
			.save(consumer, "${crate.registryName}_alt")
	}

	MItems.ENERGY_COUNTER.values.forEach {
		ShapelessRecipeBuilder(machinesCategory, it, 1)
			.requires(it)
			.unlockedBy(it)
			.save(consumer, modLocation("${it.registryName!!.path}_reset"))
	}

	ShapelessRecipeBuilder(machinesCategory, MItems.HOLO_SIGN, 1)
		.requires(MItems.HOLO_SIGN)
		.unlockedBy(MItems.HOLO_SIGN)
		.save(consumer, modLocation("holo_sign_reset"))

	MatteryRecipe(MBlocks.DRIVE_VIEWER[null]!!, category = machinesCategory)
		.rowBC(MItems.DISPLAY_SCREEN, Tags.Items.GLASS_PANES)
		.row(MItemTags.IRON_PLATES, MItems.MACHINE_FRAME, MItemTags.IRON_PLATES)
		.row(MItemTags.BASIC_CIRCUIT, MItems.MATTER_IO_PORT, MItemTags.BASIC_CIRCUIT)
		.unlockedBy(MItems.MATTER_IO_PORT)
		.build(consumer)

	MatteryRecipe(MBlocks.MATTER_BOTTLER[null]!!, category = machinesCategory)
		.row(MItems.MATTER_CAPACITOR_PARTS, MItems.MATTER_IO_PORT, MItems.MATTER_CAPACITOR_PARTS)
		.row(Tags.Items.GLASS_BLOCKS, MItems.MACHINE_FRAME, Tags.Items.GLASS_BLOCKS)
		.rowAC(MItems.MATTER_CABLE, MItems.MATTER_CABLE)
		.unlockedBy(MItems.MATTER_CAPACITOR_PARTS)
		.unlockedBy(MItems.MATTER_IO_PORT)
		.build(consumer)

	MatteryRecipe(MBlocks.MATTER_DECOMPOSER[null]!!, category = machinesCategory)
		.row(MItems.MATTER_TRANSFORM_MATRIX, MItemTags.BASIC_CIRCUIT, MItems.MATTER_IO_PORT)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MACHINE_FRAME, MItemTags.TRITANIUM_PLATES)
		.row(MItems.MATTER_CABLE, MItems.MATTER_CAPACITOR_PARTS, MItems.MATTER_CABLE)
		.unlockedBy(MItems.MATTER_CAPACITOR_PARTS)
		.unlockedBy(MItems.MATTER_IO_PORT)
		.build(consumer)

	MatteryRecipe(MBlocks.MATTER_PANEL[null]!!, category = machinesCategory)
		.row(MItems.ELECTRIC_PARTS, MItemTags.TRITANIUM_PLATES, Tags.Items.GLASS_PANES)
		.row(MItems.MATTER_CABLE, MItems.DISPLAY_SCREEN, Tags.Items.GLASS_PANES)
		.row(MItemTags.ADVANCED_CIRCUIT, MItemTags.TRITANIUM_PLATES, Tags.Items.GLASS_PANES)
		.unlockedBy(Tags.Items.GLASS_BLOCKS)
		.build(consumer)

	MatteryRecipe(MBlocks.MATTER_REPLICATOR[null]!!, category = machinesCategory)
		.row(MItems.MATTER_IO_PORT, MItemTags.ADVANCED_CIRCUIT, MItems.MATTER_TRANSFORM_MATRIX)
		.row(Tags.Items.GEMS_DIAMOND, MItems.MACHINE_FRAME, Tags.Items.GEMS_DIAMOND)
		.row(MItems.MATTER_CABLE, MItems.MATTER_CAPACITOR_PARTS, MItems.MATTER_CABLE)
		.unlockedBy(MItems.MATTER_CAPACITOR_PARTS)
		.unlockedBy(MItems.MATTER_IO_PORT)
		.unlockedBy(MItems.MATTER_TRANSFORM_MATRIX)
		.build(consumer)

	MatteryRecipe(MBlocks.PATTERN_STORAGE, category = machinesCategory)
		.row(Tags.Items.GLASS_BLOCKS, Tags.Items.GLASS_BLOCKS, Tags.Items.GLASS_BLOCKS)
		.row(MItemTags.IRON_PLATES, MItems.MACHINE_FRAME, MItemTags.IRON_PLATES)
		.row(MItems.MATTER_CABLE, MItemTags.BASIC_CIRCUIT, MItems.MATTER_CABLE)
		.unlockedBy(MItemTags.IRON_PLATES)
		.build(consumer)

	MatteryRecipe(MBlocks.ENERGY_COUNTER[null]!!, category = machinesCategory)
		.row(MItemTags.TRITANIUM_PLATES, MItems.ENERGY_BUS, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.BASIC_CIRCUIT, MItems.DISPLAY_SCREEN, MItemTags.HARDENED_GLASS_PANES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.ENERGY_BUS, MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItems.ENERGY_BUS)
		.build(consumer)

	MatteryRecipe(MBlocks.TWIN_PLATE_PRESS[null]!!, category = machinesCategory)
		.rowAC(MItems.ELECTROMOTOR, MItems.ELECTROMOTOR)
		.row(MItemTags.PISTONS, MItems.MACHINE_FRAME, MItemTags.PISTONS)
		.unlockedBy(MItemTags.TRITANIUM_INGOTS)
		.unlockedBy(MItems.MACHINE_FRAME)
		.build(consumer)

	for ((color, item) in MItems.PLATE_PRESS) {
		MatteryRecipe(MBlocks.TWIN_PLATE_PRESS[color]!!, category = machinesCategory)
			.setUpgradeSource(item)
			.addUpgradeOps(UpgradeRecipe.CopyAllComponents)
			.rowA(item)
			.build(consumer, "plate_press_migration/${color?.name?.lowercase() ?: "default"}")
	}

	MatteryRecipe(MBlocks.CHEMICAL_GENERATOR[null]!!, category = machinesCategory)
		.rowB(MItems.ENERGY_BUS)
		.row(MItemTags.TRITANIUM_INGOTS, MItemTags.FURNACES, MItemTags.TRITANIUM_INGOTS)
		.rowAC(MItems.ELECTRIC_PARTS, MItems.ELECTRIC_PARTS)
		.unlockedBy(MItemTags.FURNACES)
		.unlockedBy(MItems.ENERGY_BUS)
		.build(consumer)

	MatteryRecipe(MItems.PATTERN_DRIVE_NORMAL, category = machinesCategory)
		.row(Tags.Items.DUSTS_GLOWSTONE, MItemTags.CARBON_PLATES, Tags.Items.DUSTS_GLOWSTONE)
		.row(MItemTags.DILITHIUM_GEMS, MItemTags.ADVANCED_CIRCUIT, MItemTags.DILITHIUM_GEMS)
		.row(Tags.Items.DUSTS_GLOWSTONE, Tags.Items.GEMS_DIAMOND, Tags.Items.DUSTS_GLOWSTONE)
		.unlockedBy(MItemTags.DILITHIUM_GEMS)
		.build(consumer)

	MatteryRecipe(MItems.PATTERN_DRIVE_DOUBLE, category = machinesCategory)
		.setUpgradeSource(MItems.PATTERN_DRIVE_NORMAL)
		.addUpgradeOps(UpgradeRecipe.MergePatterns)
		.rowB(MItemTags.DILITHIUM_GEMS)
		.row(MItems.PATTERN_DRIVE_NORMAL, MItemTags.ADVANCED_CIRCUIT, MItems.PATTERN_DRIVE_NORMAL)
		.rowB(MItemTags.DILITHIUM_GEMS)
		.unlockedBy(MItems.PATTERN_DRIVE_NORMAL)
		.build(consumer)

	MatteryRecipe(MItems.PATTERN_DRIVE_TRIPLE, category = machinesCategory)
		.setUpgradeSource(MItems.PATTERN_DRIVE_DOUBLE)
		.addUpgradeOps(UpgradeRecipe.MergePatterns)
		.row(Tags.Items.DUSTS_GLOWSTONE, MItemTags.DILITHIUM_GEMS, Tags.Items.DUSTS_GLOWSTONE)
		.row(MItems.PATTERN_DRIVE_DOUBLE, MItemTags.ADVANCED_CIRCUIT, MItems.PATTERN_DRIVE_DOUBLE)
		.row(Tags.Items.DUSTS_GLOWSTONE, MItemTags.DILITHIUM_GEMS, Tags.Items.DUSTS_GLOWSTONE)
		.unlockedBy(MItems.PATTERN_DRIVE_DOUBLE)
		.build(consumer)

	MatteryRecipe(MItems.PATTERN_DRIVE_QUAD, category = machinesCategory)
		.setUpgradeSource(MItems.PATTERN_DRIVE_TRIPLE)
		.addUpgradeOps(UpgradeRecipe.MergePatterns)
		.row(MItemTags.DILITHIUM_GEMS, MItemTags.REINFORCED_TRITANIUM_PLATES, MItemTags.DILITHIUM_GEMS)
		.row(MItems.PATTERN_DRIVE_TRIPLE, MItemTags.ADVANCED_CIRCUIT, MItems.PATTERN_DRIVE_TRIPLE)
		.row(MItemTags.DILITHIUM_GEMS, MItemTags.REINFORCED_TRITANIUM_PLATES, MItemTags.DILITHIUM_GEMS)
		.unlockedBy(MItems.PATTERN_DRIVE_TRIPLE)
		.build(consumer)

	MatteryRecipe(MItems.MATTER_CABLE, count = 16, category = machinesCategory)
		.row(MItemTags.TRITANIUM_PLATES, MItemTags.TRITANIUM_PLATES, MItemTags.TRITANIUM_PLATES)
		.row(Items.REDSTONE, MItemTags.COPPER_WIRES, Items.REDSTONE)
		.row(MItemTags.TRITANIUM_PLATES, MItemTags.TRITANIUM_PLATES, MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItemTags.COPPER_WIRES)
		.build(consumer)

	// Машины
	MatteryRecipe(MItems.MATTER_RECYCLER[null]!!, category = machinesCategory)
		.row(MItems.MATTER_CAPACITOR_PARTS, Items.HOPPER, MItemTags.BASIC_CIRCUIT)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MACHINE_FRAME, MItemTags.TRITANIUM_PLATES)
		.row(MItems.MATTER_CABLE, MItems.MATTER_IO_PORT, MItems.MATTER_CABLE)
		.unlockedBy(MItems.MATTER_CABLE)
		.build(consumer)

	// Блоки
	MatteryRecipe(MItems.MATTER_CAPACITOR_BANK[null]!!, category = machinesCategory)
		.row(Tags.Items.GLASS_BLOCKS, MItemTags.IRON_PLATES, Tags.Items.GLASS_BLOCKS)
		.row(MItemTags.IRON_PLATES, MItems.MACHINE_FRAME, MItemTags.IRON_PLATES)
		.row(MItems.MATTER_CABLE, MItems.MATTER_IO_PORT, MItems.MATTER_CABLE)
		.unlockedBy(MItems.MATTER_CABLE)
		.build(consumer)

	MatteryRecipe(MItems.BATTERY_BANK[null]!!, category = machinesCategory)
		.row(Tags.Items.GLASS_BLOCKS, MItemTags.IRON_PLATES, Tags.Items.GLASS_BLOCKS)
		.row(MItemTags.IRON_PLATES, MItems.MACHINE_FRAME, MItemTags.IRON_PLATES)
		.row(MItems.ELECTRIC_PARTS, MItems.ENERGY_BUS, MItems.ELECTRIC_PARTS)
		.unlockedBy(MItems.ENERGY_BUS)
		.build(consumer)

	MatteryRecipe(MItems.GRAVITATION_STABILIZER, category = machinesCategory)
		.row(MItemTags.ADVANCED_CIRCUIT, MItems.GRAVITATION_FIELD_SENSOR, MItemTags.ADVANCED_CIRCUIT)
		.row(MItems.MATTER_TRANSFORM_MATRIX, MItems.MACHINE_FRAME, MItems.MATTER_TRANSFORM_MATRIX)
		.row(MItemTags.TRITANIUM_PLATES, MItems.GRAVITATION_FIELD_LIMITER, MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItems.GRAVITATION_FIELD_LIMITER)
		.unlockedBy(MItems.GRAVITATION_FIELD_SENSOR)
		.build(consumer)

	MatteryRecipe(MItems.PORTABLE_GRAVITATION_STABILIZER, category = RecipeCategory.COMBAT)
		.rowB(MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.GRAVITATION_FIELD_SENSOR, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.GRAVITATION_FIELD_LIMITER, MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItems.GRAVITATION_FIELD_LIMITER)
		.unlockedBy(MItems.GRAVITATION_FIELD_SENSOR)
		.build(consumer)

	MatteryRecipe(MItems.GRAVITATION_FIELD_SENSOR, category = RecipeCategory.MISC)
		.rowB(MItemTags.BASIC_CIRCUIT)
		.row(MItemTags.TRITANIUM_PLATES, MItems.ELECTROMAGNET, MItemTags.TRITANIUM_PLATES)
		.rowB(MItemTags.IRON_PLATES)
		.unlockedBy(MItems.ELECTROMAGNET)
		.build(consumer)

	MatteryRecipe(MItems.GRAVITATION_FIELD_LIMITER, category = RecipeCategory.MISC)
		.row(Tags.Items.ENDER_PEARLS, MItemTags.ADVANCED_CIRCUIT, Tags.Items.ENDER_PEARLS)
		.row(MItemTags.GOLD_WIRES, MItems.QUANTUM_TRANSCEIVER, MItemTags.GOLD_WIRES)
		.rowB(MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItems.QUANTUM_TRANSCEIVER)
		.build(consumer)

	MatteryRecipe(MItems.BLACK_HOLE_SCANNER, category = RecipeCategory.TOOLS)
		.row(MItemTags.IRON_PLATES, MItems.DISPLAY_SCREEN, MItemTags.IRON_PLATES)
		.row(MItemTags.GOLD_WIRES, MItems.GRAVITATION_FIELD_SENSOR, MItemTags.ADVANCED_CIRCUIT)
		.rowAC(Tags.Items.DUSTS_GLOWSTONE, MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItems.GRAVITATION_FIELD_SENSOR)
		.build(consumer)

	MatteryRecipe(MItems.PHANTOM_ATTRACTOR, category = machinesCategory)
		.row(Tags.Items.DUSTS_REDSTONE, Tags.Items.GLASS_BLOCKS_COLORLESS, Tags.Items.DUSTS_REDSTONE)
		.row(MItemTags.TRITANIUM_PLATES, MItems.QUANTUM_TRANSCEIVER, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, ItemTags.BEDS, MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItems.QUANTUM_TRANSCEIVER)
		.build(consumer)

	MatteryRecipe(MItems.QUANTUM_TRANSCEIVER, 2, category = RecipeCategory.MISC)
		.rowAC(MItemTags.COPPER_WIRES, MItemTags.COPPER_WIRES)
		.row(MItemTags.GOLD_WIRES, Tags.Items.ENDER_PEARLS, MItemTags.GOLD_WIRES)
		.row(MItemTags.GOLD_WIRES, MItems.ELECTROMAGNET, MItemTags.GOLD_WIRES)
		.unlockedBy(Tags.Items.ENDER_PEARLS)
		.build(consumer)

	MatteryRecipe(MItems.ELECTROMAGNET, category = RecipeCategory.MISC)
		.row(MItemTags.COPPER_WIRES, Tags.Items.INGOTS_IRON, MItemTags.COPPER_WIRES)
		.unlockedBy(Tags.Items.INGOTS_IRON)
		.build(consumer)

	MatteryRecipe(MItems.ENERGY_SERVO[null]!!, category = RecipeCategory.MISC)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MACHINE_FRAME, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.ENERGY_BUS, MItemTags.TRITANIUM_PLATES)
		.unlockedBy(MItems.ENERGY_BUS)
		.build(consumer)

	MatteryRecipe(MItems.MIRROR_COMPOUND, 3, category = RecipeCategory.MISC)
		.row(Tags.Items.GLASS_PANES_COLORLESS, Tags.Items.GLASS_PANES_COLORLESS, Tags.Items.GLASS_PANES_COLORLESS)
		.row(MItemTags.IRON_PLATES, MItemTags.IRON_PLATES, MItemTags.IRON_PLATES)
		.unlockedBy(MItemTags.IRON_PLATES)
		.unlockedBy(Tags.Items.GLASS_PANES_COLORLESS)
		.build(consumer)

	MatteryRecipe(MItems.REINFORCED_TRITANIUM_PLATE, category = RecipeCategory.MISC)
		.rowB(MItemTags.CARBON_PLATES)
		.row(MItemTags.CARBON_PLATES, MItemTags.TRITANIUM_PLATES, MItemTags.CARBON_PLATES)
		.rowB(MItemTags.CARBON_PLATES)
		.unlockedBy(MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.REINFORCED_IRON_PLATE, category = RecipeCategory.MISC)
		.rowB(MItemTags.CARBON_PLATES)
		.row(MItemTags.CARBON_PLATES, MItemTags.IRON_PLATES, MItemTags.CARBON_PLATES)
		.rowB(MItemTags.CARBON_PLATES)
		.unlockedBy(MItemTags.IRON_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.ARMOR_ASSEMBLY, category = RecipeCategory.MISC)
		.row(MItemTags.CARBON_PLATES, MItemTags.IRON_PLATES, MItemTags.CARBON_PLATES)
		.row(MItemTags.IRON_PLATES, Items.DIAMOND, MItemTags.IRON_PLATES)
		.row(MItemTags.CARBON_PLATES, MItemTags.IRON_PLATES, MItemTags.CARBON_PLATES)
		.unlockedBy(MItemTags.IRON_PLATES)
		.unlockedBy(MItemTags.CARBON_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.CARBON_FIBRE_BLOCK, category = RecipeCategory.BUILDING_BLOCKS)
		.rowAB(MItemTags.CARBON_PLATES, MItemTags.CARBON_PLATES)
		.rowAB(MItemTags.CARBON_PLATES, MItemTags.CARBON_PLATES)
		.unlockedBy(MItemTags.CARBON_PLATES)
		.build(consumer)

	ShapelessRecipeBuilder(RecipeCategory.MISC, MItems.CARBON_MESH, 4)
		.requires(Ingredient.of(MItems.CARBON_FIBRE_BLOCK))
		.unlockedBy(MItemTags.CARBON_PLATES)
		.unlockedBy(MItems.CARBON_FIBRE_BLOCK)
		.save(consumer, modLocation("carbon_mesh_from_block"))

	// броня
	MatteryRecipe(MItems.TRITANIUM_HELMET, category = RecipeCategory.COMBAT)
		.setUpgradeSource(Items.LEATHER_HELMET)
		.addUpgradeOps(UpgradeRecipe.CopyEnchantments)
		.addUpgradeOps(UpgradeRecipe.CopyComponent(DataComponents.CUSTOM_NAME))
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, MItems.ARMOR_ASSEMBLY, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, Items.LEATHER_HELMET, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.unlockedBy(MItemTags.REINFORCED_TRITANIUM_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.TRITANIUM_PANTS, category = RecipeCategory.COMBAT)
		.setUpgradeSource(Items.LEATHER_LEGGINGS)
		.addUpgradeOps(UpgradeRecipe.CopyEnchantments)
		.addUpgradeOps(UpgradeRecipe.CopyComponent(DataComponents.CUSTOM_NAME))
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, MItems.ARMOR_ASSEMBLY, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, Items.LEATHER_LEGGINGS, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.rowAC(MItemTags.REINFORCED_TRITANIUM_PLATES, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.unlockedBy(MItemTags.REINFORCED_TRITANIUM_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.TRITANIUM_CHESTPLATE, category = RecipeCategory.COMBAT)
		.setUpgradeSource(Items.LEATHER_CHESTPLATE)
		.addUpgradeOps(UpgradeRecipe.CopyEnchantments)
		.addUpgradeOps(UpgradeRecipe.CopyComponent(DataComponents.CUSTOM_NAME))
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, Items.LEATHER_CHESTPLATE, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, MItems.ARMOR_ASSEMBLY, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, MItemTags.REINFORCED_TRITANIUM_PLATES, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.unlockedBy(MItemTags.REINFORCED_TRITANIUM_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.TRITANIUM_BOOTS, category = RecipeCategory.COMBAT)
		.setUpgradeSource(Items.LEATHER_BOOTS)
		.addUpgradeOps(UpgradeRecipe.CopyEnchantments)
		.addUpgradeOps(UpgradeRecipe.CopyComponent(DataComponents.CUSTOM_NAME))
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, Items.LEATHER_BOOTS, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, MItems.ARMOR_ASSEMBLY, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.unlockedBy(MItemTags.REINFORCED_TRITANIUM_PLATES)
		.build(consumer)

	// простая броня
	MatteryRecipe(MItems.SIMPLE_TRITANIUM_HELMET, category = RecipeCategory.COMBAT)
		.row(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.unlockedBy(MItemTags.TRITANIUM_INGOTS)
		.build(consumer)

	MatteryRecipe(MItems.SIMPLE_TRITANIUM_PANTS, category = RecipeCategory.COMBAT)
		.row(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.unlockedBy(MItemTags.TRITANIUM_INGOTS)
		.build(consumer)

	MatteryRecipe(MItems.SIMPLE_TRITANIUM_CHESTPLATE, category = RecipeCategory.COMBAT)
		.rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.row(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.row(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.unlockedBy(MItemTags.TRITANIUM_INGOTS)
		.build(consumer)

	MatteryRecipe(MItems.SIMPLE_TRITANIUM_BOOTS, category = RecipeCategory.COMBAT)
		.rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
		.unlockedBy(MItemTags.TRITANIUM_INGOTS)
		.build(consumer)

	// станция андроида
	MatteryRecipe(MItems.ANDROID_STATION[null]!!, category = machinesCategory)
		.row(MItems.ELECTRIC_PARTS, MItems.QUANTUM_TRANSCEIVER, MItems.ELECTRIC_PARTS)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MACHINE_FRAME, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.ELECTRIC_PARTS, MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	// беспроводной зарядник андроидов
	MatteryRecipe(MItems.ANDROID_CHARGER[null]!!, category = machinesCategory)
		.row(MItems.ELECTRIC_PARTS, MItems.QUANTUM_TRANSCEIVER, MItems.ELECTRIC_PARTS)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MACHINE_FRAME, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MACHINE_FRAME, MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	// апгрейд на сетку крафта
	MatteryRecipe(MItems.ExopackUpgrades.CRAFTING_UPGRADE, category = RecipeCategory.TOOLS)
		.row(MItemTags.ADVANCED_CIRCUIT, MItemTags.ADVANCED_CIRCUIT, MItemTags.ADVANCED_CIRCUIT)
		.row(MItemTags.CRAFTING_TABLES, MItems.QUANTUM_TRANSCEIVER, MItemTags.CRAFTING_TABLES)
		.row(MItemTags.TRITANIUM_PLATES, MItemTags.TRITANIUM_PLATES, MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	// апгрейд на переплавку
	MatteryRecipe(MItems.ExopackUpgrades.SMELTING_UPGRADE, category = RecipeCategory.TOOLS)
		.row(MItemTags.ADVANCED_CIRCUIT, MItemTags.ADVANCED_CIRCUIT, MItemTags.ADVANCED_CIRCUIT)
		.row(Items.FURNACE, MItems.QUANTUM_TRANSCEIVER, Items.FURNACE)
		.row(MItemTags.TRITANIUM_PLATES, Items.FURNACE, MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	// апгрейд на эндер сундук
	MatteryRecipe(MItems.ExopackUpgrades.ENDER_UPGRADE, category = RecipeCategory.TOOLS)
		.row(MItemTags.ADVANCED_CIRCUIT, MItems.ELECTROMAGNET, MItemTags.ADVANCED_CIRCUIT)
		.row(MItems.ELECTROMAGNET, Items.ENDER_CHEST, MItems.ELECTROMAGNET)
		.row(MItemTags.TRITANIUM_PLATES, MItems.ELECTROMAGNET, MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	// генератор коблы
	MatteryRecipe(MItems.COBBLESTONE_GENERATOR[null]!!, category = machinesCategory)
		.row(MItemTags.HARDENED_GLASS_COLORLESS, MItems.TRITANIUM_PICKAXE, MItemTags.HARDENED_GLASS_COLORLESS)
		.row(Items.LAVA_BUCKET, Items.HOPPER, Items.WATER_BUCKET)
		.rowB(Tags.Items.CHESTS)
		.build(consumer)

	MatteryRecipe(MItems.TRITANIUM_SHEARS, category = RecipeCategory.TOOLS)
		.rowB(MItemTags.TRITANIUM_INGOTS)
		.rowA(MItemTags.TRITANIUM_INGOTS)
		.build(consumer)

	MatteryRecipe(MItems.TRITANIUM_SHIELD, category = RecipeCategory.COMBAT)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, Items.SHIELD, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, MItemTags.REINFORCED_TRITANIUM_PLATES, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.rowB(MItemTags.REINFORCED_TRITANIUM_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.ESSENCE_STORAGE[null]!!, category = machinesCategory)
		.row(MItems.MATTER_CAPACITOR_PARTS, Items.ENDER_EYE, MItemTags.ADVANCED_CIRCUIT)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MACHINE_FRAME, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.GOLD_WIRES, MItemTags.HARDENED_GLASS, MItemTags.HARDENED_GLASS)
		.build(consumer)

	MatteryRecipe(MItems.ESSENCE_SERVO, category = RecipeCategory.TOOLS)
		.row(MItemTags.TRITANIUM_PLATES, MItems.QUANTUM_TRANSCEIVER, MItemTags.TRITANIUM_PLATES)
		.rowB(Tags.Items.RODS_WOODEN)
		.rowB(Tags.Items.RODS_WOODEN)
		.build(consumer)

	for ((dye, item) in MItems.MATTER_REPLICATOR) {
		MatteryRecipe(MItems.MATTER_RECONSTRUCTOR[dye]!!, category = machinesCategory)
			.setUpgradeSource(item)
			.addUpgradeOps(
				UpgradeRecipe.CopyTileComponent(MatteryBlockEntity.ENERGY_KEY, "energy"),
				UpgradeRecipe.CopyTileComponent(MatteryBlockEntity.MATTER_STORAGE_KEY, "matter"),
			)
			.row(MItemTags.ADVANCED_CIRCUIT, Tags.Items.GEMS_EMERALD, MItemTags.ADVANCED_CIRCUIT)
			.row(MItems.ELECTRIC_PARTS, item, MItems.ELECTRIC_PARTS)
			.row(MItems.ELECTROMAGNET, MItems.ELECTROMAGNET, MItems.ELECTROMAGNET)
			.build(consumer)
	}

	MatteryRecipe(MItems.MATTER_SCANNER[null]!!, category = machinesCategory)
		.row(MItems.MIRROR, MItems.MATTER_TRANSFORM_MATRIX, MItems.MIRROR)
		.row(MItemTags.HARDENED_GLASS_COLORLESS, MItems.MACHINE_FRAME, MItemTags.HARDENED_GLASS_COLORLESS)
		.row(MItems.MATTER_CABLE, MItemTags.ADVANCED_CIRCUIT, MItems.MATTER_CABLE)
		.build(consumer)

	MatteryRecipe(MItems.FLUID_CAPSULE, category = RecipeCategory.TOOLS, count = 8)
		.row(MItemTags.TRITANIUM_NUGGETS, MItemTags.TRITANIUM_NUGGETS, MItemTags.TRITANIUM_NUGGETS)
		.rowB(MItemTags.HARDENED_GLASS_PANES)
		.row(MItemTags.TRITANIUM_NUGGETS, MItemTags.TRITANIUM_NUGGETS, MItemTags.TRITANIUM_NUGGETS)
		.unlockedBy(MItemTags.HARDENED_GLASS_PANES)
		.unlockedBy(MItemTags.TRITANIUM_NUGGETS)
		.build(consumer)

	MatteryRecipe(MItems.FLUID_TANK, category = RecipeCategory.DECORATIONS)
		.row(MItemTags.TRITANIUM_INGOTS, MItemTags.HARDENED_GLASS_PANES, MItemTags.TRITANIUM_INGOTS)
		.rowAC(MItemTags.HARDENED_GLASS_PANES, MItemTags.HARDENED_GLASS_PANES)
		.row(MItemTags.TRITANIUM_INGOTS, MItemTags.HARDENED_GLASS_PANES, MItemTags.TRITANIUM_INGOTS)
		.unlockedBy(MItemTags.HARDENED_GLASS_PANES)
		.unlockedBy(MItemTags.TRITANIUM_INGOTS)
		.build(consumer)

	MatteryRecipe(MItems.EXPLOSIVE_HAMMER, category = RecipeCategory.COMBAT)
		.rowB(Tags.Items.INGOTS_IRON)
		.rowAB(Tags.Items.INGOTS_IRON, Tags.Items.RODS_WOODEN)
		.rowB(Tags.Items.RODS_WOODEN)
		.unlockedBy(Items.FLINT_AND_STEEL)
		.build(consumer)

	MatteryRecipe(MItems.POWERED_FURNACE[null]!!, category = machinesCategory)
		.row(Items.FURNACE, MItems.MACHINE_FRAME, Items.FURNACE)
		.unlockedBy(MItems.MACHINE_FRAME)
		.build(consumer)

	MatteryRecipe(MItems.POWERED_SMOKER[null]!!, category = machinesCategory)
		.rowAC(Items.FURNACE, Items.FURNACE)
		.row(MItems.ELECTROMAGNET, MItems.MACHINE_FRAME, MItems.ELECTROMAGNET)
		.unlockedBy(MItems.MACHINE_FRAME)
		.build(consumer)

	MatteryRecipe(MItems.POWERED_BLAST_FURNACE[null]!!, category = machinesCategory)
		.row(MItems.ELECTROMAGNET, Items.FURNACE, MItems.ELECTROMAGNET)
		.row(MItems.ELECTROMAGNET, MItems.MACHINE_FRAME, MItems.ELECTROMAGNET)
		.row(MItems.ELECTROMAGNET, Items.FURNACE, MItems.ELECTROMAGNET)
		.unlockedBy(MItems.MACHINE_FRAME)
		.build(consumer)

	MatteryRecipe(MItems.INFINITE_WATER_SOURCE, category = machinesCategory)
		.row(MItemTags.IRON_PLATES, MItemTags.IRON_PLATES, MItemTags.IRON_PLATES)
		.rowAC(Items.WATER_BUCKET, Items.WATER_BUCKET)
		.row(MItemTags.IRON_PLATES, MItemTags.IRON_PLATES, MItemTags.IRON_PLATES)
		.unlockedBy(Items.WATER_BUCKET)
		.build(consumer)

	MatteryRecipe(MItems.PAINTER, category = machinesCategory)
		.row(Items.BRUSH, Items.BUCKET, Items.BUCKET)
		.row(MItemTags.IRON_PLATES, Items.BUCKET, MItemTags.IRON_PLATES)
		.row(MItemTags.IRON_PLATES, MItemTags.CRAFTING_TABLES, MItemTags.IRON_PLATES)
		.unlockedBy(Tags.Items.DYES)
		.build(consumer)

	MatteryRecipe(MItems.MATTER_ENTANGLER, category = machinesCategory)
		.row(MItemTags.ADVANCED_CIRCUIT, MItems.MATTER_TRANSFORM_MATRIX, MItemTags.ADVANCED_CIRCUIT)
		.row(MItems.MATTER_CAPACITOR_PARTS, MItems.MACHINE_FRAME, MItems.MATTER_IO_PORT)
		.row(MItemTags.DILITHIUM_GEMS, MItems.ANTIMATTER_TRANSFORM_MATRIX, MItemTags.DILITHIUM_GEMS)
		.unlockedBy(MItems.ANTIMATTER_TRANSFORM_MATRIX)
		.build(consumer)

	MatteryRecipe(MItems.CHEST_UPGRADER, category = RecipeCategory.TOOLS)
		.rowAC(Items.REDSTONE, Items.REDSTONE)
		.row(MItemTags.TRITANIUM_PLATES, Items.ENDER_PEARL, MItemTags.TRITANIUM_PLATES)
		.rowB(ItemTags.STONE_BUTTONS)
		.unlockedBy(Tags.Items.CHESTS_WOODEN)
		.unlockedBy(Tags.Items.BARRELS_WOODEN)
		.unlockedBy(MItemTags.CARGO_CRATES)
		.build(consumer)

	MatteryRecipe(MItems.ENERGY_CABLES[CablesConfig.E.CRUDE]!!, category = machinesCategory, count = 8)
		.row(Tags.Items.INGOTS_IRON, Items.REDSTONE, Tags.Items.INGOTS_IRON)
		.unlockedBy(Items.REDSTONE)
		.build(consumer)

	MatteryRecipe(MItems.ENERGY_CABLES[CablesConfig.E.REGULAR]!!, category = machinesCategory, count = 16)
		.row(MItemTags.COPPER_WIRES, MItemTags.COPPER_WIRES, MItemTags.COPPER_WIRES)
		.row(MItemTags.IRON_PLATES, Items.REDSTONE, MItemTags.IRON_PLATES)
		.row(MItemTags.COPPER_WIRES, MItemTags.COPPER_WIRES, MItemTags.COPPER_WIRES)
		.build(consumer)

	MatteryRecipe(MItems.ENERGY_CABLES[CablesConfig.E.ADVANCED]!!, category = machinesCategory, count = 16)
		.row(MItemTags.GOLD_WIRES, MItemTags.COPPER_WIRES, MItemTags.GOLD_WIRES)
		.row(MItemTags.TRITANIUM_PLATES, Items.REDSTONE, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.GOLD_WIRES, MItemTags.COPPER_WIRES, MItemTags.GOLD_WIRES)
		.build(consumer)

	MatteryRecipe(MItems.ENERGY_CABLES[CablesConfig.E.SUPERCONDUCTOR]!!, category = machinesCategory)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, MItems.ELECTROMAGNET, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.row(Tags.Items.INGOTS_GOLD, Tags.Items.INGOTS_GOLD, Tags.Items.INGOTS_GOLD)
		.row(MItemTags.REINFORCED_TRITANIUM_PLATES, Items.BLUE_ICE, MItemTags.REINFORCED_TRITANIUM_PLATES)
		.build(consumer)

	val ironRod = ItemTags.create(ResourceLocation("c", "rods/iron"))
	var condConsumer = consumer.withConditions(NotCondition(TagEmptyCondition(ironRod)))

	for ((color, item) in MItems.GRILL) {
		MatteryRecipe(item, category = RecipeCategory.DECORATIONS)
			.rowB(color?.tag)
			.row(Tags.Items.INGOTS_IRON, Tags.Items.INGOTS_IRON, Tags.Items.INGOTS_IRON)
			.rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
			.build(consumer)

		MatteryRecipe(item, category = RecipeCategory.DECORATIONS)
			.rowB(color?.tag)
			.row(ironRod, ironRod, ironRod)
			.rowAC(MItemTags.TRITANIUM_INGOTS, MItemTags.TRITANIUM_INGOTS)
			.build(condConsumer, "grill_alt_a/${color?.name?.lowercase() ?: "default"}")

		MatteryRecipe(item, category = RecipeCategory.DECORATIONS)
			.rowB(color?.tag)
			.row(ironRod, ironRod, ironRod)
			.rowB(MItemTags.TRITANIUM_PLATES)
			.build(condConsumer, "grill_alt_b/${color?.name?.lowercase() ?: "default"}")

		MatteryRecipe(item, category = RecipeCategory.DECORATIONS)
			.rowB(color?.tag)
			.row(Tags.Items.INGOTS_IRON, Tags.Items.INGOTS_IRON, Tags.Items.INGOTS_IRON)
			.rowB(MItemTags.TRITANIUM_PLATES)
			.build(consumer, "grill_alt_c/${color?.name?.lowercase() ?: "default"}")
	}

	MatteryRecipe(MItems.REDSTONE_INTERACTOR, category = RecipeCategory.TOOLS)
		.rowAB(Items.LEVER, Tags.Items.NUGGETS_IRON)
		.rowB(Tags.Items.DUSTS_REDSTONE)
		.unlockedBy(Tags.Items.DUSTS_REDSTONE)
		.build(consumer)

	ShapelessRecipeBuilder.shapeless(RecipeCategory.BUILDING_BLOCKS, ItemStack(MItems.DILITHIUM_CRYSTAL_BLOCK))
		.requires(MItems.DILITHIUM_CRYSTAL, 9)
		.unlockedBy(MItems.DILITHIUM_CRYSTAL)
		.unlockedBy(MItems.DILITHIUM_CRYSTAL_BLOCK)
		.save(consumer, modLocation("dilithium_crystal/to_block"))

	ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ItemStack(MItems.DILITHIUM_CRYSTAL, 9))
		.requires(MItems.DILITHIUM_CRYSTAL_BLOCK)
		.unlockedBy(MItems.DILITHIUM_CRYSTAL)
		.unlockedBy(MItems.DILITHIUM_CRYSTAL_BLOCK)
		.save(consumer, modLocation("dilithium_crystal/from_block"))

	MatteryRecipe(MItems.CONFIGURATOR, category = RecipeCategory.TOOLS)
		.rowA(MItemTags.IRON_PLATES)
		.row(Tags.Items.GLASS_PANES, Tags.Items.DUSTS_REDSTONE, MItems.DISPLAY_SCREEN)
		.row(MItemTags.IRON_PLATES, MItemTags.BASIC_CIRCUIT, MItems.DILITHIUM_CRYSTAL)
		.unlockedBy(MItems.DILITHIUM_CRYSTAL)
		.unlockedBy(MItems.DISPLAY_SCREEN)
		.build(consumer)
}
