plugins {
    id "fabric-loom"
    id "maven-publish"
    id "org.jetbrains.kotlin.jvm"
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

repositories {
    maven {
        name = "Modmuss50"
        url = "https://maven.modmuss50.me/"
        content {
            includeGroup "RebornCore"
            includeGroup "TechReborn"
            includeGroup "teamreborn"
        }
    }
    maven {
        url "https://maven.shedaniel.me/"
        content {
            includeGroup "dev.architectury"
            includeGroup "me.shedaniel"
            includeGroup "me.shedaniel.cloth"
            includeGroup "me.shedaniel.cloth.api"
        }
    }
    maven {
        url = "https://maven.fabricmc.net/"
        content {
            includeGroup "net.fabricmc"
        }
    }
    maven {
        name = "BuildCraft"
        url = "https://mod-buildcraft.com/maven"
        content {
            includeGroup "alexiil.mc.lib"
        }
    }
    maven {
        name = "CottonMC"
        url = "https://server.bbkr.space/artifactory/libs-release"
        content {
            includeGroup "io.github.cottonmc"
        }
    }
    maven {
        url = "https://maven.terraformersmc.com/releases/"
        content {
            includeGroup "com.terraformersmc"
        }
    }
    maven {
        name = "Patchouli"
        url = "https://maven.blamejared.com"
        content {
            includeGroup "vazkii.patchouli"
        }
    }
    maven {
        url = "https://jitpack.io"
        content {
            includeGroup "com.github.Technici4n"
            includeGroup "com.github.Draylar"
            includeGroup "com.github.Draylar.omega-config"
            includeGroup "com.github.emilyploszaj"
        }
    }
    maven {
        url "https://oskarstrom.net/maven"
        content {
            includeGroup "net.oskarstrom"
        }
    }
    maven {
        name = "Cafeteria Development"
        url = 'https://maven.cafeteria.dev'
        content {
            includeGroup 'dev.cafeteria'
            includeGroup 'me.luligabi'
            includeGroup 'net.adriantodt.fabricmc'
        }
    }
    maven {
        name = 'Ladysnake Mods'
        url = 'https://ladysnake.jfrog.io/artifactory/mods'
        content {
            includeGroup 'io.github.ladysnake'
            includeGroupByRegex 'io\\.github\\.onyxstudios.*'
        }
    }
}

dependencies {

    dependencies.ext.lib = { dep, optional = false ->
        modImplementation(dep) {
            exclude group: "net.fabricmc.fabric-api"
            exclude group: "com.jamieswhiteshirt"
            exclude group: "io.github.prospector"
        }
        if (!optional) {
            include(dep) {
                exclude group: "net.fabricmc.fabric-api"
                exclude group: "com.jamieswhiteshirt"
                exclude group: "io.github.prospector"
            }
        }
    }

    minecraft "com.mojang:minecraft:${project.minecraft_version}"
    mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
    modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

    modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

    modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"

    dependencies.ext.lib("teamreborn:energy:${project.tr_energy_version}")
    dependencies.ext.lib("io.github.cottonmc:LibGui:${project.libgui_version}")
    dependencies.ext.lib("vazkii.patchouli:Patchouli:${project.patchouli_version}")
    dependencies.ext.lib("alexiil.mc.lib:libblockattributes-core:${project.lba_version}")
    dependencies.ext.lib("alexiil.mc.lib:libblockattributes-fluids:${project.lba_version}")
    dependencies.ext.lib("alexiil.mc.lib:libblockattributes-items:${project.lba_version}")
    dependencies.ext.lib("com.github.Draylar:magna:${project.magna_version}")
    dependencies.ext.lib("com.github.emilyploszaj:step-height-entity-attribute:v1.0.1")
    dependencies.ext.lib("dev.cafeteria:fake-player-api:${project.fakeplayerapi_version}")
    dependencies.ext.lib("me.luligabi:NoIndium:1.0")
    dependencies.ext.lib("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}", true)

    modRuntimeOnly("com.terraformersmc:modmenu:${project.modmenu_version}") {
        exclude group: "net.fabricmc.fabric-api", module: "fabric-api"
    }

    // DashLoader Stuff
    modCompileOnly("net.oskarstrom:DashLoader:2.0-dev12")
    dependencies.ext.lib("io.activej:activej-serializer:${project.activej_version}", true)
    modRuntimeOnly("org.yaml:snakeyaml:1.27")
}

loom {
    accessWidenerPath = file("src/main/resources/indrev.accesswidener")
}

processResources {
    inputs.property "version", project.version

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

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
    it.options.encoding = "UTF-8"
    it.options.release = 16
}


java {
	// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
	// if it is present.
	// If you remove this line, sources will not be generated.
	withSourcesJar()
}

jar {
    from("LICENSE") {
		rename { "${it}_${project.archivesBaseName}"}
	}

    exclude("me/steven/indrev/datagen")
}

// configure the maven publication
publishing {
    publications {
        mavenJava(MavenPublication) {
            // add all the jars that should be included when publishing to maven
            artifact(remapJar) {
                builtBy remapJar
            }
            artifact(sourcesJar) {
                builtBy remapSourcesJar
            }
        }
    }

    // select the repositories you want to publish to
    repositories {
        maven {
            url "https://maven.cafeteria.dev/releases"
            credentials {
                username = project.property("mcdUsername")
                password = project.property("mcdPassword")
            }
            authentication {
                basic(BasicAuthentication)
            }
        }
    }
}

compileKotlin.kotlinOptions.jvmTarget = "16"
