plugins {
    id 'multiloader-loader'
    id 'net.neoforged.moddev'
}

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"
        }
    }
}

configurations {
    libraries
}

sourceSets {
    main {
        resources {
            srcDir 'src/generated/resources'
        }
    }

    configureEach {
        it.runtimeClasspath += configurations.libraries
    }
}


neoForge {
    version = versionConfig.neoforge.loaderVersion
    parchment {
        minecraftVersion = versionConfig.common.parchmentVersion.split(":")[0]
        mappingsVersion = versionConfig.common.parchmentVersion.split(":")[1]
    }
    runs {
        configureEach {
            jvmArguments.add("-XX:+CreateMinidumpOnCrash")
            //jvmArguments.add("-Dorg.lwjgl.util.Debug=true")
            //jvmArguments.add("-Dorg.lwjgl.util.DebugAllocator=true")
            //environment("ENABLE_VULKAN_RENDERDOC_CAPTURE", "1")
            systemProperty('neoforge.enabledGameTestNamespaces', mod_id)
            ideName = "NeoForge ${it.name.capitalize()} (${project.path})"
            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/neoforge')
        }
    }
    mods {
        "${mod_id}" {
            sourceSet sourceSets.main
        }
    }
}

dependencies {
    libraries(implementation("io.github.spair:imgui-java-app:1.87.5"))
    libraries(implementation("io.github.spair:imgui-java-binding:1.87.5"))
    libraries(implementation("io.github.spair:imgui-java-lwjgl3:1.87.5"))
    libraries(jarJar(implementation("org.lwjgl:lwjgl-vulkan:$versionConfig.common.lwjglVersion")))


    implementation "dev.architectury:architectury-neoforge:$versionConfig.common.architecturyApiVersion"
    implementation "me.shedaniel.cloth:cloth-config-neoforge:$versionConfig.common.clothConfigVersion"
    implementation "net.fabricmc.fabric-api:fabric-api-base:0.4.64+9ec45cd8e8"

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

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

    filesMatching('META-INF/neoforge.mods.toml') {
        expand(
                version: project.version,
                versionRange: versionConfig.common.neoforgeVersionRange
        )
    }
}