Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OptiFabric being unable to find the official (unmapped) Minecraft jar in dev #1219

Open
wants to merge 1 commit into
base: llama
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading