package ru.dbotthepony.mc.otm.datagen.loot

import net.minecraft.world.level.block.state.properties.BlockStateProperties
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf
import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition
import ru.dbotthepony.mc.otm.registry.game.MBlocks
import ru.dbotthepony.mc.otm.registry.MRegistry

fun addDecorativeLoot(lootTables: LootTables) {
	lootTables.dropsSelf(MRegistry.DECORATIVE_CRATE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MRegistry.COMPUTER_TERMINAL.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.STAR_CHAIR.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.CARGO_CRATES.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.INDUSTRIAL_GLASS.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.INDUSTRIAL_GLASS_PANE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.TRITANIUM_BLOCK.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.TRITANIUM_WALL.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.TRITANIUM_STAIRS.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.createSlabItemTable(MRegistry.TRITANIUM_SLAB.allBlocks.values)
	lootTables.dropsSelf(MRegistry.VENT.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.VENT_ALTERNATIVE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.FLOOR_TILES.blocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.UNREFINED_FLOOR_TILES.blocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_BLOCK.flatBlocks) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_STAIRS.flatBlocks) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MRegistry.TRITANIUM_STRIPED_WALL.flatBlocks) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.createSlabItemTable(MRegistry.TRITANIUM_STRIPED_SLAB.flatBlocks) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MRegistry.FLOOR_TILES_STAIRS.blocks.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.createSlabItemTable(MRegistry.FLOOR_TILES_SLAB.blocks.values) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.CARBON_FIBRE_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.METAL_MESH) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.METAL_RAILING) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.METAL_JUNK) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.TRITANIUM_RAW_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_BLOCK.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_WALL.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.TRITANIUM_STRIPED_STAIRS.values) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.createSlabItemTable(MBlocks.TRITANIUM_STRIPED_SLAB.values) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.LABORATORY_LAMP) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.LABORATORY_LAMP_INVERTED) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.DANGER_STRIPE_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.METAL_BEAM) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.TRITANIUM_INGOT_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.TRITANIUM_BARS) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.WITHERED_STEEL_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.TRITANIUM_HULL) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.GENERATOR_BLOCK) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.MODULAR_FRAME) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.HEAVY_MODULAR_FRAME) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.FLYWHEEL_SHAFT) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.FLYWHEEL_HOUSING) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.FLYWHEEL_BEARING) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MBlocks.ENGINE) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.REDSTONE_LAMP_INVERTED) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.REINFORCED_REDSTONE_LAMP) { condition(ExplosionCondition.survivesExplosion()) }
	lootTables.dropsSelf(MBlocks.REINFORCED_REDSTONE_LAMP_INVERTED) { condition(ExplosionCondition.survivesExplosion()) }

	MBlocks.TRITANIUM_ANVIL.values.forEach { it.forEach { lootTables.dropsSelf(it) { condition(ExplosionCondition.survivesExplosion()) } } }

	for (door in MBlocks.TRITANIUM_TRAPDOOR.values)
		lootTables.dropsSelf(door) { condition(ExplosionCondition.survivesExplosion()) }

	lootTables.dropsSelf(MRegistry.TRITANIUM_PRESSURE_PLATE.allBlocks.values) { condition(ExplosionCondition.survivesExplosion()) }

	for (door in MBlocks.TRITANIUM_DOOR.values) {
		lootTables.block(door) {
			item(door) {
				blockStateCondition(door) {
					this[BlockStateProperties.DOUBLE_BLOCK_HALF] = DoubleBlockHalf.LOWER
				}
			}

			condition(ExplosionCondition.survivesExplosion())
		}
	}
}
