Fix remapping forge dependencies

This commit is contained in:
shedaniel
2020-12-25 16:19:24 +08:00
parent d325274e4f
commit 43cef2e5a4
4 changed files with 24 additions and 9 deletions

View File

@@ -175,7 +175,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
}
TinyTree yarnWithSrg = getExtension().getMappingsProvider().getMappingsWithSrg();
AtRemapper.remap(output, yarnWithSrg);
AtRemapper.remap(getProject().getLogger(), output, yarnWithSrg);
CoreModClassRemapper.remapJar(output, yarnWithSrg, getProject().getLogger());
}
}

View File

@@ -73,7 +73,7 @@ public class ModCompileRemapper {
String version = artifact.getModuleVersion().getId().getVersion();
String classifierSuffix = artifact.getClassifier() == null ? "" : (":" + artifact.getClassifier());
if (!isFabricMod(logger, artifact)) {
if (!shouldRemapMod(logger, artifact, extension.isForge())) {
addToRegularCompile(project, regularConfig, artifact);
continue;
}
@@ -112,13 +112,20 @@ public class ModCompileRemapper {
/**
* Checks if an artifact is a fabric mod, according to the presence of a fabric.mod.json.
*/
private static boolean isFabricMod(Logger logger, ResolvedArtifact artifact) {
private static boolean shouldRemapMod(Logger logger, ResolvedArtifact artifact, boolean forge) {
File input = artifact.getFile();
try (ZipFile zipFile = new ZipFile(input)) {
if (zipFile.getEntry("fabric.mod.json") != null) {
logger.info("Found Fabric mod in modCompile: {}", artifact.getId());
return true;
if (forge) {
if (zipFile.getEntry("META-INF/mods.toml") != null) {
logger.info("Found Forge mod in modCompile: {}", artifact.getId());
return true;
}
} else {
if (zipFile.getEntry("fabric.mod.json") != null) {
logger.info("Found Fabric mod in modCompile: {}", artifact.getId());
return true;
}
}
return false;

View File

@@ -100,6 +100,7 @@ public class ModProcessor {
}
private static void stripNestedJars(File file) {
if (!ZipUtil.containsEntry(file, "fabric.mod.json")) return;
// Strip out all contained jar info as we dont want loader to try and load the jars contained in dev.
ZipUtil.transformEntries(file, new ZipEntryTransformerEntry[] {(new ZipEntryTransformerEntry("fabric.mod.json", new StringZipEntryTransformer() {
@Override
@@ -203,7 +204,7 @@ public class ModProcessor {
}
if (extension.isForge()) {
AtRemapper.remap(info.getRemappedOutput().toPath(), mappings);
AtRemapper.remap(project.getLogger(), info.getRemappedOutput().toPath(), mappings);
CoreModClassRemapper.remapJar(info.getRemappedOutput().toPath(), mappings, project.getLogger());
}
}

View File

@@ -37,6 +37,8 @@ import com.google.common.collect.ImmutableMap;
import net.fabricmc.loom.util.function.CollectionUtil;
import net.fabricmc.mapping.tree.TinyTree;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.logging.Logger;
/**
* Remaps AT classes from SRG to Yarn.
@@ -44,7 +46,7 @@ import net.fabricmc.mapping.tree.TinyTree;
* @author Juuz
*/
public final class AtRemapper {
public static void remap(Path jar, TinyTree mappings) throws IOException {
public static void remap(Logger logger, Path jar, TinyTree mappings) throws IOException {
try (FileSystem fs = FileSystems.newFileSystem(URI.create("jar:" + jar.toUri()), ImmutableMap.of("create", false))) {
Path atPath = fs.getPath("META-INF", "accesstransformer.cfg");
@@ -55,12 +57,17 @@ public final class AtRemapper {
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i).trim();
if (line.startsWith("#")) {
if (line.startsWith("#") || StringUtils.isBlank(line)) {
output.add(i, line);
continue;
}
String[] parts = line.split(" ");
if (parts.length < 3) {
logger.warn("Invalid AT Line: " + line);
output.add(i, line);
continue;
}
String name = parts[1].replace('.', '/');
parts[1] = CollectionUtil.find(
mappings.getClasses(),