|
| 1 | +package io.github.fabriccompatibiltylayers.modremappingapi.impl; |
| 2 | + |
| 3 | +import net.fabricmc.loader.api.FabricLoader; |
| 4 | +import net.fabricmc.loader.api.ObjectShare; |
| 5 | +import net.fabricmc.loader.impl.launch.FabricLauncherBase; |
| 6 | +import org.jetbrains.annotations.NotNull; |
| 7 | + |
| 8 | +import java.io.File; |
| 9 | +import java.io.IOException; |
| 10 | +import java.nio.charset.StandardCharsets; |
| 11 | +import java.nio.file.Files; |
| 12 | +import java.nio.file.Path; |
| 13 | +import java.nio.file.Paths; |
| 14 | +import java.util.ArrayList; |
| 15 | +import java.util.Arrays; |
| 16 | +import java.util.List; |
| 17 | +import java.util.stream.Collectors; |
| 18 | + |
| 19 | +public class RemapUtils { |
| 20 | + public static List<Path> getRemapClasspath() throws IOException { |
| 21 | + String remapClasspathFile = System.getProperty("fabric.remapClasspathFile"); |
| 22 | + |
| 23 | + if (remapClasspathFile == null) { |
| 24 | + System.out.println("remapClasspathFile is null! Falling back to ObjectShare."); |
| 25 | + return getClassPathFromObjectShare(); |
| 26 | + } |
| 27 | + |
| 28 | + String content = new String(Files.readAllBytes(Paths.get(remapClasspathFile)), StandardCharsets.UTF_8); |
| 29 | + |
| 30 | + return Arrays.stream(content.split(File.pathSeparator)) |
| 31 | + .map(Paths::get) |
| 32 | + .collect(Collectors.toList()); |
| 33 | + } |
| 34 | + |
| 35 | + public static @NotNull List<Path> getClassPathFromObjectShare() { |
| 36 | + ObjectShare share = FabricLoader.getInstance().getObjectShare(); |
| 37 | + Object inputs = share.get("fabric-loader:inputGameJars"); |
| 38 | + List<Path> list = new ArrayList<>(); |
| 39 | + |
| 40 | + Object oldJar = FabricLoader.getInstance().getObjectShare().get("fabric-loader:inputGameJar"); |
| 41 | + |
| 42 | + List<Path> classPaths = FabricLauncherBase.getLauncher().getClassPath(); |
| 43 | + |
| 44 | + if (inputs instanceof List) { |
| 45 | + List<Path> paths = (List<Path>) inputs; |
| 46 | + |
| 47 | + if (oldJar instanceof Path) { |
| 48 | + if (paths.get(0).toString().equals(oldJar.toString())) { |
| 49 | + list.addAll(paths); |
| 50 | + } else { |
| 51 | + list.add((Path) oldJar); |
| 52 | + } |
| 53 | + } else { |
| 54 | + list.addAll(paths); |
| 55 | + } |
| 56 | + } else { |
| 57 | + list.add((Path) oldJar); |
| 58 | + } |
| 59 | + |
| 60 | + list.addAll(classPaths); |
| 61 | + |
| 62 | + Object realmsJar = share.get("fabric-loader:inputRealmsJar"); |
| 63 | + |
| 64 | + if (realmsJar instanceof Path) list.add((Path) realmsJar); |
| 65 | + |
| 66 | + return list; |
| 67 | + } |
| 68 | +} |
0 commit comments