plugins {
    id 'fabric-loom' version "1.6-SNAPSHOT"
    id "at.petra-k.PKSubprojPlugin"
}

pkSubproj {
    platform "fabric"
    curseforgeJar remapJar.archiveFile
    curseforgeDependencies([
            "paucal:0.6.0", "patchouli:1.20.1-80", "fabric-language-kotlin:1.9.4+kotlin.1.8.21",
            "inline:1.20.1-1.0.1", "cloth-config:11.1.0",
            "cardinal-components-api:5.2.1", "fabric-api:0.84"
    ])
    modrinthJar remapJar.archiveFile
    modrinthDependencies([
            "paucal:0.6.0", "patchouli:1.20.1-80", "fabric-language-kotlin:1.9.4+kotlin.1.8.21",
            "inline:1.20.1-1.0.1", "cloth-config:11.1.0",
            "cardinal-components-api:5.2.1", "fabric-api:0.84"
    ])
}

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

    accessWidenerPath = file("src/main/resources/fabricasting.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()

    // paucal and patchi
    maven { url = 'https://maven.blamejared.com' }
    // modmenu and clothconfig
    maven { url "https://maven.shedaniel.me/" }
    maven { url 'https://maven.ladysnake.org/releases' }
    // Entity reach
    maven { url "https://maven.jamieswhiteshirt.com/libs-release/" }
    maven { url "https://mvn.devos.one/snapshots/" }
    maven { url = "https://maven.terraformersmc.com/releases/" }
    exclusiveContent {
        forRepository {
            maven { url = "https://api.modrinth.com/maven" }
        }
        filter { includeGroup "maven.modrinth" }
    }
    // pehkui
    maven { url = "https://jitpack.io" }

    // If you have mod jar dependencies in ./libs, you can declare them as a repository like so:
    flatDir {
        dir 'libs'
    }
}

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

    // Reqs
    compileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
    testCompileOnly "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
    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 "vazkii.patchouli:Patchouli:$minecraftVersion-$patchouliVersion-FABRIC-SNAPSHOT"

    modImplementation "com.samsthenerd.inline:inline-fabric:$minecraftVersion-$inlineVersion"

    modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:$cardinalComponentsVersion"
//    modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-util:$cardinalComponentsVersion"
    modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:$cardinalComponentsVersion"
    modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-item:$cardinalComponentsVersion"
    modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-block:$cardinalComponentsVersion"

//    modImplementation "com.jamieswhiteshirt:reach-entity-attributes:${entityReachVersion}"
//    include "com.jamieswhiteshirt:reach-entity-attributes:${entityReachVersion}"

    // apparently the 1.18 version Just Works on 1.19
    modImplementation "${modID}:serialization-hooks:$serializationHooksVersion"
    include "${modID}:serialization-hooks:$serializationHooksVersion"
    implementation(include("com.github.LlamaLad7:MixinExtras:0.1.1"))

    // Optional integrations

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

    modImplementation "dev.emi:trinkets:$trinketsVersion"
    modImplementation "dev.emi:emi-fabric:${emiVersion}"

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

    // *Something* is including an old version of modmenu with a broken mixin
    // We can't figure out what it is
    // so i'm just including a fresher version
    modImplementation("com.terraformersmc:modmenu:$modmenuVersion")

    // i am speed
    // sodium is causing frustum mixin errors so don't use it
//    modImplementation "maven.modrinth:sodium:${sodiumVersion}"
    modImplementation "maven.modrinth:lithium:${lithiumVersion}"
//    modImplementation "maven.modrinth:phosphor:${phosphorVersion}"
}

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