Last active
December 20, 2015 14:09
-
-
Save azenla/6144205 to your computer and use it in GitHub Desktop.
Example Mod Installer for Forge in Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def mcDir = new File(System.getProperty('user.home') + '/.minecraft/') | |
def modsDir = new File(mcDir, 'mods') | |
def mods = [:] | |
def modsToDownload = args.toList() | |
def download = { String address, String path -> | |
def file = new FileOutputStream(path) | |
def out = new BufferedOutputStream(file) | |
out << new URL(address).openStream() | |
out.close() | |
} | |
def downloadMod = { String name -> | |
def url = mods[name] as String | |
def modFile = new File(modsDir, name + '.jar') | |
if (modFile.exists()) { | |
modFile.delete() | |
} | |
println 'Mod File: ' + modFile | |
download url, modFile.absolutePath | |
} | |
def installForge = { -> | |
def installerJar = new File(mcDir.absolutePath + '/forgeInstaller.jar') | |
def installer = 'http://files.minecraftforge.net/minecraftforge/minecraftforge-installer-latest.jar' | |
download installer, installerJar.absolutePath | |
def classLoader = this.getClass().getClassLoader().rootLoader | |
classLoader.addURL(installerJar.toURI().toURL()) | |
println 'Please install Forge with the Forge Installer when it is displayed.' | |
sleep(3000) | |
def installerClass = Class.forName('cpw.mods.fml.installer.SimpleInstaller', true, classLoader) | |
installerClass.invokeMethod('main', new String[0]) | |
} | |
def loadModList = { -> | |
def modListFile = new File(mcDir.absolutePath + '/modlist.json') | |
download 'https://gist.github.com/kaendfinger/6144135/raw/mods.json', modListFile.absolutePath | |
mods = new JsonSlurper().parse(modListFile) as Map<String, String> | |
} | |
if (!modsDir.exists()) { | |
modsDir.mkdirs() | |
} | |
println 'Installing Forge' | |
installForge() | |
loadModList() | |
println mods.size() + ' mods are on the mod list.' | |
if (modsToDownload.isEmpty()) { | |
mods.keySet().each { String key -> | |
println 'Installing ' + key | |
downloadMod key | |
} | |
} else { | |
modsToDownload.each { String name -> | |
println 'Installing ' + name | |
downloadMod mods[name] as String | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment