buildscript { repositories { mavenCentral() maven { name = "Modmuss50" url = "https://maven.modmuss50.me/" } maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "net.fabricmc:fabric-loom:0.5-SNAPSHOT" classpath "gradle.plugin.net.minecrell:licenser:0.2.1" classpath 'de.undercouch:gradle-download-task:3.4.3' } } apply plugin: net.fabricmc.loom.LoomGradlePlugin apply plugin: 'maven' apply plugin: 'maven-publish' apply plugin: net.minecrell.gradle.licenser.Licenser apply plugin: 'de.undercouch.download' apply plugin: 'idea' apply plugin: 'eclipse' sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { maven { name = "Modmuss50" url = "https://maven.modmuss50.me/" } maven { name = "BuildCraft" url = "https://mod-buildcraft.com/maven" content { includeGroup "alexiil.mc.lib" } } maven { url = "https://www.cursemaven.com" content { includeGroup "curse.maven" } } maven { url = "https://jitpack.io" content { includeGroup "com.github.dexman545" includeGroup "com.github.emilyploszaj" includeGroup "io.github.onyxstudios.Cardinal-Components-API" } } } version = "3.7.1" configurations { shade compile.extendsFrom shade } def ENV = System.getenv() def build_number = ENV.BUILD_NUMBER ?: "local" version = "${version}+build.$build_number" license { header file('HEADER') include '**/*.java' ignoreFailures = true //Stops the build from failing if a file does not have a license header } group = 'TechReborn' configurations.all { resolutionStrategy.cacheDynamicVersionsFor 2, 'minutes' } dependencies { minecraft "com.mojang:minecraft:1.16.4" mappings "net.fabricmc:yarn:1.16.4+build.6:v2" modImplementation "net.fabricmc:fabric-loader:0.10.6+build.214" //Fabric api modImplementation "net.fabricmc.fabric-api:fabric-api:0.25.0+build.415-1.16" optionalDependency ("me.shedaniel:RoughlyEnoughItems:5.8.0") disabledOptionalDependency ('com.github.emilyploszaj:trinkets:2.6.7') def rcVersion = 'RebornCore:RebornCore-1.16:+' modApi (rcVersion) { exclude group: "net.fabricmc.fabric-api" } include rcVersion modApi 'teamreborn:energy:0.1.0' optionalDependency "com.github.dexman545:autoswitch-api:-SNAPSHOT" modRuntime "curse.maven:applied-energistics-2:3117933" modRuntime "alexiil.mc.lib:libblockattributes-core:0.8.0" modRuntime "alexiil.mc.lib:libblockattributes-items:0.8.0" modRuntime "alexiil.mc.lib:libblockattributes-fluids:0.8.0" } def optionalDependency(String dep) { dependencies.modRuntime (dep) { exclude group: "net.fabricmc.fabric-api" exclude module: "nbt-crafting" } dependencies.modCompileOnly (dep) { exclude group: "net.fabricmc.fabric-api" exclude module: "nbt-crafting" } } def disabledOptionalDependency(String dep) { dependencies.modCompileOnly (dep) { exclude group: "net.fabricmc.fabric-api" exclude module: "nbt-crafting" } } processResources { inputs.property "version", project.version from(sourceSets.main.resources.srcDirs) { include "fabric.mod.json" expand "version": project.version } from(sourceSets.main.resources.srcDirs) { exclude "fabric.mod.json" } } jar { exclude "**/*.psd" classifier = 'universal' from { crowdin.getDidWork() ? fileTree('build/translations').matching{exclude "**/en_US.json"} : null} dependsOn 'fixTranslations' dependsOn 'compileRecipes' } //Triggers crowdin to export the latest translations task crowdinExport() { onlyIf { project.hasProperty('crowdinKey') } doLast{ def apiKey = project.crowdinKey def projectId = 'techreborn' def response = new URL(sprintf('https://api.crowdin.com/api/project/%1$s/export?key=%2$s', [projectId, apiKey])).text def metadata = new XmlParser().parseText(response) project.logger.lifecycle("crowdin export status: " + metadata.@status) } } task crowdin(type: Download, dependsOn: 'crowdinExport'){ src 'https://crowdin.com/backend/download/project/techreborn.zip' dest file("build/translations.zip") overwrite true } task cleanCrowdin(type: Delete){ delete 'build/translations' } //Renames the translation files to be all lower case task renameCrowdin(type: Copy, dependsOn: ['crowdin', 'cleanCrowdin']){ mustRunAfter 'crowdin' from zipTree(file("build/translations.zip")) into file('build/translations') rename { String filename -> return filename.toLowerCase() } doFirst { file('build/translations').deleteDir() } } import groovy.json.JsonSlurper import groovy.json.JsonOutput //Remove all translations that do not have an entry, ensures that minecraft falls back to EN_US over writing out an empty string. task fixTranslations(dependsOn: ['renameCrowdin']) { def jsonSlurper = new JsonSlurper() doLast { file('build/translations').eachFileRecurse(groovy.io.FileType.FILES) { if(it.name.endsWith(".json")) { def lang = jsonSlurper.parseText(it.text) lang.values().removeIf { val -> val.empty} it.text = JsonOutput.prettyPrint(JsonOutput.toJson(lang)) } } } } task sourcesJar(type: Jar, dependsOn: classes) { classifier = "sources" from sourceSets.main.allSource } publishing { publications { maven(MavenPublication) { groupId 'TechReborn' artifactId project.archivesBaseName version project.version artifact(remapJar) { builtBy remapJar } artifact(sourcesJar) { builtBy remapSourcesJar } } } repositories { maven { url "http://mavenupload.modmuss50.me/" if (project.hasProperty('mavenPass')) { credentials { username 'buildslave' password project.getProperty('mavenPass') } } } } } // apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/ideconfig.gradle' import com.google.gson.JsonArray import groovy.util.XmlSlurper import org.apache.commons.io.FileUtils import java.util.function.Consumer task curseTools { doLast { def cacheFiles = new File(".gradle/curseTools") if (!cacheFiles.exists()) { cacheFiles.mkdirs() } def mavenMetadata = new File(cacheFiles, "maven-metadata.xml") logger.lifecycle(":downloading curseTools metadata") FileUtils.copyURLToFile(new URL("http://maven.modmuss50.me/CurseTools/CurseTools/maven-metadata.xml"), mavenMetadata) def metadata = new XmlSlurper().parseText(FileUtils.readFileToString(mavenMetadata)) def curseToolsVersion = metadata.versioning.release def curseTools = new File(cacheFiles, "${curseToolsVersion}.jar") logger.lifecycle(":downloading CurseTools") FileUtils.copyURLToFile(new URL("http://maven.modmuss50.me/CurseTools/CurseTools/${curseToolsVersion}/CurseTools-${curseToolsVersion}.jar"), curseTools) logger.lifecycle(":launching CurseTools") ant.java(jar: curseTools.getAbsolutePath(), fork: true, spawn: false) { arg(value: remapJar.archivePath.getAbsolutePath()) } } } // Generate recipe JSON for similar recipes import java.util.regex.Pattern task compileRecipes { def jsonSlurper = new JsonSlurper() def recipePath = "build/resources/main/data/techreborn/recipes" def smeltingPath = recipePath + "/smelting" def blastingPath = recipePath + "/blasting" doLast { // Add any recipe filenames that don't match the regex here String[] whitelist = [] def pattern = ~'^\\w+_(ingot(_from_dust)?)\\.json$' file(smeltingPath).eachFileRecurse(groovy.io.FileType.FILES) { if (whitelist.contains(it.name) || it.name ==~ pattern) { def recipe = jsonSlurper.parseText(it.text) // Final failsafe if (["smelting", "minecraft:smelting"].contains(recipe.type)) { recipe.type = "minecraft:blasting" recipe.cookingtime = recipe.cookingtime / 2 File output = new File(blastingPath, it.name) output.write(JsonOutput.prettyPrint(JsonOutput.toJson(recipe))) } } } } }