Skip to content

Commit

Permalink
Use gradle home environment variable if specified (closes #7), try to…
Browse files Browse the repository at this point in the history
… also detect data run target
  • Loading branch information
Barteks2x committed Jan 2, 2022
1 parent c126693 commit a8f84d6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'

version = "2.6"
version = "2.6.1"
group = "ofdev" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "aa_do_not_rename_OptiFineDevTweaker"

Expand Down
7 changes: 1 addition & 6 deletions src/main/java/ofdev/common/FG3.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ public static Path findObfMcJar(String mcVersion, boolean isClient) {
// because MC_VERSION has invalid value in forge 1.12.2 2855, we can't use MC_VERSION generally
//String mcVersion = System.getenv("MC_VERSION");
String dist = isClient ? "client" : "server";

return Paths.get(System.getProperty("user.home"),
".gradle/caches/forge_gradle/minecraft_repo/versions",
mcVersion,
dist + ".jar"
);
return Utils.gradleHome().resolve("caches/forge_gradle/minecraft_repo/versions").resolve(mcVersion).resolve(dist + ".jar");
}
}
9 changes: 9 additions & 0 deletions src/main/java/ofdev/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;

public class Utils {

public static Path gradleHome() {
String gradleHome = System.getenv("GRADLE_USER_HOME");
if (gradleHome == null || gradleHome.isEmpty()){
gradleHome = System.getProperty("user.home") + "/.gradle";
}
return Paths.get(gradleHome);
}

public static void rm(Path path) throws IOException {
if (Files.exists(path)) {
if (!Files.isDirectory(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -51,26 +50,28 @@
public class OptifineDevTransformerWrapper implements IClassTransformer {

// TODO: will it work on windows?
private static final String MC_JAR;
private static final Path MC_JAR;

static {
if (System.getProperty("net.minecraftforge.gradle.GradleStart.srg.notch-mcp") != null) {
String userJarValue = System.getProperty("ofdev.mcjar");
if (userJarValue != null) {
MC_JAR = Paths.get(userJarValue);
} else if (System.getProperty("net.minecraftforge.gradle.GradleStart.srg.notch-mcp") != null) {
// then using ForgeGradle 2.x or earlier.
MC_JAR = System.getProperty("ofdev.mcjar",
System.getProperty("user.home") + "/.gradle/caches/minecraft/net/minecraft/minecraft/" +
UtilsLW.mcVersion() + "/minecraft-" + UtilsLW.mcVersion() + ".jar");
MC_JAR = Utils.gradleHome().resolve("caches/minecraft/net/minecraft/minecraft")
.resolve(UtilsLW.mcVersion()).resolve("/minecraft-" + UtilsLW.mcVersion() + ".jar");
} else {
// then using ForgeGradle 3.x or later.
boolean isClient = System.getenv("assetIndex") != null;
MC_JAR = FG3.findObfMcJar(UtilsLW.mcVersion(), isClient).toString();
MC_JAR = FG3.findObfMcJar(UtilsLW.mcVersion(), isClient);
}
}

private static final FileSystem mcJar;

static {
try {
mcJar = FileSystems.newFileSystem(Paths.get(MC_JAR), Launch.classLoader);
mcJar = FileSystems.newFileSystem(MC_JAR, Launch.classLoader);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -102,7 +103,7 @@ public class OptifineDevTransformerWrapper implements IClassTransformer {
UtilsLW.setFieldValue(ofTransformerClass, "patterns", ofTransformer, patternsVal);
System.out.println("Ignore the above, OptiFine should run anyway");

Launch.classLoader.addURL(new File(MC_JAR).toURI().toURL());
Launch.classLoader.addURL(MC_JAR.toUri().toURL());
} catch (InstantiationException | IllegalAccessException | IOException | URISyntaxException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ private static Path findObfMcJar(IEnvironment env) {
throw new IllegalStateException(ex);
}
}
String target = env.getProperty(IEnvironment.Keys.LAUNCHTARGET.get()).get();//target=fmluserdevclient for client
return FG3.findObfMcJar(mcVersion, target.toLowerCase(Locale.ROOT).contains("client"));
String target = env.getProperty(IEnvironment.Keys.LAUNCHTARGET.get()).get().toLowerCase(Locale.ROOT);//target=fmluserdevclient for client
return FG3.findObfMcJar(mcVersion, target.contains("client") || target.contains("data"));
}

private static IEnvironment env;
Expand Down

0 comments on commit a8f84d6

Please sign in to comment.