Remap mod dependencies + their coremods and ATs

This commit is contained in:
Juuxel
2020-12-03 18:08:43 +02:00
parent 2d88e849ec
commit ebc4b49390
3 changed files with 85 additions and 8 deletions

View File

@@ -1,6 +1,73 @@
# fabric-loom
Gradle plugin for Fabric
# Forgified Loom
Usage: `gradlew setup idea`
(Use `./gradle` on macOS and Linux)
A fork of [Fabric Loom](https://github.com/FabricMC/fabric-loom) that supports the Forge modding toolchain.
Note that if ForgeGradle works fine for you, *use it*.
This is not meant to be a complete replacement for ForgeGradle,
and there are probably many bugs and limitations here that FG doesn't have.
## Usage
Starting with a Fabric project similar to the example mod,
switch your Loom to this fork, like with [Chocohead's Loom fork](https://github.com/Chocohead/Fabric-Loom/).
`settings.gradle`:
```diff
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
+ maven {
+ name = 'Jitpack'
+ url = 'https://jitpack.io'
+ }
}
+ resolutionStrategy {
+ eachPlugin {
+ if (requested.id.id == "fabric-loom" && requested.version?.endsWith("-SNAPSHOT") != true) {
+ useModule("com.github.Juuxel.fabric-loom:fabric-loom:${requested.version}")
+ }
+ }
+ }
}
```
`build.gradle`:
```diff
plugins {
- id 'fabric-loom' version '0.5-SNAPSHOT'
+ id 'fabric-loom' version '<commit hash here>'
}
```
Then you need to set `loom.forge = true` in your `gradle.properties`,
and add the Forge dependency:
```groovy
forge "net.minecraftforge:forge:1.16.4-35.1.7"
```
You also need to remove the Fabric Loader and Fabric API dependencies.
You should also remove any access wideners and replace them with a Forge AT.
### Mixins
Mixins are used with a property in the `loom` block in build.gradle:
```groovy
loom {
mixinConfig = "mymod.mixins.json"
}
```
## Limitations
- Launching via IDE run configs doesn't work on Eclipse or VSCode.
- You have to use Gradle 5, like with FG. I've reused it as a library
in some places.
- The srg -> yarn remapper used for coremod class names is *really* simple,
and might break with coremods that have multiple class names per line.
- Mod dependencies (apart from Forge itself) aren't remapped properly yet.

View File

@@ -48,7 +48,6 @@ import net.minecraftforge.binarypatcher.ConsoleTool;
import net.minecraftforge.gradle.mcp.util.MCPRuntime;
import net.minecraftforge.gradle.mcp.util.MCPWrapper;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.plugins.JavaPluginConvention;
@@ -218,7 +217,9 @@ public class MinecraftPatchedProvider extends DependencyProvider {
};
if (modAt != null) {
args = ArrayUtils.addAll(args, "--atFile", modAt.getAbsolutePath());
args = Arrays.copyOf(args, args.length + 2);
args[args.length - 2] = "--atFile";
args[args.length - 1] = modAt.getAbsolutePath();
}
TransformerProcessor.main(args);

View File

@@ -59,6 +59,9 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftMappedProvider;
import net.fabricmc.loom.processors.dependency.ModDependencyInfo;
import net.fabricmc.loom.util.srg.AtRemapper;
import net.fabricmc.loom.util.srg.CoreModClassRemapper;
import net.fabricmc.mapping.tree.TinyTree;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.InputTag;
import net.fabricmc.tinyremapper.OutputConsumerPath;
@@ -129,7 +132,7 @@ public class ModProcessor {
private static void remapJars(Project project, List<ModDependencyInfo> processList) throws IOException {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
String fromM = "intermediary";
String fromM = extension.isForge() ? "srg" : "intermediary";
String toM = "named";
MinecraftMappedProvider mappedProvider = extension.getMinecraftMappedProvider();
@@ -142,8 +145,9 @@ public class ModProcessor {
project.getLogger().lifecycle(":remapping " + remapList.size() + " mods (TinyRemapper, " + fromM + " -> " + toM + ")");
TinyTree mappings = extension.isForge() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings();
TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyRemapperMappingsHelper.create(mappingsProvider.getMappings(), fromM, toM, false))
.withMappings(TinyRemapperMappingsHelper.create(mappings, fromM, toM, false))
.renameInvalidLocals(false)
.build();
@@ -196,6 +200,11 @@ public class ModProcessor {
if (accessWidener != null) {
ZipUtil.replaceEntry(info.getRemappedOutput(), info.getAccessWidener(), accessWidener);
}
if (extension.isForge()) {
AtRemapper.remap(info.getRemappedOutput().toPath(), mappings);
CoreModClassRemapper.remapJar(info.getRemappedOutput().toPath(), mappings, project.getLogger());
}
}
}