plugins {
    id 'multiloader-loader'
    id 'net.neoforged.moddev.legacyforge'
}
base {
    archivesName = "super_resolution-forge-${versionConfig.common.modArtifactMinecraftVer}"
}

repositories {
    if (System.getenv().containsKey("SR_DEV")) {
        maven {
            name "minecraftdevRepository"
            url "http://127.0.0.1:8080/releases"
        }
    }
    maven {
        url "https://cursemaven.com"
        content {
            includeGroup "curse.maven"
        }
    }
    maven {
        name = 'NeoForged'
        url = 'https://maven.neoforged.net/releases'
    }
    maven {
        name = "Modrinth"
        url = "https://api.modrinth.com/maven"
        content {
            includeGroup "maven.modrinth"
        }
    }
}

legacyForge {
    version = "${versionConfig.common.minecraftVersion}-${versionConfig.forge.loaderVersion}"
    runs {
        configureEach {
            additionalRuntimeClasspathConfiguration.dependencies.add(
                    dependencies.create(
                            group: "io.github.spair",
                            name: "imgui-java-app",
                            version: "1.87.5"
                    )
            )
            additionalRuntimeClasspathConfiguration.dependencies.add(
                    dependencies.create(
                            group: "io.github.spair",
                            name: "imgui-java-binding",
                            version: "1.87.5"
                    )
            )
            additionalRuntimeClasspathConfiguration.dependencies.add(
                    dependencies.create(
                            group: "io.github.spair",
                            name: "imgui-java-lwjgl3",
                            version: "1.87.5"
                    )
            )
            additionalRuntimeClasspathConfiguration.dependencies.add(
                    dependencies.create(
                            group: "org.lwjgl",
                            name: "lwjgl-vulkan",
                            version: "$versionConfig.common.lwjglVersion"
                    )
            )
        }
        client {
            client()
            gameDirectory = rootProject.file('runs/forge')
        }
    }
    mods {
        "${mod_id}" {
            sourceSet(sourceSets.main)
        }
    }

    parchment {
        minecraftVersion = versionConfig.common.parchmentVersion.split(":")[0]
        mappingsVersion = versionConfig.common.parchmentVersion.split(":")[1]
    }
}

mixin {
    add sourceSets.main, 'super_resolution.refmap.json'
    config 'super_resolution.mixins.json'
    config 'super_resolution-forge.mixins.json'
    config 'super_resolution-forge-compat.mixins.json'
    config 'super_resolution.shadercompat.mixins.json'

}

sourceSets.main.resources.srcDir 'src/generated/resources'
dependencies {
    compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
    annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT:processor")
    //implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
    compileOnly("org.jetbrains:annotations:25.0.0")
    implementation "io.github.spair:imgui-java-app:1.87.5"
    implementation "io.github.spair:imgui-java-binding:1.87.5"
    implementation "io.github.spair:imgui-java-lwjgl3:1.87.5"
    jarJar(implementation "org.lwjgl:lwjgl-vulkan:$versionConfig.common.lwjglVersion")

    modImplementation "dev.architectury:architectury-forge:$versionConfig.common.architecturyApiVersion"
    modImplementation "me.shedaniel.cloth:cloth-config-forge:$versionConfig.common.clothConfigVersion"
    implementation "net.fabricmc.fabric-api:fabric-api-base:0.4.39+80f8cf51bb"

    for (lib in versionConfig.forge.dependencies.modrinth) {
        if (lib.compileOnly) {
            modCompileOnly("maven.modrinth:${lib.name}:${lib.version}-forge,${versionConfig.common.minecraftVersion}")
        } else {
            modImplementation("maven.modrinth:${lib.name}:${lib.version}-forge,${versionConfig.common.minecraftVersion}")
        }
    }
    for (lib in versionConfig.forge.dependencies.local) {
        if (lib.isMod) {
            if (lib.compileOnly) {
                modCompileOnly(files("../libs/" + lib.name + ".jar"))
            } else {
                modImplementation(files("../libs/" + lib.name + ".jar"))
            }
        } else {
            if (lib.compileOnly) {
                compileOnly(files("../libs/" + lib.name + ".jar"))
            } else {
                implementation(files("../libs/" + lib.name + ".jar"))
            }
        }
    }
}

sourceSets.each {
    def dir = layout.buildDirectory.dir("sourcesSets/$it.name")
    it.output.resourcesDir = dir
    it.java.destinationDirectory = dir
}

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

    filesMatching('META-INF/mods.toml') {
        expand version: project.version
        filter { String line ->
            return line.replace('"{versionRange}"', '"' + versionConfig.common.forgeVersionRange + '"')
        }
    }
}

jar {
    manifest.attributes([
            "MixinConfigs": "super_resolution.mixins.json,super_resolution-forge.mixins.json,super_resolution-forge-compat.mixins.json,super_resolution.shadercompat.mixins.json"
    ])
}
