package ru.dbotthepony.mc.otm.datagen.models

import net.minecraft.world.level.block.Block
import net.minecraftforge.client.model.generators.BlockModelProvider
import net.minecraftforge.data.event.GatherDataEvent
import ru.dbotthepony.mc.otm.datagen.DataGen
import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.datagen.modLocation
import java.util.LinkedList

class MatteryBlockModelProvider(event: GatherDataEvent) : BlockModelProvider(event.generator.packOutput, DataGen.MOD_ID, event.existingFileHelper) {
	private val callbacks = LinkedList<(MatteryBlockModelProvider) -> Unit>()

	fun exec(callback: (MatteryBlockModelProvider) -> Unit) {
		callbacks.add(callback)
	}

	override fun registerModels() {
		for (callback in callbacks) {
			callback(this)
		}
	}

	override fun getName(): String {
		return "Block Models: $modid"
	}

	fun decorativeGlassAll(blocks: Collection<Block>) {
		for (block in blocks) {
			exec {
				cubeAll(block.registryName!!.path, modLocation("block/decorative/${block.registryName!!.path}")).renderType("translucent")
			}
		}
	}

	fun decorativeGlassAll(vararg blocks: Block) {
		for (block in blocks) {
			exec {
				cubeAll(block.registryName!!.path, modLocation("block/decorative/${block.registryName!!.path}")).renderType("translucent")
			}
		}
	}

	fun decorativeCubeAll(vararg blocks: Block) {
		for (block in blocks) {
			exec {
				cubeAll(block.registryName!!.path, modLocation("block/decorative/${block.registryName!!.path}"))
			}
		}
	}

	fun decorativeCubeAll(subdir: String, vararg blocks: Block) {
		for (block in blocks) {
			exec {
				cubeAll(block.registryName!!.path, modLocation("block/decorative/${subdir}/${block.registryName!!.path}"))
			}
		}
	}

	fun decorativeCubeAll(subdir: String, suffix: String, vararg blocks: Block) {
		for (block in blocks) {
			exec {
				cubeAll(block.registryName!!.path, modLocation("block/decorative/${subdir}/${block.registryName!!.path}$suffix"))
			}
		}
	}

	fun decorativeCubeAll(blocks: Collection<Block>) {
		for (block in blocks) {
			exec {
				cubeAll(block.registryName!!.path, modLocation("block/decorative/${block.registryName!!.path}"))
			}
		}
	}

	fun decorativeCubeAll(block: Block, texture: String) {
		exec {
			cubeAll(block.registryName!!.path, modLocation("block/decorative/$texture"))
		}
	}

	fun column(block: Block, end: String, side: String) {
		exec {
			cubeColumn(block.registryName!!.path, modLocation(end), modLocation(side))
		}
	}

	fun decorativeColumn(it: Block, end: String, side: String) {
		column(it, "block/decorative/$end", "block/decorative/$side")
	}

	fun resourceCubeAll(vararg blocks: Block) {
		for (block in blocks) {
			exec {
				cubeAll(block.registryName!!.path, modLocation("block/resource/${block.registryName!!.path}"))
			}
		}
	}
}
