plugins {
    id 'com.github.johnrengelman.shadow'
    id "me.shedaniel.unified-publishing"
}

loom {
    forge {
        mixinConfig("colorwheel.mixins.json", "colorwheel.forge.mixins.json")
    }
    runs {
        client {
            property 'mixin.env.remapRefMap', 'true'
            property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
        }
    }
}

architectury {
    platformSetupLoomIde()
    forge()
}

configurations {
    common {
        canBeResolved = true
        canBeConsumed = false
    }
    compileClasspath.extendsFrom common
    runtimeClasspath.extendsFrom common
    developmentForge.extendsFrom common

    // Files in this configuration will be bundled into your mod using the Shadow plugin.
    // Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files.
    shadowBundle {
        canBeResolved = true
        canBeConsumed = false
    }
}

dependencies {
    forge "net.minecraftforge:forge:$rootProject.forge_version"
    forgeRuntimeLibrary "org.anarres:jcpp:1.4.14"

    common(project(path: ':common', configuration: 'namedElements')) { transitive false }
    shadowBundle project(path: ':common', configuration: 'transformProductionForge')

    modCompileOnly "dev.engine-room.flywheel:flywheel-forge-${minecraft_version}:${flywheel_version}"

    modLocalRuntime "dev.engine-room.flywheel:flywheel-forge-${minecraft_version}:${flywheel_version}"
    modLocalRuntime "dev.engine-room.vanillin:vanillin-forge-${minecraft_version}:${vanillin_version}"

    modCompileOnly "maven.modrinth:oculus:${oculus_version}"

    modLocalRuntime "maven.modrinth:embeddium:${embeddium_version}"
    modLocalRuntime "maven.modrinth:oculus:${oculus_version}"

    modLocalRuntime("com.simibubi.create:create-${minecraft_version}:${create_forge_version}:slim") { transitive = false }
    modLocalRuntime("net.createmod.ponder:Ponder-Forge-${minecraft_version}:${ponder_version}")
    modLocalRuntime("com.tterrag.registrate:Registrate:${registrate_forge_version}")
    localRuntime "io.github.llamalad7:mixinextras-forge:${mixin_extras_version}"
}

processResources {
    inputs.property 'version', project.version

    filesMatching('META-INF/mods.toml') {
        expand version: project.version
    }
}

shadowJar {
    configurations = [project.configurations.shadowBundle]
    archiveClassifier = 'dev-shadow'
}

remapJar {
    inputFile.set shadowJar.archiveFile
}

unifiedPublishing {
    project {
        displayName = "$project.version-forge"
        version = "$project.version"
        releaseType = "release"
        changelog = new File("${rootProject.rootDir.toPath().toString()}/CHANGELOG.md").getText('UTF-8')
        gameVersions = ["1.20.1"]
        gameLoaders = ["forge"]

        mainPublication remapJar

        relations {
            depends {
                curseforge = "oculus"
                modrinth = "oculus"
            }
            optional {
                curseforge = "create"
                modrinth = "create"
            }
            optional {
                curseforge = "vanillin"
                modrinth = "flw-vanillin"
            }
            optional {
                curseforge = "colorwheel-patcher"
                modrinth = "colorwheel-patcher"
            }
            conflicts {
                curseforge = "iris-flywheel-compat"
                modrinth = "iris-flw-compat"
            }
        }

        if (System.getenv("CF_TOKEN") != null) {
            curseforge {
                token = System.getenv("CF_TOKEN")
                id = "1254143"
            }
        }

        if (System.getenv("MODRINTH_TOKEN") != null) {
            modrinth {
                token = System.getenv("MODRINTH_TOKEN")
                id = "BzHgFoGz"
            }
        }
    }
}
