package ru.dbotthepony.mc.otm.registry

import net.minecraft.resources.ResourceLocation
import net.minecraft.world.item.crafting.Recipe
import net.minecraft.world.item.crafting.RecipeType
import net.minecraftforge.eventbus.api.IEventBus
import net.minecraftforge.registries.DeferredRegister
import net.minecraftforge.registries.ForgeRegistries
import net.minecraftforge.registries.RegistryObject
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.recipe.*

@Suppress("SameParameterValue")
object MRecipes {
	class Type<T : Recipe<*>>(id: String) : RecipeType<T> {
		val id = ResourceLocation(OverdriveThatMatters.MOD_ID, id)

		override fun toString(): String {
			return "RecipeType[$id]"
		}
	}

	private val types = DeferredRegister.create(ForgeRegistries.RECIPE_TYPES, OverdriveThatMatters.MOD_ID)
	private val serializers = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, OverdriveThatMatters.MOD_ID)

	internal fun register(bus: IEventBus) {
		types.register(bus)
		serializers.register(bus)
	}

	private fun <T : Recipe<*>> register(name: String): RegistryObject<Type<T>> {
		return types.register(name) { Type(name) }
	}

	val PLATE_PRESS by register<PlatePressRecipe>("plate_press")
	val PAINTER by register<AbstractPainterRecipe>("painter")
	val MATTER_ENTANGLER by register<IMatterEntanglerRecipe>("matter_entangler")
	val MICROWAVE by register<MicrowaveRecipe>("microwave")

	init {
		serializers.register("plate_press") { PlatePressRecipe.SERIALIZER }
		serializers.register("energy_container") { EnergyContainerRecipe.Companion }
		serializers.register("upgrade") { UpgradeRecipe.CODEC }
		serializers.register("hammer_priming") { ExplosiveHammerPrimingRecipe.CODEC }
		serializers.register("painter") { PainterRecipe.SERIALIZER }
		serializers.register("painter_armor_dye") { PainterArmorDyeRecipe.SERIALIZER }
		serializers.register("matter_entangler") { MatterEntanglerRecipe.SERIALIZER }
		serializers.register("matter_entangler_energetic") { MatterEntanglerRecipe.ENERGY_SERIALIZER }
		serializers.register("matter_entangler_matter") { MatterEntanglerRecipe.MATTER_SERIALIZER }
		serializers.register("microwave") { MicrowaveRecipe.SERIALIZER }
	}
}
