From 7e7e050f164c0a59180754f5d21235875b3d1b27 Mon Sep 17 00:00:00 2001 From: Darien Johnson <84008186+CADIndie@users.noreply.github.com> Date: Fri, 8 Dec 2023 23:03:45 -0500 Subject: [PATCH] Mod Loader Switching --- lib/src/main/java/pojlib/api/API_V1.java | 22 +++--------- .../pojlib/instance/MinecraftInstance.java | 36 ++++++++++++++++--- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/lib/src/main/java/pojlib/api/API_V1.java b/lib/src/main/java/pojlib/api/API_V1.java index 24fc7825..7f6b38d2 100644 --- a/lib/src/main/java/pojlib/api/API_V1.java +++ b/lib/src/main/java/pojlib/api/API_V1.java @@ -86,21 +86,6 @@ public static String getQCSupportedVersionName(MinecraftMeta.MinecraftVersion ve return APIHandler.getQCSupportedVersionName(version); } - /** - * A collection of loader types - */ - public enum ModLoader { - Vanilla(0), - Fabric(1), - Quilt(2); - - public final int index; - - ModLoader(int i) { - this.index = i; - } - } - /** * Loads an instance from the filesystem. * @@ -119,17 +104,18 @@ public static MinecraftInstance load(String instanceName, String gameDir) { * @param instanceName The name of the instance being created - can be anything, used for identification * @param home The base directory where minecraft should be setup * @param minecraftVersion The version of minecraft to install + * @param modLoader The mod loader to install * @return A minecraft instance object * @throws IOException Throws if download of library or asset fails */ - public static MinecraftInstance createNewInstance(Activity activity, String instanceName, String home, MinecraftMeta.MinecraftVersion minecraftVersion) throws IOException { + public static MinecraftInstance createNewInstance(Activity activity, String instanceName, String home, MinecraftMeta.MinecraftVersion minecraftVersion, MinecraftInstance.ModLoader modLoader) throws IOException { if(ignoreInstanceName) { - return MinecraftInstance.create(activity, instanceName, home, minecraftVersion); + return MinecraftInstance.create(activity, instanceName, home, minecraftVersion, modLoader); } else if (instanceName.contains("/") || instanceName.contains("!")) { throw new IOException("You cannot use special characters (!, /, ., etc) when creating instances."); } else { - return MinecraftInstance.create(activity, instanceName, home, minecraftVersion); + return MinecraftInstance.create(activity, instanceName, home, minecraftVersion, modLoader); } } diff --git a/lib/src/main/java/pojlib/instance/MinecraftInstance.java b/lib/src/main/java/pojlib/instance/MinecraftInstance.java index 4402e835..c890072e 100644 --- a/lib/src/main/java/pojlib/instance/MinecraftInstance.java +++ b/lib/src/main/java/pojlib/instance/MinecraftInstance.java @@ -39,26 +39,54 @@ public class MinecraftInstance { public String assetsDir; public String mainClass; + public enum ModLoader { + Fabric(0), + Quilt(1), + Forge(2), + NeoForge(3); + + public final int index; + + ModLoader(int i) { + this.index = i; + } + } + //creates a new instance of a minecraft version, install game + mod loader, stores non login related launch info to json - public static MinecraftInstance create(Activity activity, String instanceName, String gameDir, MinecraftMeta.MinecraftVersion minecraftVersion) throws IOException { + public static MinecraftInstance create(Activity activity, String instanceName, String gameDir, MinecraftMeta.MinecraftVersion minecraftVersion, ModLoader modLoader) throws IOException { Logger.getInstance().appendToLog("Creating new instance: " + instanceName); MinecraftInstance instance = new MinecraftInstance(); instance.versionName = minecraftVersion.id; instance.gameDir = new File(gameDir).getAbsolutePath(); + VersionInfo modLoaderVersionInfo = null; + switch (modLoader) { + case Fabric: { + FabricMeta.FabricVersion fabricVersion = FabricMeta.getLatestStableVersion(); + modLoaderVersionInfo = FabricMeta.getVersionInfo(fabricVersion, minecraftVersion); + } + case Quilt: { + QuiltMeta.QuiltVersion quiltVersion = QuiltMeta.getLatestVersion(); + modLoaderVersionInfo = QuiltMeta.getVersionInfo(quiltVersion, minecraftVersion); + } + default: { + FabricMeta.FabricVersion fabricVersion = FabricMeta.getLatestStableVersion(); + modLoaderVersionInfo = FabricMeta.getVersionInfo(fabricVersion, minecraftVersion); + } + } + VersionInfo minecraftVersionInfo = MinecraftMeta.getVersionInfo(minecraftVersion); instance.versionType = minecraftVersionInfo.type; - FabricMeta.FabricVersion fabricVersion = FabricMeta.getLatestStableVersion(); - VersionInfo modLoaderVersionInfo = FabricMeta.getVersionInfo(fabricVersion, minecraftVersion); instance.mainClass = modLoaderVersionInfo.mainClass; // Install minecraft + VersionInfo finalModLoaderVersionInfo = modLoaderVersionInfo; new Thread(() -> { try { String clientClasspath = Installer.installClient(minecraftVersionInfo, gameDir); String minecraftClasspath = Installer.installLibraries(minecraftVersionInfo, gameDir); - String modLoaderClasspath = Installer.installLibraries(modLoaderVersionInfo, gameDir); + String modLoaderClasspath = Installer.installLibraries(finalModLoaderVersionInfo, gameDir); String lwjgl = Installer.installLwjgl(activity); instance.classpath = clientClasspath + File.pathSeparator + minecraftClasspath + File.pathSeparator + modLoaderClasspath + File.pathSeparator + lwjgl;