plugins {
    id 'net.fabricmc.fabric-loom' version '1.15-SNAPSHOT'
    id 'maven-publish'
    id "com.modrinth.minotaur" version "2.+"
}

version = project.mod_version
group = project.maven_group

base {
    archivesName = project.archives_base_name
}


repositories {
    maven {
        name="Terraformers"
        url="https://maven.terraformersmc.com/"
    }
    maven {
        name 'Xander Maven'
        url 'https://maven.isxander.dev/releases'
    }
}

dependencies {
    minecraft "com.mojang:minecraft:${project.minecraft_version}"
    implementation "net.fabricmc:fabric-loader:${project.loader_version}"

    //Fabric API
    implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
    //ModMenu
    implementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
    //Yacl
    implementation "dev.isxander:yet-another-config-lib:${project.yacl_version}"
}

processResources {
    inputs.property "version", project.version
    inputs.property "minecraft_version", project.minecraft_version
    inputs.property "loader_version", project.loader_version
    filteringCharset "UTF-8"

    filesMatching("fabric.mod.json") {
        expand "version": project.version,
                "minecraft_version": project.minecraft_version,
                "loader_version": project.loader_version
    }
}

def targetJavaVersion = 25
tasks.withType(JavaCompile).configureEach {
    it.options.encoding = "UTF-8"
    if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
        it.options.release.set(targetJavaVersion)
    }
}

java {
    def javaVersion = JavaVersion.toVersion(targetJavaVersion)
    if (JavaVersion.current() < javaVersion) {
        toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
    }
    withSourcesJar()
}

jar {
    from("LICENSE") {
        rename { "${it}_${project.archives_base_name}" }
    }
}

modrinth {
    token = System.getenv("MODRINTH_TOKEN")
    projectId = "5iOVOX8K" //https://modrinth.com/mod/simple-transport-hud
    version = project.version
    versionType = project.versionType
    uploadFile = jar
    gameVersions = [project.minecraft_version]
    loaders = ["fabric"]
    dependencies {
        required.project "fabric-api"
        required.project "yacl"
        required.project "modmenu"
    }
}