From 5b63d05aaf191d228567f2dcb4bb3e1c39a31dee Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sun, 19 Nov 2023 16:31:16 -0700 Subject: [PATCH 1/2] Skip output remapping for Mojang-mapped NeoForge projects --- .../forge/FieldMigratedMappingConfiguration.java | 8 +++++++- .../providers/mappings/LayeredMappingsDependency.java | 8 ++++++++ .../providers/mappings/MappingConfiguration.java | 10 +++++++++- .../net/fabricmc/loom/task/AbstractRemapJarTask.java | 10 ++++++++++ src/main/java/net/fabricmc/loom/task/RemapJarTask.java | 4 ++++ .../net/fabricmc/loom/task/RemapSourcesJarTask.java | 7 +++++++ 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/forge/FieldMigratedMappingConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/providers/forge/FieldMigratedMappingConfiguration.java index 1c12be754..64ea773dc 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/forge/FieldMigratedMappingConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/forge/FieldMigratedMappingConfiguration.java @@ -69,9 +69,15 @@ public final class FieldMigratedMappingConfiguration extends MappingConfiguratio private Path rawTinyMappings; private Path rawTinyMappingsWithSrg; private Path rawTinyMappingsWithMojang; + private final boolean mojangMappedProject; - public FieldMigratedMappingConfiguration(String mappingsIdentifier, Path mappingsWorkingDir) { + public FieldMigratedMappingConfiguration(String mappingsIdentifier, Path mappingsWorkingDir, boolean mojangMappedProject) { super(mappingsIdentifier, mappingsWorkingDir); + this.mojangMappedProject = mojangMappedProject; + } + + public boolean isMojangMappedProject() { + return this.mojangMappedProject; } @Override diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java index c912bbe89..10b20caa5 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java @@ -49,6 +49,8 @@ import net.fabricmc.loom.api.mappings.layered.MappingLayer; import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.providers.mappings.extras.unpick.UnpickLayer; +import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpec; +import net.fabricmc.loom.configuration.providers.mappings.parchment.ParchmentMappingsSpec; import net.fabricmc.loom.configuration.providers.mappings.utils.AddConstructorMappingVisitor; import net.fabricmc.loom.util.ZipUtils; import net.fabricmc.mappingio.adapter.MappingDstNsReorder; @@ -186,4 +188,10 @@ public void because(String s) { public FileCollection getFiles() { return project.files(resolve()); } + + public boolean isMojangMappings() { + return this.layeredMappingSpec.layers().stream() + .skip(1) // see LayeredMappingSpecBuilderImpl + .allMatch(spec -> spec instanceof MojangMappingsSpec || spec instanceof ParchmentMappingsSpec); + } } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java index 0c138e38d..3b72fcc84 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java @@ -144,7 +144,15 @@ public static MappingConfiguration create(Project project, SharedServiceManager MappingConfiguration mappingConfiguration; if (extension.isForgeLike()) { - mappingConfiguration = new FieldMigratedMappingConfiguration(mappingsIdentifier, workingDir); + final boolean mojmap; + + if (dependency.getDependency() instanceof LayeredMappingsDependency layered) { + mojmap = layered.isMojangMappings(); + } else { + mojmap = false; + } + + mappingConfiguration = new FieldMigratedMappingConfiguration(mappingsIdentifier, workingDir, mojmap); } else { mappingConfiguration = new MappingConfiguration(mappingsIdentifier, workingDir); } diff --git a/src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java b/src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java index 641d32036..b2c8c19db 100644 --- a/src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java +++ b/src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java @@ -65,6 +65,7 @@ import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.build.IntermediaryNamespaces; +import net.fabricmc.loom.configuration.providers.forge.FieldMigratedMappingConfiguration; import net.fabricmc.loom.task.service.JarManifestService; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.ZipReprocessorUtil; @@ -159,6 +160,15 @@ public final
void submitWork(Class extends Abs
protected abstract List void autoSkipRemap(LoomGradleExtension extension, P params) {
+ if (getAutoSkipRemap().getOrElse(true) && shouldSkipRemap(extension)) {
+ params.getSourceNamespace().set(getTargetNamespace());
+ }
+ }
+
+ private boolean shouldSkipRemap(LoomGradleExtension extension) {
+ return extension.isNeoForge()
+ && extension.getMappingConfiguration() instanceof FieldMigratedMappingConfiguration c
+ && c.isMojangMappedProject()
+ && MappingsNamespace.of(this.getSourceNamespace().get()) == MappingsNamespace.NAMED
+ && MappingsNamespace.of(this.getTargetNamespace().get()) == MappingsNamespace.MOJANG;
+ }
+
public final void submitWork(Class extends AbstractRemapAction > workAction, Action action) {
final WorkQueue workQueue = getWorkerExecutor().noIsolation();
@@ -160,15 +179,6 @@ public final void submitWork(Class extends Abs
protected abstract List