plugins {
    id "fabric-loom" version "1.8-SNAPSHOT"
}

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

repositories {
    maven {
        name = "Meteor Dev Releases"
        url = "https://maven.meteordev.org/releases"
    }
    maven {
        name = "Meteor Dev Snapshots"
        url = "https://maven.meteordev.org/snapshots"
    }
    maven {
        name = "Modrinth"
        url = "https://api.modrinth.com/maven"
    }
}

dependencies {
    // Fabric
    minecraft "com.mojang:minecraft:${project.minecraft_version}"
    mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
    modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

    // Meteor
    modImplementation("meteordevelopment:meteor-client:${project.meteor_version}") {
        changing = true
    }

    // XaeroMinimap
    modImplementation("maven.modrinth:xaeros-minimap:${project.xaeros_minimap_version}")

    // XaeroWorldMap
    modImplementation "maven.modrinth:xaeros-world-map:${project.xaeros_worldmap_version}"

    configurations.configureEach {
        resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
    }
}

processResources {
    def propertyMap = [
        "version": project.version,
        "mc_version": project.minecraft_version,
        "commit": project.findProperty("commit") ?: ""
    ]

    inputs.properties(propertyMap)
    filesMatching("fabric.mod.json") {
        expand(propertyMap)
    }
}

tasks.withType(JavaCompile).configureEach {
    it.options.encoding("UTF-8")
}

tasks.register("sortImports", Exec) {
    description = "Runs import-organizer.py in the scripts folder to sort import blocks by length in all Java source files in the project."
    group = "build"

    var pythonCmd = System.getenv("OS") != null && System.getenv("OS").contains("Windows") ? "python" : "python3"

    commandLine(pythonCmd, "${projectDir}/scripts/import-organizer.py")

    setIgnoreExitValue(false)
}
