package ru.dbotthepony.mc.otm.datagen.tags

import net.minecraft.tags.BlockTags
import net.minecraft.tags.ItemTags
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.item.Items
import net.minecraft.world.item.Tiers
import net.minecraft.world.level.block.Blocks
import ru.dbotthepony.mc.otm.registry.MBlockTags
import ru.dbotthepony.mc.otm.registry.MBlocks
import ru.dbotthepony.mc.otm.registry.MItemTags
import ru.dbotthepony.mc.otm.registry.MItems
import ru.dbotthepony.mc.otm.registry.MRegistry

fun addTags(tagsProvider: TagsProvider) {
	tagsProvider.items.forge("pistons").add(Items.PISTON)
	tagsProvider.circuits.add("basic", MItems.BASIC_CONTROL_CIRCUIT)
	tagsProvider.circuits.add("advanced", MItems.ADVANCED_CONTROL_CIRCUIT)

	tagsProvider.dusts.add("tritanium", MItems.TRITANIUM_DUST)
	tagsProvider.ingots.add("tritanium", MItems.TRITANIUM_INGOT)

	tagsProvider.plates.add("tritanium", MItems.TRITANIUM_PLATE)
	tagsProvider.plates.add("iron", MItems.IRON_PLATE)
	tagsProvider.plates.add("gold", MItems.GOLD_PLATE)
	tagsProvider.plates.add("carbon", MItems.CARBON_MESH)

	tagsProvider.items.forge("reinforced_tritanium").add(MItems.REINFORCED_TRITANIUM_PLATE)

	tagsProvider.storageBlocksAsItem.add("tritanium", MItems.TRITANIUM_INGOT_BLOCK)
	tagsProvider.storageBlocksAsBlock.add("tritanium", MBlocks.TRITANIUM_INGOT_BLOCK)

	tagsProvider.stoneOre("tritanium", MBlocks.TRITANIUM_ORE)
	tagsProvider.deepslateOre("tritanium", MBlocks.DEEPSLATE_TRITANIUM_ORE)
	tagsProvider.singleDropOre(
		MBlocks.TRITANIUM_ORE,
		MBlocks.DEEPSLATE_TRITANIUM_ORE
	)

	tagsProvider.clump("tritanium", MItems.TRITANIUM_ORE_CLUMP, MBlocks.TRITANIUM_RAW_BLOCK)

	tagsProvider.wires.add("copper", MItems.COPPER_WIRING)
	tagsProvider.wires.add("gold", MItems.GOLD_WIRING)

	tagsProvider.requiresPickaxe(
		MBlocks.MATTER_CABLE,
		MBlocks.STORAGE_CABLE
	)

	tagsProvider.items.Appender(MItemTags.CRAFTING_TABLES).add(Items.CRAFTING_TABLE)
	tagsProvider.blocks.Appender(MBlockTags.CRAFTING_TABLES).add(Blocks.CRAFTING_TABLE)

	tagsProvider.items.Appender(MItemTags.MINECART_CARGO_CRATES).add(MItems.CARGO_CRATE_MINECARTS.values)

	tagsProvider.items.forge("hardened_glass").add(MRegistry.INDUSTRIAL_GLASS.allItems.values)
	tagsProvider.items.forge("hardened_glass/colorless").add(MRegistry.INDUSTRIAL_GLASS.item)
	tagsProvider.items.forge("hardened_glass/tinted").add(MRegistry.INDUSTRIAL_GLASS.items.values)

	tagsProvider.items.forge("hardened_glass_panes").add(MRegistry.INDUSTRIAL_GLASS_PANE.allItems.values)
	tagsProvider.items.forge("hardened_glass_panes/colorless").add(MRegistry.INDUSTRIAL_GLASS_PANE.item)
	tagsProvider.items.forge("hardened_glass_panes/tinted").add(MRegistry.INDUSTRIAL_GLASS_PANE.items.values)

	MRegistry.INDUSTRIAL_GLASS.forEachItem { s, _, item -> tagsProvider.items.forge("hardened_glass/$s").add(item) }
	MRegistry.INDUSTRIAL_GLASS_PANE.forEachItem { s, _, item -> tagsProvider.items.forge("hardened_glass_panes/$s").add(item) }

	tagsProvider.blocks.forge("hardened_glass").add(MRegistry.INDUSTRIAL_GLASS.allBlocks.values)
	tagsProvider.blocks.forge("hardened_glass/colorless").add(MRegistry.INDUSTRIAL_GLASS.block)
	tagsProvider.blocks.forge("hardened_glass/tinted").add(MRegistry.INDUSTRIAL_GLASS.blocks.values)

	tagsProvider.blocks.forge("hardened_glass_panes").add(MRegistry.INDUSTRIAL_GLASS_PANE.allBlocks.values)
	tagsProvider.blocks.forge("hardened_glass_panes/colorless").add(MRegistry.INDUSTRIAL_GLASS_PANE.block)
	tagsProvider.blocks.forge("hardened_glass_panes/tinted").add(MRegistry.INDUSTRIAL_GLASS_PANE.blocks.values)

	MRegistry.INDUSTRIAL_GLASS.forEachBlock { s, _, block -> tagsProvider.blocks.forge("hardened_glass/$s").add(block) }
	MRegistry.INDUSTRIAL_GLASS_PANE.forEachBlock { s, _, block -> tagsProvider.blocks.forge("hardened_glass_panes/$s").add(block) }

	tagsProvider.items.Appender(MItemTags.INDUSTRIAL_GLASS).add(MRegistry.INDUSTRIAL_GLASS.allItems.values)
	tagsProvider.blocks.Appender(MBlockTags.INDUSTRIAL_GLASS).add(MRegistry.INDUSTRIAL_GLASS.allBlocks.values)
	tagsProvider.blocks.Appender(MBlockTags.CARGO_CRATES).add(MRegistry.CARGO_CRATES.allBlocks.values)

	tagsProvider.items.Appender(ItemTags.DOORS).add(MItems.TRITANIUM_DOOR.values)
	tagsProvider.blocks.Appender(BlockTags.DOORS).add(MBlocks.TRITANIUM_DOOR.values)

	tagsProvider.items.Appender(ItemTags.TRAPDOORS).add(MItems.TRITANIUM_TRAPDOOR.values)
	tagsProvider.blocks.Appender(BlockTags.TRAPDOORS).add(MBlocks.TRITANIUM_TRAPDOOR.values)

	tagsProvider.blocks.Appender(BlockTags.PRESSURE_PLATES).add(MRegistry.TRITANIUM_PRESSURE_PLATE.allBlocks.values)

	tagsProvider.items.Appender(MItemTags.MACHINES).add(MItems.MACHINES)
	tagsProvider.blocks.Appender(MBlockTags.MACHINES).add(MItems.MACHINES.stream().map { it!!.block })

	tagsProvider.blocks.Appender(BlockTags.ANVIL).add(MBlocks.TRITANIUM_ANVIL)

	tagsProvider.items.Appender(MItemTags.TRITANIUM_NUGGETS).add(MItems.TRITANIUM_NUGGET)
	tagsProvider.items.Appender(MItemTags.NUGGETS).add(MItems.TRITANIUM_NUGGET)

	tagsProvider.items.forge("armors")
		.add("helmets", MItems.TRITANIUM_HELMET)
		.add("chestplates", MItems.TRITANIUM_CHESTPLATE)
		.add("leggings", MItems.TRITANIUM_PANTS)
		.add("boots", MItems.TRITANIUM_BOOTS)
		.add("helmets", MItems.SIMPLE_TRITANIUM_HELMET)
		.add("chestplates", MItems.SIMPLE_TRITANIUM_CHESTPLATE)
		.add("leggings", MItems.SIMPLE_TRITANIUM_PANTS)
		.add("boots", MItems.SIMPLE_TRITANIUM_BOOTS)

	tagsProvider.items.minecraft("swords").add(MItems.TRITANIUM_SWORD)
	tagsProvider.items.minecraft("axes").add(MItems.TRITANIUM_AXE)
	tagsProvider.items.minecraft("pickaxes").add(MItems.TRITANIUM_PICKAXE)
	tagsProvider.items.minecraft("shovels").add(MItems.TRITANIUM_SHOVEL)
	tagsProvider.items.minecraft("hoes").add(MItems.TRITANIUM_HOE)
	tagsProvider.items.forge("shears").add(MItems.TRITANIUM_SHEARS)
	tagsProvider.items.forge("shields").add(MItems.TRITANIUM_SHIELD)

	tagsProvider.items.Appender(MItemTags.UPGRADES).add(MItems.CreativeUpgrades.LIST)

	tagsProvider.blocks.Appender(BlockTags.STAIRS)
		.add(MRegistry.FLOOR_TILES_STAIRS.blocks.values)
		.add(MRegistry.TRITANIUM_STAIRS.allBlocks.values)
		.add(MRegistry.TRITANIUM_STRIPED_STAIRS.flatBlocks)
		.add(MBlocks.TRITANIUM_STRIPED_STAIRS)

	tagsProvider.blocks.Appender(BlockTags.SLABS)
		.add(MRegistry.TRITANIUM_SLAB.allBlocks.values)
		.add(MRegistry.TRITANIUM_STRIPED_SLAB.flatBlocks)
		.add(MRegistry.FLOOR_TILES_SLAB.blocks.values)
		.add(MBlocks.TRITANIUM_STRIPED_SLAB)

	tagsProvider.blocks.Appender(BlockTags.WALLS)
		.add(MRegistry.TRITANIUM_WALL.allBlocks.values)
		.add(MRegistry.TRITANIUM_STRIPED_WALL.flatBlocks)
		.add(MBlocks.TRITANIUM_STRIPED_WALL)

	tagsProvider.items.Appender(ItemTags.SLABS)
		.add(MRegistry.TRITANIUM_SLAB.allItems.values)
		.add(MRegistry.TRITANIUM_STRIPED_SLAB.flatItems)
		.add(MRegistry.FLOOR_TILES_SLAB.items.values)
		.add(MItems.TRITANIUM_STRIPED_SLAB)

	tagsProvider.items.Appender(ItemTags.WALLS)
		.add(MRegistry.TRITANIUM_WALL.allItems.values)
		.add(MRegistry.TRITANIUM_STRIPED_WALL.flatItems)
		.add(MItems.TRITANIUM_STRIPED_WALL)

	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_DOOR.values, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_TRAPDOOR.values, Tiers.IRON)

	tagsProvider.requiresPickaxe(listOf(
		MBlocks.ANDROID_STATION,
		MBlocks.BATTERY_BANK,
		MBlocks.MATTER_DECOMPOSER,
		MBlocks.MATTER_CAPACITOR_BANK,
		MBlocks.PATTERN_STORAGE,
		MBlocks.MATTER_SCANNER,
		MBlocks.MATTER_PANEL,
		MBlocks.MATTER_REPLICATOR,
		MBlocks.MATTER_BOTTLER,
		MBlocks.ENERGY_COUNTER,
		MBlocks.CHEMICAL_GENERATOR,
		MBlocks.PLATE_PRESS,
		MBlocks.TWIN_PLATE_PRESS,
		MBlocks.MATTER_RECYCLER,

		MBlocks.POWERED_FURNACE,
		MBlocks.POWERED_SMOKER,
		MBlocks.POWERED_BLAST_FURNACE,

		MBlocks.STORAGE_BUS,
		MBlocks.STORAGE_IMPORTER,
		MBlocks.STORAGE_EXPORTER,

		MBlocks.DRIVE_VIEWER,
		MBlocks.DRIVE_RACK,
		MBlocks.ITEM_MONITOR,
		MBlocks.STORAGE_POWER_SUPPLIER,

		MBlocks.PHANTOM_ATTRACTOR,
		MBlocks.ENERGY_SERVO,

		MBlocks.TRITANIUM_INGOT_BLOCK,
		MBlocks.TRITANIUM_BARS,

		MBlocks.ENGINE,
		MBlocks.HOLO_SIGN,
		MBlocks.COBBLESTONE_GENERATOR,
		MBlocks.ESSENCE_STORAGE,
		MBlocks.MATTER_RECONSTRUCTOR,
		MBlocks.FLUID_TANK,
		MBlocks.ANDROID_CHARGER,
	), Tiers.IRON)

	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_ANVIL, Tiers.IRON)

	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_ORE, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.DEEPSLATE_TRITANIUM_ORE, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_RAW_BLOCK, Tiers.IRON)

	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_STRIPED_BLOCK, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_STRIPED_STAIRS, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_STRIPED_WALL, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_STRIPED_SLAB, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.CARBON_FIBRE_BLOCK, Tiers.IRON)

	tagsProvider.requiresPickaxe(MRegistry.CARGO_CRATES.allBlocks.values, Tiers.IRON)

	tagsProvider.requiresPickaxe(MRegistry.VENT.allBlocks.values, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.VENT_ALTERNATIVE.allBlocks.values, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_BLOCK.allBlocks.values, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_SLAB.allBlocks.values, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_WALL.allBlocks.values, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_PRESSURE_PLATE.allBlocks.values, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_STAIRS.allBlocks.values, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_STRIPED_BLOCK.flatBlocks, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_STRIPED_STAIRS.flatBlocks, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_STRIPED_WALL.flatBlocks, Tiers.IRON)
	tagsProvider.requiresPickaxe(MRegistry.TRITANIUM_STRIPED_SLAB.flatBlocks, Tiers.IRON)

	tagsProvider.requiresPickaxe(MRegistry.FLOOR_TILES.blocks.values)
	tagsProvider.requiresPickaxe(MRegistry.FLOOR_TILES_STAIRS.blocks.values)
	tagsProvider.requiresPickaxe(MRegistry.FLOOR_TILES_SLAB.blocks.values)
	tagsProvider.requiresShovel(MRegistry.UNREFINED_FLOOR_TILES.blocks.values)

	tagsProvider.requiresPickaxe(MRegistry.INDUSTRIAL_GLASS.allBlocks.values, Tiers.STONE)
	tagsProvider.requiresPickaxe(MRegistry.INDUSTRIAL_GLASS_PANE.allBlocks.values, Tiers.STONE)
	tagsProvider.requiresPickaxe(MRegistry.DECORATIVE_CRATE.allBlocks.values, Tiers.STONE)

	tagsProvider.requiresPickaxe(MBlocks.LABORATORY_LAMP, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.LABORATORY_LAMP_INVERTED, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.METAL_BEAM, Tiers.IRON)
	tagsProvider.requiresPickaxe(MBlocks.DANGER_STRIPE_BLOCK)

	tagsProvider.requiresPickaxe(listOf(
		MBlocks.GRAVITATION_STABILIZER,
		MBlocks.GRAVITATION_STABILIZER_LENS,
	), Tiers.DIAMOND)

	tagsProvider.dragonImmune.add(
		MBlocks.BLACK_HOLE,
		MBlocks.GRAVITATION_STABILIZER,
		MBlocks.GRAVITATION_STABILIZER_LENS,
	)

	tagsProvider.witherImmune.add(
		MBlocks.BLACK_HOLE,
	)

	tagsProvider.androidImmuneEffects.add(
		MobEffects.CONDUIT_POWER,
		MobEffects.HEAL,
		// maybe it makes things go haywire idk
		// MobEffects.HARM,
		MobEffects.REGENERATION,
		MobEffects.WATER_BREATHING,
		MobEffects.POISON,
		// even skeletons can be withered
		// MobEffects.WITHER,
		MobEffects.HEALTH_BOOST,
		MobEffects.ABSORPTION,
		MobEffects.SATURATION,
		MobEffects.DOLPHINS_GRACE,
		MobEffects.CONFUSION,
	)
}
