Changes

2,525 bytes added ,  16:59, 11 January 2021
Forge side
Line 43: Line 43:     
In this way, MCPConfig can be thought of the vanilla side of the setup. It does not modify the game.
 
In this way, MCPConfig can be thought of the vanilla side of the setup. It does not modify the game.
 +
 +
The following steps are all executed in order of appearance.
    
=== Download and parsing MCPConfig ===
 
=== Download and parsing MCPConfig ===
 
The first thing that ForgeGradle does upon initialising a first-time setup, is starting the [https://github.com/MinecraftForge/ForgeGradle/blob/e2ed49546abced95650635f81be071441ec60995/src/mcp/java/net/minecraftforge/gradle/mcp/task/SetupMCPTask.java#L91 SetupMCP] task.  
 
The first thing that ForgeGradle does upon initialising a first-time setup, is starting the [https://github.com/MinecraftForge/ForgeGradle/blob/e2ed49546abced95650635f81be071441ec60995/src/mcp/java/net/minecraftforge/gradle/mcp/task/SetupMCPTask.java#L91 SetupMCP] task.  
 +
 
This task then seeks to [https://github.com/MinecraftForge/ForgeGradle/blob/e2ed49546abced95650635f81be071441ec60995/src/mcp/java/net/minecraftforge/gradle/mcp/task/DownloadMCPConfigTask.java#L78 download the MCPConfig.zip jar] for the version you're setting up.
 
This task then seeks to [https://github.com/MinecraftForge/ForgeGradle/blob/e2ed49546abced95650635f81be071441ec60995/src/mcp/java/net/minecraftforge/gradle/mcp/task/DownloadMCPConfigTask.java#L78 download the MCPConfig.zip jar] for the version you're setting up.
Once it is acquired, it [https://github.com/MinecraftForge/ForgeGradle/blob/e2ed49546abced95650635f81be071441ec60995/src/mcp/java/net/minecraftforge/gradle/mcp/util/MCPRuntime.java#L74 parses the steps contained within the config.json]. It does this by interpreting the file with the following rules:
+
Once it is acquired, it  
 +
[https://github.com/MinecraftForge/ForgeGradle/blob/e2ed49546abced95650635f81be071441ec60995/src/mcp/java/net/minecraftforge/gradle/mcp/util/MCPRuntime.java#L74 parses the steps contained within the config.json]. It does this by interpreting the file with the following rules:
 
* Every key, except for libraries, is interpreted as the name of a step.
 
* Every key, except for libraries, is interpreted as the name of a step.
 
* Steps are executed in order.
 
* Steps are executed in order.
Line 103: Line 107:     
It simply searches the jar for files, converts the bytecode into a reasonable best-guess interpretation.
 
It simply searches the jar for files, converts the bytecode into a reasonable best-guess interpretation.
 +
 
As you can see by the repository, a lot of work has gone into tuning it for Minecraft's needs, but it is still a far way from perfect. This is why the patches are needed.
 
As you can see by the repository, a lot of work has gone into tuning it for Minecraft's needs, but it is still a far way from perfect. This is why the patches are needed.
   Line 167: Line 172:  
It also adjusts abstract functions in some way - after running the program on a jar, the parameters of a default abstract function get renamed, but it is unclear exactly what part of the source code does this.
 
It also adjusts abstract functions in some way - after running the program on a jar, the parameters of a default abstract function get renamed, but it is unclear exactly what part of the source code does this.
    +
== The Forge Side ==
 +
 +
After the MCPConfig/SetupMCP tasks are finished, ForgeGradle will print '''MCP Environment Setup is complete''' and wait for the user input.
 +
 +
The next step is to run the <code>gradlew setup</code> task, which does what it implies: Applying the Forge system to the processed vanilla code.
 +
 +
First, it applies ATs. After that, patches. Finally, MCP/Crowdsourced mappings are applied.
 +
 +
All in all, compared to the MCPConfig setup, this is a string of extremely basic tasks - mostly just one-line commands.
 +
 +
=== Applying Access Transformers ===
 +
 +
[[Access Transformers]] are a way of changing the visibility and finality of classes and class members. A full explanation of how it works, what the specification is, and what exactly they're used for, can be found at that page.
 +
 +
They are applied by passing the AT Config (nowadays called accesstransformer.cfg) into SpecialSource:
 +
* <code>SpecialSource.jar --in-jar {input} --out-jar {output} --access-transformer {at.cfg}</code>
 +
 +
[https://github.com/MinecraftForge/MinecraftForge/blob/c3e84646db70f518dd0b37a8fcfc42cb814d7ba8/src/main/resources/META-INF/accesstransformer.cfg The current AT cfg can be found here.]
 +
 +
=== Applying Patches ===
 +
 +
The patches used for Forge itself are different from those used by MCPConfig, which means there are two separate patching stages performed.
 +
 +
As opposed to the minimal MCPConfig patching, with the goal to make the code recompileable, the Forge patching is done to apply the API and modloader to the code.
 +
 +
It does this in a very similar way, with the [https://github.com/CadixDev/gitpatcher gitpatcher] utility.
 +
 +
 +
=== Applying Mappings ===
 +
This step isn't strictly necessary, and it can be ommitted. However, working with exclusively SRG names is confusing for most people, so we have an extra step to apply human names to the SRG.
 +
 +
These renames can come from any source; as mentioned earlier, the MCP/Crowdsourced naming, the Yarn naming, or the Mojang Obf-map naming. ForgeGradle does not care, as long as there is a valid SRG->names map.
 +
 +
How ForgeGradle retrieves these mappings is covered in the [[ForgeGradle/mappings appropriate article]].
 +
 +
The process of renaming itself is a simple regex substitution, performed by [https://github.com/MinecraftForge/ForgeGradle/blob/e2ed49546abced95650635f81be071441ec60995/src/common/java/net/minecraftforge/gradle/common/util/McpNames.java#L104 ForgeGradle itself]. This is made possible by the assured uniqueness of SRG names.
 +
 +
=== Post-processing ===
 +
 +
At this point, the files are ready to go. We have processed the Minecraft jar such that it can be recompiled, we have applied appropriate access transformers and the Forge patches, and optionally renamed every applicable SRG name to whatever chosen distribution of mappings.
   −
== Mappings ==
+
There is not much left to do but package the code into a jar file, and place it into the gradle cache (so that this process does not occur every single time the project is opened). It calculates this name based on many factors, and this is covered in the [[ForgeGradle#naming]] article.
We don't need this step but coding with the <code>SRG</code> names is hard and not really fun.
  −
So we need to take the <code>SRG</code> names and make them more user friendly, the user friendly names are community sourced names.
  −
Since <code>SRG</code> names are uniquely identifiable, due to the unique ID, it literally does a search-and-replace on all the source code text to do that <code>SRG</code>-><code>MCP</code>(( <code>MCP</code> stands for ModCoderPack (or previously, Minecraft Coder Pack) which was the toolchain that did all of this before the advent of ForgeGradle)) application.
      
== Some additional Infos ==
 
== Some additional Infos ==