Skip to content

Commit

Permalink
feat: update 1.20.3 and 1.20.4 MinecraftForge
Browse files Browse the repository at this point in the history
  • Loading branch information
xfl03 committed Dec 21, 2023
1 parent 668418a commit 8aa1f30
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/java/i18nupdatemod/I18nUpdateMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/i18nupdatemod/fabricloader/FabricLoaderMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
Expand All @@ -34,7 +34,7 @@ private String getMcVersion() {

}
try {
//Quilt
// Quilt
return (String) Reflection.clazz("org.quiltmc.loader.impl.QuiltLoaderImpl")
.get("INSTANCE")
.get("getGameProvider()")
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/i18nupdatemod/launchwrapper/LaunchWrapperTweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/i18nupdatemod/modlauncher/ModLauncherService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -55,6 +60,8 @@ public void onLoad(IEnvironment env, Set<String> 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) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/i18nupdatemod/util/AssetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 8aa1f30

Please sign in to comment.