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

architectury {
    platformSetupLoomIde()
    fabric()
}

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

configurations {
    common
    shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files.
    compileClasspath.extendsFrom common
    runtimeClasspath.extendsFrom common
    developmentFabric.extendsFrom common
}

dependencies {
    // Libraries
    compileOnly("com.github.FiguraMC.luaj:luaj-core:$luaj-figura")
    compileOnly("com.github.FiguraMC.luaj:luaj-jse:$luaj-figura")
    compileOnly("com.neovisionaries:nv-websocket-client:$nv_websocket")

    //  Mod menu
    modImplementation("com.terraformersmc:modmenu:$modmenu_version")

    modImplementation "net.fabricmc:fabric-loader:$fabric_loader_version"
    modApi "net.fabricmc.fabric-api:fabric-api:$fabric_api_version+$minecraft_version"

    // Figura fabric
    modImplementation("org.figuramc:figura-fabric:$figura_version+1.20.1")

    common(project(path: ":common", configuration: "namedElements")) { transitive false }
    shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
}

processResources {
Map<String, Object> properties = new HashMap<>()

    properties.put("version", project.version)
    properties.put("java_version", java_version)
    properties.put("minecraft_version", minecraft_version)
    properties.put("minecraft_version_out", minecraft_version_out)
    properties.put("figura_version", figura_version)
    properties.put("fabric_api_version", fabric_api_version)
    properties.put("mod_id", plugin_id)
    properties.put("display_name", display_name)
    properties.put("description", project.description)
    properties.put("authors", authors)
    properties.put("figura_version", figura_version)

    properties.forEach((k, v) -> inputs.property(k, v.toString()))
    filesMatching("fabric.mod.json") {
        expand properties
    }
}

shadowJar {
    exclude "architectury.common.json"

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

remapJar {
    injectAccessWidener = true
    input.set shadowJar.archiveFile
    dependsOn shadowJar
    archiveClassifier =  null
}

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 {
        mavenFabric(MavenPublication) {
            artifactId = archives_base_name + "-" + 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.
    }
}
