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

import net.minecraft.data.recipes.RecipeCategory
import net.minecraft.data.recipes.RecipeOutput
import net.minecraft.data.recipes.ShapelessRecipeBuilder
import net.minecraft.world.item.ItemStack
import net.neoforged.neoforge.common.Tags
import ru.dbotthepony.mc.otm.datagen.modLocation
import ru.dbotthepony.mc.otm.recipe.UpgradeRecipe
import ru.dbotthepony.mc.otm.registry.MItemTags
import ru.dbotthepony.mc.otm.registry.game.MItems

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

	// energy interface
	MatteryRecipe(MItems.ENERGY_INPUT_INTERFACE, category = machinesCategory)
		.rowB(MItems.ENERGY_BUS)
		.row(MItems.ELECTRIC_PARTS, MItems.MACHINE_FRAME, MItems.ELECTRIC_PARTS)
		.build(consumer)

	ShapelessRecipeBuilder.shapeless(machinesCategory, ItemStack(MItems.ENERGY_INPUT_INTERFACE))
		.requires(MItems.ENERGY_OUTPUT_INTERFACE)
		.unlockedBy(MItems.ENERGY_OUTPUT_INTERFACE)
		.unlockedBy(MItems.ENERGY_INPUT_INTERFACE)
		.save(consumer, modLocation("energy_interface_to_input"))

	MatteryRecipe(MItems.ENERGY_OUTPUT_INTERFACE, category = machinesCategory)
		.row(MItems.ELECTRIC_PARTS, MItems.MACHINE_FRAME, MItems.ELECTRIC_PARTS)
		.rowB(MItems.ENERGY_BUS)
		.build(consumer)

	ShapelessRecipeBuilder.shapeless(machinesCategory, ItemStack(MItems.ENERGY_OUTPUT_INTERFACE))
		.requires(MItems.ENERGY_INPUT_INTERFACE)
		.unlockedBy(MItems.ENERGY_OUTPUT_INTERFACE)
		.unlockedBy(MItems.ENERGY_INPUT_INTERFACE)
		.save(consumer, modLocation("energy_interface_to_output"))

	// energy hatch
	MatteryRecipe(MItems.ENERGY_INPUT_HATCH, category = machinesCategory)
		.rowAC(MItemTags.GOLD_WIRES, MItemTags.GOLD_WIRES)
		.row(MItems.ELECTRIC_PARTS, MItems.ENERGY_INPUT_INTERFACE, MItems.ELECTRIC_PARTS)
		.row(Tags.Items.DUSTS_REDSTONE, MItemTags.DILITHIUM_GEMS, Tags.Items.DUSTS_REDSTONE)
		.build(consumer)

	MatteryRecipe(MItems.ENERGY_OUTPUT_HATCH, category = machinesCategory)
		.row(Tags.Items.DUSTS_REDSTONE, MItemTags.DILITHIUM_GEMS, Tags.Items.DUSTS_REDSTONE)
		.row(MItems.ELECTRIC_PARTS, MItems.ENERGY_OUTPUT_INTERFACE, MItems.ELECTRIC_PARTS)
		.rowAC(MItemTags.GOLD_WIRES, MItemTags.GOLD_WIRES)
		.build(consumer)

	MatteryRecipe(MItems.ENERGY_INPUT_HATCH, category = machinesCategory)
		.rowB(MItems.ENERGY_OUTPUT_HATCH)
		.setUpgradeSource(MItems.ENERGY_OUTPUT_HATCH)
		.addUpgradeOps(UpgradeRecipe.CopyAllComponents)
		.build(consumer, "from_output")

	MatteryRecipe(MItems.ENERGY_OUTPUT_HATCH, category = machinesCategory)
		.rowB(MItems.ENERGY_INPUT_HATCH)
		.setUpgradeSource(MItems.ENERGY_INPUT_HATCH)
		.addUpgradeOps(UpgradeRecipe.CopyAllComponents)
		.build(consumer, "from_input")

	// item hatch
	MatteryRecipe(MItems.ITEM_INPUT_HATCH, category = machinesCategory)
		.rowB(MItemTags.BASIC_CIRCUIT)
		.row(MItems.MECHANICAL_PARTS, MItemTags.CARGO_CRATES, MItems.MECHANICAL_PARTS)
		.build(consumer)

	MatteryRecipe(MItems.ITEM_OUTPUT_HATCH, category = machinesCategory)
		.row(MItems.MECHANICAL_PARTS, MItemTags.CARGO_CRATES, MItems.MECHANICAL_PARTS)
		.rowB(MItemTags.BASIC_CIRCUIT)
		.build(consumer)

	ShapelessRecipeBuilder.shapeless(machinesCategory, ItemStack(MItems.ITEM_INPUT_HATCH))
		.requires(MItems.ITEM_OUTPUT_HATCH)
		.unlockedBy(MItems.ITEM_INPUT_HATCH)
		.unlockedBy(MItems.ITEM_OUTPUT_HATCH)
		.save(consumer, modLocation("item_hatch_to_input"))

	ShapelessRecipeBuilder.shapeless(machinesCategory, ItemStack(MItems.ITEM_OUTPUT_HATCH))
		.requires(MItems.ITEM_INPUT_HATCH)
		.unlockedBy(MItems.ITEM_INPUT_HATCH)
		.unlockedBy(MItems.ITEM_OUTPUT_HATCH)
		.save(consumer, modLocation("item_hatch_to_output"))

	// matter hatch
	MatteryRecipe(MItems.MATTER_INPUT_HATCH, category = machinesCategory)
		.rowB(MItems.MATTER_IO_PORT)
		.row(MItems.MECHANICAL_PARTS, MItems.MACHINE_FRAME, MItems.ELECTRIC_PARTS)
		.rowAC(MItems.MATTER_CAPACITOR_PARTS, MItems.MATTER_CAPACITOR_PARTS)
		.build(consumer)

	MatteryRecipe(MItems.MATTER_OUTPUT_HATCH, category = machinesCategory)
		.rowAC(MItems.MATTER_CAPACITOR_PARTS, MItems.MATTER_CAPACITOR_PARTS)
		.row(MItems.MECHANICAL_PARTS, MItems.MACHINE_FRAME, MItems.ELECTRIC_PARTS)
		.rowB(MItems.MATTER_IO_PORT)
		.build(consumer)

	MatteryRecipe(MItems.MATTER_INPUT_HATCH, category = machinesCategory)
		.rowB(MItems.MATTER_OUTPUT_HATCH)
		.setUpgradeSource(MItems.MATTER_OUTPUT_HATCH)
		.addUpgradeOps(UpgradeRecipe.CopyAllComponents)
		.build(consumer, "from_output")

	MatteryRecipe(MItems.MATTER_OUTPUT_HATCH, category = machinesCategory)
		.rowB(MItems.MATTER_INPUT_HATCH)
		.setUpgradeSource(MItems.MATTER_INPUT_HATCH)
		.addUpgradeOps(UpgradeRecipe.CopyAllComponents)
		.build(consumer, "from_input")

	// misc
	MatteryRecipe(MItems.GENERATOR_BLOCK, category = machinesCategory)
		.row(MItems.ELECTRIC_PARTS, MItems.ELECTROMOTOR, MItems.ELECTRIC_PARTS)
		.row(MItems.ELECTROMOTOR, MItems.MACHINE_FRAME, MItems.ELECTROMOTOR)
		.row(MItems.ELECTRIC_PARTS, MItems.ELECTROMOTOR, MItems.ELECTRIC_PARTS)
		.build(consumer)

	MatteryRecipe(MItems.MODULAR_FRAME, count = 4, category = machinesCategory)
		.row(MItemTags.IRON_PLATES, Tags.Items.INGOTS_IRON, MItemTags.IRON_PLATES)
		.rowAC(Tags.Items.INGOTS_IRON, Tags.Items.INGOTS_IRON)
		.row(MItemTags.IRON_PLATES, Tags.Items.INGOTS_IRON, MItemTags.IRON_PLATES)
		.unlockedBy(MItemTags.IRON_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.HEAVY_MODULAR_FRAME, count = 2, category = machinesCategory)
		.row(MItems.WITHERED_STEEL, MItems.REINFORCED_IRON_PLATE, MItems.WITHERED_STEEL,)
		.row(MItems.REINFORCED_IRON_PLATE, MItems.MODULAR_FRAME, MItems.REINFORCED_IRON_PLATE)
		.row(MItems.WITHERED_STEEL, MItems.REINFORCED_IRON_PLATE, MItems.WITHERED_STEEL,)
		.unlockedBy(MItems.MODULAR_FRAME)
		.build(consumer)

	// blackhole generator
	MatteryRecipe(MItems.BLACK_HOLE_GENERATOR, category = machinesCategory)
		.row(MItemTags.ADVANCED_CIRCUIT, MItems.BLACK_HOLE_SCANNER, MItemTags.ADVANCED_CIRCUIT)
		.row(MItemTags.DILITHIUM_GEMS, MItems.MACHINE_FRAME, MItemTags.DILITHIUM_GEMS)
		.row(MItems.MATTER_CAPACITOR_PARTS, Tags.Items.GEMS_DIAMOND, MItems.MATTER_CAPACITOR_PARTS)
		.build(consumer)

	MatteryRecipe(MItems.TRITANIUM_HULL, count = 2, category = machinesCategory)
		.row(MItemTags.TRITANIUM_PLATES, MItemTags.IRON_PLATES, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.IRON_PLATES, MItems.MODULAR_FRAME, MItemTags.IRON_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItemTags.IRON_PLATES, MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.MATTER_INJECTOR, category = machinesCategory)
		.row(MItemTags.ADVANCED_CIRCUIT, MItems.MATTER_TRANSFORM_MATRIX, MItemTags.ADVANCED_CIRCUIT)
		.row(MItemTags.DILITHIUM_GEMS, MItems.MACHINE_FRAME, MItemTags.DILITHIUM_GEMS)
		.row(MItems.MATTER_IO_PORT, MItems.GRAVITATION_FIELD_SENSOR, MItems.MATTER_IO_PORT)
		.build(consumer)

	MatteryRecipe(MItems.ANTIMATTER_INJECTOR, category = machinesCategory)
		.row(MItemTags.ADVANCED_CIRCUIT, MItems.ANTIMATTER_TRANSFORM_MATRIX, MItemTags.ADVANCED_CIRCUIT)
		.row(MItemTags.DILITHIUM_GEMS, MItems.MACHINE_FRAME, MItemTags.DILITHIUM_GEMS)
		.row(MItems.MATTER_IO_PORT, MItems.GRAVITATION_FIELD_SENSOR, MItems.MATTER_IO_PORT)
		.build(consumer)

	MatteryRecipe(MItems.HIGH_ENERGY_PARTICLE_COLLECTOR, category = machinesCategory)
		.row(MItemTags.ADVANCED_CIRCUIT, MItems.MECHANICAL_PARTS, MItemTags.ADVANCED_CIRCUIT)
		.row(Tags.Items.GEMS_QUARTZ, MItems.MACHINE_FRAME, Tags.Items.GEMS_QUARTZ)
		.row(MItemTags.DILITHIUM_GEMS, MItems.GRAVITATION_FIELD_LIMITER, MItemTags.DILITHIUM_GEMS)
		.build(consumer)

	// flywheel
	MatteryRecipe(MItems.FLYWHEEL_SHAFT, category = machinesCategory)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MECHANICAL_PARTS, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MECHANICAL_PARTS, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MECHANICAL_PARTS, MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.FLYWHEEL_BEARING, category = machinesCategory)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MECHANICAL_PARTS, MItemTags.TRITANIUM_PLATES)
		.row(MItems.MECHANICAL_PARTS, MItems.MECHANICAL_PARTS, MItems.MECHANICAL_PARTS)
		.row(MItemTags.TRITANIUM_PLATES, MItems.MECHANICAL_PARTS, MItemTags.TRITANIUM_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.FLYWHEEL_HOUSING, count = 4, category = machinesCategory)
		.row(MItemTags.CARBON_PLATES, MItemTags.TRITANIUM_PLATES, MItemTags.CARBON_PLATES)
		.row(MItemTags.TRITANIUM_PLATES, MItems.ELECTRIC_PARTS, MItemTags.TRITANIUM_PLATES)
		.row(MItemTags.CARBON_PLATES, MItemTags.TRITANIUM_PLATES, MItemTags.CARBON_PLATES)
		.build(consumer)

	MatteryRecipe(MItems.FLYWHEEL_BATTERY, category = machinesCategory)
		.row(MItemTags.ADVANCED_CIRCUIT, MItems.FLYWHEEL_HOUSING, MItemTags.ADVANCED_CIRCUIT)
		.row(MItemTags.GOLD_WIRES, MItemTags.COPPER_WIRES, MItemTags.GOLD_WIRES)
		.build(consumer)
}
