plugins {
    id 'java-library'
    id 'idea'
    id 'maven-publish'
    id 'net.neoforged.gradle.userdev' version '7.0.165'
}

tasks.named('wrapper', Wrapper).configure {
    // Define wrapper values here so as to not have to always do so when updating gradlew.properties.
    // Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with
    // documentation attached on cursor hover of gradle classes and methods. However, this comes with increased
    // file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards.
    // (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`)
    distributionType = Wrapper.DistributionType.BIN
}

group = mod_group_id
version = "${minecraft_version}-" + mod_version

libsDirName = "../output"
distsDirName = "../output"

repositories {
    mavenLocal()
}

base {
    archivesName = mod_id
}

java.toolchain.languageVersion = JavaLanguageVersion.of(21)

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))



minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')

runs {

    configureEach {

        systemProperty 'forge.logging.markers', 'REGISTRIES'

        systemProperty 'forge.logging.console.level', 'debug'

        modSource project.sourceSets.main
    }

    client {

        systemProperty 'forge.enabledGameTestNamespaces', project.mod_id

    }

    server {

        systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
        programArgument '--nogui'

    }

    gameTestServer {

        systemProperty 'forge.enabledGameTestNamespaces', project.mod_id

    }

    data {

        programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()

    }
}

sourceSets.main.resources { srcDir 'src/generated/resources' }

configurations {
    runtimeClasspath.extendsFrom localRuntime
}

dependencies {
    def Folder = new File("C:/AmpzLibz/1.21")
    if(Folder.exists()) {
        implementation fileTree(Folder)
    }
    def Folder2 = new File("libs")
    if(Folder2.exists()) {
        implementation fileTree(Folder2)
    }

    implementation "net.neoforged:neoforge:${neo_version}"
    compileOnly "mezz.jei:jei-${minecraft_version}-common-api:${jei_version}"
    compileOnly "mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}"
    localRuntime "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}"
    compileOnly "mekanism:Mekanism:${mekanism_version}"
    //runtimeOnly "mekanism:Mekanism:${mekanism_version}"
   
}

tasks.register('sourcesJar', Jar).configure {
    dependsOn classes
    from sourceSets.main.allSource
    archiveClassifier = 'sources'
}

tasks.register('deobfJar', Jar).configure {
    from sourceSets.main.output
    archiveClassifier = 'deobf'
}

tasks.named('publish').configure {
    dependsOn 'reobfJar'
}


tasks.withType(ProcessResources).configureEach {
    var replaceProperties = [
            minecraft_version      : minecraft_version,
            minecraft_version_range: minecraft_version_range,
            neo_version            : neo_version,
            neo_version_range      : neo_version_range,
            loader_version_range   : loader_version_range,
            mod_id                 : mod_id,
            mod_name               : mod_name,
            mod_license            : mod_license,
            mod_version            : mod_version,
            mod_authors            : mod_authors,
            mod_description        : mod_description
    ]
    inputs.properties replaceProperties

    filesMatching(['META-INF/neoforge.mods.toml']) {
        expand replaceProperties
    }
}

artifacts {
    archives sourcesJar
    archives deobfJar
}

publishing {
    publications {
        register('mavenJava', MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            url "file://${project.projectDir}/repo"
        }
    }
}

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

idea {
    module {
        downloadSources = true
        downloadJavadoc = true
    }
}

repositories {
    maven {
        // location of the maven that hosts JEI files since January 2023
        name = "Jared's maven"
        url = "https://maven.blamejared.com/"
    }
    maven {
        // location of a maven mirror for JEI files, as a fallback
        name = "ModMaven"
        url = "https://modmaven.dev"
    }
}