Forge PRs can be quite tricky to understand and get working but if you can get your new event or hook or fix into Forge, you benefit a ton of modders! Don't let the idea of a Forge PR scare you or seem too daunting! Just follow this gist and hopefully you'll get the hang of it!
The first step is check out gigaherz's gist for creating a PR:
https://gist.github.com/gigaherz/ca256fea517cb925dfc31d7cd48c487e
Forge's doc on making PRs with extra into and styling rules:
https://github.com/MinecraftForge/MinecraftForge/wiki/If-you-want-to-contribute-to-Forge
Though there are several notes to keep in mind as you make the PR. This gist serves to be like a nice checklist to glance over after you got your PR nearly ready after following the above links. Do note, these notes are split up into two parts because best practices for the code you put in the Forge codebase may not be the same best practice for the PR's patch code being put into the vanilla codebase.
Also, do not mention any other modloader besides Forge and do not mention coremods in any form (example: saying this PR is needed because x mod is coremodding due to lack of a hook. Saying that will get your PR closed and denied)
-
Do not edit in the
forge/cleansubproject, only editforge/main. If you editforge/clean, everything blows up! -
All new files need license headers added. Run
checkLicensestask to see if there is any file that is missing license headers. If so, then runupdateLicensestask to scan all files and automatically add the Forge license headers to them. -
Spaces around the outside of parentheses
()in if/while/for/switch statements such asif (someBool)instead ofif(someBool). -
Braces belong on new lines, if statements that are a single line do not need braces, and switch statement's cases are indented.
-
Always use spaces instead of tabs. Check your IDE settings as some may try to convert spaces to tabs which will cause GitHub to mess up the formatting as it displays tabs weirdly.
-
Try to keep your patch's changes to Minecraft's code as small as possible. By this, they mean keeping the diff in code itself minimal. So make if statements with a single line of code inside be entirely on a single line if possible. And no extra blank lines as well around the if statement. More info about this is here:
https://github.com/MinecraftForge/MinecraftForge/wiki/If-you-want-to-contribute-to-Forge#conventions-for-coding-patches-for-a-minecraft-class-javapatch -
Do not remove, add, or modify any existing import in a patch. Double check your IDE's settings and make sure it won't auto-create wildcard * imports or re-organize/delete imports. If you need to use a class outside the patch, use fully qualified names. This means to use Forge's
BlockSnapshotclass in a patch, donet.minecraftforge.common.util.BlockSnapshotto avoid needing to add an import. -
If you add ATs (AccessTransformers) as part of your PR, run
checkATstask. Then run thesetuptask. If the AT still doesn't apply for whatever reason, run thecleantask and then runsetuptask again. -
If you need to de-OnlyIn a thing, add it to forge.sas and run
checkSAStask. (SAS stands for Side Annotation Stripper) -
When you believe your PR looks good, run
gradlew build checkPatches checkATs checkSAS publishto have all those tasks look over your PR's code and point out if anything is wrong.
If you are unsure how to best format your patch to keep it as small as possible while also maintaining readability, you can ask for advice in #issues-and-prs channel of Forge's official discord. But ultimately, they will tell you if your formatting needs to be adjusted as part of the PR review process later on anyway.
Creating a test mod for your PR significantly raises the chances of it being merged or reviewed as it is now less work for the Forge team. Here's how to slap in a test mod:
-
Create the test mod's constructor class in
src/test/java/net/minecraftforge/debug/<folder>. <folder> will be the folder that your PR best fits in but you can make a new folder instead if none of the existing ones fits your PR. Typically, the test mod class is usually named<event name>Testsuch asBiomeLoadingEventTestto make it clear as to what it is testing. -
If your test mod requires some assets or data files to work, put those in
src/test/resources's assets/data folder under your test mod's modid. -
Now go to the
src/test/resources/META-INF/mods.tomlfile and add your modid to it to tell Forge it exists and can be ran.
[[mods]]
modId="test_mod_id_goes_here"- Follow this Forge doc to run your test mod to make sure that it works and that your PR also works properly:
https://mcforge.readthedocs.io/en/latest/forgedev/#enabling-test-mods
Note: If you are trying to test on servers in dev and you find it is crashing because of other people's client-side test mods, you can temporarily disable those test mods by removing them from themods.tomland then run your serverside testing (make sure you add them back after you are done testing your test mod)
Once your PR is ready and finished and you uploaded it to the Forge PR section, now you need to get the Triage label so that the triage team can review it later. Make a reply to your PR that tags @Minecraftforge/issuemanager and say that your PR is ready for review and merging. If you want to make extra sure that your PR will not get forgotten, you can go to the #issues-and-prs channel in the official Forge Discord and (without pinging anyone), ask for the triage label to be put on your PR. The Forge Discord is here: https://discord.gg/UvedJ9m