plugins {
    id 'java'
}

group 'wtf.bhopper'
version '1.0'

sourceCompatibility = 1.8

project.ext.lwjglNatives = 'natives-windows'
project.ext.jinputNatives = 'natives-windows'
project.ext.imguiNatives = 'imgui-java-natives-windows'
project.ext.twitchNatives = 'natives-windows-64'

configurations {
    library
    nativeLib
}

repositories {
    mavenCentral()
    maven { url 'https://libraries.minecraft.net' }
    maven { url 'https://maven.meteordev.org/releases' }
    maven { url 'https://jitpack.io' }
}

dependencies {

    configurations.implementation.extendsFrom(configurations.library)

    // Minecraft libraries, taken from the 1.8.9.json file in the versions directory
    library 'commons-codec:commons-codec:1.9'
    library 'commons-io:commons-io:2.4'
    library 'commons-logging:commons-logging:1.1.3'
    library 'com.google.code.gson:gson:2.2.4'
    library 'com.google.guava:guava:17.0'
    library 'com.ibm.icu:icu4j-core-mojang:51.2'
    library 'com.mojang:authlib:1.5.21'
    library 'com.mojang:netty:1.8.8'
    library 'com.mojang:realms:1.7.59'
    library 'io.netty:netty-all:4.0.23.Final'
    library 'net.java.dev.jna:jna:3.4.0'
    library 'net.java.dev.jna:platform:3.4.0'
    library 'net.java.jinput:jinput:2.0.5'
    library 'net.java.jinput:jinput-platform:2.0.5'
    library 'net.java.jutils:jutils:1.0.0'
    library 'net.sf.jopt-simple:jopt-simple:4.6'
    library 'org.apache.commons:commons-compress:1.8.1'
    library 'org.apache.commons:commons-lang3:3.3.2'
    library 'org.apache.httpcomponents:httpclient:4.3.3'
    library 'org.apache.httpcomponents:httpcore:4.3.2'
    library 'org.apache.logging.log4j:log4j-api:2.24.0' // Log4j libraries need to be updated to the latest version to patch the Log4shell exploit
    library 'org.apache.logging.log4j:log4j-core:2.24.0'
    library 'oshi-project:oshi-core:1.1'
    library 'tv.twitch:twitch:6.5'

    // LWJGL
    library 'org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209'
    library 'org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209'

    library 'com.paulscode:codecjorbis:20101023'
    library 'com.paulscode:codecwav:20101023'
    library 'com.paulscode:libraryjavasound:20101123'
    library 'com.paulscode:librarylwjglopenal:20100824'
    library 'com.paulscode:soundsystem:20120107'


    // Other libraries used by Nonsense
    library 'javax.vecmath:vecmath:1.5.2'
    library 'meteordevelopment:orbit:0.2.3'
    library 'org.reflections:reflections:0.10.2'
    library 'com.github.Vatuu:discord-rpc:1.6.2'

    // Native libraries download
    configurations.implementation.extendsFrom(configurations.nativeLib)

    nativeLib "org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209:$lwjglNatives"
    nativeLib "net.java.jinput:jinput-platform:2.0.5:$jinputNatives"
    nativeLib "tv.twitch:twitch-platform:6.5:$twitchNatives"


}

jar {
    baseName 'client'
    version ''
}

task libraryJar(type: Jar) {
    baseName 'libs'
    version ''
    from configurations.library.collect { zipTree(it) }
    exclude('*.dll', '*.so', '*.dylib', '*.jnilib')
}

configure(libraryJar) {
    group = 'Nonsense'
}

jar.dependsOn(libraryJar)

task extractNatives(type: Copy) {
    from configurations.nativeLib.collect { zipTree(it).flatten() }
    include('*.dll')
    into "${buildDir}/libs/bin"
}

configure(extractNatives) {
    group = 'Nonsense'
}

compileJava.dependsOn(extractNatives)

task copyAssets(type: Copy) {
    from file(System.getenv("appdata")).getAbsolutePath() + "/.minecraft/assets"
    exclude 'skins/' // Too big :(
    into "${rootDir}/run/assets"

}

configure(copyAssets) {
    group = 'Nonsense'
}

