plugins {
    id 'java-library'
    id 'eclipse'
    id 'idea'
    id 'maven-publish'
    id 'net.neoforged.moddev' version '2.0.123'
}

tasks.named('wrapper', Wrapper).configure {
    distributionType = Wrapper.DistributionType.BIN
}

version = mod_version
group = mod_group_id

repositories {
    mavenLocal()
    maven {
        name = "Jared's maven"
        url = "https://maven.blamejared.com/"
    }
    maven {
        name = "ModMaven"
        url = "https://modmaven.dev"
    }
}

base {
    archivesName = mod_id
}

// NeoForge requires Java 21 - Gradle will automatically download it if needed
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

neoForge {
    version = project.neo_version

    // Default run configurations.
    runs {
        client {
            client()
            systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
        }

        server {
            server()
            programArgument '--nogui'
            systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
        }

        gameTestServer {
            type = 'gameTestServer'
            systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
        }

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

        configureEach {
            systemProperty 'forge.logging.markers', 'REGISTRIES'
            logLevel = org.slf4j.event.Level.DEBUG
        }
    }

    mods {
        "${mod_id}" {
            sourceSet(sourceSets.main)
        }
    }
}

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

configurations {
    runtimeClasspath.extendsFrom localRuntime
}

dependencies {
    // KubeJS dependency - version will need to be updated for 1.21
    // localRuntime "dev.latvian.mods:kubejs-neoforge:${kubejs_version}"
	
	testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
    testImplementation 'org.mockito:mockito-core:4.5.1'
    testImplementation 'org.mockito:mockito-junit-jupiter:4.5.1'
}

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
    }
}

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'
}

tasks.withType(Test).configureEach {
    useJUnitPlatform()
}

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