Skip to content

Instantly share code, notes, and snippets.

@dexman545
Created January 17, 2021 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexman545/6461b5fe75e617328c7faafb6091ced3 to your computer and use it in GitHub Desktop.
Save dexman545/6461b5fe75e617328c7faafb6091ced3 to your computer and use it in GitHub Desktop.
Gradle scripts to make pulling data easier for Fabric mods
buildscript {
dependencies {
classpath "com.github.yuchi:npm-semver:1.0.0"
}
}
import com.github.yuchi.semver.Version
import groovy.json.JsonSlurper
import java.util.regex.Matcher
import java.util.regex.Pattern
/**
* Get the newest available loader version.
*
* @return loader version.
*/
static String getNewestLoaderVersion() {
def loaderVersions = new JsonSlurper().parse(new URL("https://meta.fabricmc.net/v2/versions/loader/"))
assert loaderVersions instanceof ArrayList<LinkedHashMap> // Type check to to remove visual errors
return loaderVersions.first().version
}
/**
* Get correct Yarn version for project's MC version.
*
* @param newest whether to return the newest available Yarn version, or the oldest. Oldest may be preferred to avoid
* invalidating genSources' output.
* @return the correct Yarn version.
*/
String getChosenYarnVersion(boolean newest) {
def yarnVersions = new JsonSlurper().parse(
new URL("https://meta.fabricmc.net/v2/versions/yarn/${project.minecraft_version}"))
assert yarnVersions instanceof ArrayList<LinkedHashMap> // Type check to to remove visual errors
return newest ? yarnVersions.first().version : yarnVersions.last().version
}
/**
* Get the latest MC version.
*
* @param isStable if snapshots should be ignored or not.
* @return the MC version.
*/
static String getLatestMc(boolean isStable) {
def mcVersions = new JsonSlurper().parse(new URL("https://meta.fabricmc.net/v2/versions/game"))
assert mcVersions instanceof ArrayList<LinkedHashMap> // Type check to to remove visual errors
if (!isStable) return mcVersions.first().version
for (LinkedHashMap mcVer : mcVersions) {
if (mcVer.stable) return mcVer.version
}
return "" // No MC version was found
}
/**
* Get latest Mod Menu version from Fabric's maven. Not keyed to MC version.
*
* @return mod menu version.
*/
// I got tired of having to find the right version, ok?
static String getLatestModMenu() {
def modMenuVersions = new XmlSlurper().parseText(
new URL("https://maven.fabricmc.net/io/github/prospector/modmenu/maven-metadata.xml").text)
// For some reason Groovy was not happy with accessing it as a map, so this nonsense exists
def x = modMenuVersions.getProperty('versioning')
return x['latest']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment