Skip to content

Instantly share code, notes, and snippets.

@dexman545
Created January 16, 2021 06:34
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/2bff5caf7caaaba6d3aa6add5b13d3a7 to your computer and use it in GitHub Desktop.
Save dexman545/2bff5caf7caaaba6d3aa6add5b13d3a7 to your computer and use it in GitHub Desktop.
(Almost) Lazy Man's https://modmuss50.me/fabric.html
/**
* 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
}
}
/**
* 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