// https://maven.shedaniel.me/architectury-plugin/architectury-plugin.gradle.plugin/
// https://maven.shedaniel.me/dev/architectury/loom/dev.architectury.loom.gradle.plugin/
plugins {
    id "java"
    id "architectury-plugin" version "3.4-SNAPSHOT"
    id "dev.architectury.loom" version "1.10-SNAPSHOT" apply false
    id "moe.plushie.armourers_workshop.loom" version "2.3.10" apply false
}

architectury {
    minecraft = rootProject.minecraft_api_version
}

subprojects {
    apply plugin: "dev.architectury.loom"
    apply plugin: "moe.plushie.armourers_workshop.loom"

    sourceSets.forEach {
        it.java.srcDirs "../versions/${rootProject.minecraft_version}/${project.name}/src/${it.name}/java"
        it.resources.srcDirs "../versions/${rootProject.minecraft_version}/${project.name}/src/${it.name}/resources"
        it.java.srcDirs "../versions/library/${project.name}/src/${it.name}/java"
        it.resources.srcDirs "../versions/library/${project.name}/src/${it.name}/resources"
        it.java.srcDirs "../versions/gametest/${project.name}/src/${it.name}/java"
        it.resources.srcDirs "../versions/gametest/${project.name}/src/${it.name}/resources"
    }

    dependencies {
        minecraft "com.mojang:minecraft:${rootProject.minecraft_api_version}"
        // The following line declares the mojmap mappings, you may use other mappings as well
        mappings loom.officialMojangMappings()
        // The following line declares the yarn mappings you may select this one as well.
        // mappings "net.fabricmc:yarn:1.16.5+build.10:v2"
    }

    signJar {
        alias = System.getenv("AW_SIGN_ALIAS")
        keyPass = System.getenv("AW_SIGN_KEY_PASS")
        keyStore = System.getenv("AW_SIGN_STORE")
        keyStorePass = System.getenv("AW_SIGN_STORE_PASS")
    }
}

allprojects {
    apply plugin: "architectury-plugin"
    apply plugin: "maven-publish"

    if (version == "unspecified") {
        version = "2.0.0-homebaked"
    }

    def uname = rootProject.archives_base_name.replaceAll("-", "")

    group = rootProject.maven_group
    archivesBaseName = "${uname.toLowerCase()}-${project.name}-${rootProject.minecraft_version}"
    targetCompatibility = rootProject.java_version
    sourceCompatibility = 16

    repositories {
        // Add repositories to retrieve artifacts from in here.
        // You should only use this when depending on other mods because
        // Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
        // See https://docs.gradle.org/current/userguide/declaring_repositories.html
        // for more information about repositories.
        mavenLocal()
        maven { url "https://maven.neoforged.net/releases/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://api.modrinth.com/maven/" }
        maven { url "https://cursemaven.com/" }
        maven { url "https://maven.blamejared.com/" }
    }

    dependencies {
        compileOnly "systems.manifold:manifold-ext:${rootProject.manifold_version}"
        annotationProcessor "systems.manifold:manifold-ext:${rootProject.manifold_version}"
        testCompileOnly "systems.manifold:manifold-ext:${rootProject.manifold_version}"
        testAnnotationProcessor "systems.manifold:manifold-ext:${rootProject.manifold_version}"
    }

    tasks.withType(JavaCompile) {
        options.encoding = "UTF-8"
        options.compilerArgs << "-Xplugin:Manifold no-bootstrap"
    }

    java {
        withSourcesJar()
    }
}