mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
wip forge
This commit is contained in:
@@ -37,6 +37,14 @@ public final class IntermediaryNamespaces {
|
||||
return intermediaryNamespace(project).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the runtime intermediary namespace of the project.
|
||||
* This is the namespace used in the compiled jar.
|
||||
*/
|
||||
public static String runtimeIntermediary(Project project) {
|
||||
return runtimeIntermediaryNamespace(project).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intermediary namespace of the project.
|
||||
*/
|
||||
@@ -49,6 +57,15 @@ public final class IntermediaryNamespaces {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intermediary namespace of the project.
|
||||
*/
|
||||
public static MappingsNamespace runtimeIntermediaryNamespace(Project project) {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
if (extension.isForge() && extension.getForgeProvider().usesMojangAtRuntime()) return MappingsNamespace.MOJANG;
|
||||
return intermediaryNamespace(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Potentially replaces the remapping target namespace for mixin refmaps.
|
||||
*
|
||||
@@ -62,6 +79,6 @@ public final class IntermediaryNamespaces {
|
||||
* @return the correct namespace to use
|
||||
*/
|
||||
public static String replaceMixinIntermediaryNamespace(Project project, String namespace) {
|
||||
return namespace.equals(intermediary(project)) ? MappingsNamespace.INTERMEDIARY.toString() : namespace;
|
||||
return namespace.equals(runtimeIntermediary(project)) ? MappingsNamespace.INTERMEDIARY.toString() : namespace;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class ModProcessor {
|
||||
private void remapJars(List<ModDependency> remapList) throws IOException {
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
final MappingConfiguration mappingConfiguration = extension.getMappingConfiguration();
|
||||
String fromM = IntermediaryNamespaces.intermediary(project);
|
||||
String fromM = IntermediaryNamespaces.runtimeIntermediary(project);
|
||||
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
|
||||
|
||||
@@ -60,6 +60,10 @@ public class ForgeProvider extends DependencyProvider {
|
||||
return version;
|
||||
}
|
||||
|
||||
public boolean usesMojangAtRuntime() {
|
||||
return platform == ModPlatform.NEOFORGE || version.getMajorVersion() >= Constants.Forge.MIN_USE_MOJANG_NS_VERSION;
|
||||
}
|
||||
|
||||
public File getGlobalCache() {
|
||||
if (globalCache == null) {
|
||||
globalCache = getMinecraftProvider().dir(platform.id() + "/" + version.getCombined());
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -45,6 +46,9 @@ import java.util.Objects;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.architectury.loom.util.MappingOption;
|
||||
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
import org.apache.tools.ant.util.StringUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
@@ -211,28 +215,20 @@ public class MappingConfiguration {
|
||||
// Generate the Mojmap-merged mappings if needed.
|
||||
// Note that this needs to happen before manipulateMappings for FieldMigratedMappingConfiguration.
|
||||
if (Files.notExists(tinyMappingsWithMojang) || extension.refreshDeps()) {
|
||||
final Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
final MappingContext context = new GradleMappingContext(project, "tmp-neoforge");
|
||||
|
||||
try (Tiny2FileWriter writer = new Tiny2FileWriter(Files.newBufferedWriter(tinyMappingsWithMojang), false)) {
|
||||
ForgeMappingsMerger.mergeMojang(context, tinyMappings, null, true).accept(writer);
|
||||
}
|
||||
|
||||
project.getLogger().info(":merged mojang mappings in {}", stopwatch.stop());
|
||||
mergeMojang(project, tinyMappings, tinyMappingsWithMojang);
|
||||
}
|
||||
}
|
||||
|
||||
if (extension.shouldGenerateSrgTiny()) {
|
||||
if (Files.notExists(tinyMappingsWithSrg) || extension.refreshDeps()) {
|
||||
// Merge tiny mappings with srg
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
ForgeMappingsMerger.ExtraMappings extraMappings = ForgeMappingsMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));
|
||||
|
||||
try (Tiny2FileWriter writer = new Tiny2FileWriter(Files.newBufferedWriter(tinyMappingsWithSrg), false)) {
|
||||
ForgeMappingsMerger.mergeSrg(getRawSrgFile(project), tinyMappings, extraMappings, true).accept(writer);
|
||||
if (extension.isForge() && extension.getForgeProvider().usesMojangAtRuntime()) {
|
||||
Path tmp = Files.createTempFile("mappings", ".tiny");
|
||||
mergeMojang(project, tinyMappings, tmp);
|
||||
mergeSrg(project, tmp, tinyMappingsWithSrg);
|
||||
Files.deleteIfExists(tmp);
|
||||
} else {
|
||||
mergeSrg(project, tinyMappings, tinyMappingsWithSrg);
|
||||
}
|
||||
|
||||
project.getLogger().info(":merged srg mappings in " + stopwatch.stop());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,6 +283,28 @@ public class MappingConfiguration {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void mergeMojang(Project project, Path source, Path target) throws IOException {
|
||||
final Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
final MappingContext context = new GradleMappingContext(project, "tmp-mojang");
|
||||
|
||||
try (Tiny2FileWriter writer = new Tiny2FileWriter(Files.newBufferedWriter(target, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING), false)) {
|
||||
ForgeMappingsMerger.mergeMojang(context, source, null, true).accept(writer);
|
||||
}
|
||||
|
||||
project.getLogger().info(":merged mojang mappings in {}", stopwatch.stop());
|
||||
}
|
||||
|
||||
private static void mergeSrg(Project project, Path source, Path target) throws IOException {
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
ForgeMappingsMerger.ExtraMappings extraMappings = ForgeMappingsMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));
|
||||
|
||||
try (Tiny2FileWriter writer = new Tiny2FileWriter(Files.newBufferedWriter(target, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING), false)) {
|
||||
ForgeMappingsMerger.mergeSrg(getRawSrgFile(project), source, extraMappings, true).accept(writer);
|
||||
}
|
||||
|
||||
project.getLogger().info(":merged srg mappings in " + stopwatch.stop());
|
||||
}
|
||||
|
||||
protected void manipulateMappings(Project project, Path mappingsJar) throws IOException {
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ 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.intermediary(project)));
|
||||
.convention(project.provider(() -> IntermediaryNamespaces.runtimeIntermediary(project)));
|
||||
this.refmapTargetNamespace.finalizeValueOnRead();
|
||||
|
||||
this.messages = project.getObjects().mapProperty(String.class, String.class);
|
||||
|
||||
@@ -116,7 +116,7 @@ public abstract class AbstractRemapJarTask extends Jar {
|
||||
@Inject
|
||||
public AbstractRemapJarTask() {
|
||||
getSourceNamespace().convention(MappingsNamespace.NAMED.toString()).finalizeValueOnRead();
|
||||
getTargetNamespace().convention(IntermediaryNamespaces.intermediary(getProject())).finalizeValueOnRead();
|
||||
getTargetNamespace().convention(getProject().provider(() -> IntermediaryNamespaces.runtimeIntermediary(getProject()))).finalizeValueOnRead();
|
||||
getRemapperIsolation().convention(true).finalizeValueOnRead();
|
||||
getIncludesClientOnlyClasses().convention(false).finalizeValueOnRead();
|
||||
getJarType().finalizeValueOnRead();
|
||||
|
||||
@@ -186,6 +186,11 @@ public class Constants {
|
||||
public static final String UNION_RELAUNCHER_MAIN_CLASS = "juuxel.unionrelauncher.UnionRelauncher";
|
||||
public static final String UNION_RELAUNCHER_MAIN_CLASS_PROPERTY = "unionRelauncher.mainClass";
|
||||
|
||||
/**
|
||||
* The minimum version of Forge that uses "mojang" as the namespace at runtime.
|
||||
*/
|
||||
public static final int MIN_USE_MOJANG_NS_VERSION = 50;
|
||||
|
||||
private Forge() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class SourceRemapper {
|
||||
private Mercury mercury;
|
||||
|
||||
public SourceRemapper(Project project, SharedServiceManager serviceManager, boolean toNamed) {
|
||||
this(project, serviceManager, toNamed ? IntermediaryNamespaces.intermediary(project) : "named", !toNamed ? IntermediaryNamespaces.intermediary(project) : "named");
|
||||
this(project, serviceManager, toNamed ? IntermediaryNamespaces.runtimeIntermediary(project) : "named", !toNamed ? IntermediaryNamespaces.runtimeIntermediary(project) : "named");
|
||||
}
|
||||
|
||||
public SourceRemapper(Project project, SharedServiceManager serviceManager, String from, String to) {
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class CoreModClassRemapper {
|
||||
|
||||
public static void remapJar(Project project, ModPlatform platform, Path jar, MappingTree mappings) throws IOException {
|
||||
final Logger logger = project.getLogger();
|
||||
final String sourceNamespace = IntermediaryNamespaces.intermediary(project);
|
||||
final String sourceNamespace = IntermediaryNamespaces.runtimeIntermediary(project);
|
||||
|
||||
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jar, false)) {
|
||||
Path coremodsJsonPath = fs.getPath("META-INF", "coremods.json");
|
||||
|
||||
@@ -65,6 +65,7 @@ import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
*/
|
||||
public final class ForgeMappingsMerger {
|
||||
private static final List<String> INPUT_NAMESPACES = List.of("official", "intermediary", "named");
|
||||
private static final List<String> INPUT_NAMESPACES_WITH_MOJANG = List.of("official", "mojang", "intermediary", "named");
|
||||
private final MemoryMappingTree newNs;
|
||||
private final MemoryMappingTree src;
|
||||
private final MemoryMappingTree output;
|
||||
@@ -111,8 +112,8 @@ public final class ForgeMappingsMerger {
|
||||
List<String> inputNamespaces = new ArrayList<>(src.getDstNamespaces());
|
||||
inputNamespaces.add(0, src.getSrcNamespace());
|
||||
|
||||
if (!inputNamespaces.equals(INPUT_NAMESPACES)) {
|
||||
throw new MappingException("Mapping file " + tiny + " does not have 'official, intermediary, named' as its namespaces! Found: " + inputNamespaces);
|
||||
if (!inputNamespaces.equals(INPUT_NAMESPACES) && !inputNamespaces.equals(INPUT_NAMESPACES_WITH_MOJANG)) {
|
||||
throw new MappingException("Mapping file " + tiny + " does not have 'official(, mojang), intermediary, named' as its namespaces! Found: " + inputNamespaces);
|
||||
}
|
||||
|
||||
return src;
|
||||
|
||||
Reference in New Issue
Block a user