Created
May 7, 2016 18:22
-
-
Save vQuadX/cd33fd3847d3ecc9d641f622096b582f to your computer and use it in GitHub Desktop.
Simple Minecraft 1.9 Launcher
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 java.io.File | |
import java.io.FileOutputStream | |
import java.io.IOException | |
import java.nio.file.Files | |
import java.nio.file.Path | |
import java.nio.file.Paths | |
import java.util.* | |
import java.util.zip.ZipEntry | |
import java.util.zip.ZipFile | |
class MinecraftLauncher { | |
fun main(args : Array<String>) { | |
Launcher.launch() | |
} | |
} | |
class Launcher { | |
companion object { | |
fun launch() { | |
var javaParameters = "-Xmx2G" | |
var gameDir = "\"D:\\Games\\Minecraft\"" | |
var version = "1.9.2" | |
var nativesPath = "$gameDir\\versions\\$version\\natives" | |
var librariesPath = "$gameDir\\libraries" | |
var libraries = arrayOf("$librariesPath\\oshi-project\\oshi-core\\1.1\\oshi-core-1.1.jar", | |
"$librariesPath\\net\\java\\dev\\jna\\jna\\3.4.0\\jna-3.4.0.jar", | |
"$librariesPath\\net\\java\\dev\\jna\\platform\\3.4.0\\platform-3.4.0.jar", | |
"$librariesPath\\com\\ibm\\icu\\icu4j-core-mojang\\51.2\\icu4j-core-mojang-51.2.jar", | |
"$librariesPath\\net\\sf\\jopt-simple\\jopt-simple\\4.6\\jopt-simple-4.6.jar", | |
"$librariesPath\\com\\paulscode\\codecjorbis\\20101023\\codecjorbis-20101023.jar", | |
"$librariesPath\\com\\paulscode\\codecwav\\20101023\\codecwav-20101023.jar", | |
"$librariesPath\\com\\paulscode\\libraryjavasound\\20101123\\libraryjavasound-20101123.jar", | |
"$librariesPath\\com\\paulscode\\librarylwjglopenal\\20100824\\librarylwjglopenal-20100824.jar", | |
"$librariesPath\\com\\paulscode\\soundsystem\\20120107\\soundsystem-20120107.jar", | |
"$librariesPath\\io\\netty\\netty-all\\4.0.23.Final\\netty-all-4.0.23.Final.jar", | |
"$librariesPath\\com\\google\\guava\\guava\\17.0\\guava-17.0.jar", | |
"$librariesPath\\org\\apache\\commons\\commons-lang3\\3.3.2\\commons-lang3-3.3.2.jar", | |
"$librariesPath\\commons-io\\commons-io\\2.4\\commons-io-2.4.jar", | |
"$librariesPath\\commons-codec\\commons-codec\\1.9\\commons-codec-1.9.jar", | |
"$librariesPath\\net\\java\\jinput\\jinput\\2.0.5\\jinput-2.0.5.jar", | |
"$librariesPath\\net\\java\\jutils\\jutils\\1.0.0\\jutils-1.0.0.jar", | |
"$librariesPath\\com\\google\\code\\gson\\gson\\2.2.4\\gson-2.2.4.jar", | |
"$librariesPath\\com\\mojang\\authlib\\1.5.22\\authlib-1.5.22.jar", | |
"$librariesPath\\com\\mojang\\realms\\1.8.18\\realms-1.8.18.jar", | |
"$librariesPath\\org\\apache\\commons\\commons-compress\\1.8.1\\commons-compress-1.8.1.jar", | |
"$librariesPath\\org\\apache\\httpcomponents\\httpclient\\4.3.3\\httpclient-4.3.3.jar", | |
"$librariesPath\\commons-logging\\commons-logging\\1.1.3\\commons-logging-1.1.3.jar", | |
"$librariesPath\\org\\apache\\httpcomponents\\httpcore\\4.3.2\\httpcore-4.3.2.jar", | |
"$librariesPath\\org\\apache\\logging\\log4j\\log4j-api\\2.0-beta9\\log4j-api-2.0-beta9.jar", | |
"$librariesPath\\org\\apache\\logging\\log4j\\log4j-core\\2.0-beta9\\log4j-core-2.0-beta9.jar", | |
"$librariesPath\\org\\lwjgl\\lwjgl\\lwjgl\\2.9.4-nightly-20150209\\lwjgl-2.9.4-nightly-20150209.jar", | |
"$librariesPath\\org\\lwjgl\\lwjgl\\lwjgl_util\\2.9.4-nightly-20150209\\lwjgl_util-2.9.4-nightly-20150209.jar", | |
"$gameDir\\versions\\1.9.2\\1.9.2.jar") | |
var mainClass = "net.minecraft.client.main.Main" | |
var username = "QuadX" | |
var assetDir = "$gameDir\\assets" | |
var assetIndex = "1.9" | |
var uuid = UUID.randomUUID().toString().replace("-", "") | |
var accessToken = "1a2b3c4d5e6f7g8h9i0g" | |
var userType = "mojang" | |
var versionType = "release" | |
var fullscreen = false | |
var connectToServer = false | |
var server = mapOf( | |
"ip" to "127.0.0.1", | |
"port" to "25565" | |
) | |
var run = "java $javaParameters " + | |
"-Djava.library.path=$nativesPath " + | |
"-cp ${libraries.joinToString(";")} $mainClass " + | |
"--username $username " + | |
"--version $version " + | |
"--gameDir $gameDir " + | |
"--assetsDir $assetDir " + | |
"--assetIndex $assetIndex " + | |
"--uuid $uuid " + | |
"--accessToken $accessToken " + | |
"--userType $userType " + | |
"--versionType $versionType" + | |
"${if (fullscreen) " --fullscreen" else ""} " + | |
"${if (connectToServer) " --server ${server["ip"]} --port ${server["port"]}" else ""}" | |
var _nativesPath = Paths.get(nativesPath.replace("\"", "")) | |
if (Files.notExists(_nativesPath)) { | |
Files.createDirectories(_nativesPath) | |
} | |
if (Utils.isDirEmpty(_nativesPath)) { | |
var nativesPaths = arrayOf( | |
"${librariesPath.replace("\"", "")}\\org\\lwjgl\\lwjgl\\lwjgl-platform\\2.9.4-nightly-20150209\\lwjgl-platform-2.9.4-nightly-20150209-natives-windows.jar", | |
"${librariesPath.replace("\"", "")}\\net\\java\\jinput\\jinput-platform\\2.0.5\\jinput-platform-2.0.5-natives-windows.jar" | |
) | |
for (path in nativesPaths) { | |
Utils.unzip(path, _nativesPath.toString(), arrayOf("META-INF")) | |
} | |
} | |
var p = Runtime.getRuntime().exec(run) | |
} | |
} | |
} | |
class Utils { | |
companion object { | |
fun unzip(zipPath: String, unzipPath: String, skip: Array<String>) { | |
try { | |
var zipFile = ZipFile(zipPath) | |
var enu = zipFile.entries() | |
while (enu.hasMoreElements()) { | |
var zipEntry: ZipEntry = enu.nextElement() | |
var name = zipEntry.name | |
if (skip.find { it -> name.contains(it) } != null) continue | |
var file = File("$unzipPath\\$name") | |
var parent = file.parentFile | |
if (parent != null) { | |
parent.mkdirs() | |
} | |
var inputStream = zipFile.getInputStream(zipEntry) | |
var fos = FileOutputStream(file) | |
var bytes = ByteArray(1024) | |
var length = inputStream.read(bytes) | |
while (length >= 0) { | |
fos.write(bytes, 0, length) | |
length = inputStream.read(bytes) | |
} | |
inputStream.close() | |
fos.close() | |
} | |
zipFile.close() | |
} catch (e: IOException) { | |
e.printStackTrace() | |
} | |
} | |
fun isDirEmpty(directory: Path): Boolean { | |
var dirStream = Files.newDirectoryStream(directory) | |
return !dirStream.iterator().hasNext(); | |
} | |
} | |
} |
Author
vQuadX
commented
May 7, 2016
Only for Windows
how do we run this?
i dont understand
Can you make it an ChromeOS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment