plugins {
    id 'eclipse'
    id 'idea'
    id 'maven-publish'
    id 'net.minecraftforge.gradle' version '[6.0,6.2)'
    id 'org.spongepowered.mixin' version '0.7.+'
}

version = mod_version
group = mod_group_id

base {
    archivesName = mod_id
}

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

println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
minecraft {

    mappings channel: mapping_channel, version: mapping_version

    accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

    copyIdeResources = true

    runs {
        configureEach {
            workingDirectory project.file('run')

            property 'forge.logging.markers', 'REGISTRIES'
            property 'forge.logging.console.level', 'debug'

            property 'mixin.env.remapRefMap', 'true'
            property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"

            arg '-mixin.config = enigmaticaddons.mixins.json'

            mods {
                "${mod_id}" {
                    source sourceSets.main
                }
            }
        }

        client {
            property 'forge.enabledGameTestNamespaces', mod_id
        }

        server {
            property 'forge.enabledGameTestNamespaces', mod_id
            args '--nogui'
        }

        gameTestServer {
            property 'forge.enabledGameTestNamespaces', mod_id
        }

        data {
            workingDirectory project.file('run-data')

            args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
        }
    }
}

mixin {
    config "enigmaticaddons.mixins.json"
    add sourceSets.main, 'enigmaticaddons.refmap.json'
}

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

repositories {
    maven {
        name = "Illusive Soulworks maven"
        url = "https://maven.theillusivec4.top/"
    }
    maven {
        name = "Progwml6's maven"
        url = "https://dvs1.progwml6.com/files/maven/"
    }
    maven {
        name = "Jared's maven"
        url = "https://maven.blamejared.com/"
    }
    maven {
        name = "ModMaven"
        url = "https://modmaven.dev"
    }
    maven {
        name = "CurseForge"
        url = "https://minecraft.curseforge.com/api/maven/"
    }
    maven {
        name = "CurseMaven"
        url = "https://cursemaven.com"
        content {
            includeGroup "curse.maven"
        }
    }
}

dependencies {
    minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
    annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'

    implementation fg.deobf("curse.maven:just-enough-resources-jer-240630:5057220")

    implementation fg.deobf("curse.maven:jade-324717:4986594")
    implementation fg.deobf("vazkii.patchouli:Patchouli:${minecraft_version}-81-FORGE")

    runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}")
    compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_version}:api")

    runtimeOnly fg.deobf("top.theillusivec4.caelus:caelus-forge:${caelus_version}")
    compileOnly fg.deobf("top.theillusivec4.caelus:caelus-forge:${caelus_version}:api")

    compileOnly fg.deobf("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}")
    compileOnly fg.deobf("mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}")
    runtimeOnly fg.deobf("mezz.jei:jei-${minecraft_version}-forge:${jei_version}")

    implementation fg.deobf("curse.maven:l2library-620203:5921890")
    implementation fg.deobf("curse.maven:appleskin-248787:4770828")
    implementation fg.deobf("curse.maven:legendary-tooltips-532127:4662781")
    implementation fg.deobf("curse.maven:iceberg-520110:5138899")
    implementation fg.deobf("curse.maven:prism-lib-638111:4650325")
//    implementation fg.deobf("curse.maven:farmers-delight-${farmersdelight_id}:${farmersdelight_version}")
    implementation fg.deobf("curse.maven:enigmaticlegacy-${enigmaticlegacy_id}:${enigmaticlegacy_version}")
//    implementation fg.deobf("curse.maven:create-328085:6323270")
//    implementation fg.deobf("curse.maven:supplementaries-412082:6408423")
//    implementation fg.deobf("curse.maven:tameable-1110434:5979011")
//    implementation fg.deobf("curse.maven:the-man-from-the-fog-890565:5947084")
//    implementation fg.deobf("curse.maven:geckolib-388172:6333474")
    implementation fg.deobf("curse.maven:selene-499980:6740431")
    implementation fg.deobf("curse.maven:mmmmmmmmmmmm-225738:6608233")
    implementation fg.deobf("curse.maven:mob-battle-mod-268746:6596542")
}

tasks.named('processResources', ProcessResources).configure {
    var replaceProperties = [
            minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
            forge_version: forge_version, forge_version_range: forge_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/mods.toml', 'pack.mcmeta']) {
        expand replaceProperties + [project: project]
    }
}

tasks.named('jar', Jar).configure {
    manifest {
        attributes([
                'Specification-Title'     : mod_id,
                'Specification-Vendor'    : mod_authors,
                'Specification-Version'   : '1',
                'Implementation-Title'    : project.name,
                'Implementation-Version'  : project.jar.archiveVersion,
                'Implementation-Vendor'   : mod_authors,
                'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
        ])
    }

    finalizedBy 'reobfJar'
}

publishing {
    publications {
        register('mavenJava', MavenPublication) {
            artifact jar
        }
    }
    repositories {
        maven {
            url "file://${project.projectDir}/mcmodsrepo"
        }
    }
}

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