package ru.dbotthepony.mc.otm.datagen.blocks

import net.minecraft.world.item.DyeColor
import net.minecraft.world.level.block.Block
import net.neoforged.neoforge.client.model.generators.BlockStateProvider
import net.neoforged.neoforge.client.model.generators.ConfiguredModel
import net.neoforged.neoforge.data.event.GatherDataEvent
import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.yRotationBlockstateNorth
import ru.dbotthepony.mc.otm.datagen.DataGen
import ru.dbotthepony.mc.otm.datagen.modLocation
import ru.dbotthepony.mc.otm.registry.game.MBlocks

private fun nothingOrNumber(input: Int): String {
	if (input == 0)
		return ""

	return (input - 1).toString()
}

open class BatteryBankProvider(event: GatherDataEvent, val color: DyeColor?) : BlockStateProvider(event.generator.packOutput, DataGen.MOD_ID, event.existingFileHelper) {
	protected var block = "battery_bank"
	protected var batteryPath = "block/battery/battery"
	protected var registry: Block = MBlocks.BATTERY_BANK[color]!!

	override fun registerStatesAndModels() {
		with(getVariantBuilder(registry)) {
			forAllStates {
				ConfiguredModel.builder()
					.modelFile(models().getExistingFile(modLocation("block/$block${if (color != null) "_${color.name.lowercase()}" else ""}")))
					.rotationY(it[BlockRotationFreedom.HORIZONTAL.property].front.yRotationBlockstateNorth())
					.build()
			}
		}
	}

	override fun getName(): String {
		return "Battery Bank Model Provider for color $color"
	}
}

class MatterBankProvider(event: GatherDataEvent, color: DyeColor?) : BatteryBankProvider(event, color) {
	init {
		block = "matter_capacitor_bank"
		batteryPath = "block/battery/matter_capacitor"
		registry = MBlocks.MATTER_CAPACITOR_BANK[color]!!
	}

	override fun getName(): String {
		return "Matter Bank Model Provider for color $color"
	}
}
