Remap Forge dependency from mojang instead of srg

This commit is contained in:
shedaniel
2024-07-26 23:22:58 +09:00
parent 8c2b72af72
commit d30d38e9af
10 changed files with 42 additions and 38 deletions

View File

@@ -28,6 +28,7 @@ import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
@@ -114,7 +115,10 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
yield getSrgMinecraftProvider().getMinecraftJarPaths();
}
case MOJANG -> {
ModPlatform.assertPlatform(this, ModPlatform.NEOFORGE, () -> "Mojang-mapped jars are only available on NeoForge.");
if (!this.isForgeLike() || !this.getForgeProvider().usesMojangAtRuntime()) {
throw new GradleException("Mojang-mapped jars are only available on NeoForge / Forge 50+.");
}
yield getMojangMappedMinecraftProvider().getMinecraftJarPaths();
}
};

View File

@@ -76,7 +76,7 @@ public final class IntermediaryNamespaces {
/**
* Potentially replaces the remapping target namespace for mixin refmaps.
*
* <p>All {@linkplain #intermediary(Project) intermediary-like namespaces} are replaced
* <p>All {@linkplain #runtimeIntermediary(Project) intermediary-like namespaces} are replaced
* by {@code intermediary} since fabric-mixin-compile-extensions only supports intermediary.
* We transform the namespaces in the input mappings, e.g. {@code intermediary} -> {@code yraidemretni} and
* {@code srg} -> {@code intermediary}.

View File

@@ -268,7 +268,9 @@ public abstract class CompileConfiguration implements Runnable {
final SrgMinecraftProvider<?> srgMinecraftProvider = jarConfiguration.createSrgMinecraftProvider(project);
extension.setSrgMinecraftProvider(srgMinecraftProvider);
srgMinecraftProvider.provide(provideContext);
} else if (extension.isNeoForge()) {
}
if (extension.isForge() && extension.getForgeProvider().usesMojangAtRuntime()) {
final MojangMappedMinecraftProvider<?> mojangMappedMinecraftProvider = jarConfiguration.createMojangMappedMinecraftProvider(project);
extension.setMojangMappedMinecraftProvider(mojangMappedMinecraftProvider);
mojangMappedMinecraftProvider.provide(provideContext);

View File

@@ -55,10 +55,10 @@ public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequi
private static final String QUILT_INSTALLER_PATH = "quilt_installer.json";
public static ArtifactMetadata create(ArtifactRef artifact, String currentLoomVersion) throws IOException {
return create(artifact, currentLoomVersion, ModPlatform.FABRIC);
return create(artifact, currentLoomVersion, ModPlatform.FABRIC, null);
}
public static ArtifactMetadata create(ArtifactRef artifact, String currentLoomVersion, ModPlatform platform) throws IOException {
public static ArtifactMetadata create(ArtifactRef artifact, String currentLoomVersion, ModPlatform platform, @Nullable Boolean forcesStaticMixinRemap) throws IOException {
boolean isFabricMod;
RemapRequirements remapRequirements = RemapRequirements.DEFAULT;
InstallerData installerData = null;
@@ -93,11 +93,10 @@ public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequi
} catch (IllegalArgumentException e) {
throw new IllegalStateException("Unknown mixin remap type: " + mixinRemapType);
}
} else if (platform == ModPlatform.FORGE) {
// Use certain refmap remap types by the current platform
refmapRemapType = MixinRemapType.MIXIN;
} else if (platform == ModPlatform.NEOFORGE) {
refmapRemapType = MixinRemapType.STATIC;
} else if (forcesStaticMixinRemap != null) {
// The mixin remap type is not specified in the manifest, but we have a forced value
// This is forced to be static on NeoForge or Forge 50+.
refmapRemapType = forcesStaticMixinRemap ? MixinRemapType.STATIC : MixinRemapType.MIXIN;
}
if (loomVersion != null && refmapRemapType != MixinRemapType.STATIC) {

View File

@@ -151,7 +151,8 @@ public class ModConfigurationRemapper {
artifactMetadata = metaCache.computeIfAbsent(artifact, a -> {
try {
return ArtifactMetadata.create(a, LoomGradlePlugin.LOOM_VERSION, extension.getPlatform().get());
return ArtifactMetadata.create(a, LoomGradlePlugin.LOOM_VERSION, extension.getPlatform().get(),
extension.isForgeLike() && extension.getForgeProvider().usesMojangAtRuntime() ? true : null);
} catch (IOException e) {
throw ExceptionUtil.createDescriptiveWrapper(UncheckedIOException::new, "Failed to read metadata from " + a.path(), e);
}

View File

@@ -206,7 +206,7 @@ public class ModProcessor {
final TinyRemapper remapper = builder.build();
remapper.readClassPath(extension.getMinecraftJars(IntermediaryNamespaces.intermediaryNamespace(project)).toArray(Path[]::new));
remapper.readClassPath(extension.getMinecraftJars(IntermediaryNamespaces.runtimeIntermediaryNamespace(project)).toArray(Path[]::new));
final Map<ModDependency, InputTag> tagMap = new HashMap<>();
final Map<ModDependency, OutputConsumerPath> outputConsumerMap = new HashMap<>();

View File

@@ -43,6 +43,7 @@ import java.util.Map;
import java.util.Objects;
import com.google.common.base.Stopwatch;
import com.google.common.base.Supplier;
import com.google.gson.JsonObject;
import dev.architectury.loom.util.MappingOption;
import org.apache.tools.ant.util.StringUtils;
@@ -94,6 +95,7 @@ public class MappingConfiguration {
public Path tinyMappingsWithSrg;
public final Map<String, Path> mixinTinyMappings; // The mixin mappings have other names in intermediary.
public final Path srgToNamedSrg; // FORGE: srg to named in srg file format
private final Map<MappingOption, Supplier<Path>> mappingOptions;
private final Path unpickDefinitions;
private boolean hasUnpickDefinitions;
@@ -112,6 +114,8 @@ public class MappingConfiguration {
this.tinyMappingsWithMojang = mappingsWorkingDir.resolve("mappings-mojang.tiny");
this.mixinTinyMappings = new HashMap<>();
this.srgToNamedSrg = mappingsWorkingDir.resolve("mappings-srg-named.srg");
this.mappingOptions = new HashMap<>();
this.mappingOptions.put(MappingOption.DEFAULT, () -> this.tinyMappings);
}
public static MappingConfiguration create(Project project, SharedServiceManager serviceManager, DependencyInfo dependency, MinecraftProvider minecraftProvider) {
@@ -164,25 +168,15 @@ public class MappingConfiguration {
}
public TinyMappingsService getMappingsService(SharedServiceManager serviceManager, MappingOption mappingOption) {
final Path tinyMappings = switch (mappingOption) {
case WITH_SRG -> {
if (Files.notExists(this.tinyMappingsWithSrg)) {
throw new UnsupportedOperationException("Cannot get mappings service with SRG mappings without SRG enabled!");
}
Supplier<Path> mappingsSupplier = this.mappingOptions.get(mappingOption);
yield this.tinyMappingsWithSrg;
if (mappingsSupplier == null) {
throw new UnsupportedOperationException("Unsupported mapping option: " + mappingOption + ", it is possible that this option is not supported by this project / platform!");
} else if (Files.notExists(mappingsSupplier.get())) {
throw new UnsupportedOperationException("Mapping option " + mappingOption + " found but file does not exist!");
}
case WITH_MOJANG -> {
if (Files.notExists(this.tinyMappingsWithMojang)) {
throw new UnsupportedOperationException("Cannot get mappings service with Mojang mappings without Mojang merging enabled!");
}
yield this.tinyMappingsWithMojang;
}
default -> this.tinyMappings;
};
return TinyMappingsService.create(serviceManager, Objects.requireNonNull(tinyMappings));
return TinyMappingsService.create(serviceManager, Objects.requireNonNull(mappingsSupplier.get()));
}
protected void setup(Project project, SharedServiceManager serviceManager, MinecraftProvider minecraftProvider, Path inputJar) throws IOException {
@@ -208,6 +202,8 @@ public class MappingConfiguration {
LoomGradleExtension extension = LoomGradleExtension.get(project);
if (extension.isNeoForge()) {
this.mappingOptions.put(MappingOption.WITH_MOJANG, () -> this.tinyMappingsWithMojang);
// Generate the Mojmap-merged mappings if needed.
// Note that this needs to happen before manipulateMappings for FieldMigratedMappingConfiguration.
if (Files.notExists(tinyMappingsWithMojang) || extension.refreshDeps()) {
@@ -216,6 +212,12 @@ public class MappingConfiguration {
}
if (extension.shouldGenerateSrgTiny()) {
this.mappingOptions.put(MappingOption.WITH_SRG, () -> this.tinyMappingsWithSrg);
if (extension.isForge() && extension.getForgeProvider().usesMojangAtRuntime()) {
this.mappingOptions.put(MappingOption.WITH_MOJANG, () -> this.tinyMappingsWithSrg);
}
if (Files.notExists(tinyMappingsWithSrg) || extension.refreshDeps()) {
if (extension.isForge() && extension.getForgeProvider().usesMojangAtRuntime()) {
Path tmp = Files.createTempFile("mappings", ".tiny");

View File

@@ -245,7 +245,7 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
className = "net.minecraftforge.registries.ObjectHolderRegistry";
}
final String sourceNamespace = IntermediaryNamespaces.intermediary(project);
final String sourceNamespace = IntermediaryNamespaces.runtimeIntermediary(project);
final MemoryMappingTree mappings = mappingsService.getMappingTree();
RemapObjectHolderVisitor.remapObjectHolder(remappedJars.outputJar().getPath(), className, mappings, sourceNamespace, "named");
}

View File

@@ -50,7 +50,7 @@ public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
public MixinExtensionApiImpl(Project project) {
this.project = Objects.requireNonNull(project);
this.useMixinAp = project.getObjects().property(Boolean.class)
.convention(project.provider(() -> !LoomGradleExtension.get(project).isNeoForge()));
.convention(project.provider(() -> !LoomGradleExtension.get(project).isNeoForge() && (!LoomGradleExtension.get(project).isForge() || !LoomGradleExtension.get(project).getForgeProvider().usesMojangAtRuntime())));
this.refmapTargetNamespace = project.getObjects().property(String.class)
.convention(project.provider(() -> IntermediaryNamespaces.runtimeIntermediary(project)));

View File

@@ -98,7 +98,7 @@ public class SourceRemapper {
return;
}
project.getLogger().lifecycle(":remapping sources");
project.getLogger().lifecycle(":remapping sources (Mercury, {} -> {})", from, to);
ProgressLoggerFactory progressLoggerFactory = ((ProjectInternal) project).getServices().get(ProgressLoggerFactory.class);
ProgressLogger progressLogger = progressLoggerFactory.newOperation(SourceRemapper.class.getName());
@@ -199,13 +199,9 @@ public class SourceRemapper {
mercury.getClassPath().add(intermediaryJar);
}
if (extension.isForge()) {
for (Path srgJar : extension.getMinecraftJars(MappingsNamespace.SRG)) {
mercury.getClassPath().add(srgJar);
}
} else if (extension.isNeoForge()) {
for (Path mojangJar : extension.getMinecraftJars(MappingsNamespace.MOJANG)) {
mercury.getClassPath().add(mojangJar);
if (extension.isForgeLike()) {
for (Path jar : extension.getMinecraftJars(IntermediaryNamespaces.runtimeIntermediaryNamespace(project))) {
mercury.getClassPath().add(jar);
}
}