plugins {
    id 'unimined-fabric'
}


// ==================== Dependencies ====================

def addMod(path, enabled) {
    if (enabled == "2")
        dependencies { modImplementation(path) }
    else if (enabled == "1")
        dependencies { compileOnly(path) }
}

dependencies {
    // Fabric loader
    modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"

    // Fabric API (bundled as jar-in-jar so users don't need to install it separately)
    modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
    include "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"

    // Mod Menu
    addMod("com.terraformersmc:modmenu:${rootProject.modmenu_version}", rootProject.enable_mod_menu)

    // Starlight
    addMod("curse.maven:starlight-521783:${rootProject.starlight_version_fabric}", rootProject.enable_starlight)

    // Phosphor
    addMod("curse.maven:phosphor-372124:${rootProject.phosphor_version_fabric}", rootProject.enable_phosphor)

    // Sodium
    addMod("maven.modrinth:sodium:${rootProject.sodium_version}", rootProject.enable_sodium)
    if (rootProject.enable_sodium == "2") implementation "org.joml:joml:1.10.2"
    
	// Lithium
    addMod("maven.modrinth:lithium:${rootProject.lithium_version}", rootProject.enable_lithium)
    
    // Iris
    addMod("maven.modrinth:iris:${rootProject.iris_version}", rootProject.enable_iris)
    
    // BCLib
    addMod("com.github.quiqueck:BCLib:${rootProject.bclib_version}", rootProject.enable_bclib)
    
    // Canvas
    addMod("io.vram:canvas-fabric-${rootProject.canvas_version}", rootProject.enable_canvas)
    
    // Immersive Portals
    if (rootProject.enable_immersive_portals == "1") {
        modCompileOnly("com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:${rootProject.immersive_portals_version}")
    }
    else if (rootProject.enable_immersive_portals == "2") {
        modImplementation ("com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:${rootProject.immersive_portals_version}") {
            exclude(group: "net.fabricmc.fabric-api")
            transitive(false)
        }
        modImplementation("com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:${rootProject.immersive_portals_version}") {
            exclude(group: "net.fabricmc.fabric-api")
            transitive(false)
        }
        modImplementation("com.github.iPortalTeam.ImmersivePortalsMod:build:${rootProject.immersive_portals_version}") {
            exclude(group: "net.fabricmc.fabric-api")
            transitive(false)
        }
        api("com.github.LlamaLad7:MixinExtras:0.2.0-beta.4")
        annotationProcessor("com.github.LlamaLad7:MixinExtras:0.2.0-beta.4")
    }
}


// ==================== Tasks ====================

task deleteResources(type: Delete) {
    delete file("build/resources/main")
}

processResources {
    dependsOn(copyCoreResources)
    dependsOn(copyCommonLoaderResources)
}

tasks.named('runClient') {
    dependsOn(copyCoreResources)
    dependsOn(copyCommonLoaderResources)
    finalizedBy(deleteResources)
}

sourcesJar {
    def commonSources = project(":common").sourcesJar
    dependsOn commonSources
    from commonSources.archiveFile.map { zipTree(it) }
}
