package ru.dbotthepony.mc.otm.datagen

import net.minecraft.tags.ItemTags
import net.minecraft.world.item.Item
import net.minecraft.world.item.Items
import net.minecraftforge.common.Tags
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.matter.ComputeAction
import ru.dbotthepony.mc.otm.matter.MatterDataProvider
import ru.dbotthepony.mc.otm.registry.MItemTags
import ru.dbotthepony.mc.otm.registry.MItems

// general rule - anything plant or organic is much more complex than mineral
// and anything mineral has much bigger matter value than complexity (just throw a lot of same molecules)

fun addMatterData(provider: MatterDataProvider) {
	provider.inherit(Items.CHIPPED_ANVIL, Items.ANVIL, 0.75)
	provider.inherit(Items.DAMAGED_ANVIL, Items.ANVIL, 0.5)

	for (i in 1 until MItems.TRITANIUM_ANVIL.size) {
		provider.inherit(MItems.TRITANIUM_ANVIL[i], MItems.TRITANIUM_ANVIL[i - 1], 0.85)
	}

	provider.inherit(Items.MILK_BUCKET, Items.BUCKET) {
		plus(Decimal(7), 480.0)
	}

	val copper = listOf<Pair<List<Item>, Item>>(
		listOf(
			Items.EXPOSED_COPPER,
			Items.WEATHERED_COPPER,
			Items.OXIDIZED_COPPER,
		) to Items.COPPER_BLOCK,

		listOf(
			Items.EXPOSED_CUT_COPPER,
			Items.WEATHERED_CUT_COPPER,
			Items.OXIDIZED_CUT_COPPER,
		) to Items.CUT_COPPER,

		listOf(
			Items.WAXED_EXPOSED_COPPER,
			Items.WAXED_WEATHERED_COPPER,
			Items.WAXED_OXIDIZED_COPPER,
		) to Items.WAXED_COPPER_BLOCK,

		listOf(
			Items.WAXED_EXPOSED_CUT_COPPER,
			Items.WAXED_WEATHERED_CUT_COPPER,
			Items.WAXED_OXIDIZED_CUT_COPPER,
		) to Items.WAXED_CUT_COPPER,
	)

	for ((children, parent) in copper) {
		for (item in children) {
			provider.inherit(item, parent)
		}
	}

	provider.inherit(Items.WHITE_CONCRETE, Items.WHITE_CONCRETE_POWDER)
	provider.inherit(Items.ORANGE_CONCRETE, Items.ORANGE_CONCRETE_POWDER)
	provider.inherit(Items.MAGENTA_CONCRETE, Items.MAGENTA_CONCRETE_POWDER)
	provider.inherit(Items.LIGHT_BLUE_CONCRETE, Items.LIGHT_BLUE_CONCRETE_POWDER)
	provider.inherit(Items.YELLOW_CONCRETE, Items.YELLOW_CONCRETE_POWDER)
	provider.inherit(Items.LIME_CONCRETE, Items.LIME_CONCRETE_POWDER)
	provider.inherit(Items.PINK_CONCRETE, Items.PINK_CONCRETE_POWDER)
	provider.inherit(Items.GRAY_CONCRETE, Items.GRAY_CONCRETE_POWDER)
	provider.inherit(Items.LIGHT_GRAY_CONCRETE, Items.LIGHT_GRAY_CONCRETE_POWDER)
	provider.inherit(Items.CYAN_CONCRETE, Items.CYAN_CONCRETE_POWDER)
	provider.inherit(Items.PURPLE_CONCRETE, Items.PURPLE_CONCRETE_POWDER)
	provider.inherit(Items.BLUE_CONCRETE, Items.BLUE_CONCRETE_POWDER)
	provider.inherit(Items.BROWN_CONCRETE, Items.BROWN_CONCRETE_POWDER)
	provider.inherit(Items.GREEN_CONCRETE, Items.GREEN_CONCRETE_POWDER)
	provider.inherit(Items.RED_CONCRETE, Items.RED_CONCRETE_POWDER)
	provider.inherit(Items.BLACK_CONCRETE, Items.BLACK_CONCRETE_POWDER)

	with(provider) {
		blacklist(Tags.Items.RAW_MATERIALS)
		blacklist(Tags.Items.RAW_MATERIALS_COPPER)
		blacklist(Tags.Items.RAW_MATERIALS_GOLD)
		blacklist(Tags.Items.RAW_MATERIALS_IRON)

		blacklist(Tags.Items.ORES)
		blacklist(Tags.Items.ORES_COAL)
		blacklist(Tags.Items.ORES_COPPER)
		blacklist(Tags.Items.ORES_DIAMOND)
		blacklist(Tags.Items.ORES_EMERALD)
		blacklist(Tags.Items.ORES_REDSTONE)
		blacklist(Tags.Items.ORES_IRON)
		blacklist(Tags.Items.ORES_LAPIS)
		blacklist(Tags.Items.ORES_NETHERITE_SCRAP)
		blacklist(Tags.Items.ORES_QUARTZ)

		blacklist(Tags.Items.ORES_IN_GROUND_STONE)
		blacklist(Tags.Items.ORES_IN_GROUND_DEEPSLATE)
		blacklist(Tags.Items.ORES_IN_GROUND_NETHERRACK)

		blacklist(MItemTags.TRITANIUM_ORE_CLUMPS)
		blacklist(MItemTags.TRITANIUM_ORES)
	}

	provider.scope(Items.DIRT, Decimal(1), 20.0) {
		equal(
			Items.GRASS_BLOCK,
			Items.PODZOL,
			Items.DIRT_PATH,
			Items.ICE,
			Items.MUD
		)

		relative(Items.NETHER_STAR, 2000, 1200)

		relative(MItems.ZPM_BATTERY, 80000000, 720000)

		relative(MItems.PILL_HEAL, 14, 8)
		relative(MItems.PILL_ANDROID, 20, 20)
		relative(MItems.PILL_HUMANE, 8, 8)
		relative(MItems.PILL_OBLIVION, 40, 40)

		relative(Items.PACKED_ICE, 1.5, 1)

		// rocks
		scope(Tags.Items.STONE, 1.1, 1.1) {
			equal(Tags.Items.COBBLESTONE)
			equal(Tags.Items.GRAVEL)
			equal(Items.FLINT)
			equal(Tags.Items.SAND)
			equal(Tags.Items.NETHERRACK)

			scope(1.4, 1.5) {
				equal(Items.BASALT)
				equal(Items.BLACKSTONE)
				equal(Items.END_STONE)
			}

			equal(Items.CLAY)

			relative(Items.CLAY_BALL, 0.25, 0.25)
			relative(Items.SNOWBALL, 0.25, 0.25)

			scope(Items.SOUL_SAND, 1.2, 4) {
				equal(Items.SOUL_SOIL)
			}

			relative(Items.POINTED_DRIPSTONE, 1, 1.4)

			scope(Items.DEEPSLATE, 1.1, 1.1) {
				equal(Items.COBBLED_DEEPSLATE)

				relative(Items.CALCITE, 1, 1.2)
				relative(Items.TUFF, 1, 1.2)

				relative(Items.REINFORCED_DEEPSLATE, 3, 1.4)
			}

			relative(Tags.Items.OBSIDIAN, 10, 1.5)
			relative(Items.CRYING_OBSIDIAN, 14, 3)
		}

		// valuable minerals
		scope(Items.COAL, 8, 1.5) {
			scope(Tags.Items.INGOTS_IRON, 4, 1.25) {
				relative(MItemTags.TRITANIUM_INGOTS, 2.2, 1.15)

				relative(Tags.Items.INGOTS_COPPER, 0.8, 0.9)

				relative(Tags.Items.GEMS_QUARTZ, 1, 1.1)

				relative(Tags.Items.GEMS_LAPIS, 1.25, 2)
				relative(Tags.Items.DUSTS_REDSTONE, 1.15, 2.5)
				relative(Tags.Items.DUSTS_GLOWSTONE, 1.15, 4)

				relative(Tags.Items.INGOTS_GOLD, 4, 1.6)
				relative(Tags.Items.GEMS_DIAMOND, 8, 2.1)
				relative(Tags.Items.GEMS_EMERALD, 8, 2.2)
				relative(Items.NETHERITE_SCRAP, 2, 6)

				scope(Tags.Items.GEMS_AMETHYST, 1.5, 2) {
					relative(Items.BUDDING_AMETHYST, 2.5, 9)
				}
			}
		}

		// sponge
		scope(Items.SPONGE, 2.5, 4) {
			relative(Items.WET_SPONGE, 1.1, 1.25)
		}

		// drops from mobs
		scope(Items.ROTTEN_FLESH, 8, 1.5) {
			equal(Items.INK_SAC)
			equal(Tags.Items.LEATHER)
			equal(Items.LEATHER)

			relative(Items.RABBIT_FOOT, 1.1, 1.5)
			relative(Items.RABBIT, 1.1, 1.5)

			relative(Items.GLOW_INK_SAC, 1.2, 2)

			relative(Tags.Items.BONES, 1, 1.25)

			relative(Tags.Items.STRING, 0.8, 0.75)
			relative(Items.COBWEB, 0.8, 0.75)
			relative(Items.SPIDER_EYE, 0.8, 1.8)

			relative(Tags.Items.SLIMEBALLS, 1, 1.4)
			relative(Tags.Items.GUNPOWDER, 0.85, 1.15)

			relative(Items.SCUTE, 1, 1.5)
			relative(Items.FEATHER, 0.7, 1.25)
			relative(Items.EGG, 1.25, 4)

			relative(Items.HONEYCOMB, 1.5, 1.75)
			relative(Items.HONEY_BLOCK, 6, 1.75)

			relative(Tags.Items.GEMS_PRISMARINE, 6, 2.75)
			relative(Items.PRISMARINE_SHARD, 6, 2.75)

			relative(Tags.Items.RODS_BLAZE, 1.4, 2)
			relative(Items.GHAST_TEAR, 2.5, 2.5)
			relative(Tags.Items.ENDER_PEARLS, 2, 2.5)

			relative(Items.SHULKER_SHELL, 2, 5)
		}

		// skulk
		relative(Items.SCULK, 6, 24)
		relative(Items.SCULK_CATALYST, 12, 40)
		relative(Items.SCULK_VEIN, 2.5, 24)

		// planty
		scope(Items.GRASS, 1.5, 2.5) {
			equal(Items.SUNFLOWER)
			equal(Items.LILAC)
			equal(Items.ROSE_BUSH)
			equal(Items.PEONY)
			equal(Items.TALL_GRASS)
			equal(Items.LARGE_FERN)
			equal(Items.FERN)

			equal(Items.VINE)
			equal(Items.LILY_PAD)
			relative(Items.GLOW_LICHEN, 1.1, 1.4)

			equal(Items.DANDELION)
			equal(Items.POPPY)
			equal(Items.BLUE_ORCHID)
			equal(Items.ALLIUM)
			equal(Items.AZURE_BLUET)
			equal(Items.RED_TULIP)
			equal(Items.ORANGE_TULIP)
			equal(Items.WHITE_TULIP)
			equal(Items.PINK_TULIP)
			equal(Items.OXEYE_DAISY)
			equal(Items.CORNFLOWER)
			equal(Items.LILY_OF_THE_VALLEY)

			equal(Items.SPORE_BLOSSOM)

			equal(Items.BROWN_MUSHROOM)
			equal(Items.BROWN_MUSHROOM_BLOCK)
			equal(Items.RED_MUSHROOM)
			equal(Items.RED_MUSHROOM_BLOCK)

			equal(Items.HANGING_ROOTS)
			equal(Items.AZALEA)
			relative(Items.FLOWERING_AZALEA, 1.05, 1.2)
			equal(Items.MOSS_BLOCK)
			equal(Items.BIG_DRIPLEAF)
			equal(Items.SMALL_DRIPLEAF)

			relative(Items.BAMBOO, 1.25, 1.5)

			scope(1, 1.1) {
				equal(Items.CRIMSON_FUNGUS)
				equal(Items.WARPED_FUNGUS)

				equal(Items.CRIMSON_ROOTS)
				equal(Items.WARPED_ROOTS)
				equal(Items.NETHER_SPROUTS)
				equal(Items.WEEPING_VINES)
				equal(Items.TWISTING_VINES)
			}

			equal(Items.SEAGRASS)
			equal(Items.TUBE_CORAL_BLOCK)
			equal(Items.BRAIN_CORAL_BLOCK)
			equal(Items.BUBBLE_CORAL_BLOCK)
			equal(Items.FIRE_CORAL_BLOCK)
			equal(Items.HORN_CORAL_BLOCK)
			equal(Items.TUBE_CORAL)
			equal(Items.BRAIN_CORAL)
			equal(Items.BUBBLE_CORAL)
			equal(Items.FIRE_CORAL)
			equal(Items.HORN_CORAL)

			equal(Items.DEAD_TUBE_CORAL_BLOCK)
			equal(Items.DEAD_BRAIN_CORAL_BLOCK)
			equal(Items.DEAD_BUBBLE_CORAL_BLOCK)
			equal(Items.DEAD_FIRE_CORAL_BLOCK)
			equal(Items.DEAD_HORN_CORAL_BLOCK)

			equal(Items.TUBE_CORAL_FAN)
			equal(Items.BRAIN_CORAL_FAN)
			equal(Items.BUBBLE_CORAL_FAN)
			equal(Items.FIRE_CORAL_FAN)
			equal(Items.HORN_CORAL_FAN)

			equal(Items.DEAD_BRAIN_CORAL)
			equal(Items.DEAD_BUBBLE_CORAL)
			equal(Items.DEAD_FIRE_CORAL)
			equal(Items.DEAD_HORN_CORAL)
			equal(Items.DEAD_TUBE_CORAL)

			equal(Items.DEAD_TUBE_CORAL_FAN)
			equal(Items.DEAD_BRAIN_CORAL_FAN)
			equal(Items.DEAD_BUBBLE_CORAL_FAN)
			equal(Items.DEAD_FIRE_CORAL_FAN)
			equal(Items.DEAD_HORN_CORAL_FAN)

			equal(Items.KELP)

			equal(ItemTags.SAPLINGS)

			relative(Items.CACTUS, 2.5, 2)

			scope(1.5, 2) {
				equal(Items.MELON_SLICE)
				equal(Items.POTATO, Items.POISONOUS_POTATO)
				equal(Items.CARROT)
				equal(Items.WHEAT)
				equal(Items.BEETROOT)
				equal(Items.SUGAR_CANE)

				equal(Items.APPLE)

				relative(Items.COCOA_BEANS, 1, 1.2)

				relative(Items.NETHER_WART, 1.1, 1.75)
			}

			scope(0.75, 2) {
				equal(Tags.Items.SEEDS)
				equal(Tags.Items.SEEDS_BEETROOT)
				equal(Tags.Items.SEEDS_MELON)
				equal(Tags.Items.SEEDS_PUMPKIN)
				equal(Tags.Items.SEEDS_WHEAT)
			}

			scope(Items.PUMPKIN, 2, 2) {
				equal(Items.CARVED_PUMPKIN)
			}

			scope(2.5, 6) {
				equal(Items.CHORUS_FRUIT)
				equal(Items.CHORUS_PLANT)
				equal(Items.CHORUS_FLOWER)
			}
		}

		// leaves
		scope(ItemTags.LEAVES, 1.5, 4) {
			// directly map them this matter value
			// equal(Items.OAK_LEAVES)
			// equal(Items.SPRUCE_LEAVES)
			// equal(Items.BIRCH_LEAVES)
			// equal(Items.JUNGLE_LEAVES)
			// equal(Items.ACACIA_LEAVES)
			// equal(Items.DARK_OAK_LEAVES)
			// equal(Items.MANGROVE_LEAVES)
		}

		// wood
		scope(ItemTags.LOGS, 2.5, 4) {
			// directly map them this matter value
			// equal(Items.OAK_LOG)
			// equal(Items.SPRUCE_LOG)
			// equal(Items.BIRCH_LOG)
			// equal(Items.JUNGLE_LOG)
			// equal(Items.ACACIA_LOG)
			// equal(Items.DARK_OAK_LOG)
			// equal(Items.MANGROVE_LOG)

			scope(0.9, 0.95) {
				equal(Items.STRIPPED_OAK_LOG)
				equal(Items.STRIPPED_SPRUCE_LOG)
				equal(Items.STRIPPED_BIRCH_LOG)
				equal(Items.STRIPPED_JUNGLE_LOG)
				equal(Items.STRIPPED_ACACIA_LOG)
				equal(Items.STRIPPED_DARK_OAK_LOG)
				equal(Items.STRIPPED_MANGROVE_LOG)
				equal(Items.STRIPPED_CRIMSON_STEM)
				equal(Items.STRIPPED_WARPED_STEM)
				equal(Items.STRIPPED_OAK_WOOD)
				equal(Items.STRIPPED_SPRUCE_WOOD)
				equal(Items.STRIPPED_BIRCH_WOOD)
				equal(Items.STRIPPED_JUNGLE_WOOD)
				equal(Items.STRIPPED_ACACIA_WOOD)
				equal(Items.STRIPPED_DARK_OAK_WOOD)
				equal(Items.STRIPPED_MANGROVE_WOOD)
				equal(Items.STRIPPED_CRIMSON_HYPHAE)
				equal(Items.STRIPPED_WARPED_HYPHAE)
			}
		}
	}
}
