Try to fix the loom injection

This commit is contained in:
Juuxel
2020-11-30 20:40:49 +02:00
parent 385e0c9544
commit 76a171556e

View File

@@ -27,6 +27,7 @@ package net.fabricmc.loom.providers;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.net.URI;
@@ -36,7 +37,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.Optional;
@@ -53,6 +53,7 @@ import com.google.gson.GsonBuilder;
import net.minecraftforge.binarypatcher.ConsoleTool;
import net.minecraftforge.gradle.mcp.util.MCPRuntime;
import net.minecraftforge.gradle.mcp.util.MCPWrapper;
import org.apache.commons.io.FileUtils;
import org.cadixdev.atlas.Atlas;
import org.cadixdev.bombe.asm.jar.JarEntryRemappingTransformer;
import org.cadixdev.lorenz.MappingSet;
@@ -276,20 +277,21 @@ public class MinecraftProvider extends DependencyProvider {
private void injectForgeClasses(Logger logger) throws IOException {
logger.lifecycle(":injecting forge classes into minecraft");
copyAll(getExtension().getForgeUniversalProvider().getForge().toPath(), minecraftClientPatchedSrgJar.toPath());
copyAll(getExtension().getForgeUniversalProvider().getForge().toPath(), minecraftServerPatchedSrgJar.toPath());
copyAll(getExtension().getForgeUniversalProvider().getForge(), minecraftClientPatchedSrgJar);
copyAll(getExtension().getForgeUniversalProvider().getForge(), minecraftServerPatchedSrgJar);
copyUserdevFiles(getExtension().getForgeUserdevProvider().getUserdevJar().toPath(), minecraftClientPatchedSrgJar.toPath());
copyUserdevFiles(getExtension().getForgeUserdevProvider().getUserdevJar().toPath(), minecraftServerPatchedSrgJar.toPath());
copyUserdevFiles(getExtension().getForgeUserdevProvider().getUserdevJar(), minecraftClientPatchedSrgJar);
copyUserdevFiles(getExtension().getForgeUserdevProvider().getUserdevJar(), minecraftServerPatchedSrgJar);
try {
logger.lifecycle(":injecting loom classes into minecraft");
Path injection = Paths.get(MinecraftProvider.class.getResource("/inject/injection.jar").toURI());
copyAll(injection, minecraftClientPatchedSrgJar.toPath());
copyAll(injection, minecraftServerPatchedSrgJar.toPath());
} catch (URISyntaxException e) {
throw new IOException(e);
logger.lifecycle(":injecting loom classes into minecraft");
File injection = File.createTempFile("loom-injection", ".jar");
try (InputStream in = MinecraftProvider.class.getResourceAsStream("/inject/injection.jar")) {
FileUtils.copyInputStreamToFile(in, injection);
}
copyAll(injection, minecraftClientPatchedSrgJar);
copyAll(injection, minecraftServerPatchedSrgJar);
}
private void remapPatchedJars(Logger logger) throws IOException {
@@ -327,8 +329,8 @@ public class MinecraftProvider extends DependencyProvider {
patchJars(minecraftServerSrgJar, minecraftServerPatchedSrgJar, patchProvider.serverPatches);
logger.lifecycle(":copying missing classes into patched jars");
copyMissingClasses(minecraftClientSrgJar.toPath(), minecraftClientPatchedSrgJar.toPath());
copyMissingClasses(minecraftServerSrgJar.toPath(), minecraftServerPatchedSrgJar.toPath());
copyMissingClasses(minecraftClientSrgJar, minecraftClientPatchedSrgJar);
copyMissingClasses(minecraftServerSrgJar, minecraftServerPatchedSrgJar);
}
private void patchJars(File clean, File output, Path patches) throws IOException {
@@ -347,8 +349,8 @@ public class MinecraftProvider extends DependencyProvider {
logger.lifecycle(":copying resources");
// Copy resources
copyNonClassFiles(minecraftClientJar.toPath(), minecraftMergedJar.toPath());
copyNonClassFiles(minecraftServerJar.toPath(), minecraftMergedJar.toPath());
copyNonClassFiles(minecraftClientJar, minecraftMergedJar);
copyNonClassFiles(minecraftServerJar, minecraftMergedJar);
} else {
logger.lifecycle(":merging jars");
@@ -359,9 +361,9 @@ public class MinecraftProvider extends DependencyProvider {
}
}
private void walkFileSystems(Path source, Path target, Predicate<Path> filter, Function<FileSystem, Iterable<Path>> toWalk, FsPathConsumer action) throws IOException {
try (FileSystem sourceFs = FileSystems.newFileSystem(new URI("jar:" + source.toUri()), ImmutableMap.of("create", false));
FileSystem targetFs = FileSystems.newFileSystem(new URI("jar:" + target.toUri()), ImmutableMap.of("create", false))) {
private void walkFileSystems(File source, File target, Predicate<Path> filter, Function<FileSystem, Iterable<Path>> toWalk, FsPathConsumer action) throws IOException {
try (FileSystem sourceFs = FileSystems.newFileSystem(new URI("jar:" + source.toURI()), ImmutableMap.of("create", false));
FileSystem targetFs = FileSystems.newFileSystem(new URI("jar:" + target.toURI()), ImmutableMap.of("create", false))) {
for (Path sourceDir : toWalk.apply(sourceFs)) {
Path dir = sourceDir.toAbsolutePath();
java.nio.file.Files.walk(dir)
@@ -384,15 +386,15 @@ public class MinecraftProvider extends DependencyProvider {
}
}
private void walkFileSystems(Path source, Path target, Predicate<Path> filter, FsPathConsumer action) throws IOException {
private void walkFileSystems(File source, File target, Predicate<Path> filter, FsPathConsumer action) throws IOException {
walkFileSystems(source, target, filter, FileSystem::getRootDirectories, action);
}
private void copyAll(Path source, Path target) throws IOException {
private void copyAll(File source, File target) throws IOException {
walkFileSystems(source, target, it -> true, this::copyReplacing);
}
private void copyMissingClasses(Path source, Path target) throws IOException {
private void copyMissingClasses(File source, File target) throws IOException {
walkFileSystems(source, target, it -> it.toString().endsWith(".class"), (sourceFs, targetFs, sourcePath, targetPath) -> {
if (java.nio.file.Files.exists(targetPath)) return;
Path parent = targetPath.getParent();
@@ -405,7 +407,7 @@ public class MinecraftProvider extends DependencyProvider {
});
}
private void copyNonClassFiles(Path source, Path target) throws IOException {
private void copyNonClassFiles(File source, File target) throws IOException {
walkFileSystems(source, target, it -> !it.toString().endsWith(".class"), this::copyReplacing);
}
@@ -419,7 +421,7 @@ public class MinecraftProvider extends DependencyProvider {
java.nio.file.Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
}
private void copyUserdevFiles(Path source, Path target) throws IOException {
private void copyUserdevFiles(File source, File target) throws IOException {
walkFileSystems(source, target, file -> true, fs -> Collections.singleton(fs.getPath("inject")), (sourceFs, targetFs, sourcePath, targetPath) -> {
Path parent = targetPath.getParent();