Fix optifine

This commit is contained in:
huangyuhui
2018-03-06 11:19:21 +08:00
parent 71cfa64b16
commit fb1fc92b7c
10 changed files with 60 additions and 54 deletions

View File

@@ -41,9 +41,12 @@ public class MaintainTask extends TaskResult<Version> {
@Override
public void execute() {
Version newVersion = version;
setResult(maintain(version));
}
public static Version maintain(Version version) {
Library forge = null, liteLoader = null, optiFine = null;
List<String> args = new ArrayList<>(StringUtils.tokenize(newVersion.getMinecraftArguments().orElse("")));
List<String> args = new ArrayList<>(StringUtils.tokenize(version.getMinecraftArguments().orElse("")));
for (Library library : version.getLibraries()) {
if (library.getGroupId().equalsIgnoreCase("net.minecraftforge") && library.getArtifactId().equalsIgnoreCase("forge"))
@@ -84,11 +87,13 @@ public class MaintainTask extends TaskResult<Version> {
}
if ((liteLoader != null || forge != null) && optiFine != null) {
// If forge or LiteLoader installed, OptiFine Tweaker will cause crash.
// If forge or LiteLoader installed, OptiFine Forge Tweaker is needed.
removeTweakClass(args, "optifine");
args.add("--tweakClass");
args.add("optifine.OptiFineForgeTweaker");
}
setResult(newVersion.setMinecraftArguments(StringUtils.makeCommand(args)));
return version.setMinecraftArguments(StringUtils.makeCommand(args));
}
@Override

View File

@@ -70,13 +70,13 @@ public final class OptiFineInstallTask extends TaskResult<Version> {
@Override
public void execute() {
String remoteVersion = remote.getSelfVersion();
String remoteVersion = remote.getGameVersion() + "-" + remote.getSelfVersion();
Library library = new Library(
"net.optifine", "optifine", remoteVersion, null, null,
new LibrariesDownloadInfo(new LibraryDownloadInfo(
"net/optifine/optifine/" + remoteVersion + "/optifine-" + remoteVersion + ".jar",
remote.getUrl())), true
remote.getUrl()))
);
List<Library> libraries = new LinkedList<>();
@@ -99,6 +99,8 @@ public final class OptiFineInstallTask extends TaskResult<Version> {
String minecraftArguments = version.getMinecraftArguments().orElse("");
if (!hasFMLTweaker)
minecraftArguments = minecraftArguments + " --tweakClass optifine.OptiFineTweaker";
else
minecraftArguments = minecraftArguments + " --tweakClass optifine.OptiFineForgeTweaker";
if (version.getMainClass() == null || !version.getMainClass().startsWith("net.minecraft.launchwrapper."))
libraries.add(0, new Library("net.minecraft", "launchwrapper", "1.12"));

View File

@@ -40,7 +40,7 @@ public class ClassicVersion extends Version {
public ClassicLibrary(String name) {
super("", "", "", null, null,
new LibrariesDownloadInfo(new LibraryDownloadInfo("bin/" + name + ".jar"), null),
false, null, null, null, null);
null, null, null, null);
}
}

View File

@@ -45,7 +45,6 @@ public class Library implements Comparable<Library> {
private final LibrariesDownloadInfo downloads;
private final LibraryDownloadInfo download;
private final ExtractRules extract;
private final boolean lateload;
private final Map<OperatingSystem, String> natives;
private final List<CompatibilityRule> rules;
private final List<String> checksums;
@@ -55,16 +54,12 @@ public class Library implements Comparable<Library> {
public Library(String groupId, String artifactId, String version) {
this(groupId, artifactId, version, null, null, null);
}
public Library(String groupId, String artifactId, String version, String classifier, String url, LibrariesDownloadInfo downloads) {
this(groupId, artifactId, version, classifier, url, downloads, false);
this(groupId, artifactId, version, classifier, url, downloads, null, null, null, null);
}
public Library(String groupId, String artifactId, String version, String classifier, String url, LibrariesDownloadInfo downloads, boolean lateload) {
this(groupId, artifactId, version, classifier, url, downloads, lateload, null, null, null, null);
}
public Library(String groupId, String artifactId, String version, String classifier, String url, LibrariesDownloadInfo downloads, boolean lateload, List<String> checksums, ExtractRules extract, Map<OperatingSystem, String> natives, List<CompatibilityRule> rules) {
public Library(String groupId, String artifactId, String version, String classifier, String url, LibrariesDownloadInfo downloads, List<String> checksums, ExtractRules extract, Map<OperatingSystem, String> natives, List<CompatibilityRule> rules) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
@@ -78,7 +73,6 @@ public class Library implements Comparable<Library> {
this.url = url;
this.downloads = downloads;
this.extract = extract;
this.lateload = lateload;
this.natives = natives;
this.rules = rules;
this.checksums = checksums;
@@ -139,10 +133,6 @@ public class Library implements Comparable<Library> {
return download;
}
public boolean isLateload() {
return lateload;
}
public List<String> getChecksums() {
return checksums;
}
@@ -179,7 +169,7 @@ public class Library implements Comparable<Library> {
}
public Library setClassifier(String classifier) {
return new Library(groupId, artifactId, version, classifier, url, downloads, lateload, checksums, extract, natives, rules);
return new Library(groupId, artifactId, version, classifier, url, downloads, checksums, extract, natives, rules);
}
public static Library fromName(String name) {
@@ -191,7 +181,7 @@ public class Library implements Comparable<Library> {
if (arr.length != 3 && arr.length != 4)
throw new IllegalArgumentException("Library name is malformed. Correct example: group:artifact:version(:classifier).");
return new Library(arr[0].replace("\\", "/"), arr[1], arr[2], arr.length >= 4 ? arr[3] : null, url, downloads, false, checksums, extract, natives, rules);
return new Library(arr[0].replace("\\", "/"), arr[1], arr[2], arr.length >= 4 ? arr[3] : null, url, downloads, checksums, extract, natives, rules);
}
public static class Serializer implements JsonDeserializer<Library>, JsonSerializer<Library> {

View File

@@ -110,29 +110,23 @@ public class DefaultLauncher extends Launcher {
res.add("-Dfml.ignorePatchDiscrepancies=true");
}
LinkedList<File> lateload = new LinkedList<>();
StringBuilder classpath = new StringBuilder();
LinkedList<String> classpath = new LinkedList<>();
for (Library library : version.getLibraries())
if (library.appliesToCurrentEnvironment() && !library.isNative()) {
File f = repository.getLibraryFile(version, library);
if (f.exists() && f.isFile())
if (library.isLateload())
lateload.add(f);
else
classpath.append(f.getAbsolutePath()).append(OperatingSystem.PATH_SEPARATOR);
classpath.add(f.getAbsolutePath());
}
for (File library : lateload)
classpath.append(library.getAbsolutePath()).append(OperatingSystem.PATH_SEPARATOR);
File jar = repository.getVersionJar(version);
if (!jar.exists() || !jar.isFile())
throw new IOException("Minecraft jar does not exist");
classpath.append(jar.getAbsolutePath());
classpath.add(jar.getAbsolutePath());
// Provided Minecraft arguments
File gameAssets = repository.getActualAssetDirectory(version.getId(), version.getAssetIndex().getId());
Map<String, String> configuration = getConfigurations();
configuration.put("${classpath}", classpath.toString());
configuration.put("${classpath}", String.join(OperatingSystem.PATH_SEPARATOR, classpath));
configuration.put("${natives_directory}", nativeFolder.getAbsolutePath());
configuration.put("${game_assets}", gameAssets.getAbsolutePath());
configuration.put("${assets_root}", gameAssets.getAbsolutePath());