Skip to content

Commit 9989191

Browse files
committed
Also guess gradle cache dir from assets location on launchwrapper
1 parent bf5d2f8 commit 9989191

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ buildscript {
1212
apply plugin: 'com.github.johnrengelman.shadow'
1313
apply plugin: 'java'
1414

15-
version = "2.6.9"
15+
version = "2.6.10"
1616
group = "ofdev" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
1717
archivesBaseName = "aa_do_not_rename_OptiFineDevTweaker"
1818

src/main/java/ofdev/common/Utils.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import java.nio.file.Paths;
1616
import java.nio.file.StandardOpenOption;
1717
import java.nio.file.attribute.BasicFileAttributes;
18+
import java.util.ArrayList;
1819
import java.util.Arrays;
1920
import java.util.HashSet;
21+
import java.util.List;
2022
import java.util.Set;
2123

2224
public class Utils {
@@ -84,19 +86,37 @@ public static Path findMinecraftJar(Path maybeFgCache) {
8486
return absolutePath;
8587
}
8688
String mcVersion = mcVersion();
89+
List<Path> attemptedPaths = new ArrayList<>();
8790

8891
if (maybeFgCache != null) {
8992
// provided likely FG cache:
93+
Path fg1fg2Path = maybeFgCache.resolve("net/minecraft/minecraft")
94+
.resolve(mcVersion).resolve("minecraft-" + mcVersion + ".jar").toAbsolutePath();
95+
attemptedPaths.add(fg1fg2Path);
96+
if (Files.exists(fg1fg2Path)) {
97+
LOGGER.info("Found Minecraft jar {} from FG1.x/FG2.x (provided cache)", fg1fg2Path);
98+
return fg1fg2Path;
99+
}
100+
// RetroFuturaGradle https://github.com/GTNewHorizons/RetroFuturaGradle
101+
//caches/retro_futura_gradle/mc-vanilla/1.12.2/
102+
Path rfgPath = maybeFgCache.resolve("mc-vanilla").resolve(mcVersion).resolve(mcVersion + ".jar").toAbsolutePath();
103+
attemptedPaths.add(rfgPath);
104+
if (Files.exists(rfgPath)) {
105+
LOGGER.info("Found Minecraft jar {} from RetroFuturaGradle (provided cache)", rfgPath);
106+
return rfgPath;
107+
}
90108
// FG3 - FG5
91109
Path fg3plusPath = maybeFgCache.resolve("minecraft_repo/versions")
92110
.resolve(mcVersion).resolve("client.jar").toAbsolutePath();
111+
attemptedPaths.add(fg3plusPath);
93112
if (Files.exists(fg3plusPath)) {
94113
LOGGER.info("Found Minecraft jar {} from FG3+ (provided cache)", fg3plusPath);
95114
return fg3plusPath;
96115
}
97116
// very old FG3 versions used slightly different path
98117
Path oldFg3Path = maybeFgCache.resolve("minecraft_repo/version")
99118
.resolve(mcVersion).resolve("client.jar").toAbsolutePath();
119+
attemptedPaths.add(oldFg3Path);
100120
if (Files.exists(oldFg3Path)) {
101121
LOGGER.info("Found Minecraft jar {} from old FG3 (provided cache)", oldFg3Path);
102122
return oldFg3Path;
@@ -112,6 +132,7 @@ public static Path findMinecraftJar(Path maybeFgCache) {
112132
// FG1 - FG2
113133
Path fg1fg2Path = gradleHome.resolve("caches/minecraft/net/minecraft/minecraft")
114134
.resolve(mcVersion).resolve("minecraft-" + mcVersion + ".jar").toAbsolutePath();
135+
attemptedPaths.add(fg1fg2Path);
115136
if (Files.exists(fg1fg2Path)) {
116137
LOGGER.info("Found Minecraft jar {} from FG1.x/FG2.x (global cache)", fg1fg2Path);
117138
return fg1fg2Path;
@@ -120,6 +141,7 @@ public static Path findMinecraftJar(Path maybeFgCache) {
120141
//caches/retro_futura_gradle/mc-vanilla/1.12.2/
121142
Path rfgPath = gradleHome.resolve("caches/retro_futura_gradle/mc-vanilla")
122143
.resolve(mcVersion).resolve(mcVersion + ".jar").toAbsolutePath();
144+
attemptedPaths.add(rfgPath);
123145
if (Files.exists(rfgPath)) {
124146
LOGGER.info("Found Minecraft jar {} from RetroFuturaGradle (global cache)", rfgPath);
125147
return rfgPath;
@@ -128,25 +150,27 @@ public static Path findMinecraftJar(Path maybeFgCache) {
128150
// FG3 - FG5
129151
Path fg3plusPath = Utils.gradleHome().resolve("caches/forge_gradle/minecraft_repo/versions")
130152
.resolve(mcVersion).resolve("client.jar").toAbsolutePath();
153+
attemptedPaths.add(fg3plusPath);
131154
if (Files.exists(fg3plusPath)) {
132155
LOGGER.info("Found Minecraft jar {} from FG3+ (global cache)", fg3plusPath);
133156
return fg3plusPath;
134157
}
135158
// very old FG3 versions used slightly different path
136159
Path oldFg3Path = Utils.gradleHome().resolve("caches/forge_gradle/minecraft_repo/version")
137160
.resolve(mcVersion).resolve("client.jar").toAbsolutePath();
161+
attemptedPaths.add(oldFg3Path);
138162
if (Files.exists(oldFg3Path)) {
139163
LOGGER.info("Found Minecraft jar {} from old FG3 (global cache)", oldFg3Path);
140164
return oldFg3Path;
141165
}
142166
// as a last resort, attempt vanilla launcher
143167
Path mcLauncherJar = Paths.get(System.getProperty("user.home")).resolve(".minecraft/versions").resolve(mcVersion).resolve(mcVersion + ".jar");
168+
attemptedPaths.add(mcLauncherJar);
144169
if (Files.exists(mcLauncherJar)) {
145170
LOGGER.info("Found Minecraft jar {} from Minecraft Launcher", mcLauncherJar);
146171
return mcLauncherJar;
147172
}
148-
String list = String.join("\n\t",
149-
fg1fg2Path.toString(), rfgPath.toString(), fg3plusPath.toString(), oldFg3Path.toString(), mcLauncherJar.toString());
173+
String list = String.join("\n\t", attemptedPaths.stream().map(Object::toString).toArray(String[]::new));
150174
throw new IllegalStateException("Could not fine Minecraft jar file. Try specifying Minecraft jar location with -Dofdev.mcjar=path\n\t"
151175
+ "Attempted locations:\n\t" + list);
152176
}

src/main/java/ofdev/launchwrapper/OptifineDevTransformerWrapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.nio.file.FileSystems;
3434
import java.nio.file.Files;
3535
import java.nio.file.Path;
36+
import java.nio.file.Paths;
3637
import java.util.HashMap;
3738
import java.util.HashSet;
3839
import java.util.Iterator;
@@ -42,11 +43,16 @@
4243
// this is needed only in dev environment to get deobfuscated version of OptiFine running
4344
public class OptifineDevTransformerWrapper implements IClassTransformer {
4445

45-
private static final Path MC_JAR = Utils.findMinecraftJar(null);
46+
private static final Path MC_JAR;
4647
private static final FileSystem mcJarFs;
4748

4849
static {
4950
try {
51+
Map<String, String> launchArgs = (Map<String, String>) Launch.blackboard.get("launchArgs");
52+
String assetsDir = launchArgs == null ? null : launchArgs.get("--assetsDir");
53+
// it just so happens that FG1,2,3+ and RetroFuturaGradle all have assets dir in about the same place relative to everything else
54+
Path mcGradleCacheDir = assetsDir == null ? null : Paths.get(assetsDir).getParent();
55+
MC_JAR = Utils.findMinecraftJar(mcGradleCacheDir);
5056
mcJarFs = FileSystems.newFileSystem(MC_JAR, Launch.classLoader);
5157
Launch.classLoader.addURL(MC_JAR.toUri().toURL());
5258
} catch (IOException e) {

0 commit comments

Comments
 (0)