mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 21:05:58 -05:00
Fix support for Forge 1.18
Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
@@ -52,6 +52,7 @@ import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.MirrorUtil;
|
||||
import net.fabricmc.loom.util.DownloadUtil;
|
||||
import net.fabricmc.loom.util.HashedDownloadUtil;
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
import net.fabricmc.stitch.merge.JarMerger;
|
||||
|
||||
public class MinecraftProviderImpl extends DependencyProvider implements MinecraftProvider {
|
||||
@@ -67,6 +68,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
|
||||
public File minecraftServerJar;
|
||||
// The extracted server jar from the boostrap, only exists in >=21w39a
|
||||
public File minecraftExtractedServerJar;
|
||||
private Boolean isNewerThan21w39a;
|
||||
private File minecraftMergedJar;
|
||||
private File versionManifestJson;
|
||||
private File experimentalVersionsJson;
|
||||
@@ -332,6 +334,26 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
|
||||
}
|
||||
}
|
||||
|
||||
public File getMinecraftServerJar() {
|
||||
if (isNewerThan21w39a()) {
|
||||
try {
|
||||
return getServerJarToMerge(getProject().getLogger());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return minecraftServerJar;
|
||||
}
|
||||
|
||||
public boolean isNewerThan21w39a() {
|
||||
if (isNewerThan21w39a != null) {
|
||||
return isNewerThan21w39a;
|
||||
}
|
||||
|
||||
return isNewerThan21w39a = ZipUtils.contains(minecraftServerJar.toPath(), "META-INF/versions.list");
|
||||
}
|
||||
|
||||
public File getMergedJar() {
|
||||
return minecraftMergedJar;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,6 @@ public class ForgeUserdevProvider extends DependencyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Read launch configs from the JSON too
|
||||
// TODO: Should I copy the patches from here as well?
|
||||
// That'd require me to run the "MCP environment" fully up to merging.
|
||||
for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject("runs").entrySet()) {
|
||||
|
||||
@@ -24,20 +24,30 @@
|
||||
|
||||
package net.fabricmc.loom.configuration.providers.forge;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
|
||||
import net.fabricmc.loom.configuration.DependencyProvider;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyDownloader;
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
|
||||
public class McpConfigProvider extends DependencyProvider {
|
||||
@@ -46,6 +56,7 @@ public class McpConfigProvider extends DependencyProvider {
|
||||
private Path mappings;
|
||||
private Boolean official;
|
||||
private String mappingsPath;
|
||||
private RemapAction remapAction;
|
||||
|
||||
public McpConfigProvider(Project project) {
|
||||
super(project);
|
||||
@@ -70,6 +81,22 @@ public class McpConfigProvider extends DependencyProvider {
|
||||
|
||||
official = json.has("official") && json.getAsJsonPrimitive("official").getAsBoolean();
|
||||
mappingsPath = json.get("data").getAsJsonObject().get("mappings").getAsString();
|
||||
|
||||
if (json.has("functions")) {
|
||||
JsonObject functions = json.getAsJsonObject("functions");
|
||||
|
||||
if (functions.has("rename")) {
|
||||
remapAction = new ConfigDefinedRemapAction(getProject(), functions.getAsJsonObject("rename"));
|
||||
}
|
||||
}
|
||||
|
||||
if (remapAction == null) {
|
||||
throw new RuntimeException("Could not find remap action, this is probably a version Architectury Loom does not support!");
|
||||
}
|
||||
}
|
||||
|
||||
public RemapAction getRemapAction() {
|
||||
return remapAction;
|
||||
}
|
||||
|
||||
private void init(String version) throws IOException {
|
||||
@@ -111,4 +138,95 @@ public class McpConfigProvider extends DependencyProvider {
|
||||
public String getTargetConfig() {
|
||||
return Constants.Configurations.MCP_CONFIG;
|
||||
}
|
||||
|
||||
public interface RemapAction {
|
||||
FileCollection getClasspath();
|
||||
|
||||
String getMainClass();
|
||||
|
||||
List<String> getArgs(Path input, Path output, Path mappings, FileCollection libraries);
|
||||
}
|
||||
|
||||
public static class ConfigDefinedRemapAction implements RemapAction {
|
||||
private final Project project;
|
||||
private final String name;
|
||||
private final File mainClasspath;
|
||||
private final FileCollection classpath;
|
||||
private final List<String> args;
|
||||
private boolean hasLibraries;
|
||||
|
||||
public ConfigDefinedRemapAction(Project project, JsonObject json) {
|
||||
this.project = project;
|
||||
this.name = json.get("version").getAsString();
|
||||
this.mainClasspath = DependencyDownloader.download(project, this.name, false, true)
|
||||
.getSingleFile();
|
||||
this.classpath = DependencyDownloader.download(project, this.name, true, true);
|
||||
this.args = StreamSupport.stream(json.getAsJsonArray("args").spliterator(), false)
|
||||
.map(JsonElement::getAsString)
|
||||
.collect(Collectors.toList());
|
||||
for (int i = 1; i < this.args.size(); i++) {
|
||||
if (this.args.get(i).equals("{libraries}")) {
|
||||
this.args.remove(i);
|
||||
this.args.remove(i - 1);
|
||||
this.hasLibraries = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileCollection getClasspath() {
|
||||
return classpath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainClass() {
|
||||
try {
|
||||
byte[] manifestBytes = ZipUtils.unpackNullable(mainClasspath.toPath(), "META-INF/MANIFEST.MF");
|
||||
|
||||
if (manifestBytes == null) {
|
||||
throw new RuntimeException("Could not find MANIFEST.MF in " + mainClasspath + "!");
|
||||
}
|
||||
|
||||
Manifest manifest = new Manifest(new ByteArrayInputStream(manifestBytes));
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
String value = attributes.getValue(Attributes.Name.MAIN_CLASS);
|
||||
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Could not find main class in " + mainClasspath + "!");
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getArgs(Path input, Path output, Path mappings, FileCollection libraries) {
|
||||
List<String> args = this.args.stream()
|
||||
.map(str -> {
|
||||
return switch (str) {
|
||||
case "{input}" -> input.toAbsolutePath().toString();
|
||||
case "{output}" -> output.toAbsolutePath().toString();
|
||||
case "{mappings}" -> mappings.toAbsolutePath().toString();
|
||||
default -> str;
|
||||
};
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (hasLibraries) {
|
||||
for (File file : libraries) {
|
||||
args.add("-e=" + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import net.fabricmc.loom.configuration.DependencyProvider;
|
||||
import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl;
|
||||
import net.fabricmc.loom.extension.LoomGradleExtensionImpl;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyDownloader;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
@@ -338,20 +339,17 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
|
||||
private void createSrgJars(Logger logger) throws Exception {
|
||||
MinecraftProviderImpl minecraftProvider = getExtension().getMinecraftProvider();
|
||||
String dep = getExtension().isForgeAndOfficial() ? Constants.Dependencies.VIGNETTE + Constants.Dependencies.Versions.VIGNETTE
|
||||
: Constants.Dependencies.SPECIAL_SOURCE + Constants.Dependencies.Versions.SPECIAL_SOURCE + ":shaded";
|
||||
FileCollection classpath = DependencyDownloader.download(getProject(), dep, true, true);
|
||||
produceSrgJar(getExtension().isForgeAndOfficial(), minecraftProvider.minecraftClientJar.toPath(), minecraftProvider.minecraftServerJar.toPath(), classpath);
|
||||
produceSrgJar(getExtension().isForgeAndOfficial(), minecraftProvider.minecraftClientJar.toPath(), minecraftProvider.getMinecraftServerJar().toPath());
|
||||
}
|
||||
|
||||
private void produceSrgJar(boolean official, Path clientJar, Path serverJar, FileCollection classpath) throws IOException {
|
||||
private void produceSrgJar(boolean official, Path clientJar, Path serverJar) throws IOException {
|
||||
Path tmpSrg = getToSrgMappings();
|
||||
Set<File> mcLibs = getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES).resolve();
|
||||
|
||||
ThreadingUtils.run(() -> {
|
||||
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().isForgeAndNotOfficial(), getProject(), "client", classpath, mcLibs, clientJar, tmpSrg), minecraftClientSrgJar.toPath());
|
||||
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "client", mcLibs, clientJar, tmpSrg), minecraftClientSrgJar.toPath());
|
||||
}, () -> {
|
||||
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().isForgeAndNotOfficial(), getProject(), "server", classpath, mcLibs, serverJar, tmpSrg), minecraftServerSrgJar.toPath());
|
||||
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "server", mcLibs, serverJar, tmpSrg), minecraftServerSrgJar.toPath());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -481,8 +479,9 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
}
|
||||
|
||||
private void accessTransformForge(Logger logger) throws Exception {
|
||||
MinecraftProviderImpl minecraftProvider = getExtension().getMinecraftProvider();
|
||||
List<File> toDelete = new ArrayList<>();
|
||||
String atDependency = Constants.Dependencies.ACCESS_TRANSFORMERS + Constants.Dependencies.Versions.ACCESS_TRANSFORMERS;
|
||||
String atDependency = Constants.Dependencies.ACCESS_TRANSFORMERS + (minecraftProvider.isNewerThan21w39a() ? Constants.Dependencies.Versions.ACCESS_TRANSFORMERS_NEW : Constants.Dependencies.Versions.ACCESS_TRANSFORMERS);
|
||||
FileCollection classpath = DependencyDownloader.download(getProject(), atDependency);
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
|
||||
@@ -655,7 +654,7 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
// Copy resources
|
||||
MinecraftProviderImpl minecraftProvider = getExtension().getMinecraftProvider();
|
||||
copyNonClassFiles(minecraftProvider.minecraftClientJar, minecraftMergedPatchedSrgJar);
|
||||
copyNonClassFiles(minecraftProvider.minecraftServerJar, minecraftMergedPatchedSrgJar);
|
||||
copyNonClassFiles(minecraftProvider.getMinecraftServerJar(), minecraftMergedPatchedSrgJar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,8 +107,6 @@ public class Constants {
|
||||
public static final String JAVAX_ANNOTATIONS = "com.google.code.findbugs:jsr305:"; // I hate that I have to add these.
|
||||
public static final String FORGE_RUNTIME = "dev.architectury:architectury-loom-runtime:";
|
||||
public static final String ACCESS_TRANSFORMERS = "net.minecraftforge:accesstransformers:";
|
||||
public static final String SPECIAL_SOURCE = "net.md-5:SpecialSource:";
|
||||
public static final String VIGNETTE = "net.minecraftforge.lex:vignette:";
|
||||
|
||||
private Dependencies() {
|
||||
}
|
||||
@@ -124,8 +122,7 @@ public class Constants {
|
||||
public static final String JAVAX_ANNOTATIONS = "3.0.2";
|
||||
public static final String FORGE_RUNTIME = "1.1.3";
|
||||
public static final String ACCESS_TRANSFORMERS = "3.0.1";
|
||||
public static final String SPECIAL_SOURCE = "1.8.3";
|
||||
public static final String VIGNETTE = "0.2.0.10";
|
||||
public static final String ACCESS_TRANSFORMERS_NEW = "8.0.5";
|
||||
|
||||
private Versions() {
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -44,6 +42,7 @@ import org.gradle.api.logging.LogLevel;
|
||||
import org.gradle.api.logging.configuration.ShowStacktrace;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.providers.forge.McpConfigProvider.RemapAction;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.ThreadingUtils;
|
||||
|
||||
@@ -58,7 +57,7 @@ public class SpecialSourceExecutor {
|
||||
return string;
|
||||
}
|
||||
|
||||
public static Path produceSrgJar(boolean specialSource, Project project, String side, FileCollection classpath, Set<File> mcLibs, Path officialJar, Path mappings)
|
||||
public static Path produceSrgJar(RemapAction remapAction, Project project, String side, Set<File> mcLibs, Path officialJar, Path mappings)
|
||||
throws Exception {
|
||||
Set<String> filter = Files.readAllLines(mappings, StandardCharsets.UTF_8).stream()
|
||||
.filter(s -> !s.startsWith("\t"))
|
||||
@@ -105,79 +104,30 @@ public class SpecialSourceExecutor {
|
||||
Files.deleteIfExists(output);
|
||||
stopwatch = Stopwatch.createStarted();
|
||||
|
||||
if (specialSource) {
|
||||
String[] args = new String[] {
|
||||
"--in-jar",
|
||||
stripped.toAbsolutePath().toString(),
|
||||
"--out-jar",
|
||||
output.toAbsolutePath().toString(),
|
||||
"--srg-in",
|
||||
mappings.toAbsolutePath().toString()
|
||||
};
|
||||
List<String> args = remapAction.getArgs(stripped, output, mappings, project.files(mcLibs));
|
||||
|
||||
project.getLogger().lifecycle(":remapping minecraft (SpecialSource, " + side + ", official -> srg)");
|
||||
project.getLogger().lifecycle(":remapping minecraft (" + remapAction + ", " + side + ", official -> mojang)");
|
||||
|
||||
Path workingDir = tmpDir();
|
||||
Path workingDir = tmpDir();
|
||||
|
||||
project.javaexec(spec -> {
|
||||
spec.setArgs(Arrays.asList(args));
|
||||
spec.setClasspath(classpath);
|
||||
spec.workingDir(workingDir.toFile());
|
||||
spec.getMainClass().set("net.md_5.specialsource.SpecialSource");
|
||||
project.javaexec(spec -> {
|
||||
spec.setArgs(args);
|
||||
spec.setClasspath(remapAction.getClasspath());
|
||||
spec.workingDir(workingDir.toFile());
|
||||
spec.getMainClass().set(remapAction.getMainClass());
|
||||
|
||||
// if running with INFO or DEBUG logging
|
||||
if (project.getGradle().getStartParameter().getShowStacktrace() != ShowStacktrace.INTERNAL_EXCEPTIONS
|
||||
|| project.getGradle().getStartParameter().getLogLevel().compareTo(LogLevel.LIFECYCLE) < 0) {
|
||||
spec.setStandardOutput(System.out);
|
||||
spec.setErrorOutput(System.err);
|
||||
} else {
|
||||
spec.setStandardOutput(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||
spec.setErrorOutput(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||
}
|
||||
}).rethrowFailure().assertNormalExitValue();
|
||||
|
||||
project.getLogger().lifecycle(":remapped minecraft (SpecialSource, " + side + ", official -> srg) in " + stopwatch.stop());
|
||||
} else {
|
||||
List<String> args = new ArrayList<>(Arrays.asList(
|
||||
"--jar-in",
|
||||
stripped.toAbsolutePath().toString(),
|
||||
"--jar-out",
|
||||
output.toAbsolutePath().toString(),
|
||||
"--mapping-format",
|
||||
"tsrg2",
|
||||
"--mappings",
|
||||
mappings.toAbsolutePath().toString(),
|
||||
"--create-inits",
|
||||
"--fix-param-annotations"
|
||||
));
|
||||
|
||||
for (File file : mcLibs) {
|
||||
args.add("-e=" + file.getAbsolutePath());
|
||||
// if running with INFO or DEBUG logging
|
||||
if (project.getGradle().getStartParameter().getShowStacktrace() != ShowStacktrace.INTERNAL_EXCEPTIONS
|
||||
|| project.getGradle().getStartParameter().getLogLevel().compareTo(LogLevel.LIFECYCLE) < 0) {
|
||||
spec.setStandardOutput(System.out);
|
||||
spec.setErrorOutput(System.err);
|
||||
} else {
|
||||
spec.setStandardOutput(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||
spec.setErrorOutput(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||
}
|
||||
}).rethrowFailure().assertNormalExitValue();
|
||||
|
||||
project.getLogger().lifecycle(":remapping minecraft (Vignette, " + side + ", official -> mojang)");
|
||||
|
||||
Path workingDir = tmpDir();
|
||||
|
||||
project.javaexec(spec -> {
|
||||
spec.setArgs(args);
|
||||
spec.setClasspath(classpath);
|
||||
spec.workingDir(workingDir.toFile());
|
||||
spec.getMainClass().set("org.cadixdev.vignette.VignetteMain");
|
||||
|
||||
// if running with INFO or DEBUG logging
|
||||
if (project.getGradle().getStartParameter().getShowStacktrace() != ShowStacktrace.INTERNAL_EXCEPTIONS
|
||||
|| project.getGradle().getStartParameter().getLogLevel().compareTo(LogLevel.LIFECYCLE) < 0) {
|
||||
spec.setStandardOutput(System.out);
|
||||
spec.setErrorOutput(System.err);
|
||||
} else {
|
||||
spec.setStandardOutput(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||
spec.setErrorOutput(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||
}
|
||||
}).rethrowFailure().assertNormalExitValue();
|
||||
|
||||
project.getLogger().lifecycle(":remapped minecraft (Vignette, " + side + ", official -> mojang) in " + stopwatch.stop());
|
||||
}
|
||||
project.getLogger().lifecycle(":remapped minecraft (" + remapAction + ", " + side + ", official -> mojang) in " + stopwatch.stop());
|
||||
|
||||
Files.deleteIfExists(stripped);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user