import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

buildscript {
    repositories {
        gradlePluginPortal()
        maven {
            name = "forge"
            url = "https://maven.minecraftforge.net/"
        }
        maven {
            name = "SpongePowered"
            url = "https://repo.spongepowered.org/repository/maven-public/"
        }
    }
    dependencies {
        classpath "net.minecraftforge.gradle:ForgeGradle:5+"
        classpath "org.spongepowered:mixingradle:0.7-SNAPSHOT"
        classpath "gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0"
    }
}
apply plugin: "net.minecraftforge.gradle"
apply plugin: "org.spongepowered.mixin"
apply plugin: "com.github.johnrengelman.shadow"

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8

minecraft {
    mappings channel: "stable", version: "39-1.12"
}

dependencies {
    // minecraftforge dependency
    minecraft "net.minecraftforge:forge:1.12.2-14.23.5.2854"

    implementation "dev.tigr:simpleevents:1.2"
    implementation 'org.json:json:20211205'
    implementation "com.mojang:brigadier:1.0.17"
    implementation "com.github.Vatuu:discord-rpc:1.6.2"

    // ares core
    implementation project(":ares-core")
    shadow(project(":ares-core")) {
        exclude group: "org.apache.logging.log4j", module: "log4j-api"
        exclude group: "com.google.guava", module: "guava"
    }

    // ares installer
    implementation project(":ares-installer")
    shadow(project(":ares-installer"))

    // mixins
    implementation "org.spongepowered:mixin:0.7.11-SNAPSHOT"
    shadow("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
        exclude module: "launchwrapper"
        exclude module: "guava"
        exclude module: "gson"
        exclude module: "commons-io"
        exclude module: "log4j-core"
    }
    annotationProcessor("org.spongepowered:mixin:0.8.5:processor")

    // baritone
    implementation "com.github.cabaletta:baritone:1.2.14"
    implementation "cabaletta:baritone-api:1.2"
    shadow "cabaletta:baritone-api:1.2"
}

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

    from(sourceSets.main.resources.srcDirs) {
        duplicatesStrategy = DuplicatesStrategy.INCLUDE
        expand "version": project.version
    }

    from(sourceSets.main.resources.srcDirs) {
        duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    }
}

mixin {
    defaultObfuscationEnv "searge"
    add sourceSets.main, "mixins.ares.refmap.json"
}

task customShadowJar(type: ShadowJar) {
    configurations = [project.configurations.shadow]
    archiveClassifier.set("release")
    from project.file("build/libs/ares-forge-${project.aresVersion}.jar")
    from project.file("${project.tasks[sourceSets.main.compileJavaTaskName].temporaryDir}/mixins.ares.refmap.json")
    exclude("META-INF/MUMFREY.RSA")
    exclude("META-INF/MUMFREY.SF")

    //noinspection GroovyAssignabilityCheck
    manifest {
        attributes(
                "MixinConfigs": "mixins.ares.json",
                "TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
                "TweakOrder": 0,
                "FMLCorePluginContainsFMLMod": "true",
                "FMLCorePlugin": "dev.tigr.ares.forge.mixin.MixinLoader",
                "ForceLoadAsMod": "true",
                "Main-Class": "dev.tigr.ares.installer.Installer"
        )
    }
}
build.dependsOn(customShadowJar)