import net.fabricmc.loom.task.RemapJarTask

plugins {
	id 'fabric-loom' version '1.11.8'
}

dependencies {
	minecraft("com.mojang:minecraft:${fabric_minecraft_version}")
	mappings("net.fabricmc:yarn:${yarn_mappings_version}:v2")

	modCompileOnly("net.fabricmc:fabric-loader:${fabric_loader_version}")
	Set<String> fabricApiModules = [
			'fabric-api-base',
			'fabric-command-api-v2',
			'fabric-lifecycle-events-v1',
			'fabric-networking-api-v1'
	]

	fabricApiModules.forEach {
		modCompileOnly(fabricApi.module(it, "$fabric_api_version"))
	}

	Set<String> adventureApiModules = [
			'adventure-text-minimessage',
			'adventure-api',
			'adventure-nbt',
			'adventure-key',
			'adventure-text-serializer-gson',
			'adventure-text-serializer-plain',
			'adventure-text-serializer-json-legacy-impl',
			'adventure-text-serializer-legacy',
			'adventure-text-serializer-ansi'
	]

	adventureApiModules.forEach {
		modCompileOnly("net.kyori:$it:$adventure_api")
	}

	modCompileOnly("com.github.retrooper:packetevents-fabric:$packetevents_spigot_version")
	modCompileOnly("eu.pb4:placeholder-api:$text_placeholder_api_version")
	modCompileOnly("maven.modrinth:vanish:1.6.1+1.21.10")
    modCompileOnly("io.github.miniplaceholders:miniplaceholders-api:$miniplaceholders_api_version")

	// fix integration with LuckPerms
	modImplementation(include("org.incendo:cloud-fabric:${cloud_fabric_version}"))

    implementation fileTree("library") { include "*.jar" }
	implementation project(":core")
}

shadowJar {
	archiveFileName = "flectonepulsedev-" + project.name + "-" + project_version + ".jar"

	outputs.cacheIf { true }

	archiveBaseName.set("${project_name}-${project.name}")
	archiveVersion.set("${project_version}")

	dependencies {
		exclude('net.fabricmc:.*')
		exclude '/mappings/*'

		include(dependency("com.alessiodp.libby:.*"))
		include(dependency("org.xerial:.*"))
		include(dependency("net.kyori:.*"))
		include(project(":core"))
	}

	minimize()
}

processResources {
	def props = [version: "$project_version", author: "$project_author", description: "$project_description"]
	inputs.properties props
	filteringCharset 'UTF-8'
	filesMatching('**/fabric.mod.json') {
		expand props
	}
}

tasks.register("fabricRemapJar", RemapJarTask) {
    dependsOn tasks.shadowJar
    input = tasks.shadowJar.archiveFile
    addNestedDependencies = true
}

tasks.named("buildFinalJar", Jar) {
    from {
        zipTree(tasks.fabricRemapJar.archiveFile)
    }

    dependsOn tasks.fabricRemapJar
}
