mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 05:27:43 -05:00
@@ -62,7 +62,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
|
||||
private File minecraftMergedJar;
|
||||
private File versionManifestJson;
|
||||
private File experimentalVersionsJson;
|
||||
private String jarSuffix = "";
|
||||
private String jarPrefix = "";
|
||||
|
||||
public MinecraftProviderImpl(Project project) {
|
||||
super(project);
|
||||
@@ -323,12 +323,12 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
|
||||
return libraryProvider;
|
||||
}
|
||||
|
||||
public String getJarSuffix() {
|
||||
return jarSuffix;
|
||||
public String getJarPrefix() {
|
||||
return jarPrefix;
|
||||
}
|
||||
|
||||
public void setJarSuffix(String jarSuffix) {
|
||||
this.jarSuffix = jarSuffix;
|
||||
public void setJarPrefix(String jarSuffix) {
|
||||
this.jarPrefix = jarSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
package net.fabricmc.loom.configuration.providers.forge;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
@@ -33,6 +34,8 @@ import net.fabricmc.loom.util.Constants;
|
||||
|
||||
public class ForgeProvider extends DependencyProvider {
|
||||
private ForgeVersion version = new ForgeVersion(null);
|
||||
private File globalCache;
|
||||
private File projectCache;
|
||||
|
||||
public ForgeProvider(Project project) {
|
||||
super(project);
|
||||
@@ -49,6 +52,24 @@ public class ForgeProvider extends DependencyProvider {
|
||||
return version;
|
||||
}
|
||||
|
||||
public File getGlobalCache() {
|
||||
if (globalCache == null) {
|
||||
globalCache = getMinecraftProvider().dir("forge/" + version.getCombined());
|
||||
globalCache.mkdirs();
|
||||
}
|
||||
|
||||
return globalCache;
|
||||
}
|
||||
|
||||
public File getProjectCache() {
|
||||
if (projectCache == null) {
|
||||
projectCache = new File(getDirectories().getProjectPersistentCache(), "forge/" + getExtension().getForgeProvider().getVersion().getCombined());
|
||||
projectCache.mkdirs();
|
||||
}
|
||||
|
||||
return projectCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetConfig() {
|
||||
return Constants.Configurations.FORGE;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ForgeUniversalProvider extends DependencyProvider {
|
||||
|
||||
@Override
|
||||
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||
forge = new File(getDirectories().getProjectPersistentCache(), "forge-" + dependency.getDependency().getVersion() + "-universal.jar");
|
||||
forge = new File(getExtension().getForgeProvider().getGlobalCache(), "forge-universal.jar");
|
||||
|
||||
if (!forge.exists() || isRefreshDeps()) {
|
||||
File dep = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve Forge"));
|
||||
|
||||
@@ -92,12 +92,8 @@ public class ForgeUserdevProvider extends DependencyProvider {
|
||||
type.getAttributes().attribute(transformed, false);
|
||||
}
|
||||
|
||||
userdevJar = new File(getDirectories().getProjectPersistentCache(), "forge-" + dependency.getDependency().getVersion() + "-userdev.jar");
|
||||
|
||||
Path configJson = getDirectories()
|
||||
.getProjectPersistentCache()
|
||||
.toPath()
|
||||
.resolve("forge-config-" + dependency.getDependency().getVersion() + ".json");
|
||||
userdevJar = new File(getExtension().getForgeProvider().getGlobalCache(), "forge-userdev.jar");
|
||||
Path configJson = getExtension().getForgeProvider().getGlobalCache().toPath().resolve("forge-config.json");
|
||||
|
||||
if (!userdevJar.exists() || Files.notExists(configJson) || isRefreshDeps()) {
|
||||
File resolved = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve Forge userdev"));
|
||||
@@ -266,6 +262,8 @@ public class ForgeUserdevProvider extends DependencyProvider {
|
||||
}
|
||||
|
||||
string = String.join(File.pathSeparator, modClasses);
|
||||
} else if (key.equals("mcp_mappings")) {
|
||||
string = "loom.stub";
|
||||
} else if (json.has(key)) {
|
||||
JsonElement element = json.get(key);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package net.fabricmc.loom.configuration.providers.forge;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -92,7 +93,6 @@ import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.DependencyProvider;
|
||||
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingNamespace;
|
||||
@@ -114,7 +114,7 @@ import net.fabricmc.mappingio.MappingVisitor;
|
||||
|
||||
public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
private static final String LOOM_PATCH_VERSION_KEY = "Loom-Patch-Version";
|
||||
private static final String CURRENT_LOOM_PATCH_VERSION = "4";
|
||||
private static final String CURRENT_LOOM_PATCH_VERSION = "5";
|
||||
private static final String NAME_MAPPING_SERVICE_PATH = "/inject/META-INF/services/cpw.mods.modlauncher.api.INameMappingService";
|
||||
|
||||
// Step 1: Remap Minecraft to SRG (global)
|
||||
@@ -179,13 +179,14 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
MinecraftProviderImpl minecraftProvider = getExtension().getMinecraftProvider();
|
||||
PatchProvider patchProvider = getExtension().getPatchProvider();
|
||||
String minecraftVersion = minecraftProvider.minecraftVersion();
|
||||
String patchId = "forge-" + getExtension().getForgeProvider().getVersion().getCombined();
|
||||
String patchId = "forge-" + getExtension().getForgeProvider().getVersion().getCombined() + "-";
|
||||
|
||||
minecraftProvider.setJarSuffix(patchId);
|
||||
if (getExtension().isForgeAndOfficial()) {
|
||||
minecraftProvider.setJarPrefix(patchId);
|
||||
}
|
||||
|
||||
File globalCache = getMinecraftProvider().dir("forge/" + getExtension().getForgeProvider().getVersion().getCombined());
|
||||
File cache = usesProjectCache() ? getDirectories().getProjectPersistentCache() : globalCache;
|
||||
File projectDir = new File(cache, "forge/" + getExtension().getForgeProvider().getVersion().getCombined());
|
||||
File globalCache = getExtension().getForgeProvider().getGlobalCache();
|
||||
File projectDir = usesProjectCache() ? getExtension().getForgeProvider().getProjectCache() : globalCache;
|
||||
projectDir.mkdirs();
|
||||
|
||||
minecraftClientSrgJar = new File(globalCache, "minecraft-client-srg.jar");
|
||||
@@ -294,10 +295,8 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
this.dirty = true;
|
||||
}
|
||||
|
||||
Path input = minecraftMergedPatchedSrgAtJar.toPath();
|
||||
|
||||
if (dirty) {
|
||||
remapPatchedJar(input, getProject().getLogger());
|
||||
remapPatchedJar(getProject().getLogger());
|
||||
|
||||
if (getExtension().isForgeAndOfficial()) {
|
||||
fillClientExtraJar();
|
||||
@@ -360,9 +359,9 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
Set<File> mcLibs = getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES).resolve();
|
||||
|
||||
ThreadingUtils.run(() -> {
|
||||
Files.copy(SpecialSourceExecutor.produceSrgJar(getProject(), "client", classpath, clientJar, tmpSrg), minecraftClientSrgJar.toPath());
|
||||
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().isForgeAndNotOfficial(), getProject(), "client", classpath, mcLibs, clientJar, tmpSrg), minecraftClientSrgJar.toPath());
|
||||
}, () -> {
|
||||
Files.copy(SpecialSourceExecutor.produceSrgJar(getProject(), "server", classpath, serverJar, tmpSrg), minecraftServerSrgJar.toPath());
|
||||
Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().isForgeAndNotOfficial(), getProject(), "server", classpath, mcLibs, serverJar, tmpSrg), minecraftServerSrgJar.toPath());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -406,7 +405,7 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
}
|
||||
|
||||
public static Path getMojmapTsrg2(LoomGradleExtension extension) throws IOException {
|
||||
Path path = extension.getMinecraftProvider().dir("forge").toPath().resolve("mojmap.tsrg");
|
||||
Path path = extension.getMinecraftProvider().dir("forge").toPath().resolve("mojmap.tsrg2");
|
||||
|
||||
if (Files.notExists(path)) {
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
|
||||
@@ -649,35 +648,43 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private void remapPatchedJar(Path input, Logger logger) throws Exception {
|
||||
private void remapPatchedJar(Logger logger) throws Exception {
|
||||
getProject().getLogger().lifecycle(":remapping minecraft (TinyRemapper, srg -> official)");
|
||||
Path mcInput = minecraftMergedPatchedSrgAtJar.toPath();
|
||||
Path mcOutput = minecraftMergedPatchedJar.toPath();
|
||||
Path forgeOutput = forgeMergedJar.toPath();
|
||||
Path forgeJar = getForgeJar().toPath();
|
||||
Path forgeUserdevJar = getForgeUserdevJar().toPath();
|
||||
Path forgeOutput = null;
|
||||
Files.deleteIfExists(mcOutput);
|
||||
Files.deleteIfExists(forgeOutput);
|
||||
TinyRemapper remapper = buildRemapper(input);
|
||||
boolean splitJars = forgeMergedJar != null;
|
||||
|
||||
if (splitJars) {
|
||||
forgeOutput = forgeMergedJar.toPath();
|
||||
Files.deleteIfExists(forgeOutput);
|
||||
}
|
||||
|
||||
TinyRemapper remapper = buildRemapper(mcInput);
|
||||
|
||||
try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(mcOutput).build();
|
||||
OutputConsumerPath outputConsumerForge = new OutputConsumerPath.Builder(forgeOutput).build()) {
|
||||
outputConsumer.addNonClassFiles(input);
|
||||
Closeable outputConsumerForge = !splitJars ? () -> {
|
||||
} : new OutputConsumerPath.Builder(forgeOutput).build()) {
|
||||
outputConsumer.addNonClassFiles(mcInput);
|
||||
|
||||
InputTag mcTag = remapper.createInputTag();
|
||||
InputTag forgeTag = remapper.createInputTag();
|
||||
List<CompletableFuture<?>> futures = new ArrayList<>();
|
||||
futures.add(remapper.readInputsAsync(mcTag, input));
|
||||
futures.add(remapper.readInputsAsync(mcTag, mcInput));
|
||||
futures.add(remapper.readInputsAsync(forgeTag, forgeJar, forgeUserdevJar));
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
||||
remapper.apply(outputConsumer, mcTag);
|
||||
remapper.apply(outputConsumerForge, forgeTag);
|
||||
remapper.apply(splitJars ? (OutputConsumerPath) outputConsumerForge : outputConsumer, forgeTag);
|
||||
} finally {
|
||||
remapper.finish();
|
||||
}
|
||||
|
||||
copyNonClassFiles(forgeJar.toFile(), splitJars ? forgeMergedJar : minecraftMergedPatchedJar);
|
||||
copyUserdevFiles(forgeUserdevJar.toFile(), splitJars ? forgeMergedJar : minecraftMergedPatchedJar);
|
||||
applyLoomPatchVersion(mcOutput);
|
||||
copyNonClassFiles(forgeJar.toFile(), forgeMergedJar);
|
||||
copyUserdevFiles(forgeUserdevJar.toFile(), forgeMergedJar);
|
||||
}
|
||||
|
||||
private void patchJars(Logger logger) throws IOException {
|
||||
|
||||
@@ -64,7 +64,8 @@ public class SrgProvider extends DependencyProvider {
|
||||
}
|
||||
|
||||
private void init(String version) {
|
||||
srg = new File(getDirectories().getUserCache(), "srg-" + version + ".tsrg");
|
||||
File dir = getMinecraftProvider().dir("srg/" + version);
|
||||
srg = new File(dir, "srg.tsrg");
|
||||
}
|
||||
|
||||
public File getSrg() {
|
||||
|
||||
@@ -159,8 +159,6 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
addDependencies(dependency, postPopulationScheduler);
|
||||
|
||||
if (getExtension().isForgeAndNotOfficial()) {
|
||||
getProject().getRepositories().flatDir(repository -> repository.dir(new File(getJarDirectory(getDirectories().getUserCache(), "mapped"), "forge")));
|
||||
|
||||
getProject().getDependencies().add(Constants.Configurations.FORGE_NAMED,
|
||||
getProject().getDependencies().module("net.minecraftforge-loom:forge-mapped:" + getMinecraftProvider().minecraftVersion() + "/" + getExtension().getMappingsProvider().mappingsIdentifier() + "/forge"));
|
||||
}
|
||||
@@ -351,14 +349,14 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
|
||||
protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) {
|
||||
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
|
||||
getProject().getDependencies().module("net.minecraft:minecraft-mapped:" + getMinecraftProvider().minecraftVersion() + "/" + getExtension().getMappingsProvider().mappingsIdentifier()));
|
||||
getProject().getDependencies().module("net.minecraft:" + minecraftProvider.getJarPrefix() + "minecraft-mapped:" + getMinecraftProvider().minecraftVersion() + "/" + getExtension().getMappingsProvider().mappingsIdentifier()));
|
||||
}
|
||||
|
||||
public void initFiles(MinecraftProviderImpl minecraftProvider, MappingsProviderImpl mappingsProvider) {
|
||||
this.minecraftProvider = minecraftProvider;
|
||||
minecraftIntermediaryJar = new File(getExtension().getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-intermediary.jar");
|
||||
minecraftSrgJar = !getExtension().isForge() ? null : new File(getExtension().getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-srg.jar");
|
||||
minecraftMappedJar = new File(getExtension().getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-mapped.jar");
|
||||
minecraftMappedJar = new File(getExtension().getMappingsProvider().mappingsWorkingDir().toFile(), minecraftProvider.getJarPrefix() + "minecraft-mapped.jar");
|
||||
inputJar = getExtension().isForge() ? mappingsProvider.patchedProvider.getMergedJar() : minecraftProvider.getMergedJar();
|
||||
|
||||
if (getExtension().isForgeAndNotOfficial()) {
|
||||
@@ -379,7 +377,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
}
|
||||
|
||||
protected String getJarVersionString(String type) {
|
||||
return String.format("%s-%s%s", type, getExtension().getMappingsProvider().mappingsIdentifier(), minecraftProvider.getJarSuffix());
|
||||
return String.format("%s-%s%s", type, getExtension().getMappingsProvider().mappingsIdentifier(), minecraftProvider.getJarPrefix());
|
||||
}
|
||||
|
||||
public File getIntermediaryJar() {
|
||||
|
||||
@@ -24,11 +24,14 @@
|
||||
|
||||
package net.fabricmc.loom.util.srg;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -45,9 +48,9 @@ import org.zeroturnaround.zip.ZipUtil;
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
|
||||
public class SpecialSourceExecutor {
|
||||
public static Path produceSrgJar(Project project, String side, FileCollection specialSourceCp, Path officialJar, Path srgPath)
|
||||
public static Path produceSrgJar(boolean specialSource, Project project, String side, FileCollection classpath, Set<File> mcLibs, Path officialJar, Path mappings)
|
||||
throws Exception {
|
||||
Set<String> filter = Files.readAllLines(srgPath, StandardCharsets.UTF_8).stream()
|
||||
Set<String> filter = Files.readAllLines(mappings, StandardCharsets.UTF_8).stream()
|
||||
.filter(s -> !s.startsWith("\t"))
|
||||
.map(s -> s.split(" ")[0] + ".class")
|
||||
.collect(Collectors.toSet());
|
||||
@@ -68,35 +71,75 @@ public class SpecialSourceExecutor {
|
||||
Path output = extension.getFiles().getProjectBuildCache().toPath().resolve(officialJar.getFileName().toString().substring(0, officialJar.getFileName().toString().length() - 4) + "-srg-output.jar");
|
||||
Files.deleteIfExists(output);
|
||||
|
||||
String[] args = new String[] {
|
||||
"--in-jar",
|
||||
stripped.toAbsolutePath().toString(),
|
||||
"--out-jar",
|
||||
output.toAbsolutePath().toString(),
|
||||
"--srg-in",
|
||||
srgPath.toAbsolutePath().toString()
|
||||
};
|
||||
if (specialSource) {
|
||||
String[] args = new String[] {
|
||||
"--in-jar",
|
||||
stripped.toAbsolutePath().toString(),
|
||||
"--out-jar",
|
||||
output.toAbsolutePath().toString(),
|
||||
"--srg-in",
|
||||
mappings.toAbsolutePath().toString()
|
||||
};
|
||||
|
||||
project.getLogger().lifecycle(":remapping minecraft (SpecialSource, " + side + ", official -> srg)");
|
||||
project.getLogger().lifecycle(":remapping minecraft (SpecialSource, " + side + ", official -> srg)");
|
||||
|
||||
Path workingDir = tmpDir();
|
||||
Path workingDir = tmpDir();
|
||||
|
||||
project.javaexec(spec -> {
|
||||
spec.setArgs(Arrays.asList(args));
|
||||
spec.setClasspath(specialSourceCp);
|
||||
spec.workingDir(workingDir.toFile());
|
||||
spec.setMain("net.md_5.specialsource.SpecialSource");
|
||||
project.javaexec(spec -> {
|
||||
spec.setArgs(Arrays.asList(args));
|
||||
spec.setClasspath(classpath);
|
||||
spec.workingDir(workingDir.toFile());
|
||||
spec.setMain("net.md_5.specialsource.SpecialSource");
|
||||
|
||||
// if running with INFO or DEBUG logging
|
||||
if (project.getGradle().getStartParameter().getShowStacktrace() != ShowStacktrace.INTERNAL_EXCEPTIONS
|
||||
// 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);
|
||||
spec.setStandardOutput(System.out);
|
||||
spec.setErrorOutput(System.err);
|
||||
} else {
|
||||
spec.setStandardOutput(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||
spec.setErrorOutput(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||
}
|
||||
}).rethrowFailure().assertNormalExitValue();
|
||||
} 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());
|
||||
}
|
||||
}).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.setMain("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();
|
||||
}
|
||||
|
||||
Files.deleteIfExists(stripped);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user