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

import net.minecraft.world.level.block.Block
import net.minecraftforge.client.model.generators.BlockStateProvider
import net.minecraftforge.client.model.generators.ConfiguredModel
import net.minecraftforge.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.MBlocks

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

	return (input - 1).toString()
}

open class BatteryBankProvider(event: GatherDataEvent) : 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

	override fun registerStatesAndModels() {
		with(getVariantBuilder(registry)) {
			forAllStates {
				ConfiguredModel.builder()
					.modelFile(models().getExistingFile(modLocation("block/$block")))
					.rotationY(it[BlockRotationFreedom.ONE.property].front.yRotationBlockstateNorth())
					.build()
			}
		}
	}

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

class MatterBankProvider(event: GatherDataEvent) : BatteryBankProvider(event) {
	init {
		block = "matter_capacitor_bank"
		batteryPath = "block/battery/matter_capacitor"
		registry = MBlocks.MATTER_CAPACITOR_BANK
	}

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