plugins {
    id "fabric-loom" version "1.11-SNAPSHOT"
    id "com.matthewprenger.cursegradle" version "1.4.0"
    id "com.modrinth.minotaur" version "2.+"
}

base.archivesName.set("${mod_name}-fabric")

dependencies {
    minecraft "com.mojang:minecraft:${minecraft_version}"
    mappings loom.officialMojangMappings()
    modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
    modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
    compileOnly project(":Common")
    include implementation("com.electronwill.night-config:toml:${nightconfig_version}")
    include implementation("com.electronwill.night-config:core:${nightconfig_version}")
}

loom {
    accessWidenerPath = project(":Common").file("src/main/resources/terrablender.accesswidener")
    runs {
        client {
            client()
            setConfigName("Fabric Client")
            ideConfigGenerated(true)
            runDir("run")
        }
        server {
            server()
            setConfigName("Fabric Server")
            ideConfigGenerated(true)
            runDir("run")
        }
    }
}

processResources {
    from project(":Common").sourceSets.main.resources
    inputs.property "version", project.version

    filesMatching("fabric.mod.json") {
        expand "version": mod_version
    }
    
    filesMatching("${mod_id}.mixins.json") {
        expand "refmap_target": "${archivesBaseName}-"
    }
}

tasks.withType(JavaCompile) {
    source(project(":Common").sourceSets.main.allSource)
}

jar {
    from("LICENSE") {
        rename { "${it}_${mod_name}" }
    }
}

curseforge {
    apiKey = project.findProperty('curseApiKey') ?: 'unset'
    project {
        id = '565956'

        if (changelog_file.exists()) {
            changelog = changelog_file
        }

        releaseType = release_channel
        addGameVersion minecraft_version
        addGameVersion 'Fabric'

        mainArtifact(remapJar) {
            displayName = "TerraBlender Fabric ${version}"

            relations {
                requiredDependency "fabric-api"
            }
        }
    }

    options {
        forgeGradleIntegration = false
    }
}

modrinth {
    token = project.findProperty('modrinthToken')
    projectId = "terrablender"
    versionNumber = mod_version
    versionName = mod_version + " for Fabric " + minecraft_version
    versionType = release_channel // can be release, beta, or alpha
    uploadFile = remapJar
    gameVersions = [minecraft_version]
    loaders = ['fabric']

    if (changelog_file.exists()) {
        changelog = trimChangelog(changelog_file.text)
    }

    dependencies {
        required.project "fabric-api"
    }
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId project.group
            artifactId project.archivesBaseName
            version project.version
            from components.java

            pom {
                name = 'TerraBlender-fabric'
                description = "A library mod for adding biomes in a simple and compatible manner with Minecraft's new biome/terrain system."
                url = 'https://github.com/Glitchfiend/TerraBlender'
                scm {
                    url = 'https://github.com/Glitchfiend/TerraBlender'
                    connection = 'scm:git:git://github.com/Glitchfiend/TerraBlender.git'
                    developerConnection = 'scm:git:git@github.com:Glitchfiend/TerraBlender.git'
                }
                issueManagement {
                    system = 'github'
                    url = 'https://github.com/Glitchfiend/TerraBlender/issues'
                }
                licenses {
                    license {
                        name = 'LGPLv3'
                        url = 'https://www.gnu.org/licenses/lgpl-3.0.txt'
                    }
                }
                developers {
                    developer {
                        id = 'adubbz'
                        name = 'Adubbz'
                    }
                }
            }
        }
    }
    repositories {
        maven {
            url = "https://maven.minecraftforge.net/releases/"
            credentials {
                username = System.getenv("MAVEN_USER")
                password = System.getenv("MAVEN_PASSWORD")
            }
        }
    }
}
