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

architectury {
    platformSetupLoomIde()
    forge()
}


loom {
    accessWidenerPath = project(":common").loom.accessWidenerPath

    forge {
        convertAccessWideners = true
        extraAccessWideners.add loom.accessWidenerPath.get().asFile.name

        mixinConfig  "immersive_weathering-common.mixins.json"
        mixinConfig  "immersive_weathering.mixins.json"

    }
}

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
    developmentForge.extendsFrom common
}


processResources {

    inputs.property "version", project.version
    inputs.property "moonlight_version", rootProject.moonlight_version
    //inputs.property "mod_name": project.getArchivesBaseName()

    filesMatching("META-INF/mods.toml") {
        expand "version": project.version, "moonlight_version": rootProject.moonlight_version
        expand "mod_name": project.getArchivesBaseName()
    }
}

shadowJar {
    exclude "fabric.mod.json"
    exclude "architectury.common.json"

    configurations = [project.configurations.shadowCommon]
    archiveClassifier = "dev-shadow"
}

remapJar {
    input.set shadowJar.archiveFile
    dependsOn shadowJar
    archiveClassifier = "forge"
}

jar {
    archiveClassifier = "dev"
}

sourcesJar {
    def commonSources = project(":common").sourcesJar
    dependsOn commonSources
    from commonSources.archiveFile.map { zipTree(it) }
}

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

publishing {
    publications {
        mavenForge(MavenPublication) {
            artifactId = rootProject.mod_id + "-" + project.name
            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.
        maven {
            url = "https://www.cursemaven.com"
            allowInsecureProtocol = true
        }
        maven {
            name = "TerraformersMC"
            url = "https://maven.terraformersmc.com/releases"
        }
    }
}


def dev_mods_dir = "mods_forge"

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }


repositories{
    maven { url "https://maven.terraformersmc.com/releases" }
    // Built mods
    flatDir {
        dirs dev_mods_dir
    }
    mavenCentral()
}

dependencies {
    forge "net.minecraftforge:forge:${rootProject.forge_version}"
    common(project(path: ":common", configuration: "namedElements")) { transitive false }
    shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }

    implementation 'org.jetbrains:annotations:22.0.0'

    modImplementation("curse.maven:selene-499980:5619074")

    modLocalRuntime "dev.emi:emi-forge:${rootProject.emi_version}"
}