Skip to content

Commit

Permalink
Mod Loader Switching
Browse files Browse the repository at this point in the history
  • Loading branch information
CADIndie committed Dec 9, 2023
1 parent e5ed0f9 commit f56243c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
22 changes: 4 additions & 18 deletions lib/src/main/java/pojlib/api/API_V1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}
}

Expand Down
36 changes: 32 additions & 4 deletions lib/src/main/java/pojlib/instance/MinecraftInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f56243c

Please sign in to comment.