Skip to content

Commit

Permalink
Fix unmapped game jar not being found in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
XXMA16 committed Sep 15, 2023
1 parent 559a166 commit f119d75
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/main/java/me/modmuss50/optifabric/mod/OptifineSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
Expand All @@ -35,9 +34,7 @@

import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.RecordComponentNode;

import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -326,7 +323,7 @@ private static IMappingProvider createMappings(String from, String to, IMappingP
};
}

//Gets the minecraft librarys
//Gets the minecraft libraries
private static Path[] getLibs(Path minecraftJar) {
Path[] libs = FabricLauncherBase.getLauncher().getLoadTimeDependencies().stream().map(url -> {
try {
Expand Down Expand Up @@ -355,7 +352,7 @@ private static Path[] getLibs(Path minecraftJar) {
return libs;
}

//Gets the offical minecraft jar
//Gets the official minecraft jar
private static Path getMinecraftJar() {
String givenJar = System.getProperty("optifabric.mc-jar");
if (givenJar != null) {
Expand All @@ -371,29 +368,29 @@ private static Path getMinecraftJar() {
Path minecraftJar = getLaunchMinecraftJar();

if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
Path officialNames = minecraftJar.resolveSibling(String.format("minecraft-%s-client.jar", OptifineVersion.minecraftVersion));
return getMinecraftDevJar(minecraftJar);
}

if (Files.notExists(officialNames)) {
Path parent = minecraftJar.getParent().resolveSibling(String.format("minecraft-%s-client.jar", OptifineVersion.minecraftVersion));
return minecraftJar;
}

if (Files.notExists(parent)) {
Path alternativeParent = parent.resolveSibling("minecraft-client.jar");
private static Path getMinecraftDevJar(Path minecraftJar) {
Path officialNames = minecraftJar.resolveSibling(String.format("minecraft-%s-client.jar", OptifineVersion.minecraftVersion));
if (Files.exists(officialNames)) return officialNames;

if (Files.notExists(alternativeParent)) {
throw new AssertionError("Unable to find Minecraft dev jar! Tried " + officialNames + ", " + parent + " and " + alternativeParent
+ "\nPlease supply it explicitly with -Doptifabric.mc-jar");
}
Path parent = minecraftJar.getParent().resolveSibling(String.format("minecraft-%s-client.jar", OptifineVersion.minecraftVersion));
if (Files.exists(parent)) return parent;

parent = alternativeParent;
}
Path alternativeParent = parent.resolveSibling("minecraft-client.jar");
if (Files.exists(alternativeParent)) return alternativeParent;

officialNames = parent;
}

minecraftJar = officialNames;
}
//user.home shouldn't be null (but it can be)
String gradleUserHome = System.getProperty("GRADLE_USER_HOME", System.getProperty("user.home", "."));
Path newLoom = Paths.get(gradleUserHome, ".gradle/caches/fabric-loom", OptifineVersion.minecraftVersion, "minecraft-client.jar");
if (Files.exists(newLoom)) return newLoom;

return minecraftJar;
throw new AssertionError(String.format("Unable to find Minecraft dev jar! Tried %s, %s, %s and %s", officialNames, parent, alternativeParent, newLoom)
+ "\nPlease supply it explicitly with -Doptifabric.mc-jar");
}

private static Path getLaunchMinecraftJar() {
Expand Down

0 comments on commit f119d75

Please sign in to comment.