diff options
| author | ZekerZhayard <trees1000@qq.com> | 2020-03-26 20:46:22 +0800 |
|---|---|---|
| committer | ZekerZhayard <trees1000@qq.com> | 2020-03-26 20:46:22 +0800 |
| commit | 812a810acc6d516652310634eee5c49351796e2c (patch) | |
| tree | 578e7abe0b662a84f9d8fcaea4cf37accf9417a1 | |
| parent | c04ad2e036fd965bc9114d2bc8dcbfffa1174eb7 (diff) | |
| download | Project-Tick-812a810acc6d516652310634eee5c49351796e2c.tar.gz Project-Tick-812a810acc6d516652310634eee5c49351796e2c.zip | |
Skip installing forge while extract files exist.
5 files changed, 37 insertions, 36 deletions
diff --git a/build.gradle b/build.gradle index d5b5bc0e23..39d82af4ce 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 ff61563242..dbe8dafd18 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<String> 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 - // /<version> /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 1e8c365ba5..cd70fac004 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<String> 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); - - Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer"); - if (!(boolean) installer.getMethod("install").invoke(null)) { - return; + + 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); + + 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 + // /<version> /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 2d82a72b9c..0000000000 --- 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 d30c5bb32e..1add7375e8 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" } |
