From 8aa1f30ea024e85c088653bda788d66cc83539c1 Mon Sep 17 00:00:00 2001 From: 33 Date: Thu, 21 Dec 2023 21:56:04 +0800 Subject: [PATCH] feat: update 1.20.3 and 1.20.4 MinecraftForge --- .../java/i18nupdatemod/I18nUpdateMod.java | 2 +- .../fabricloader/FabricLoaderMod.java | 4 ++-- .../launchwrapper/LaunchWrapperTweaker.java | 22 ++++++++++--------- .../modlauncher/ModLauncherService.java | 20 ++++++++++++++++- .../java/i18nupdatemod/util/AssetUtil.java | 2 +- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/java/i18nupdatemod/I18nUpdateMod.java b/src/main/java/i18nupdatemod/I18nUpdateMod.java index ff45ce2..69f49ea 100644 --- a/src/main/java/i18nupdatemod/I18nUpdateMod.java +++ b/src/main/java/i18nupdatemod/I18nUpdateMod.java @@ -22,7 +22,7 @@ public class I18nUpdateMod { public static final String MOD_ID = "i18nupdatemod"; public static String MOD_VERSION; - private static final Gson GSON = new Gson(); + public static final Gson GSON = new Gson(); public static void init(Path minecraftPath, String minecraftVersion, String loader) { try (InputStream is = I18nConfig.class.getResourceAsStream("/i18nMetaData.json")) { diff --git a/src/main/java/i18nupdatemod/fabricloader/FabricLoaderMod.java b/src/main/java/i18nupdatemod/fabricloader/FabricLoaderMod.java index b55fae0..ad740a0 100644 --- a/src/main/java/i18nupdatemod/fabricloader/FabricLoaderMod.java +++ b/src/main/java/i18nupdatemod/fabricloader/FabricLoaderMod.java @@ -25,7 +25,7 @@ public void onInitializeClient() { private String getMcVersion() { try { - //Fabric + // Fabric return (String) Reflection.clazz("net.fabricmc.loader.impl.FabricLoaderImpl") .get("INSTANCE") .get("getGameProvider()") @@ -34,7 +34,7 @@ private String getMcVersion() { } try { - //Quilt + // Quilt return (String) Reflection.clazz("org.quiltmc.loader.impl.QuiltLoaderImpl") .get("INSTANCE") .get("getGameProvider()") diff --git a/src/main/java/i18nupdatemod/launchwrapper/LaunchWrapperTweaker.java b/src/main/java/i18nupdatemod/launchwrapper/LaunchWrapperTweaker.java index f32f68c..72e522f 100644 --- a/src/main/java/i18nupdatemod/launchwrapper/LaunchWrapperTweaker.java +++ b/src/main/java/i18nupdatemod/launchwrapper/LaunchWrapperTweaker.java @@ -40,25 +40,27 @@ public String[] getLaunchArguments() { private String getMcVersion() { try { - //1.8.8-1.12.2 - return (String) Reflection.clazz("net.minecraftforge.common.ForgeVersion").get("mcVersion").get(); + // 1.6~1.7.10 + // 1.6: https://github.com/MinecraftForge/FML/blob/16launch/common/cpw/mods/fml/relauncher/FMLInjectionData.java#L32 + // 1.7.10: https://github.com/MinecraftForge/MinecraftForge/blob/1.7.10/fml/src/main/java/cpw/mods/fml/relauncher/FMLInjectionData.java#L32 + return (String) + Reflection.clazz("cpw.mods.fml.relauncher.FMLInjectionData").get("mccversion").get(); } catch (Exception ignored) { } try { - //1.6-1.7.10 - //1.6: https://github.com/MinecraftForge/FML/blob/902772ed0cb6c22c4cd7ad9b0ec7a02961b5e016/common/cpw/mods/fml/relauncher/FMLInjectionData.java#L32 - //1.7.10: https://github.com/MinecraftForge/MinecraftForge/blob/1.7.10/fml/src/main/java/cpw/mods/fml/relauncher/FMLInjectionData.java#L32 + // 1.8 + // https://github.com/MinecraftForge/FML/blob/1.8/src/main/java/net/minecraftforge/fml/relauncher/FMLInjectionData.java#L32 return (String) - Reflection.clazz("cpw.mods.fml.relauncher.FMLInjectionData").get("mccversion").get(); + Reflection.clazz("net.minecraftforge.fml.relauncher.FMLInjectionData").get("mccversion").get(); } catch (Exception ignored) { } try { - //1.8 - //https://github.com/MinecraftForge/FML/blob/d4ded9d6e218ac097990e836676bbe22b47e5966/src/main/java/net/minecraftforge/fml/relauncher/FMLInjectionData.java#L32 - return (String) - Reflection.clazz("net.minecraftforge.fml.relauncher.FMLInjectionData").get("mccversion").get(); + // 1.8.8~1.12.2 + // 1.8.8: https://github.com/MinecraftForge/MinecraftForge/blob/1.8.8/src/main/java/net/minecraftforge/common/ForgeVersion.java#L42 + // 1.12.2: https://github.com/MinecraftForge/MinecraftForge/blob/1.12.x/src/main/java/net/minecraftforge/common/ForgeVersion.java#L64 + return (String) Reflection.clazz("net.minecraftforge.common.ForgeVersion").get("mcVersion").get(); } catch (Exception ignored) { } return null; diff --git a/src/main/java/i18nupdatemod/modlauncher/ModLauncherService.java b/src/main/java/i18nupdatemod/modlauncher/ModLauncherService.java index 8626354..f8323e4 100644 --- a/src/main/java/i18nupdatemod/modlauncher/ModLauncherService.java +++ b/src/main/java/i18nupdatemod/modlauncher/ModLauncherService.java @@ -1,5 +1,6 @@ package i18nupdatemod.modlauncher; +import com.google.gson.JsonObject; import cpw.mods.modlauncher.Launcher; import cpw.mods.modlauncher.api.IEnvironment; import cpw.mods.modlauncher.api.ITransformationService; @@ -10,12 +11,16 @@ import i18nupdatemod.util.Reflection; import org.jetbrains.annotations.NotNull; +import java.io.InputStream; +import java.io.InputStreamReader; import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; +import static i18nupdatemod.I18nUpdateMod.GSON; + //1.13-latest public class ModLauncherService implements ITransformationService { @Override @@ -55,6 +60,8 @@ public void onLoad(IEnvironment env, Set otherServices) throws Incompati } private String getMinecraftVersion() { + // MinecraftForge 1.13~1.20.2 + // NeoForge 1.20.1~ try { String[] args = (String[]) Reflection.clazz(Launcher.INSTANCE).get("argumentHandler").get("args").get(); for (int i = 0; i < args.length - 1; ++i) { @@ -63,7 +70,18 @@ private String getMinecraftVersion() { } } } catch (Exception e) { - Log.warning(String.format("Error getting minecraft version: %s", e)); + Log.warning("Error getting minecraft version: %s", e); + } + + // MinecraftForge 1.20.3~ + // 1.20.3: https://github.com/MinecraftForge/MinecraftForge/blob/1.20.x/fmlloader/src/main/java/net/minecraftforge/fml/loading/VersionInfo.java + try { + Class clazz = Class.forName("net.minecraftforge.fml.loading.FMLLoader"); + try (InputStream is = clazz.getResourceAsStream("/forge_version.json")) { + return GSON.fromJson(new InputStreamReader(is), JsonObject.class).get("mc").getAsString(); + } + } catch (Exception e) { + Log.warning("Error getting minecraft version: %s", e); } return null; } diff --git a/src/main/java/i18nupdatemod/util/AssetUtil.java b/src/main/java/i18nupdatemod/util/AssetUtil.java index bb12246..713ea10 100644 --- a/src/main/java/i18nupdatemod/util/AssetUtil.java +++ b/src/main/java/i18nupdatemod/util/AssetUtil.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.concurrent.TimeUnit; @@ -16,6 +15,7 @@ public static void download(String url, Path localFile) throws IOException, URIS Log.info("Downloading: %s -> %s", url, localFile); FileUtils.copyURLToFile(new URI(url).toURL(), localFile.toFile(), (int) TimeUnit.SECONDS.toMillis(3), (int) TimeUnit.SECONDS.toMillis(33)); + Log.debug("Downloaded: %s -> %s", url, localFile); } public static String getString(String url) throws IOException, URISyntaxException {