diff --git a/build.gradle b/build.gradle index d5b5bc0..39d82af 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ apply plugin: "idea" sourceCompatibility = targetCompatibility = 1.8 -version = "1.3.0" +version = "1.3.1" group = "io.github.zekerzhayard" archivesBaseName = rootProject.name diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java index ff61563..dbe8daf 100644 --- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java +++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java @@ -1,10 +1,8 @@ package io.github.zekerzhayard.forgewrapper.installer; import java.io.File; -import java.net.URISyntaxException; import java.util.function.Predicate; -import cpw.mods.modlauncher.Launcher; import net.minecraftforge.installer.actions.ActionCanceledException; import net.minecraftforge.installer.actions.ClientInstall; import net.minecraftforge.installer.actions.ProgressCallback; @@ -17,15 +15,7 @@ public class ClientInstall4MultiMC extends ClientInstall { @Override public boolean run(File target, Predicate optionals) { - File librariesDir; - try { - File laucnher = new File(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI()); - // see https://github.com/MinecraftForge/MinecraftForge/blob/863ab2ca184cf2e2dfa134d07bfc20d6a9a6a4e8/src/main/java/net/minecraftforge/fml/relauncher/libraries/LibraryManager.java#L151 - // / /modlauncher /mods /cpw /libraries - librariesDir = laucnher.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile(); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } + File librariesDir = Main.getLibrariesDir(); File clientTarget = new File(String.format("%s/com/mojang/minecraft/%s/minecraft-%s-client.jar", librariesDir.getAbsolutePath(), this.profile.getMinecraft(), this.profile.getMinecraft())); boolean downloadLibraries = true; // Force true when without an internet connection. diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java index 1e8c365..cd70fac 100644 --- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java +++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java @@ -1,8 +1,11 @@ package io.github.zekerzhayard.forgewrapper.installer; import java.io.File; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -14,21 +17,38 @@ public class Main { public static void main(String[] args) throws Exception { List argsList = Stream.of(args).collect(Collectors.toList()); String version = argsList.get(argsList.indexOf("--fml.mcVersion") + 1) + "-" + argsList.get(argsList.indexOf("--fml.forgeVersion") + 1); - String installerUrl = String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/forge-%s-installer.jar", version, version); - String installerFileStr = String.format("./.forgewrapper/forge-%s-installer.jar", version); - Utils.download(installerUrl, installerFileStr); - URLClassLoader ucl = URLClassLoader.newInstance(new URL[] { - Main.class.getProtectionDomain().getCodeSource().getLocation(), - Launcher.class.getProtectionDomain().getCodeSource().getLocation(), - new File(installerFileStr).toURI().toURL() - }, null); + Path forgeDir = getLibrariesDir().toPath().resolve("net").resolve("minecraftforge").resolve("forge").resolve(version); + Path clientJar = forgeDir.resolve("forge-" + version + "-client.jar"); + Path extraJar = forgeDir.resolve("forge-" + version + "-extra.jar"); + if (Files.exists(clientJar) && Files.exists(extraJar)) { + String installerUrl = String.format("https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/forge-%s-installer.jar", version, version); + String installerFileStr = String.format("./.forgewrapper/forge-%s-installer.jar", version); + Utils.download(installerUrl, installerFileStr); - Class installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer"); - if (!(boolean) installer.getMethod("install").invoke(null)) { - return; + URLClassLoader ucl = URLClassLoader.newInstance(new URL[] { + Main.class.getProtectionDomain().getCodeSource().getLocation(), + Launcher.class.getProtectionDomain().getCodeSource().getLocation(), + new File(installerFileStr).toURI().toURL() + }, null); + + Class installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer"); + if (!(boolean) installer.getMethod("install").invoke(null)) { + return; + } } Launcher.main(args); } + + public static File getLibrariesDir() { + try { + File laucnher = new File(Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI()); + // see https://github.com/MinecraftForge/MinecraftForge/blob/863ab2ca184cf2e2dfa134d07bfc20d6a9a6a4e8/src/main/java/net/minecraftforge/fml/relauncher/libraries/LibraryManager.java#L151 + // / /modlauncher /mods /cpw /libraries + return laucnher.getParentFile().getParentFile().getParentFile().getParentFile().getParentFile(); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } } diff --git a/src/main/java/why/does/multimc/target/Me.java b/src/main/java/why/does/multimc/target/Me.java deleted file mode 100644 index 2d82a72..0000000 --- a/src/main/java/why/does/multimc/target/Me.java +++ /dev/null @@ -1,9 +0,0 @@ -package why.does.multimc.target; - -import io.github.zekerzhayard.forgewrapper.installer.Main; - -public class Me { - public static void main(String[] args) throws Exception { - Main.main(args); - } -} diff --git a/src/main/resources/patches/net.minecraftforge.json b/src/main/resources/patches/net.minecraftforge.json index d30c5bb..1add737 100644 --- a/src/main/resources/patches/net.minecraftforge.json +++ b/src/main/resources/patches/net.minecraftforge.json @@ -1,6 +1,6 @@ { "formatVersion": 1, - "mainClass": "why.does.multimc.target.Me", + "mainClass": "io.github.zekerzhayard.forgewrapper.installer.Main", "minecraftArguments": "", "name": "Forge", "requires": [ @@ -14,7 +14,7 @@ "version": "{FORGE_VERSION}", "libraries": [ { - "name": "io.github.zekerzhayard:ForgeWrapper:${version}", + "name": "io.github.zekerzhayard:Forge-Wrapper:${version}", "MMC-hint": "local", "MMC-filename": "ForgeWrapper-${version}.jar" }