mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-01 21:17:46 -05:00
Many changes related to NeoForge mappings and remapping
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package dev.architectury.loom.neoforge;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingLayer;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
@@ -13,15 +20,17 @@ import net.fabricmc.mappingio.adapter.MappingNsRenamer;
|
||||
import net.fabricmc.mappingio.format.MappingFormat;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public final class MojangMappingsMerger {
|
||||
public static void mergeMojangMappings(MappingContext context, Path raw, Path merged) {
|
||||
try (MappingWriter writer = MappingWriter.create(merged, MappingFormat.TINY_2)) {
|
||||
final MemoryMappingTree mappingTree = mergeMojangMappings(context, raw);
|
||||
mappingTree.accept(writer);
|
||||
} catch (IOException e) {
|
||||
throw ExceptionUtil.createDescriptiveWrapper(UncheckedIOException::new, "Could not write Mojang-merged mappings", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static MemoryMappingTree mergeMojangMappings(MappingContext context, Path raw) {
|
||||
try {
|
||||
var processor = new LayeredMappingsProcessor(null);
|
||||
var inputLayer = new FileLayer(raw, MappingsNamespace.NAMED);
|
||||
@@ -30,11 +39,7 @@ public final class MojangMappingsMerger {
|
||||
Map<String, String> renames = Map.of(MappingsNamespace.NAMED.toString(), MappingsNamespace.MOJANG.toString());
|
||||
return new MappingNsRenamer(next, renames);
|
||||
});
|
||||
MemoryMappingTree mappingTree = processor.getMappings(List.of(inputLayer, renamedMojangLayer));
|
||||
|
||||
try (MappingWriter writer = MappingWriter.create(merged, MappingFormat.TINY_2)) {
|
||||
mappingTree.accept(writer);
|
||||
}
|
||||
return processor.getMappings(List.of(inputLayer, renamedMojangLayer));
|
||||
} catch (IOException e) {
|
||||
throw ExceptionUtil.createDescriptiveWrapper(UncheckedIOException::new, "Could not merge Mojang mappings", e);
|
||||
}
|
||||
|
||||
18
src/main/java/dev/architectury/loom/util/MappingOption.java
Normal file
18
src/main/java/dev/architectury/loom/util/MappingOption.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package dev.architectury.loom.util;
|
||||
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
|
||||
|
||||
public enum MappingOption {
|
||||
DEFAULT,
|
||||
WITH_SRG,
|
||||
WITH_MOJANG,
|
||||
;
|
||||
|
||||
public static MappingOption forPlatform(LoomGradleExtensionAPI extension) {
|
||||
return switch (extension.getPlatform().get()) {
|
||||
case FORGE -> WITH_SRG;
|
||||
case NEOFORGE -> WITH_MOJANG;
|
||||
default -> DEFAULT;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -41,10 +41,12 @@ import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
import dev.architectury.tinyremapper.InputTag;
|
||||
import dev.architectury.tinyremapper.NonClassCopyMode;
|
||||
import dev.architectury.tinyremapper.OutputConsumerPath;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import dev.architectury.tinyremapper.extension.mixin.MixinExtension;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.attributes.Usage;
|
||||
@@ -166,8 +168,15 @@ public class ModProcessor {
|
||||
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
|
||||
boolean srg = (fromM.equals("srg") || toM.equals("srg")) && extension.isForgeLike();
|
||||
MemoryMappingTree mappings = mappingConfiguration.getMappingsService(serviceManager, srg).getMappingTree();
|
||||
MappingOption mappingOption = MappingOption.DEFAULT;
|
||||
|
||||
if ((fromM.equals(MappingsNamespace.SRG.toString()) || toM.equals(MappingsNamespace.SRG.toString())) && extension.isForge()) {
|
||||
mappingOption = MappingOption.WITH_SRG;
|
||||
} else if ((fromM.equals(MappingsNamespace.MOJANG.toString()) || toM.equals(MappingsNamespace.MOJANG.toString())) && extension.isNeoForge()) {
|
||||
mappingOption = MappingOption.WITH_MOJANG;
|
||||
}
|
||||
|
||||
MemoryMappingTree mappings = mappingConfiguration.getMappingsService(serviceManager, mappingOption).getMappingTree();
|
||||
LoggerFilter.replaceSystemOut();
|
||||
TinyRemapper.Builder builder = TinyRemapper.newRemapper()
|
||||
.withKnownIndyBsm(extension.getKnownIndyBsms().get())
|
||||
@@ -185,6 +194,10 @@ public class ModProcessor {
|
||||
builder.extension(kotlinRemapperClassloader.getTinyRemapperExtension());
|
||||
}
|
||||
|
||||
if (extension.isNeoForge()) {
|
||||
builder.extension(new MixinExtension());
|
||||
}
|
||||
|
||||
final TinyRemapper remapper = builder.build();
|
||||
|
||||
for (Path minecraftJar : extension.getMinecraftJars(extension.isForgeLike() ? MappingsNamespace.SRG : MappingsNamespace.INTERMEDIARY)) {
|
||||
@@ -265,8 +278,8 @@ public class ModProcessor {
|
||||
remapJarManifestEntries(output);
|
||||
|
||||
if (extension.isForgeLike()) {
|
||||
AtRemapper.remap(project.getLogger(), output, mappings);
|
||||
CoreModClassRemapper.remapJar(output, mappings, project.getLogger());
|
||||
AtRemapper.remap(project, output, mappings);
|
||||
CoreModClassRemapper.remapJar(project, output, mappings);
|
||||
}
|
||||
|
||||
dependency.copyToCache(project, output, null);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
package net.fabricmc.loom.configuration.processors;
|
||||
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
@@ -64,6 +65,7 @@ public record ProcessorContextImpl(ConfigContext configContext, MinecraftJar min
|
||||
@Override
|
||||
public MemoryMappingTree getMappings() {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(configContext().project());
|
||||
return extension.getMappingConfiguration().getMappingsService(configContext().serviceManager(), extension.isForgeLike()).getMappingTree();
|
||||
final MappingOption mappingOption = MappingOption.forPlatform(extension);
|
||||
return extension.getMappingConfiguration().getMappingsService(configContext().serviceManager(), mappingOption).getMappingTree();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ import java.util.List;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.gson.JsonElement;
|
||||
import dev.architectury.loom.neoforge.MojangMappingsMerger;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
|
||||
import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.artifacts.ModuleDependency;
|
||||
@@ -158,6 +164,10 @@ public class ForgeLibrariesProvider {
|
||||
if (Files.exists(fs.get().getPath("net/minecraftforge/fml/common/asm/ObjectHolderDefinalize.class"))) {
|
||||
remapObjectHolder(project, outputJar, mappingConfiguration);
|
||||
}
|
||||
|
||||
if (Files.exists(fs.getPath("net/neoforged/fml/common/asm/ObjectHolderDefinalize.class"))) {
|
||||
remapNeoForgeObjectHolder(project, outputJar, mappingConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy sources when not running under CI.
|
||||
@@ -191,6 +201,24 @@ public class ForgeLibrariesProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private static void remapNeoForgeObjectHolder(Project project, Path outputJar, MappingConfiguration mappingConfiguration) throws IOException {
|
||||
try {
|
||||
// Merge Mojang mappings. The real Mojang mapping file hasn't been created yet since the usual Mojang merging
|
||||
// process occurs after all Forge libraries have been provided.
|
||||
// Forge libs are needed for MC, which is needed for the mappings.
|
||||
final MappingContext context = new GradleMappingContext(project, "tmp-neoforge-libs");
|
||||
final MemoryMappingTree mappings = MojangMappingsMerger.mergeMojangMappings(context, mappingConfiguration.tinyMappings);
|
||||
|
||||
// Remap the object holders.
|
||||
RemapObjectHolderVisitor.remapObjectHolder(
|
||||
outputJar, "net.neoforged.fml.common.asm.ObjectHolderDefinalize", mappings,
|
||||
MappingsNamespace.MOJANG.toString(), MappingsNamespace.NAMED.toString()
|
||||
);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Could not remap object holders in " + outputJar, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconstructs the dependency notation of a resolved artifact.
|
||||
* @param artifact the artifact
|
||||
|
||||
@@ -52,11 +52,15 @@ import java.util.stream.Stream;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import de.oceanlabs.mcp.mcinjector.adaptors.ParameterAnnotationFixer;
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
import dev.architectury.loom.util.TempFiles;
|
||||
import dev.architectury.tinyremapper.InputTag;
|
||||
import dev.architectury.tinyremapper.NonClassCopyMode;
|
||||
import dev.architectury.tinyremapper.OutputConsumerPath;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.logging.LogLevel;
|
||||
import org.gradle.api.logging.Logger;
|
||||
@@ -220,14 +224,16 @@ public class MinecraftPatchedProvider {
|
||||
|
||||
private TinyRemapper buildRemapper(SharedServiceManager serviceManager, Path input) throws IOException {
|
||||
Path[] libraries = TinyRemapperHelper.getMinecraftCompileLibraries(project);
|
||||
TinyMappingsService mappingsService = getExtension().getMappingConfiguration().getMappingsService(serviceManager, true);
|
||||
MemoryMappingTree mappingsWithSrg = mappingsService.getMappingTree();
|
||||
final MappingOption mappingOption = MappingOption.forPlatform(getExtension());
|
||||
TinyMappingsService mappingsService = getExtension().getMappingConfiguration().getMappingsService(serviceManager, mappingOption);
|
||||
final String sourceNamespace = IntermediaryNamespaces.intermediary(project);
|
||||
MemoryMappingTree mappings = mappingsService.getMappingTree();
|
||||
|
||||
TinyRemapper remapper = TinyRemapper.newRemapper()
|
||||
.logger(logger::lifecycle)
|
||||
.logUnknownInvokeDynamic(false)
|
||||
.withMappings(TinyRemapperHelper.create(mappingsWithSrg, "srg", "official", true))
|
||||
.withMappings(InnerClassRemapper.of(InnerClassRemapper.readClassNames(input), mappingsWithSrg, "srg", "official"))
|
||||
.withMappings(TinyRemapperHelper.create(mappings, sourceNamespace, "official", true))
|
||||
.withMappings(InnerClassRemapper.of(InnerClassRemapper.readClassNames(input), mappings, sourceNamespace, "official"))
|
||||
.renameInvalidLocals(true)
|
||||
.rebuildSourceFilenames(true)
|
||||
.build();
|
||||
|
||||
@@ -44,12 +44,8 @@ import java.util.Objects;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import dev.architectury.loom.neoforge.MojangMappingsMerger;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.mappingio.adapter.MappingNsRenamer;
|
||||
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
import org.apache.tools.ant.util.StringUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
@@ -60,6 +56,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.loom.configuration.DependencyInfo;
|
||||
import net.fabricmc.loom.configuration.providers.forge.FieldMigratedMappingConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.forge.SrgProvider;
|
||||
@@ -146,7 +143,7 @@ public class MappingConfiguration {
|
||||
|
||||
MappingConfiguration mappingConfiguration;
|
||||
|
||||
if (extension.isForgeLike()) {
|
||||
if (extension.isForge()) { // TODO (Neo): Field migration support
|
||||
mappingConfiguration = new FieldMigratedMappingConfiguration(mappingsIdentifier, workingDir);
|
||||
} else {
|
||||
mappingConfiguration = new MappingConfiguration(mappingsIdentifier, workingDir);
|
||||
@@ -163,22 +160,27 @@ public class MappingConfiguration {
|
||||
}
|
||||
|
||||
public TinyMappingsService getMappingsService(SharedServiceManager serviceManager) {
|
||||
return getMappingsService(serviceManager, false);
|
||||
return getMappingsService(serviceManager, MappingOption.DEFAULT);
|
||||
}
|
||||
|
||||
public TinyMappingsService getMappingsService(SharedServiceManager serviceManager, boolean withSrg) {
|
||||
final Path tinyMappings;
|
||||
|
||||
// TODO (Neo): Needs a "with Mojang" option
|
||||
if (withSrg) {
|
||||
public TinyMappingsService getMappingsService(SharedServiceManager serviceManager, MappingOption mappingOption) {
|
||||
final Path tinyMappings = switch (mappingOption) {
|
||||
default -> this.tinyMappings;
|
||||
case WITH_SRG -> {
|
||||
if (Files.notExists(this.tinyMappingsWithSrg)) {
|
||||
throw new UnsupportedOperationException("Cannot get mappings service with SRG mappings without SRG enabled!");
|
||||
}
|
||||
|
||||
tinyMappings = this.tinyMappingsWithSrg;
|
||||
} else {
|
||||
tinyMappings = this.tinyMappings;
|
||||
yield this.tinyMappingsWithSrg;
|
||||
}
|
||||
case WITH_MOJANG -> {
|
||||
if (Files.notExists(this.tinyMappingsWithMojang)) {
|
||||
throw new UnsupportedOperationException("Cannot get mappings service with Mojang mappings without Mojang merging enabled!");
|
||||
}
|
||||
|
||||
yield this.tinyMappings;
|
||||
}
|
||||
};
|
||||
|
||||
return TinyMappingsService.create(serviceManager, Objects.requireNonNull(tinyMappings));
|
||||
}
|
||||
@@ -243,14 +245,14 @@ public class MappingConfiguration {
|
||||
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
|
||||
if (extension.isForgeLike()) {
|
||||
if (extension.isForge()) {
|
||||
if (!extension.shouldGenerateSrgTiny()) {
|
||||
throw new IllegalStateException("We have to generate srg tiny in a forge environment!");
|
||||
}
|
||||
|
||||
if (Files.notExists(srgToNamedSrg) || extension.refreshDeps()) {
|
||||
try (var serviceManager = new ScopedSharedServiceManager()) {
|
||||
TinyMappingsService mappingsService = getMappingsService(serviceManager, true);
|
||||
TinyMappingsService mappingsService = getMappingsService(serviceManager, MappingOption.WITH_SRG);
|
||||
SrgNamedWriter.writeTo(project.getLogger(), srgToNamedSrg, mappingsService.getMappingTree(), "srg", "named");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,12 @@ import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
import dev.architectury.tinyremapper.OutputConsumerPath;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
@@ -221,9 +225,19 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
|
||||
if (extension.isForgeLikeAndOfficial()) {
|
||||
try (var serviceManager = new ScopedSharedServiceManager()) {
|
||||
TinyMappingsService mappingsService = extension.getMappingConfiguration().getMappingsService(serviceManager, true);
|
||||
MemoryMappingTree mappingsWithSrg = mappingsService.getMappingTree();
|
||||
RemapObjectHolderVisitor.remapObjectHolder(remappedJars.outputJar().getPath(), "net.minecraftforge.registries.ObjectHolderRegistry", mappingsWithSrg, "srg", "named");
|
||||
final MappingOption mappingOption = MappingOption.forPlatform(extension);
|
||||
final TinyMappingsService mappingsService = extension.getMappingConfiguration().getMappingsService(serviceManager, mappingOption);
|
||||
final String className;
|
||||
|
||||
if (extension.isNeoForge()) {
|
||||
className = "net.neoforged.neoforge.registries.ObjectHolderRegistry";
|
||||
} else {
|
||||
className = "net.minecraftforge.registries.ObjectHolderRegistry";
|
||||
}
|
||||
|
||||
final String sourceNamespace = IntermediaryNamespaces.intermediary(project);
|
||||
final MemoryMappingTree mappings = mappingsService.getMappingTree();
|
||||
RemapObjectHolderVisitor.remapObjectHolder(remappedJars.outputJar().getPath(), className, mappings, sourceNamespace, "named");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021-2022 FabricMC
|
||||
* Copyright (c) 2021-2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -40,6 +40,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
|
||||
import org.apache.commons.io.output.NullOutputStream;
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
@@ -202,8 +206,10 @@ public class ForgeSourcesRemapper {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
Mercury mercury = SourceRemapper.createMercuryWithClassPath(project, false);
|
||||
|
||||
TinyMappingsService mappingsService = extension.getMappingConfiguration().getMappingsService(serviceManager, true);
|
||||
MappingSet mappings = new TinyMappingsReader(mappingsService.getMappingTree(), "srg", "named").read();
|
||||
final MappingOption mappingOption = MappingOption.forPlatform(extension);
|
||||
final String sourceNamespace = IntermediaryNamespaces.intermediary(project);
|
||||
TinyMappingsService mappingsService = extension.getMappingConfiguration().getMappingsService(serviceManager, mappingOption);
|
||||
MappingSet mappings = new TinyMappingsReader(mappingsService.getMappingTree(), sourceNamespace, "named").read();
|
||||
|
||||
for (Map.Entry<String, String> entry : TinyRemapperHelper.JSR_TO_JETBRAINS.entrySet()) {
|
||||
mappings.getOrCreateClassMapping(entry.getKey()).setDeobfuscatedName(entry.getValue());
|
||||
|
||||
@@ -416,9 +416,12 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
if (Files.exists(linemap)) {
|
||||
if (getParameters().getForge().get()) {
|
||||
try {
|
||||
// Remove Forge classes from linemap
|
||||
// Remove Forge and NeoForge classes from linemap
|
||||
// TODO: We should instead not decompile Forge's classes at all
|
||||
LineMapVisitor.process(linemap, next -> new LineMapClassFilter(next, name -> !name.startsWith("net/minecraftforge/")));
|
||||
LineMapVisitor.process(linemap, next -> new LineMapClassFilter(next, name -> {
|
||||
// Skip both Forge and NeoForge classes.
|
||||
return !name.startsWith("net/minecraftforge/") && !name.startsWith("net/neoforged/");
|
||||
}));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to process linemap", e);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.logging.configuration.ConsoleOutput;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
@@ -129,7 +131,8 @@ public abstract class GenerateDLIConfigTask extends AbstractLoomTask {
|
||||
}
|
||||
|
||||
if (PropertyUtil.getAndFinalize(getExtension().getForge().getUseCustomMixin())) {
|
||||
launchConfig.property("mixin.forgeloom.inject.mappings.srg-named", getExtension().getMappingConfiguration().getReplacedTarget(getExtension(), "srg").toAbsolutePath().toString());
|
||||
final String intermediaryNs = IntermediaryNamespaces.intermediary(getProject());
|
||||
launchConfig.property("mixin.forgeloom.inject.mappings.srg-named", getExtension().getMappingConfiguration().getReplacedTarget(getExtension(), intermediaryNs).toAbsolutePath().toString());
|
||||
} else {
|
||||
launchConfig.property("net.minecraftforge.gradle.GradleStart.srg.srg-mcp", getExtension().getMappingConfiguration().srgToNamedSrg.toAbsolutePath().toString());
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
@@ -46,8 +47,15 @@ public final class LorenzMappingService implements SharedService {
|
||||
|
||||
public static synchronized LorenzMappingService create(SharedServiceManager sharedServiceManager, MappingConfiguration mappingConfiguration, MappingsNamespace from, MappingsNamespace to) {
|
||||
return sharedServiceManager.getOrCreateService(mappingConfiguration.getBuildServiceName("LorenzMappingService", from.toString(), to.toString()), () -> {
|
||||
boolean srg = (from == MappingsNamespace.SRG || to == MappingsNamespace.SRG);
|
||||
MemoryMappingTree m = mappingConfiguration.getMappingsService(sharedServiceManager, srg).getMappingTree();
|
||||
MappingOption mappingOption = MappingOption.DEFAULT;
|
||||
|
||||
if (from == MappingsNamespace.SRG || to == MappingsNamespace.SRG) {
|
||||
mappingOption = MappingOption.WITH_SRG;
|
||||
} else if (from == MappingsNamespace.MOJANG || to == MappingsNamespace.MOJANG) {
|
||||
mappingOption = MappingOption.WITH_MOJANG;
|
||||
}
|
||||
|
||||
MemoryMappingTree m = mappingConfiguration.getMappingsService(sharedServiceManager, mappingOption).getMappingTree();
|
||||
|
||||
try {
|
||||
try (var reader = new TinyMappingsReader(m, from.toString(), to.toString())) {
|
||||
|
||||
@@ -82,7 +82,7 @@ public class TinyRemapperService implements SharedService {
|
||||
extension.getKnownIndyBsms().get().stream().sorted().forEach(joiner::add);
|
||||
|
||||
if (extension.isForgeLike()) {
|
||||
joiner.add("forge");
|
||||
joiner.add(extension.getPlatform().get().id());
|
||||
}
|
||||
|
||||
final String id = joiner.toString();
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
import dev.architectury.tinyremapper.IMappingProvider;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import org.gradle.api.Project;
|
||||
@@ -70,8 +71,9 @@ public final class TinyRemapperHelper {
|
||||
|
||||
public static TinyRemapper getTinyRemapper(Project project, SharedServiceManager serviceManager, String fromM, String toM, boolean fixRecords, Consumer<TinyRemapper.Builder> builderConsumer, Set<String> fromClassNames) throws IOException {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
boolean srg = (fromM.equals(MappingsNamespace.SRG.toString()) || toM.equals(MappingsNamespace.SRG.toString())) && extension.isForgeLike();
|
||||
MemoryMappingTree mappingTree = extension.getMappingConfiguration().getMappingsService(serviceManager, srg).getMappingTree();
|
||||
// TODO (Neo): Bring back the fromM.equals(srg) || toM.equals(srg) check, also for mojang ns?
|
||||
final MappingOption mappingOption = MappingOption.forPlatform(extension);
|
||||
MemoryMappingTree mappingTree = extension.getMappingConfiguration().getMappingsService(serviceManager, mappingOption).getMappingTree();
|
||||
|
||||
if (fixRecords && !mappingTree.getSrcNamespace().equals(fromM)) {
|
||||
throw new IllegalStateException("Mappings src namespace must match remap src namespace");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2020-2021 FabricMC
|
||||
* Copyright (c) 2020-2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -34,8 +34,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.logging.Logger;
|
||||
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.function.CollectionUtil;
|
||||
@@ -47,7 +49,10 @@ import net.fabricmc.mappingio.tree.MappingTree;
|
||||
* @author Juuz
|
||||
*/
|
||||
public final class AtRemapper {
|
||||
public static void remap(Logger logger, Path jar, MappingTree mappings) throws IOException {
|
||||
public static void remap(Project project, Path jar, MappingTree mappings) throws IOException {
|
||||
final Logger logger = project.getLogger();
|
||||
final String sourceNamespace = IntermediaryNamespaces.intermediary(project);
|
||||
|
||||
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jar, false)) {
|
||||
Path atPath = fs.getPath(Constants.Forge.ACCESS_TRANSFORMER_PATH);
|
||||
|
||||
@@ -76,7 +81,7 @@ public final class AtRemapper {
|
||||
String name = parts[1].replace('.', '/');
|
||||
parts[1] = CollectionUtil.find(
|
||||
mappings.getClasses(),
|
||||
def -> def.getName("srg").equals(name)
|
||||
def -> def.getName(sourceNamespace).equals(name)
|
||||
).map(def -> def.getName("named")).orElse(name).replace('/', '.');
|
||||
|
||||
if (parts.length >= 3) {
|
||||
@@ -84,7 +89,7 @@ public final class AtRemapper {
|
||||
parts[2] = parts[2].substring(0, parts[2].indexOf('(')) + remapDescriptor(parts[2].substring(parts[2].indexOf('(')), s -> {
|
||||
return CollectionUtil.find(
|
||||
mappings.getClasses(),
|
||||
def -> def.getName("srg").equals(s)
|
||||
def -> def.getName(sourceNamespace).equals(s)
|
||||
).map(def -> def.getName("named")).orElse(s);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2020-2021 FabricMC
|
||||
* Copyright (c) 2020-2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -40,8 +40,10 @@ import java.util.regex.Pattern;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.logging.Logger;
|
||||
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.function.CollectionUtil;
|
||||
import net.fabricmc.mappingio.tree.MappingTree;
|
||||
@@ -54,7 +56,10 @@ import net.fabricmc.mappingio.tree.MappingTree;
|
||||
public final class CoreModClassRemapper {
|
||||
private static final Pattern CLASS_NAME_PATTERN = Pattern.compile("^(.*')((?:com\\.mojang\\.|net\\.minecraft\\.)[A-Za-z0-9.-_$]+)('.*)$");
|
||||
|
||||
public static void remapJar(Path jar, MappingTree mappings, Logger logger) throws IOException {
|
||||
public static void remapJar(Project project, Path jar, MappingTree mappings) throws IOException {
|
||||
final Logger logger = project.getLogger();
|
||||
final String sourceNamespace = IntermediaryNamespaces.intermediary(project);
|
||||
|
||||
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jar, false)) {
|
||||
Path coremodsJsonPath = fs.getPath("META-INF", "coremods.json");
|
||||
|
||||
@@ -75,7 +80,7 @@ public final class CoreModClassRemapper {
|
||||
|
||||
if (Files.exists(js)) {
|
||||
logger.info(":remapping coremod '" + file + "'");
|
||||
remap(js, mappings);
|
||||
remap(js, mappings, sourceNamespace);
|
||||
} else {
|
||||
logger.warn("Coremod '" + file + "' listed in coremods.json but not found");
|
||||
}
|
||||
@@ -83,7 +88,7 @@ public final class CoreModClassRemapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void remap(Path js, MappingTree mappings) throws IOException {
|
||||
public static void remap(Path js, MappingTree mappings, String sourceNamespace) throws IOException {
|
||||
List<String> lines = Files.readAllLines(js);
|
||||
List<String> output = new ArrayList<>(lines);
|
||||
|
||||
@@ -93,7 +98,7 @@ public final class CoreModClassRemapper {
|
||||
|
||||
if (matcher.matches()) {
|
||||
String className = matcher.group(2).replace('.', '/');
|
||||
String remapped = CollectionUtil.find(mappings.getClasses(), def -> def.getName("srg").equals(className))
|
||||
String remapped = CollectionUtil.find(mappings.getClasses(), def -> def.getName(sourceNamespace).equals(className))
|
||||
.map(def -> def.getName("named"))
|
||||
.orElse(className);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user