plugins {
    id "com.github.johnrengelman.shadow" version "7.0.0"
    id "com.modrinth.minotaur" version "1.2.1"
}

configurations {
    shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
}

architectury {
    platformSetupLoomIde()
    forge()
}

loom {
    forge {
        mixinConfig "keeptherain.mixins.json"
    }
}

dependencies {
    forge "net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}"
    // Remove the next line if you don't want to depend on the API
    modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"

    implementation(project(path: ":common", configuration: "dev")) {
        transitive = false
    }
    developmentForge(project(path: ":common", configuration: "dev")) {
        transitive = false
    }
    shadowCommon(project(path: ":common", configuration: "transformProductionForge")) {
        transitive = false
    }
}

processResources {
    inputs.property "version", project.version

    filesMatching("META-INF/mods.toml") {
        expand "version": project.version
    }
}

shadowJar {
    exclude "fabric.mod.json"

    configurations = [project.configurations.shadowCommon]
    classifier "dev-shadow"
}

remapJar {
    input.set shadowJar.archiveFile
    dependsOn shadowJar
    classifier "forge"
}

jar {
    classifier "dev"
}

sourcesJar {
    def commonSources = project(":common").sourcesJar
    dependsOn commonSources
    from commonSources.archiveFile.map { zipTree(it) }
}

publishing {
    publications {
        mavenForge(MavenPublication) {
            artifactId = rootProject.archives_base_name + "-" + project.name
            // add all the jars that should be included when publishing to maven
            artifact(remapJar) {
                classifier null
            }
            artifact(sourcesJar) {
                builtBy remapSourcesJar
            }
        }
    }

    // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
    repositories {
        // Add repositories to publish to here.
    }

}

import com.modrinth.minotaur.TaskModrinthUpload

String fileContents = new File("./", "CHANGELOG.md").text

task publishModrinth (type: TaskModrinthUpload) {
    token = project.findProperty('modrinth_key')
    projectId = 'Cprd9pHZ'
    versionNumber = 'forge-' + mod_version
    versionName = mod_version + '-' + project.minecraft_version
    uploadFile = jar.outputs.getFiles().asPath
    changelog = fileContents
    addGameVersion(project.minecraft_version)
    addLoader('forge')
}