buildscript {
    repositories {
        mavenCentral()
        maven { url "https://maven.minecraftforge.net" }
        maven {
            name = "GTNH Maven"
            url = uri("https://nexus.gtnewhorizons.com/repository/public/")
        }
        maven {
            name = "LegacyModdingMC"
            url = uri("https://maven.legacy-modding.dev/releases")
        }
    }
}

plugins {
    id 'java'
    id 'com.gtnewhorizons.retrofuturagradle' version '1.3.24'
}

group = modGroup
version = modVersion
archivesBaseName = modName

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(8))
    }
}

if (enableModernJavaSyntax.toBoolean()) {
    dependencies {
        annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
        compileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') {
            transitive = false
        }
    }

    tasks.withType(JavaCompile).configureEach {
        sourceCompatibility = 17
        options.release.set(8)

        javaCompiler.set(javaToolchains.compilerFor {
            languageVersion.set(JavaLanguageVersion.of(17))
        })
    }
}

if (generateGradleTokenClass) {
    tasks.named("injectTags").configure {
        outputClassName.set(generateGradleTokenClass)
    }
    tasks.named("compileJava").configure {
        dependsOn("injectTags")
    }
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

minecraft {
    mcVersion = minecraftVersion
    username = developmentEnvironmentUserName

    if (gradleTokenModId) {
        injectedTags.put gradleTokenModId, modId
    }
    if (gradleTokenModName) {
        injectedTags.put gradleTokenModName, modName
    }
    if (gradleTokenVersion) {
        injectedTags.put gradleTokenVersion, modVersion
    }
    if (gradleTokenGroupName) {
        injectedTags.put gradleTokenGroupName, modGroup
    }

    if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
        extraRunJvmArguments.add("-Dmixin.env.disableRefMap=true")
    }

    if (coreModClass) {
        extraRunJvmArguments.add("-Dfml.coreMods.load=${modGroup}.${coreModClass}")
    }
}


repositories {
    flatDir { dirs 'libs' }

    mavenCentral()

    maven {
        url = uri("https://maven.minecraftforge.net")
    }

    maven {
        name = "GTNH Maven"
        url = uri("https://nexus.gtnewhorizons.com/repository/public/")
    }

    maven {
        name = "LegacyModdingMC"
        url = uri("https://maven.legacy-modding.dev/releases")
    }
}

dependencies {
    implementation name: 'cindercore'
    implementation name: 'lotr'
    implementation name: 'optifine'
    implementation name: 'variabletriggers'
    implementation name: 'metweaks'

    if (usesMixins.toBoolean()) {
        annotationProcessor("io.github.legacymoddingmc:unimixins:0.1.13:dev")
        implementation(modUtils.enableMixins("io.github.legacymoddingmc:unimixins:0.1.13:dev", "mixins.${modId}.refmap.json"))
    }
}

jar {
    manifest {
        attributes(
            "FMLCorePlugin": "${modGroup}.${coreModClass}",
            "FMLCorePluginContainsFMLMod": "true",
            "TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
            "MixinConfigs": "mixins.${modId}.json",
            "ForceLoadAsMod": "true"
        )
    }
}

tasks.processResources {
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.mcVersion

    filesMatching("mcmod.info") {
        expand(
            "minecraftVersion": project.minecraft.mcVersion,
            "modVersion": modVersion,
            "modId": modId,
            "modName": modName
        )
    }
}
