buildscript {
  repositories {
    maven { url = "http://files.minecraftforge.net/maven" }
    maven { url = "https://plugins.gradle.org/m2/" }
  }
  dependencies {
    classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT"
    classpath "com.wynprice.cursemaven:CurseMaven:2.1.1"
  }
}

apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: "com.wynprice.cursemaven"

def mod_file = getModFile("net.gegy1000.terrarium.Terrarium")
version = getModField("VERSION", mod_file)
group = "net.gegy1000"
archivesBaseName = "terrarium"
sourceCompatibility = targetCompatibility = "1.8"

minecraft {
  version = "1.12.2-14.23.5.2847"
  runDir = "minecraft"
  mappings = "stable_39"
}

repositories {
  mavenCentral()
  maven { url = "https://oss.sonatype.org/content/repositories/public/" }
  maven { url = "https://repo.spongepowered.org/maven/" }
  maven { url = "https://maven.gegy.dev" }
  maven { url = "https://www.cursemaven.com" }
  maven { url = "http://mvn.topobyte.de" }
}

configurations {
  embed
  compile.extendsFrom(embed)
}

dependencies {
  // optional dependencies
  deobfCompile 'io.github.opencubicchunks:cubicchunks-api:1.12.2-0.0-SNAPSHOT'
  deobfCompile 'io.github.opencubicchunks:cubicchunks:1.12.2-0.0-SNAPSHOT'

  deobfCompile 'com.github.glitchfiend.biomesoplenty:BiomesOPlenty:1.12.2-7.0.1.2399:universal'
  deobfCompile 'curse.maven:dynamictrees-252818:2822231'

  // embedded dependencies
  embed 'dev.gegy:gengen:0.1.0-SNAPSHOT'
  embed 'net.gegy1000:just-now:0.1.0-SNAPSHOT'
  embed 'com.vividsolutions:jts:1.13'
  embed 'org.tukaani:xz-fork:1.8'
}

jar {
  from configurations.embed.collect {
    it.isDirectory() ? it : zipTree(it)
  }
  manifest {
    attributes "FMLAT": "terrarium_at.cfg"
    attributes "Maven-Artifact": "${project.group}:${project.archivesBaseName}:${project.version}"
    attributes "Timestamp": System.currentTimeMillis()
  }
}

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

  from(sourceSets.main.resources.srcDirs) {
    include "mcmod.info"
    expand "version": project.version, "mcversion": project.minecraft.version
  }

  from(sourceSets.main.resources.srcDirs) {
    exclude "mcmod.info"
  }
}

File getModFile(String fq_name) {
  return file("src/main/java/${fq_name.replace('.', '/')}.java")
}

String getModField(String type, File mod_file) {
  String field = ""
  String prefix = "public static final String $type = \""
  mod_file.eachLine { String s ->
    s = s.trim()
    if (s.startsWith(prefix)) {
      s = s.substring(prefix.length(), s.length() - 2)
      field = s
    }
  }
  return field
}
