plugins {
    id 'java-library'
    id 'maven-publish'
    id 'net.neoforged.moddev' version '1.0.21'
}

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

version = mod_version
group = mod_group_id

repositories {
    mavenLocal()
    maven { url = "https://modmaven.dev"}
    maven { url = "https://www.cursemaven.com"}
    maven { url = "https://maven.octo-studios.com/releases"}
    maven { url = "https://modmaven.dev"}
    maven { url = uri("https://maven.blakesmods.com") }
    maven { url 'https://maven.blamejared.com'}
    maven { url 'https://maven.rover656.dev/releases' }
}

base {
    archivesName = mod_id
}

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

neoForge {
    version = project.neo_version

    parchment {
        mappingsVersion = project.parchment_mappings_version
        minecraftVersion = project.parchment_minecraft_version
    }

     accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg')

    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 {
    compileOnly("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}") //Just Enough Items
    compileOnly("mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}") //Just Enough Items
    runtimeOnly("mezz.jei:jei-${minecraft_version}-common:${jei_version}") //Just Enough Items
    runtimeOnly("mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}") //Just Enough Items
    runtimeOnly("curse.maven:just-enough-professions-jep-417645:${jep_version}") //Curios Continuation
    compileOnly("vazkii.patchouli:Patchouli:1.21-${patchouli_version}-NEOFORGE-SNAPSHOT:api") //Patchouli
    runtimeOnly("vazkii.patchouli:Patchouli:1.21-${patchouli_version}-NEOFORGE-SNAPSHOT") //Patchouli
    compileOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}") //Curios Continuation
    runtimeOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}") //Curios Continuation
    compileOnly "curse.maven:projecte-226410:${projecte_version}" //ProjectE
    runtimeOnly "curse.maven:projecte-226410:${projecte_version}" //ProjectE
    implementation "blusunrize.immersiveengineering:ImmersiveEngineering:${immersive_engineering_version}" // Immersive Engineering
    compileOnly "mekanism:Mekanism:${mekanism_version}:api" // Mekanism
    runtimeOnly "mekanism:Mekanism:${mekanism_version}" // Mekanism
    runtimeOnly "mekanism:Mekanism:${mekanism_version}:additions" // Mekanism: Additions
    runtimeOnly "mekanism:Mekanism:${mekanism_version}:generators" // Mekanism: Generators
    runtimeOnly "mekanism:Mekanism:${mekanism_version}:tools" // Mekanism: Tools
    runtimeOnly "com.enderio:enderio-base:${ender_io_version}" // EnderIO
    runtimeOnly "com.enderio:enderio-conduits:${ender_io_version}" //EnderIO Conduits
    runtimeOnly "com.enderio:enderio-machines:${ender_io_version}" //EnderIO Machines

    runtimeOnly("curse.maven:resource-pandas-410681:${resource_pandas_id}") // Resource Pandas
    runtimeOnly("curse.maven:productivebees-377897:${productivebees_id}") // Productive Bees
    runtimeOnly("curse.maven:common_capabilities-247007:${common_capabilities_id}") // Common Capabilities
    runtimeOnly("curse.maven:cyclops_core-232758:${cyclops_core_id}") // Cyclops Core
    runtimeOnly("curse.maven:farmers-delight-398521:${farmers_delight_id}") // Farmer's Delight
    runtimeOnly("curse.maven:integrated_dynamics-236307:${integrated_dynamics_id}") // Integrated Dynamics
    runtimeOnly("curse.maven:titanium-287342:${titanium_id}") // Titanium
    runtimeOnly("curse.maven:industrial-foregoing-266515:${industrial_foregoing_id}") // Industrial Foregoing
    runtimeOnly("curse.maven:pneumaticcraft-repressurized-281849:${pneumaticcraft_id}") // Pneumaticcraft
    compileOnly("curse.maven:just-enough-resources-jer-240630:${jer_id}") //Just Enough Resources
    runtimeOnly("curse.maven:just-enough-resources-jer-240630:${jer_id}") //Just Enough Resources
    runtimeOnly "curse.maven:not-enough-crashes-forge-442354:${not_enough_crashes_id}" //Not Enough Crashes
}

var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
    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
    expand replaceProperties
    from "src/main/templates"
    into "build/generated/sources/modMetadata"
}
sourceSets.main.resources.srcDir generateModMetadata
neoForge.ideSyncTask generateModMetadata

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

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

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