plugins {
    id "com.github.johnrengelman.shadow" version "7.0.0"
}

architectury {
    platformSetupLoomIde()
    neoForge()
}

configurations {
    common
    shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
    compileClasspath.extendsFrom common
    runtimeClasspath.extendsFrom common
    developmentNeoForge.extendsFrom common
    dev
}

loom {
    accessWidenerPath = project(":common").file("src/main/resources/ftblibrary.accesswidener")
}

artifacts {
    dev(jar)
}

repositories {
    maven {
        url "https://maven.neoforged.net/releases/"
    }
}

dependencies {
    neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}"

    modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_version}"

    // modCompileOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${rootProject.rei_version}"
    //modCompileOnly("mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}")
    // modCompileOnly("mezz.jei:jei-1.21.1-neoforge-api:${jei_version}")

    common(project(path: ":common", configuration: "dev")) { transitive false }
    shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive false }
}

apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/extra-local-mods.gradle"

processResources {
    exclude '.cache'

    inputs.property "version", project.version

    filesMatching("META-INF/neoforge.mods.toml") {
        expand "version": project.version,
                "archversion": project.architectury_version,
                "neoforgeversionrange": project.neoforge_version_range,
                "neoforgeloaderversion": project.neoforge_loader_version,
                "mcversion": project.minecraft_version
    }
}

shadowJar {
    exclude "fabric.mod.json"

    configurations = [project.configurations.shadowCommon]
    setArchiveClassifier("dev-shadow")
}

remapJar {
    inputFile.set shadowJar.archiveFile
    dependsOn shadowJar
    archiveBaseName.set "${rootProject.archives_base_name}-${project.name}"
    archiveClassifier.set null
    atAccessWideners.add('ftblibrary.accesswidener')
}

jar {
    manifest {
        attributes([
                "Specification-Title"     : project.mod_id,
                "Specification-Vendor"    : project.mod_author,
                "Specification-Version"   : "1",
                "Implementation-Title"    : project.name,
                "Implementation-Version"  : version,
                "Implementation-Vendor"   : project.mod_author,
                "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
        ])
    }

    setArchiveClassifier("dev")
}

components.java {
    withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
        skip()
    }
}

publishing {
    publications {
        mavenForge(MavenPublication) {
            artifactId = "${rootProject.archives_base_name}-${project.name}"
            version ftbPublishing.mavenVersion
            from components.java
        }
    }
}
