import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

apply plugin: "application"

application {
    mainClassName = "net.minecraft.client.main.Main"
}

run {
    workingDir = new File(buildDir, "run")
    if (!workingDir.exists()) {
        workingDir.mkdir()
    }

    systemProperty "java.library.path", file("$buildDir/natives")
    args "--version", "1.8.8", "--accessToken", "0", "--assetsDir", "assets", "--assetIndex", "1.8", "--userProperties", "{}"
}

dependencies {
    implementation name: "com/mojang/authlib/1.5.21/authlib-1.5.21"
    implementation name: "tv/twitch/twitch/6.5/twitch-6.5"
    implementation name: "com/paulscode/soundsystem/20120107/soundsystem-20120107"
    implementation name: "com/paulscode/codecjorbis/20101023/codecjorbis-20101023"
    implementation name: "com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824"
    implementation name: "oshi-project/oshi-core/1.1/oshi-core-1.1"

    implementation "org.lwjgl.lwjgl:lwjgl:2.9.3"
    implementation "org.lwjgl.lwjgl:lwjgl_util:2.9.3"

    implementation "com.ibm.icu:icu4j:52.2"
    implementation "net.sf.jopt-simple:jopt-simple:4.6"
    implementation "org.apache.commons:commons-lang3:3.3.2"
    implementation "com.google.guava:guava:17.0"
    implementation "org.apache.logging.log4j:log4j-core:2.0-beta9"
    implementation "io.netty:netty-all:4.0.23.Final"
    implementation "com.google.code.gson:gson:2.2.4"
    implementation "commons-io:commons-io:2.4"
}

tasks.register("copyNatives").configure {
    doLast {
        def classifier
        def suffix
        if (DefaultNativePlatform.currentOperatingSystem.isWindows()) {
            classifier = "natives-windows"
            suffix = "-natives-windows"
        } else {
            classifier = "natives-linux"
            suffix = "-natives-linux"
        }

        copy {
            def resolvedArtifacts = configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts
            def matches = resolvedArtifacts.findAll {it.classifier == classifier || it.name.endsWith(suffix)}
            from matches.collect { it.file }.collect { zipTree(it).matching { exclude "META-INF/**" } }
            into "$buildDir/natives"
        }
    }
}