|
| 1 | +# ModDevGradle Legacy Forge Plugin |
| 2 | +ModDevGradle has a secondary plugin (ID: `net.neoforged.moddev.legacyforge`, released alongside the normal plugin with the same version) |
| 3 | +that adds support for developing mods against MinecraftForge and Vanilla Minecraft versions 1.17 up to 1.20.1. |
| 4 | + |
| 5 | +The legacy plugin is an "addon" plugin, meaning it operates on top of the normal plugin. This means that the APIs normally used |
| 6 | +are also available when using the legacy plugin. |
| 7 | + |
| 8 | +## Basic Usage for MinecraftForge Mods |
| 9 | +An example `build.gradle` file for developing a mod against MinecraftForge for 1.20.1 is provided below: |
| 10 | +```groovy |
| 11 | +plugins { |
| 12 | + // Apply the plugin. You can find the latest version at https://projects.neoforged.net/neoforged/ModDevGradle |
| 13 | + id 'net.neoforged.moddev.legacyforge' version '2.0.28-beta' |
| 14 | +} |
| 15 | +
|
| 16 | +neoForge { |
| 17 | + // Develop against MinecraftForge version 47.3.0 for 1.20.1 (the versions can be found at https://files.minecraftforge.net/) |
| 18 | + version = "1.20.1-47.3.0" |
| 19 | + |
| 20 | + // Validate AT files and raise errors when they have invalid targets |
| 21 | + // This option is false by default, but turning it on is recommended |
| 22 | + validateAccessTransformers = true |
| 23 | +
|
| 24 | + runs { |
| 25 | + client { |
| 26 | + client() |
| 27 | + } |
| 28 | + data { |
| 29 | + data() |
| 30 | + } |
| 31 | + server { |
| 32 | + server() |
| 33 | + } |
| 34 | + } |
| 35 | +
|
| 36 | + mods { |
| 37 | + testproject { |
| 38 | + sourceSet sourceSets.main |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +## Reobfuscating artifacts |
| 45 | +Forge used SRG mappings as intermediary mappings in 1.20.1 and below. While your mod is developed against the mappings provided |
| 46 | +by Mojang (known as official mappings), you need to reobfuscate it to SRG mappings for it to work in production. |
| 47 | +Reobfuscation will automatically be configured for the `jar` task; the non-obfuscated jar will have a `-dev` classifier |
| 48 | +and will not be published in favour of the reobfuscated variant. You should upload the `reobfJar` task's output when using a |
| 49 | +task to upload to a mod hosting platform, or otherwise the jar without a `-dev` classifier if you're uploading it manually. |
| 50 | + |
| 51 | +You may reobfuscate other jar tasks using `obfuscation.reobfuscate(TaskProvider<AbstractArchiveTask>, SourceSet, Action<RemapJarTask>)`. |
| 52 | +For instance, if you want to reobfuscate a `shadowJar` task: |
| 53 | +```groovy |
| 54 | +shadowJar { |
| 55 | + // Change the classifier of the shadow jar to be -dev-all as it's not mapped in intermediary and not usable for production |
| 56 | + archiveClassifier = 'dev-all' |
| 57 | +} |
| 58 | +
|
| 59 | +obfuscation { |
| 60 | + // Reobfuscate the shadowJar task, using the classpath of the main sourceset for properly remapping inherited members |
| 61 | + reobfuscate(tasks.named('shadowJar'), sourceSets.main) { |
| 62 | + // Make the reobfuscated shadowJar have the all classifier |
| 63 | + // You could also change it to an empty string if you want it to not have a classifier (in that case, you will also need to change the classifier of the slim `reobfJar` task |
| 64 | + archiveClassifier = 'all' |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +When reobfuscating a jar, it will be replaced in publications with the obfuscated version to avoid publishing jars that aren't mapped to SRG. |
| 70 | + |
| 71 | +## Remapping mod dependencies |
| 72 | +As published mods are using intermediary mappings, you must remap them to official mappings before being able to use them as a dependencies. |
| 73 | +ModDevGradle creates configurations that will automatically remap dependencies added to them from SRG mappings to official mappings. |
| 74 | +The following configurations are created automatically and are children of the configurations without the `mod` prefix: |
| 75 | +- `modImplementation` |
| 76 | +- `modRuntimeOnly` |
| 77 | +- `modCompileOnly` |
| 78 | +- `modApi` (only if the `java-library` plugin is applied) |
| 79 | +- `modCompileOnlyApi` (only if the `java-library` plugin is applied) |
| 80 | + |
| 81 | +You may create your own remapping configurations using `obfuscation.createRemappingConfiguration(Configuration)`: |
| 82 | +```groovy |
| 83 | +configurations { |
| 84 | + // Create a custom configuration named "custom" |
| 85 | + custom |
| 86 | +} |
| 87 | +
|
| 88 | +obfuscation { |
| 89 | + // Create a configuration named "modCustom" that remaps its dependencies and then adds them to the "custom" configuration |
| 90 | + createRemappingConfiguration(configurations.custom) |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +## Effects of applying the legacy plugin |
| 95 | +When applied, the legacy plugin will change the base NeoForm and NeoForge artifact coordinates of the `neoForge` extension to |
| 96 | +`de.oceanlabs.mcp:mcp_config` and `net.minecraftforge:forge`. |
| 97 | +It will also trigger the creation of various intermediary (SRG) to named (official) mapping files used by various parts of the toolchain, such as |
| 98 | +mod reobfuscation and runtime naming services. |
| 99 | +Reobfuscation to the intermediary mappings will automatically be configured for the `jar` task, the non-obfuscated jar will have a `-dev` classifier |
| 100 | +and will not be published in favour of the reobfuscated variant. |
0 commit comments