plugins {
    id 'fabric-loom' version "$loomVersion"
    id "com.modrinth.minotaur" version "2.+"
    // It's safest to have this on 2.+ to get the latest features and
    // bug fixes without having to worry about breaking changes.
}

archivesBaseName = getArtifactID("fabric")

loom {
    mixin.defaultRefmapName = "hexucasting.mixins.refmap.json"

    accessWidenerPath = file("src/main/resources/hexucasting.accesswidener")

    runs {
        client {
            client()
            setConfigName("Fabric Client")
        }
        server {
            server()
            setConfigName("Fabric Server")
        }
        datagen {
            client()
            vmArg "-Dfabric-api.datagen"
            vmArg "-Dfabric-api.datagen.modid=${modID}"
            vmArg "-Dfabric-api.datagen.output-dir=${file("src/generated/resources")}"
        }

        configureEach {
            runDir "Fabric/run"
            ideConfigGenerated(true)
        }
    }
}

repositories {
    mavenCentral()
    maven { url "https://maven.shedaniel.me/" }
    maven {
        url 'https://ladysnake.jfrog.io/artifactory/mods'
    }
    maven {
        name "entity reach"
        url "https://maven.jamieswhiteshirt.com/libs-release/"
    }
    maven { url "https://mvn.devos.one/snapshots/" }
    maven {
        name = "TerraformersMC"
        url = "https://maven.terraformersmc.com/"
    }
}

dependencies {
    minecraft "com.mojang:minecraft:${minecraftVersion}"
    mappings loom.officialMojangMappings()
    modImplementation("net.fabricmc:fabric-language-kotlin:1.7.4+kotlin.1.6.21")
    modImplementation "net.fabricmc:fabric-loader:${fabricLoaderVersion}"
    modImplementation "net.fabricmc.fabric-api:fabric-api:${fabricVersion}"

    // Reqs
    compileOnly "com.demonwav.mcdev:annotations:1.0"

    implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
    compileOnly project(":Common")

    modImplementation "at.petra-k.paucal:paucal-fabric-$minecraftVersion:$paucalVersion"
    modImplementation("at.petra-k.hexcasting:hexcasting-fabric-$minecraftVersion:$hexcastingVersion") {
        exclude module: "phosphor"
    }
    modImplementation "vazkii.patchouli:Patchouli:$minecraftVersion-$patchouliVersion-FABRIC"

    modImplementation "me.zeroeightsix:fiber:$fiberVersion"
    include "me.zeroeightsix:fiber:$fiberVersion"

    modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-api:$cardinalComponentsVersion"
    include "dev.onyxstudios.cardinal-components-api:cardinal-components-api:$cardinalComponentsVersion"

    modImplementation "com.jamieswhiteshirt:reach-entity-attributes:2.1.1"
    include "com.jamieswhiteshirt:reach-entity-attributes:2.1.1"

    modImplementation "io.github.tropheusj:serialization-hooks:$serializationHooksVersion"
    include "io.github.tropheusj:serialization-hooks:$serializationHooksVersion"

    // Optional integrations

    modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:$reiVersion"

    modApi("me.shedaniel.cloth:cloth-config-fabric:$clothConfigVersion") {
        exclude(group: "net.fabricmc.fabric-api")
    }

    modImplementation "dev.emi:emi:${emiVersion}"

    modImplementation "maven.modrinth:gravity-api:$gravityApiVersion"
    modApi("com.github.Virtuoel:Pehkui:${pehkuiVersion}", {
        exclude group: "net.fabricmc.fabric-api"
    })

    implementation 'org.jetbrains:annotations:23.0.0'

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
}

tasks.withType(JavaCompile) {
    source(project(":Common").sourceSets.main.allSource)
}
compileKotlin {
    source(project(":Common").sourceSets.main.kotlin)
}

sourcesJar {
    from project(":Common").sourceSets.main.allJava
}

sourceSets {
    main.resources.srcDirs += ['src/generated/resources', '../Common/src/generated/resources']
}

processResources {
    from project(":Common").sourceSets.main.resources
    inputs.property "version", project.version

    filesMatching("fabric.mod.json") {
        expand "version": project.version
    }
}

def loadProperties = { filename ->
    def properties = new Properties()
    rootProject.file(filename).withInputStream {
        properties.load(it)
    }
    return properties
}

/**
 * To setup automatic modrinth exporting, get your API key from the modrinth website and place it in a
 * file in the root project directory called keys.properties
 * e.g.
 * MODRINTH_TOKEN=exampletoken
 * Then, uncomment the modrinth blocks in every build.gradle. When you run the modrinth build task
 * in the base project task space, it will upload both Forge and Fabric versions of the mod to
 * modrinth automatically, with the changelog from the changelog.md file in the base project directory.
 */
//modrinth {
//    token = loadProperties("keys.properties").MODRINTH_TOKEN
//    projectId = "$modID" // This can be the project ID or the slug. Either will work!
//    versionNumber = "$modVersion" // You don't need to set this manually. Will fail if Modrinth has this version already
//    versionName = "$modVersion-fabric"
//    changelog = rootProject.file("changelog.md").text
//
//    versionType = "release" // This is the default -- can also be `beta` or `alpha`
//    uploadFile = remapJar // With Loom, this MUST be set to `remapJar` instead of `jar`!
//    gameVersions = ["1.19.2"] // Must be an array, even with only one version
//    loaders = ["fabric"] // Must also be an array - no need to specify this if you're using Loom or ForgeGradle
//    dependencies { // A special DSL for creating dependencies
//        // scope.type
//        // The scope can be `required`, `optional`, `incompatible`, or `embedded`
//        // The type can either be `project` or `version`
//        required.project "hex-casting" // Creates a new required dependency on Hex Casting
//        required.project "paucal"
//        required.project "patchouli"
//        required.project "fabric-language-kotlin"
//        required.project "cardinal-components-api"
//    }
//}

setupJar(this)
