plugins {
    id 'dev.architectury.loom' version '1.10-SNAPSHOT' apply false
    id 'architectury-plugin' version '3.4-SNAPSHOT'
    id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
}

architectury {
    minecraft = project.minecraft_version
}

allprojects {
    def loader = project.findProperty("loom.platform") ?: "common"

    group = rootProject.maven_group
    version = "${rootProject.mod_version}+${rootProject.minecraft_version}-${loader}"
}

subprojects {
    apply plugin: 'dev.architectury.loom'
    apply plugin: 'architectury-plugin'
    apply plugin: 'maven-publish'

    base {
        archivesName = rootProject.mod_id
    }

    repositories {
        maven {
            name = 'NeoForged'
            url = 'https://maven.neoforged.net/releases'
        }
        maven {
            name = 'Kotlin for Forge'
            url = 'https://thedarkcolour.github.io/KotlinForForge/'
        }
        maven {
            name = "QuiltMC"
            url = "https://maven.quiltmc.org/repository/release/"
        }
        maven {
            name = "modrinth"
            url = "https://api.modrinth.com/maven"
        }
        maven {
            url = "https://maven.terraformersmc.com/releases/"
        }
        maven {
            url = "https://gitlab.com/api/v4/projects/21830712/packages/maven"
        }
        maven {
            name = "Xander Maven"
            url = "https://maven.isxander.dev/releases"
        }
        maven {
            url = "https://maven.architectury.dev/"
        }
        maven {
            name = "SmartBrainLib (SBL) Maven Repo"
            url = "https://dl.cloudsmith.io/public/tslat/sbl/maven/"
        }
        maven {
            name = 'ParchmentMC'
            url = 'https://maven.parchmentmc.org'
        }
        maven {
            url = "https://maven.shedaniel.me/"
        }
    }

    dependencies {
        // Minecraft
        minecraft("com.mojang:minecraft:${rootProject.minecraft_version}")
    }

    processResources {
        Map<String, Object> properties = [
            "version"              : project.version,
            "fabric_loader_version": rootProject.fabric_loader_version,
            "fabric_api_version"   : rootProject.fabric_api_version,
            "neoforge_version"     : rootProject.neoforge_version,
            "architectury_version" : rootProject.architectury_version,
            "sbl_version"          : rootProject.sbl_version,
            "yacl_version"         : rootProject.yacl_version
        ]

        properties.each { key, value ->
            inputs.property(key, value)
        }

        filesMatching(["fabric.mod.json", "META-INF/neoforge.mods.toml"]) {
            expand(properties)
        }
    }

    tasks.register("cleanGenerated", Delete) {
        delete file("src/main/generated")
    }

    tasks.withType(JavaCompile).configureEach {
        it.dependsOn tasks.named("cleanGenerated")
    }

    tasks.withType(JavaCompile).configureEach {
        it.options.release = 21
    }

    java {
        // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
        // if it is present.
        // If you remove this line, sources will not be generated.
        withSourcesJar()

        sourceCompatibility = JavaVersion.VERSION_21
        targetCompatibility = JavaVersion.VERSION_21
    }

// If you plan to use a different file for the license, don't forget to change the file name here!
    jar {
        from("LICENSE.md") {
            rename { "${it}_${project.base.archivesName.get()}" }
        }
    }

// Configure the maven publication
    publishing {
        publications {
            create("mavenJava", MavenPublication) {
                artifactId = project.base.archivesName.get()
                from components.java
            }
        }

        // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
        repositories {
            // Add repositories to publish to here.
            // Notice: This block does NOT have the same function as the block in the top level.
            // The repositories here will be used for publishing your artifact, not for
            // retrieving dependencies.
        }
    }
}