plugins {
    id "java-library"
    id "net.neoforged.moddev" version "${moddev_version}"
}

version = project.mod_version
group = project.maven_group

base {
    archivesName = "${project.archives_base_name}-neoforge"
}

dependencies {
    implementation project(path: ":common", configuration: "namedElements")
}

sourceSets {
    main {
        java {
            srcDir "../common/src/main/java"
        }
        resources {
            srcDir "../common/src/main/resources"
        }
    }
}

neoForge {
    version = project.neoforge_version

    if (
        project.parchment_minecraft_version?.trim()
        && project.parchment_mappings_version?.trim()
    ) {
        parchment {
            minecraftVersion = project.parchment_minecraft_version
            mappingsVersion = project.parchment_mappings_version
        }
    }

    runs {
        client {
            client()
            gameDirectory = project.file("../run")
        }

        server {
            server()
            gameDirectory = project.file("../run")

            programArgument "--nogui"
        }

        configureEach {
            // Recommended logging data for a userdev environment
            // The markers can be added/remove as needed separated by commas.
            // "SCAN": For mods scan.
            // "REGISTRIES": For firing of registry events.
            // "REGISTRYDUMP": For getting the contents of all registries.
            systemProperty "forge.logging.markers", "REGISTRIES"

            // Recommended logging level for the console
            // You can set various levels here.
            // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
            logLevel = org.slf4j.event.Level.DEBUG
        }
    }

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

// Include resources generated by data generators.
sourceSets.main.resources {
    srcDir "src/generated/resources"
}

// Sets up a dependency configuration called 'localRuntime'.
// This configuration should be used instead of 'runtimeOnly' to declare
// a dependency that will be present for runtime testing but that is
// "optional", meaning it will not be pulled by dependents of this mod.
configurations {
    runtimeClasspath.extendsFrom localRuntime
}

// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
    var replaceProperties = [
        version: project.version,
    ]
    inputs.properties replaceProperties
    expand replaceProperties
    from "src/main/templates"
    into "../build/generated/sources/modMetadata"
}
// Include the output of "generateModMetadata" as an input directory for the build
// this works with both building through Gradle and the IDE.
sourceSets.main.resources.srcDir generateModMetadata
// To avoid having to run "generateModMetadata" manually, make it run on every project reload
neoForge.ideSyncTask generateModMetadata

java {
    withSourcesJar()

    toolchain.languageVersion = JavaLanguageVersion.of(21)

    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}

jar {
    from "../LICENSE"
}

sourcesJar {
    from "../LICENSE"
}
