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

version = mod_version
group = mod_group_id

repositories {
    mavenLocal()
}

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
    }

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

// Inclut les ressources générées
sourceSets.main.resources { srcDir 'src/generated/resources' }

// 🔧 Gère la substitution automatique dans META-INF/neoforge.mods.toml
processResources {
    def 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
    }
}

dependencies {
    // Tu peux ajouter ici d’autres dépendances si besoin
}

// 📦 Publication locale (utile pour tests ou modpack perso)
publishing {
    publications {
        register('mavenJava', MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            url "file://${project.projectDir}/repo"
        }
    }
}

// 🔍 Téléchargement auto des sources et Javadoc dans IntelliJ
idea {
    module {
        downloadSources = true
        downloadJavadoc = true
    }
}
