package ru.dbotthepony.mc.otm.datagen.items

import net.minecraft.world.item.DyeColor
import ru.dbotthepony.mc.otm.core.ResourceLocation
import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.datagen.modLocation
import ru.dbotthepony.mc.otm.registry.game.MItems
import ru.dbotthepony.mc.otm.registry.MRegistry

fun addItemModels(provider: MatteryItemModelProvider) {
	provider.coloredWithBaseBlock(MItems.ANDROID_STATION, "android_station", "_working")
	provider.coloredWithBaseBlock(MItems.BATTERY_BANK, "matter_capacitor_bank")
	provider.coloredWithBaseBlock(MItems.MATTER_CAPACITOR_BANK, "matter_capacitor_bank")
	provider.block(MItems.PATTERN_STORAGE)

	provider.exec {
		provider
			.withExistingParent(MItems.BLACK_HOLE.registryName!!.path, MatteryItemModelProvider.GENERATED)
			.texture("layer0", modLocation("item/" + MItems.BLACK_HOLE.registryName!!.path))
			.renderType("translucent")
	}

	provider.block(MItems.CARBON_FIBRE_BLOCK)
	provider.block(MItems.METAL_JUNK, MItems.METAL_JUNK.registryName!!.path + "_a")
	provider.block(MItems.METAL_MESH)
	provider.generatedTranslucent(MItems.TRITANIUM_BARS, modLocation("block/decorative/tritanium_bars"))
	provider.generatedTranslucent(MItems.METAL_RAILING, modLocation("block/decorative/metal_railing"))
	provider.blocks(MItems.TRITANIUM_STRIPED_BLOCK.values)
	provider.coloredWithBaseBlock(MItems.ITEM_MONITOR, "item_monitor")
	provider.block(MItems.PHANTOM_ATTRACTOR)
	provider.block(MItems.HOLO_SIGN)

	provider.block(MItems.TRITANIUM_ORE)
	provider.block(MItems.DEEPSLATE_TRITANIUM_ORE)
	provider.block(MItems.TRITANIUM_RAW_BLOCK)
	provider.block(MItems.TRITANIUM_INGOT_BLOCK)

	provider.block(MItems.WITHERED_STEEL_BLOCK)
	provider.block(MItems.ROFLITE_ALLOY_BLOCK)

	provider.block(MItems.DILITHIUM_ORE)
	provider.block(MItems.DEEPSLATE_DILITHIUM_ORE)
	provider.block(MItems.DILITHIUM_CRYSTAL_BLOCK)

	provider.withExistingParent(MItems.REDSTONE_LAMP_INVERTED, ResourceLocation("minecraft", "block/redstone_lamp_on"))
	provider.withExistingParent(MItems.REINFORCED_REDSTONE_LAMP, modLocation("block/reinforced_redstone_lamp"))
	provider.withExistingParent(MItems.REINFORCED_REDSTONE_LAMP_INVERTED, modLocation("block/reinforced_redstone_lamp_on"))

	MRegistry.VENT.allItems.values.forEach(provider::block)
	MRegistry.VENT_ALTERNATIVE.allItems.values.forEach(provider::block)
	MRegistry.TRITANIUM_BLOCK.allItems.values.forEach(provider::block)
	MRegistry.COMPUTER_TERMINAL.allItems.values.forEach(provider::block)
	MRegistry.STAR_CHAIR.allItems.values.forEach(provider::block)
	MRegistry.INDUSTRIAL_GLASS.allItems.values.forEach(provider::block)

	for (block in MRegistry.TRITANIUM_STRIPED_BLOCK.flatItems) {
		provider.block(block)
	}

	for ((color, glass) in MRegistry.INDUSTRIAL_GLASS_PANE.allItems) {
		provider.generatedTranslucent(glass, modLocation("block/decorative/${MRegistry.INDUSTRIAL_GLASS.allItems[color]!!.registryName!!.path}"))
	}

	provider.blocks(MRegistry.DECORATIVE_CRATE.allItems.values)

	provider.components(MItems.DATAGEN_COMPONENTS)

	provider.generated(MItems.PILL_ANDROID)
	provider.generated(MItems.PILL_HUMANE)
	provider.generated(MItems.PILL_OBLIVION)
	provider.generated(MItems.PILL_HEAL)
	provider.generated(MItems.PILL_NOT_NORMAL)
	provider.generated(MItems.NUTRIENT_PASTE)
	provider.generated(MItems.IMPERFECT_BREAD)
	provider.generated(MItems.REDSTONE_INTERACTOR)

	provider.generated(MItems.ESSENCE_DRIVE)
	provider.generated(MItems.ESSENCE_CAPSULE)
	provider.generated(MItems.ESSENCE_SERVO)

	for (item in MItems.ExopackUpgrades.INVENTORY_UPGRADES) {
		provider.generated(item, modLocation("item/exosuit_inventory_upgrade"))
	}

	for (item in listOf(
		MItems.ExopackUpgrades.INVENTORY_UPGRADE_HUGE,
		MItems.ExopackUpgrades.INVENTORY_UPGRADE_BIG,
		MItems.ExopackUpgrades.INVENTORY_UPGRADE_PROCEDURAL,
		MItems.ExopackUpgrades.INVENTORY_UPGRADE_WITHER,
		MItems.ExopackUpgrades.INVENTORY_UPGRADE_ENDER_DRAGON,
	)) {
		provider.generated(item, modLocation("item/exosuit_inventory_upgrade"))
	}

	provider.generated(MItems.ExopackUpgrades.INVENTORY_UPGRADE_CREATIVE)
	provider.generated(MItems.ExopackUpgrades.CRAFTING_UPGRADE)
	provider.generated(MItems.ExopackUpgrades.SMELTING_UPGRADE)
	provider.generated(MItems.ExopackUpgrades.ENDER_UPGRADE)

	provider.resource(MItems.TRITANIUM_DUST)
	provider.resource(MItems.TRITANIUM_INGOT)
	provider.resource(MItems.TRITANIUM_NUGGET)
	provider.resource(MItems.TRITANIUM_ORE_CLUMP)

	provider.resource(MItems.DILITHIUM_CRYSTAL)
	provider.resource(MItems.WITHERED_STEEL)
	provider.resource(MItems.ROFLITE_ALLOY_INGOT)

	provider.generated(MItems.EXOPACK_PROBE)

	provider.handheld(MItems.TRITANIUM_TOOLS)
	provider.armorColored(MItems.TRITANIUM_ARMOR)
	provider.armorWithTrims(MItems.SIMPLE_TRITANIUM_ARMOR)

	provider.handheld(MItems.CHEST_UPGRADER)

	provider.exec {
		val path = MItems.CONFIGURATOR.registryName!!.path

		val ready = provider.withExistingParent("${path}_ready", MatteryItemModelProvider.HANDHELD)
			.texture("layer0", modLocation("item/${path}_ready"))

		provider.withExistingParent(path, MatteryItemModelProvider.HANDHELD)
			.texture("layer0", modLocation("item/$path"))
			.override().predicate(modLocation("has_configuration_saved"), 1f).model(ready).end()
	}

	provider.generated(MItems.BREAD_MONSTER_SPAWN_EGG, modLocation("item/egg/bread_monster"))
	provider.generated(MItems.LOADER_SPAWN_EGG, modLocation("item/egg/loader"))

	provider.generatedTiered(MItems.BATTERIES, "battery_tier")
	provider.generated(MItems.BATTERY_CREATIVE)
	provider.generated(MItems.PROCEDURAL_BATTERY, modLocation("item/battery_procedural"))

	provider.generated(MItems.MATTER_CAPACITOR_BASIC, modLocation("item/matter_capacitor_tier1"))
	provider.generated(MItems.MATTER_CAPACITOR_NORMAL, modLocation("item/matter_capacitor_tier2"))
	provider.generated(MItems.MATTER_CAPACITOR_DENSE, modLocation("item/matter_capacitor_tier3"))
	provider.generated(MItems.MATTER_CAPACITOR_CREATIVE)

	provider.generated(MItems.MachineUpgrades.Basic.BLANK, modLocation("item/machine_upgrade_tier1"))
	provider.upgrade(MItems.MachineUpgrades.Basic.SPEED, "speed", "tier1")
	provider.upgrade(MItems.MachineUpgrades.Basic.ENERGY_CONSUMPTION, "energy", "tier1")
	provider.upgrade(MItems.MachineUpgrades.Basic.FAILSAFE, "failure", "tier1")
	provider.upgrade(MItems.MachineUpgrades.Basic.ENERGY_STORAGE, "capacity", "tier1")
	provider.upgrade(MItems.MachineUpgrades.Basic.MATTER_STORAGE, "matter", "tier1")
	provider.upgrade(MItems.MachineUpgrades.Basic.PROCESSING_ITEMS, "processing", "tier1")

	provider.generated(MItems.MachineUpgrades.Normal.BLANK, modLocation("item/machine_upgrade_tier2"))
	provider.upgrade(MItems.MachineUpgrades.Normal.SPEED, "speed", "tier2")
	provider.upgrade(MItems.MachineUpgrades.Normal.ENERGY_CONSUMPTION, "energy", "tier2")
	provider.upgrade(MItems.MachineUpgrades.Normal.FAILSAFE, "failure", "tier2")
	provider.upgrade(MItems.MachineUpgrades.Normal.ENERGY_STORAGE, "capacity", "tier2")
	provider.upgrade(MItems.MachineUpgrades.Normal.MATTER_STORAGE, "matter", "tier2")
	provider.upgrade(MItems.MachineUpgrades.Normal.PROCESSING_ITEMS, "processing", "tier2")

	provider.generated(MItems.MachineUpgrades.Advanced.BLANK, modLocation("item/machine_upgrade_tier3"))
	provider.upgrade(MItems.MachineUpgrades.Advanced.SPEED, "speed", "tier3")
	provider.upgrade(MItems.MachineUpgrades.Advanced.ENERGY_CONSUMPTION, "energy", "tier3")
	provider.upgrade(MItems.MachineUpgrades.Advanced.FAILSAFE, "failure", "tier3")
	provider.upgrade(MItems.MachineUpgrades.Advanced.ENERGY_STORAGE, "capacity", "tier3")
	provider.upgrade(MItems.MachineUpgrades.Advanced.MATTER_STORAGE, "matter", "tier3")
	provider.upgrade(MItems.MachineUpgrades.Advanced.PROCESSING_ITEMS, "processing", "tier3")

	provider.upgrade(MItems.MachineUpgrades.Creative.SPEED, "speed", "creative")

	provider.upgrade(MItems.MachineUpgrades.Creative.ENERGY_CONSUMPTION, "energy", "creative")
	provider.upgrade(MItems.MachineUpgrades.Creative.ENERGY_THROUGHPUT, "energy", "creative")
	provider.upgrade(MItems.MachineUpgrades.Creative.ENERGY_THROUGHPUT_FLAT, "energy", "creative")
	provider.upgrade(MItems.MachineUpgrades.Creative.ENERGY_THROUGHPUT_FLAT_SMALL, "energy", "creative")

	provider.upgrade(MItems.MachineUpgrades.Creative.ENERGY_STORAGE, "capacity", "creative")
	provider.upgrade(MItems.MachineUpgrades.Creative.ENERGY_STORAGE_FLAT, "capacity", "creative")
	provider.upgrade(MItems.MachineUpgrades.Creative.ENERGY_STORAGE_FLAT_SMALL, "capacity", "creative")

	provider.upgrade(MItems.MachineUpgrades.Creative.FAILSAFE, "failure", "creative")
	provider.upgrade(MItems.MachineUpgrades.Creative.FAILURE, "failure", "creative")

	provider.upgrade(MItems.MachineUpgrades.Creative.PROCESSING_ITEMS, "processing", "creative")

	provider.upgrade(MItems.MachineUpgrades.Creative.MATTER_STORAGE, "matter", "creative")
	provider.upgrade(MItems.MachineUpgrades.Creative.MATTER_STORAGE_FLAT, "matter", "creative")
	provider.upgrade(MItems.MachineUpgrades.Creative.MATTER_STORAGE_FLAT_SMALL, "matter", "creative")


	provider.generated(MItems.QUANTUM_BATTERY)
	provider.generated(MItems.QUANTUM_CAPACITOR)
	provider.generated(MItems.QUANTUM_BATTERY_CREATIVE)

	provider.generated(MItems.PATTERN_DRIVE_NORMAL, modLocation("item/pattern_drive_tier1"))
	provider.generated(MItems.PATTERN_DRIVE_DOUBLE, modLocation("item/pattern_drive_tier2"))
	provider.generated(MItems.PATTERN_DRIVE_TRIPLE, modLocation("item/pattern_drive_tier3"))
	provider.generated(MItems.PATTERN_DRIVE_QUAD, modLocation("item/pattern_drive_tier4"))

	provider.generated(MItems.PATTERN_DRIVE_CREATIVE)
	provider.generated(MItems.PATTERN_DRIVE_CREATIVE2)

	provider.withExistingParent(MItems.GOLD_DISK, MItems.PATTERN_DRIVE_CREATIVE.registryName!!)

	provider.generated(MItems.MATTER_DUST)

	provider.generated(MItems.TRITANIUM_DOOR.values)

	provider.block(MItems.TRITANIUM_TRAPDOOR[null]!!, "tritanium_trapdoor_bottom")


	for (color in DyeColor.entries)
		provider.block(MItems.TRITANIUM_TRAPDOOR[color]!!, "tritanium_trapdoor_${color.name.lowercase()}_bottom")

	for (item in MRegistry.CARGO_CRATES.allItems.values)
		provider.block(item, "${item.registryName!!.path}_closed")

	provider.coloredWithBaseBlock(MItems.CHEMICAL_GENERATOR, "chemical_generator", "_working")
	provider.coloredWithBaseBlock(MItems.ENERGY_COUNTER, "energy_counter_down")
	provider.coloredWithBaseBlock(MItems.MATTER_BOTTLER, "matter_bottler", "_idle")
	provider.coloredWithBaseBlock(MItems.MATTER_SCANNER, "matter_scanner", "_idle")
	provider.coloredWithBaseBlock(MItems.MATTER_REPLICATOR, "matter_replicator", "_idle")
	provider.block(MItems.MATTER_ENTANGLER, "matter_entangler_idle")
	provider.coloredWithBaseBlock(MItems.DRIVE_VIEWER, "drive_viewer", "_idle")
	provider.coloredWithBaseBlock(MItems.MATTER_DECOMPOSER, "matter_decomposer", "_idle")
	provider.coloredWithBaseBlock(MItems.ENERGY_SERVO, "energy_servo")
	provider.coloredWithBaseBlock(MItems.MATTER_RECONSTRUCTOR, "matter_reconstructor")

	provider.coloredWithBaseBlock(MItems.POWERED_BLAST_FURNACE, "powered_blast_furnace", "_idle")
	provider.coloredWithBaseBlock(MItems.POWERED_FURNACE, "powered_furnace", "_idle")
	provider.coloredWithBaseBlock(MItems.POWERED_SMOKER, "powered_smoker", "_idle")

	provider.coloredWithBaseBlock(MItems.PLATE_PRESS, "plate_press", "_idle")
	provider.coloredWithBaseBlock(MItems.TWIN_PLATE_PRESS, "twin_plate_press", "_idle")
	provider.coloredWithBaseBlock(MItems.STORAGE_POWER_SUPPLIER, "storage_power_supplier")
	provider.coloredWithBaseBlock(MItems.MATTER_RECYCLER, "matter_recycler", "_idle")
	provider.coloredWithBaseBlock(MItems.COBBLESTONE_GENERATOR, "cobblestone_generator")

	provider.block(MItems.PAINTER, "painter")
	provider.block(MItems.INFINITE_WATER_SOURCE, "infinite_water_source")

	provider.exec {
		provider.withExistingParent("essence_storage", modLocation("block/essence_storage_empty"))
			.override()
			.predicate(modLocation("is_filled"), 1f)
			.model(provider.withExistingParent("essence_storage_filled", modLocation("block/essence_storage_filled")))
			.end()
	}

	for (dye in DyeColor.entries) {
		provider.exec {
			provider.withExistingParent("android_charger_${dye.name.lowercase()}", modLocation("item/android_charger")).texture("0", modLocation("block/android_charger/${dye.name.lowercase()}"))
			provider.withExistingParent("matter_panel_${dye.name.lowercase()}", modLocation("item/matter_panel")).texture("texture", modLocation("block/matter_panel/${dye.name.lowercase()}"))
			provider.withExistingParent("essence_storage_${dye.name.lowercase()}", modLocation("block/essence_storage_${dye.name.lowercase()}_empty"))
				.override()
				.predicate(modLocation("is_filled"), 1f)
				.model(provider.withExistingParent("essence_storage_${dye.name.lowercase()}_filled", modLocation("block/essence_storage_${dye.name.lowercase()}_filled")))
				.end()
		}
	}

	provider.block(MItems.STORAGE_BUS)
	provider.block(MItems.STORAGE_IMPORTER)
	provider.block(MItems.STORAGE_EXPORTER)

	provider.block(MItems.FLYWHEEL_HOUSING)
	provider.block(MItems.FLYWHEEL_BEARING)
	provider.block(MItems.FLYWHEEL_SHAFT)
	provider.block(MItems.FLYWHEEL_BATTERY)

	provider.block(MItems.TRITANIUM_HULL)

	provider.block(MItems.GENERATOR_BLOCK)
	provider.block(MItems.ENERGY_INPUT_INTERFACE)
	provider.block(MItems.ENERGY_OUTPUT_INTERFACE)

	provider.block(MItems.ENERGY_INPUT_HATCH)
	provider.block(MItems.ENERGY_OUTPUT_HATCH)

	provider.block(MItems.MATTER_INPUT_HATCH)
	provider.block(MItems.MATTER_OUTPUT_HATCH)

	provider.block(MItems.ITEM_INPUT_HATCH)
	provider.block(MItems.ITEM_OUTPUT_HATCH)

	provider.block(MItems.MODULAR_FRAME)
	provider.block(MItems.HEAVY_MODULAR_FRAME)

	MItems.TRITANIUM_ANVIL.values.forEach { provider.blocks(it) }

	for ((color, item) in MItems.CARGO_CRATE_MINECARTS) {
		provider.generated(item)
	}

	MItems.SUSPICIOUS_FOODS.ITEMS.forEach { provider.inherit(it, it.mimicking()) }
}
