package ru.dbotthepony.mc.otm.registry.game

import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.stats.StatFormatter
import net.minecraft.stats.Stats
import net.neoforged.bus.api.IEventBus
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent
import ru.dbotthepony.mc.otm.registry.MDeferredRegister
import ru.dbotthepony.mc.otm.registry.StatNames.DAMAGE_ABSORBED
import ru.dbotthepony.mc.otm.registry.StatNames.HEALTH_REGENERATED
import ru.dbotthepony.mc.otm.registry.StatNames.POWER_CONSUMED

object MStats {
	private val registrar = MDeferredRegister(BuiltInRegistries.CUSTOM_STAT)

	fun register(bus: IEventBus) {
		registrar.register(bus)
	}

	init {
		registrar.register(DAMAGE_ABSORBED, DAMAGE_ABSORBED)
		registrar.register(HEALTH_REGENERATED, HEALTH_REGENERATED)
		registrar.register(POWER_CONSUMED, POWER_CONSUMED)
	}

	fun registerVanilla(event: FMLCommonSetupEvent) {
		event.enqueueWork {
			Stats.CUSTOM[DAMAGE_ABSORBED, StatFormatter.DIVIDE_BY_TEN]
			Stats.CUSTOM[HEALTH_REGENERATED, StatFormatter.DIVIDE_BY_TEN]
			Stats.CUSTOM[POWER_CONSUMED, StatFormatter.DIVIDE_BY_TEN]
		}
	}
}
