package ru.dbotthepony.mc.otm.datagen

import net.minecraft.resources.ResourceLocation
import net.minecraft.sounds.SoundEvent
import net.minecraftforge.common.data.SoundDefinition
import net.minecraftforge.common.data.SoundDefinitionsProvider
import net.minecraftforge.data.event.GatherDataEvent
import ru.dbotthepony.mc.otm.registry.MSoundEvents

fun SoundDefinition.subtitle(value: SoundEvent): SoundDefinition {
	return subtitle("otm.sound." + value.location.path)
}

class SoundDataProvider(event: GatherDataEvent) : SoundDefinitionsProvider(event.generator.packOutput, DataGen.MOD_ID, event.existingFileHelper) {
	override fun registerSounds() {
		add(MSoundEvents.PLASMA_WEAPON_OVERHEAT,
			definition().subtitle("otm.sound.plasma_weapon_overheat")
				.with(SoundDefinition.Sound.sound(modLocation("item/plasma_weapon_overheat"), SoundDefinition.SoundType.SOUND)))

		add(MSoundEvents.PLAYER_BECOME_ANDROID,
			definition().subtitle("otm.sound.player_become_android")
				.with(SoundDefinition.Sound.sound(modLocation("player_become_android"), SoundDefinition.SoundType.SOUND)))

		add(MSoundEvents.RIFLE_SHOT,
			definition().subtitle("otm.sound.rifle_shot")
				.with(SoundDefinition.Sound.sound(modLocation("item/rifle_shot"), SoundDefinition.SoundType.SOUND)))

		simple(MSoundEvents.CARGO_CRATE_OPEN)

		add(MSoundEvents.ANDROID_JUMP_BOOST,
			definition().subtitle("otm.sound.android.jump_boost")
				.with(SoundDefinition.Sound.sound(modLocation("android/jump_boost"), SoundDefinition.SoundType.SOUND)))

		add(MSoundEvents.ANDROID_SHOCKWAVE,
			definition().subtitle("otm.sound.android.shockwave")
				.with(SoundDefinition.Sound.sound(modLocation("android/shockwave"), SoundDefinition.SoundType.SOUND)))

		add(MSoundEvents.ANDROID_PROJ_PARRY,
			definition().subtitle("otm.sound.android.projectile_parry")
				.with(SoundDefinition.Sound.sound(modLocation("android/punch_projectile"), SoundDefinition.SoundType.SOUND))
		)
	}

	private inline fun add(value: SoundEvent, block: SoundDefinition.() -> Unit) {
		add(value, definition().subtitle(value).also(block))
	}

	private fun add(value: SoundEvent, path: String) {
		add(value) {
			with(SoundDefinition.Sound.sound(modLocation(path), SoundDefinition.SoundType.SOUND))
		}
	}

	private fun simple(value: SoundEvent) {
		add(value, value.location.path)
	}
}
