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

architectury {
    platformSetupLoomIde()
    forge()
}

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

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

        mixinConfig "dimdoors-common.mixins.json"
        mixinConfig "dimdoors.mixins.json"
    }
}

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

dependencies {
    forge "net.minecraftforge:forge:${rootProject.forge_version}"
    // Remove the next line if you don't want to depend on the API
    modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"
    modApi "me.shedaniel.cloth:cloth-config-forge:${rootProject.cloth_config}"
    common(project(path: ":common", configuration: "namedElements")) { transitive false }
    shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }

    include "com.flowpowered:flow-math:1.0.3"
    include "org.jgrapht:jgrapht-core:1.1.0"
    include "com.github.DimensionalDevelopment:poly2tri.java:0.1.1"

    modApi "mcp.mobius.waila:wthit-api:forge-${wthitVersion}"
//    modApi "lol.bai:badpackets:forge-0.4.2"
//    modApi "com.sk89q.worldedit:worldedit-forge-mc${rootProject.world_edit_minecraft_version}:${rootProject.worldedit}"
    modApi("curse.maven:worldedit-${project.properties["worldedit_CF"]}:${project.properties["worldedit_CF_version"]}")
    modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-forge:$rei_version"
    modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-forge:$rei_version"
    modCompileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin-forge:$rei_version"

//    modApi("curse.maven:jei-${project.properties["jei_project"]}:${project.properties["jei_forge"]}")
}

processResources {
//    inputs.property "version", project.version
//    inputs.property "minecraft_version", minecraft_version
//    inputs.property "architectury_version", architectury_version
//    inputs.property "cloth_config_version", cloth_config

    def props = [
            "version": project.version,
            "minecraft_version": minecraft_version,
            "architectury_version": architectury_version,
            "cloth_config_version": cloth_config
    ]

    filesMatching("META-INF/mods.toml") {
        expand props
    }

    from(rootProject.file("common/src/main/resources")) {
        include("**/**")
        duplicatesStrategy = DuplicatesStrategy.WARN
    }
}

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

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

remapJar {
    inputFile.set(shadowJar.archiveFile)
    dependsOn shadowJar
    archiveClassifier = "${project.properties["minecraft_version"]}-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()
    }
}

sourceSets {
    main {
        resources {
            srcDirs += [
                    project(":common").file("src/main/generated")
            ]
        }
    }
}