-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Legacy plugin for 1.17 to 1.20.1 #118
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# ModDevGradle Legacy Plugin | ||
ModDevGradle has a secondary plugin (ID: `net.neoforged.moddevgradle.legacy`, released alongside the normal plugin with the same version) | ||
that adds support for developing mods against MinecraftForge and Vanilla Minecraft versions 1.17 up to 1.20.1. | ||
|
||
The legacy plugin is an "addon" plugin, meaning it operates on top of the normal plugin. This means that the APIs normally used | ||
are also available when using the legacy plugin. | ||
|
||
## Basic Usage for MinecraftForge Mods | ||
An example `build.gradle` file for developing a mod against MinecraftForge for 1.20.1 is provided below: | ||
```groovy | ||
plugins { | ||
// Apply the plugin. You can find the latest version at https://projects.neoforged.net/neoforged/ModDevGradle | ||
id 'net.neoforged.moddev.legacy' version '2.0.28-beta' | ||
} | ||
|
||
neoForge { | ||
// Develop against MinecraftForge version 47.3.0 for 1.20.1 (the versions can be found at https://files.minecraftforge.net/) | ||
version = "1.20.1-47.3.0" | ||
|
||
// Validate AT files and raise errors when they have invalid targets | ||
// This option is false by default, but turning it on is recommended | ||
validateAccessTransformers = true | ||
|
||
runs { | ||
client { | ||
client() | ||
} | ||
data { | ||
data() | ||
} | ||
server { | ||
server() | ||
} | ||
} | ||
|
||
mods { | ||
testproject { | ||
sourceSet sourceSets.main | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Reobfuscating artifacts | ||
Forge used SRG mappings as intermediary mappings in 1.20.1 and below. While your mod is developed against the mappings provided | ||
by Mojang (known as official mappings), you need to reobfuscate it to SRG mappings for it to work in production. | ||
Reobfuscation will automatically be configured for the `jar` task; the non-obfuscated jar will have a `-dev` classifier | ||
and will not be published in favour of the reobfuscated variant. You should upload the `reobfJar` task's output when using a | ||
task to upload to a mod hosting platform, or otherwise the jar without a `-dev` classifier if you're uploading it manually. | ||
|
||
You may reobfuscate other jar tasks using `obfuscation.reobfuscate(TaskProvider<AbstractArchiveTask>, SourceSet, Action<RemapJarTask>)`. | ||
For instance, if you want to reobfuscate a `shadowJar` task: | ||
```groovy | ||
shadowJar { | ||
// Change the classifier of the shadow jar to be -dev-all as it's not mapped in intermediary and not usable for production | ||
archiveClassifier = 'dev-all' | ||
} | ||
|
||
obfuscation { | ||
// Reobfuscate the shadowJar task, using the classpath of the main sourceset for properly remapping inherited members | ||
reobfuscate(tasks.named('shadowJar'), sourceSets.main) { | ||
// Make the reobfuscated shadowJar have the all classifier | ||
// 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 | ||
archiveClassifier = 'all' | ||
} | ||
} | ||
``` | ||
|
||
When reobfuscating a jar, it will be replaced in publications with the obfuscated version to avoid publishing jars that aren't mapped to SRG. | ||
|
||
## Remapping mod dependencies | ||
As published mods are using intermediary mappings, you must remap them to official mappings before being able to use them as a dependencies. | ||
ModDevGradle creates configurations that will automatically remap dependencies added to them from SRG mappings to official mappings. | ||
The following configurations are created automatically and are children of the configurations without the `mod` prefix: | ||
- `modImplementation` | ||
- `modRuntimeOnly` | ||
- `modCompileOnly` | ||
- `modApi` (only if the `java-library` plugin is applied) | ||
- `modCompileOnlyApi` (only if the `java-library` plugin is applied) | ||
|
||
You may create your own remapping configurations using `obfuscation.createRemappingConfiguration(Configuration)`: | ||
```groovy | ||
configurations { | ||
// Create a custom configuration named "custom" | ||
custom | ||
} | ||
|
||
obfuscation { | ||
// Create a configuration named "modCustom" that remaps its dependencies and then adds them to the "custom" configuration | ||
createRemappingConfiguration(configurations.custom) | ||
} | ||
``` | ||
|
||
## Effects of applying the legacy plugin | ||
When applied, the legacy plugin will change the base NeoForm and NeoForge artifact coordinates of the `neoForge` extension to | ||
`de.oceanlabs.mcp:mcp_config` and `net.minecraftforge:forge`. | ||
It will also trigger the creation of various intermediary (SRG) to named (official) mapping files used by various parts of the toolchain, such as | ||
mod reobfuscation and runtime naming services. | ||
Reobfuscation to the intermediary mappings will automatically be configured for the `jar` task, the non-obfuscated jar will have a `-dev` classifier | ||
and will not be published in favour of the reobfuscated variant. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
run/ | ||
repo/ | ||
*.log |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
plugins { | ||
id 'maven-publish' | ||
id 'net.neoforged.moddev.legacy' | ||
} | ||
|
||
group = 'com.example.legacy' | ||
version = '1.0.0' | ||
|
||
repositories { | ||
mavenLocal() | ||
maven { | ||
name 'cursemaven' | ||
url 'https://cursemaven.com' | ||
content { | ||
includeGroup "curse.maven" | ||
} | ||
} | ||
} | ||
Comment on lines
+9
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused mavens. (Before merging) |
||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
neoForge { | ||
neoFormVersion = '1.19.2' | ||
} | ||
|
||
publishing { | ||
publications { | ||
maven(MavenPublication) { | ||
from components.java | ||
} | ||
} | ||
repositories { | ||
maven { | ||
url file('local') | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
plugins { | ||
id 'net.neoforged.moddev.legacy' | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
maven { | ||
name = "Jared's maven" | ||
url = "https://maven.blamejared.com/" | ||
} | ||
maven { | ||
name 'cursemaven' | ||
url 'https://cursemaven.com' | ||
content { | ||
includeGroup "curse.maven" | ||
} | ||
} | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
dependencies { | ||
modCompileOnly('mezz.jei:jei-1.20.1-forge:15.17.0.76') { | ||
transitive = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
} | ||
modRuntimeOnly('curse.maven:mekanism-268560:5662583') | ||
modImplementation('curse.maven:applied-energistics-2-223794:5641282') | ||
} | ||
Comment on lines
+26
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really want to have these deps in repo? 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a test project of an old MC version, why not |
||
|
||
neoForge { | ||
version = '1.20.1-47.3.0' | ||
runs { | ||
client { | ||
client() | ||
} | ||
data { | ||
data() | ||
} | ||
} | ||
mods { | ||
myMod { | ||
sourceSet(sourceSets.main) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package mymod; | ||
|
||
import mezz.jei.api.IModPlugin; | ||
import mezz.jei.api.JeiPlugin; | ||
import mezz.jei.api.registration.ISubtypeRegistration; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Items; | ||
|
||
@JeiPlugin | ||
public class JeiCompat implements IModPlugin { | ||
@Override | ||
public ResourceLocation getPluginUid() { | ||
return new ResourceLocation("mymod:mymod"); | ||
} | ||
|
||
@Override | ||
public void registerItemSubtypes(ISubtypeRegistration registration) { | ||
registration.registerSubtypeInterpreter(Items.ALLIUM, (ingredient, context) -> "allium"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to comment here that calling this method tests the remapping of the JEI artifact since this method call would otherwise fail to compile because of the Item argument |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package mymod; | ||
|
||
import net.minecraftforge.fml.common.Mod; | ||
|
||
@Mod("mymod") | ||
public class MyMod { | ||
public void run() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
modLoader="javafml" #mandatory | ||
loaderVersion="*" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. | ||
license="ARR" | ||
[[mods]] #mandatory | ||
# The modid of the mod | ||
modId="mymod" #mandatory | ||
# The version number of the mod | ||
version="1.0" #mandatory | ||
# A display name for the mod | ||
displayName="My Mod" #mandatory | ||
authors="MDG" #optional | ||
description='''Hi.''' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.gradle.configuration-cache=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-all.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are writing a plugin, I want the sources.