Skip to content

Commit

Permalink
[Custom version] Improve MC version inheriting combination
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Nov 15, 2020
1 parent bfec5cd commit a33dcfa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static class Arguments {
public static class ArgValue {
public ArgRules[] rules;
public String value;

// TLauncher styled argument...
public String[] values;

public static class ArgRules {
public String action;
Expand Down
48 changes: 40 additions & 8 deletions app/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,17 @@ public static String[] getMinecraftArgs(MCProfile.Builder profile, JMinecraftVer
if (arg instanceof String) {
minecraftArgs.add((String) arg);
} else {
/*
for (JMinecraftVersionList.Arguments.ArgValue.ArgRules rule : arg.rules) {
// rule.action = allow
// TODO implement this
}
*/
JMinecraftVersionList.Arguments.ArgValue argv = (JMinecraftVersionList.Arguments.ArgValue) arg;
if (argv.values != null) {
minecraftArgs.add(argv.values[0]);
} else {
/*
for (JMinecraftVersionList.Arguments.ArgValue.ArgRules rule : arg.rules) {
// rule.action = allow
// TODO implement this
}
*/
}
}
}
}
Expand Down Expand Up @@ -573,7 +578,7 @@ public static JMinecraftVersionList.Version getVersionInfo(String versionName) {

insertSafety(inheritsVer, customVer,
"assetIndex", "assets",
"id", "mainClass", "minecraftArguments",
"mainClass", "minecraftArguments",
"optifineLib", "releaseTime", "time", "type"
);

Expand All @@ -589,8 +594,35 @@ public static JMinecraftVersionList.Version getVersionInfo(String versionName) {
// Inheriting Minecraft 1.13+ with append custom args
if (inheritsVer.arguments != null && customVer.arguments != null) {
List totalArgList = new ArrayList();
totalArgList.addAll(Arrays.asList(customVer.arguments.game));
totalArgList.addAll(Arrays.asList(inheritsVer.arguments.game));

int nskip = 0;
for (int i = 0; i < customVer.arguments.game.length; i++) {
if (nskip > 0) {
nskip--;
continue;
}

Object perCustomArg = customVer.arguments.game[i];
if (perCustomArg instanceof String) {
String perCustomArgStr = (String) perCustomArg;
// Check if there is a duplicate argument on combine
if (perCustomArgStr.startsWith("--") && totalArgList.contains(perCustomArgStr)) {
perCustomArg = customVer.arguments.game[i + 1];
if (perCustomArg instanceof String) {
perCustomArgStr = (String) perCustomArg;
// If the next is argument value, skip it
if (!perCustomArgStr.startsWith("--")) {
nskip++;
}
}
} else {
totalArgList.add(perCustomArgStr);
}
} else if (!totalArgList.contains(perCustomArg)) {
totalArgList.add(perCustomArg);
}
}

inheritsVer.arguments.game = totalArgList.toArray(new Object[0]);
}
Expand Down

0 comments on commit a33dcfa

Please sign in to comment.