buildscript {
    repositories {
        maven { url = "https://maven.minecraftforge.net" }
        mavenCentral()
    }
    dependencies {
		    //Leave FG5 at this version.  Newer versions do fucky stuff with 1.12.2 builds that result in odd Gradle errors.
        classpath group: "net.minecraftforge.gradle", name: "ForgeGradle", version: "5.1.60", changing: true
    }
}

//Apply plugins
apply plugin: "net.minecraftforge.gradle"
apply plugin: "eclipse"

//Set file name.
version = "${project.mc_version}-${project.mod_version}"
group = project.mod_group
archivesBaseName = project.archive_name

//Options for Java version to compile to.
//This won't work with Java 17 compilers, but is required for eclipse file generation.  Un-comment when running gradlew eclipse or manually set IDE version.
//java.toolchain.languageVersion = JavaLanguageVersion.of(8)
compileJava {
    options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
		options.release = 8
}

//Minecraft mappings and run configs.
minecraft {
    // The mappings can be changed at any time, and must be in the following format.
    // Channel:   Version:
    // snapshot   YYYYMMDD   Snapshot are built nightly.
    // stable     #          Stables are built at the discretion of the MCP team.
    // official   MCVersion  Official field/method names from Mojang mapping files
    mappings channel: project.mappings_channel, version: project.mappings_version

    //Run configurations.
    runs {
        client {
            workingDirectory file("run")
        }

        //Run the server in a different directory so that the run directory isn't a mess
        server {
            workingDirectory file("runServer")
        }
    }
}

repositories {
    //JEI
    maven { url = "https://dvs1.progwml6.com/files/maven/" }
}

//Configuration that holds jars to include in the jar
configurations {
    embed
    implementation.extendsFrom(embed)
}

//Specify dependencies.
dependencies {
    //Minecraft to use.
    minecraft "net.minecraftforge:forge:${project.mc_version}-${project.forge_version}"
		
		//Core to use.
    embed(project(":mccore"))


    //Compile against the JEI API but do not include it at runtime
    compileOnly fg.deobf("mezz.jei:${project.jei_api_version}")
    //At runtime, use the full JEI jar
    //Disabled as Access Transformers don"t work on FG 3.0 runtimes despite them saying they do.
    //Not a huge issue, as it just prevents using JEI in-dev, and we already have it working so don"t really need to test.
    //runtimeOnly fg.deobf("mezz.jei:${project.jei_run_version}")
}

jar {
    //Zip all embeds and add them to the jar
    configurations.embed.each { dependency ->
        from(project.zipTree(dependency)) {
            dependency.isDirectory() ? dependency : zipTree(dependency)
            rename("LICENSE.txt", "org/spongepowered/LICENSE.txt")
            exclude(["META-INF/*.SF", "META-INF/*.RSA", "META-INF/*.MF", "**/*.html", "module-info.class"])
        }
    }
}

tasks.withType(JavaCompile).configureEach {
    options.encoding = "UTF-8" // Use the UTF-8 charset for Java compilation
}

//Now compile the mod.
jar.finalizedBy("reobfJar")
