mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-31 05:15:57 -05:00
@@ -166,6 +166,7 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
|
||||
boolean supportsInclude();
|
||||
|
||||
DependencyProviders getDependencyProviders();
|
||||
|
||||
void setDependencyProviders(DependencyProviders dependencyProviders);
|
||||
|
||||
default SrgProvider getSrgProvider() {
|
||||
|
||||
@@ -36,6 +36,8 @@ public interface MixinExtensionAPI {
|
||||
|
||||
Property<String> getDefaultRefmapName();
|
||||
|
||||
Property<String> getLegacyRemapToNamespace();
|
||||
|
||||
/**
|
||||
* Apply Mixin AP to sourceSet.
|
||||
* @param sourceSet the sourceSet that applies Mixin AP.
|
||||
|
||||
@@ -85,7 +85,7 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
try {
|
||||
LoomGradleExtension loom = LoomGradleExtension.get(project);
|
||||
String refmapName = Objects.requireNonNull(MixinExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
|
||||
Path mappings = loom.isForge() ? loom.getMappingsProvider().mixinTinyMappingsWithSrg : loom.getMappingsProvider().tinyMappings;
|
||||
Path mappings = loom.getMappingsProvider().getReplacedTarget(loom, loom.getMixin().getLegacyRemapToNamespace().get());
|
||||
Map<String, String> args = new HashMap<>() {{
|
||||
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, mappings.toFile().getCanonicalPath());
|
||||
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, MixinMappingsService.getMixinMappingFile(project, sourceSet).getCanonicalPath());
|
||||
|
||||
@@ -38,6 +38,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -93,7 +94,7 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
public Path tinyMappings;
|
||||
public final Path tinyMappingsJar;
|
||||
public Path tinyMappingsWithSrg;
|
||||
public final Path mixinTinyMappingsWithSrg; // FORGE: The mixin mappings have srg names in intermediary.
|
||||
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 Path unpickDefinitions;
|
||||
|
||||
@@ -112,7 +113,7 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
this.tinyMappingsJar = mappingsWorkingDir.resolve("mappings.jar");
|
||||
this.unpickDefinitions = mappingsWorkingDir.resolve("mappings.unpick");
|
||||
this.tinyMappingsWithSrg = mappingsWorkingDir.resolve("mappings-srg.tiny");
|
||||
this.mixinTinyMappingsWithSrg = mappingsWorkingDir.resolve("mappings-mixin-srg.tiny");
|
||||
this.mixinTinyMappings = new HashMap<>();
|
||||
this.srgToNamedSrg = mappingsWorkingDir.resolve("mappings-srg-named.srg");
|
||||
|
||||
this.intermediaryService = intermediaryService;
|
||||
@@ -228,13 +229,6 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
throw new IllegalStateException("We have to generate srg tiny in a forge environment!");
|
||||
}
|
||||
|
||||
if (Files.notExists(mixinTinyMappingsWithSrg) || isRefreshDeps()) {
|
||||
List<String> lines = new ArrayList<>(Files.readAllLines(tinyMappingsWithSrg));
|
||||
lines.set(0, lines.get(0).replace("intermediary", "yraidemretni").replace("srg", "intermediary"));
|
||||
Files.deleteIfExists(mixinTinyMappingsWithSrg);
|
||||
Files.write(mixinTinyMappingsWithSrg, lines);
|
||||
}
|
||||
|
||||
if (Files.notExists(srgToNamedSrg) || isRefreshDeps()) {
|
||||
SrgNamedWriter.writeTo(project.getLogger(), srgToNamedSrg, getMappingsWithSrg(), "srg", "named");
|
||||
}
|
||||
@@ -511,6 +505,27 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
|
||||
return "%s:%s:%s>%S".formatted(name, mappingsIdentifier(), from, to);
|
||||
}
|
||||
|
||||
public Path getReplacedTarget(LoomGradleExtension loom, String namespace) {
|
||||
if (namespace.equals("intermediary")) return loom.shouldGenerateSrgTiny() ? tinyMappingsWithSrg : tinyMappings;
|
||||
|
||||
return mixinTinyMappings.computeIfAbsent(namespace, k -> {
|
||||
Path path = mappingsWorkingDir.resolve("mappings-mixin-" + namespace + ".tiny");
|
||||
|
||||
try {
|
||||
if (Files.notExists(path) || isRefreshDeps()) {
|
||||
List<String> lines = new ArrayList<>(Files.readAllLines(loom.shouldGenerateSrgTiny() ? tinyMappingsWithSrg : tinyMappings));
|
||||
lines.set(0, lines.get(0).replace("intermediary", "yraidemretni").replace(namespace, "intermediary"));
|
||||
Files.deleteIfExists(path);
|
||||
Files.write(path, lines);
|
||||
}
|
||||
|
||||
return path;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public record UnpickMetadata(String unpickGroup, String unpickVersion) {
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +132,11 @@ public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
|
||||
throw new RuntimeException("Yeah... something is really wrong");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property<String> getLegacyRemapToNamespace() {
|
||||
throw new RuntimeException("Yeah... something is really wrong");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PatternSet add0(SourceSet sourceSet, Provider<String> refmapName) {
|
||||
throw new RuntimeException("Yeah... something is really wrong");
|
||||
|
||||
@@ -48,9 +48,12 @@ import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.util.PatternSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
|
||||
public class MixinExtensionImpl extends MixinExtensionApiImpl implements MixinExtension {
|
||||
private boolean isDefault;
|
||||
private final Property<String> defaultRefmapName;
|
||||
private final Property<String> legacyRemapToNamespace;
|
||||
|
||||
@Inject
|
||||
public MixinExtensionImpl(Project project) {
|
||||
@@ -58,6 +61,8 @@ public class MixinExtensionImpl extends MixinExtensionApiImpl implements MixinEx
|
||||
this.isDefault = true;
|
||||
this.defaultRefmapName = project.getObjects().property(String.class)
|
||||
.convention(project.provider(this::getDefaultMixinRefmapName));
|
||||
this.legacyRemapToNamespace = project.getObjects().property(String.class)
|
||||
.convention(project.provider(() -> SourceRemapper.intermediary(project)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,6 +72,13 @@ public class MixinExtensionImpl extends MixinExtensionApiImpl implements MixinEx
|
||||
return defaultRefmapName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property<String> getLegacyRemapToNamespace() {
|
||||
if (!super.getUseLegacyMixinAp().get()) throw new IllegalStateException("You need to set useLegacyMixinAp = true to configure Mixin annotation processor.");
|
||||
|
||||
return legacyRemapToNamespace;
|
||||
}
|
||||
|
||||
private String getDefaultMixinRefmapName() {
|
||||
String defaultRefmapName = project.getExtensions().getByType(BasePluginExtension.class).getArchivesName().get() + "-refmap.json";
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public abstract class GenerateDLIConfigTask extends AbstractLoomTask {
|
||||
.property("mixin.env.remapRefMap", "true");
|
||||
|
||||
if (PropertyUtil.getAndFinalize(getExtension().getForge().getUseCustomMixin())) {
|
||||
launchConfig.property("mixin.forgeloom.inject.mappings.srg-named", getExtension().getMappingsProvider().mixinTinyMappingsWithSrg.toAbsolutePath().toString());
|
||||
launchConfig.property("mixin.forgeloom.inject.mappings.srg-named", getExtension().getMappingsProvider().getReplacedTarget(getExtension(), "srg").toAbsolutePath().toString());
|
||||
} else {
|
||||
launchConfig.property("net.minecraftforge.gradle.GradleStart.srg.srg-mcp", getExtension().getMappingsProvider().srgToNamedSrg.toAbsolutePath().toString());
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class TinyRemapperService implements SharedService {
|
||||
mappings.add(MappingsService.createDefault(project, from, to).getMappingsProvider());
|
||||
|
||||
if (legacyMixin) {
|
||||
mappings.add(MixinMappingsService.getService(SharedServiceManager.get(project)).getMappingProvider(from, extension.isForge() && to.equals("srg") ? "intermediary" : to));
|
||||
mappings.add(MixinMappingsService.getService(SharedServiceManager.get(project)).getMappingProvider("named", "intermediary"));
|
||||
}
|
||||
|
||||
return new TinyRemapperService(mappings, !legacyMixin, useKotlinExtension);
|
||||
|
||||
Reference in New Issue
Block a user