EDIT (14/08/2016): After receiving input on the article, I have made certain corrections and improvements to its content. I would also like to point out the context of the article, as some have read it incorrectly - the article was written after listening to many, many people say that making a new mod loader is easy and put the blame on modders for not challenging the status quo, as some would like to see happen. This was intended as a set of instructions for those people, even though I could reasonably assume most of them would never carry on beyond complaining on anonymous imageboards, which is why why the first paragraph begins with an acknowledgement of /vg/ - one of the 4chan boards about video gaming where I was usually asked the question on. While one could still read it as a “call to arms” of sorts, it was really a form of attempting to show that saying is much easier than doing, which is acknowledged in the second paragraph.
Thanks to /vg/ for inspiration.
I get to answer the question of “Why don’t we just make a new mod loader?” surprisingly often, and - to be honest - I’m tired of it, so here’s a proper response from me to those people.
Are you an aspiring modded Minecraft community member annoyed at the way in which Forge is being run? Do you want to show everyone that it can be done better and not just whine about inefficiencies of the current developers on social media? Or perhaps you just want a new challenge? If so, this tutorial is for you!
If you want to set out on the
missing mission to create a new modding API, you’re going to need to keep a few things in mind. First of all, Minecraft is obfuscated. You need mappings to translate method names
like ahz.c into something more coherent and less changing every version. Where are you going to get them?
- “Ah, yes!” says the young revolutionary. “I’m going to use MCP!”, he adds. Except he might run into some problems. Mod Coder Pack mappings have a fairly restrictive license, which means you cannot redistribute them
without the explicit
permission of MCP. However, despite Minecraft 1.7.2 bringing very close integration of MCP and Forge via ForgeGradle, the Coder Pack alone is still being updated, although far more quietly. You
can do what Forge did pre-1.7.2 and wrap it with a series of scripts which plug your modding API in - however, that still means you need to distribute mods in the obfuscated format or acquire permission to use the
mappings, because MCP’s version-consistent,
unique-identifier-based intermediary mapping (SRG mappings) is still under the restrictive license - and its maintainers are not keen on giving the permission to
othersother general-purpose mod loaders. The SRG mappings were supposed to maximize mod compatibility across patch releases of Minecraft however history shows that it wasn’t anywhere near as useful as hoped, as those patch versions often broke very commonly used parts of the codebasewhich have come in handy on a number of occasions. In other words, you can use them, and they have many benefits, but with notablecertain restrictions.
- “Alright, then”, continues the visionary, “I will make my own mappings!”. Except he probably won’t. Minecraft is a massive codebase (over 250,000 lines of code) and documenting it all on your own, as well as maintaining it without access to Mojang’s own mappings, is very tough and unrewarding work. “Are you telling me that nobody made tools for it?” Of course they have! Cuchaz made a tool for deobfuscating Java software called Enigma. It includes many tools to help you figure out what a given field or method does, as well as intelligent algorithms - allegedly more powerful than MCP’s own - which match those deobfuscated names to new versions of the software. With this, I’d say it’s doable - but still a fair amount of work.
- There’s also DynamicMappings. It tries to dynamically figure out the obfuscated names for classes, fields and methods while being given a set of directions based on the logic of the code using them. It is certainly an interesting approach, but impractical in the long run - however, FyberOptic is only targeting a subset of Minecraft.
- Don’t even think about working on obfuscated code directly unless your mod is
DirtPodzol to Diamonds.
Okay, so now that you (hopefully) figured out the mappings, you need a mod loader - a tool to load JAR files from a directory into the classpath and initialize them so that they can execute their own code and hook into Minecraft while it is loading.
- Mojang has made it a lot easier with the new launcher and Minecraft 1.6, as the game now includes the LaunchWrapper - a piece of code which runs before Minecraft and lets modders inject their own “tweaks”. This means you no longer need to patch the JAR to load your own code, which is great!
- The only reasonable answer here seems to be Meddle, FyberOptic’s version-independent mod loader which relies only on the LaunchWrapper and provides no functionality by itself. Go use that - don’t reinvent the wheel.
- There were historically many non-Forge-dependent mod loaders, such as Risugami’s ModLoader, LiteLoader and Cuchaz’s M3L. You might want to research how they worked.
Have a mod loader? Great! Now you can run your own mods, which is… kind of cool, I guess? They can’t really do much to affect the game itself, though - the hooks are missing! Now you’re going to need to start the slow process of implementing various hooks. Forge has a lot of features and it’s going to be hard to match even half of them, while MeddleAPI seems to only provide hooks for server-side crafting recipes, GUIs and block rendering. (It also forces you to input block/item IDs manually - thought that was provided by vanilla? Think again!) Here’s some of the examples of the hooks modders have come to expect the most:
- Dynamic block/item ID allocation
- Hooking the “custom payload” packet to let modders send custom packets from their mods
- Hooks for custom block/armor models
- Hooks for custom GUI spawning
- Fluid API for intercompatibility
- Some kind of dictionary for modders to have their mods be intercompatible
- A way to define custom dimensions, biomes, loot, etc.
- Events for ticks, player interaction, entities, block placement, breaking, etc.
- Probably some other minor hooks I’m forgetting. There’s really a lot of it, though not all of it is strictly necessary.
If you have all of those and more, congratulations! Now you just have to find modders willing to use it - and if you prove yourself to be a lot more friendly while providing improvements over Forge, that probably won’t be a problem.
“Wait! Can’t I just fork Forge?” Um, no. While Forge as a whole is under
a combination of the LGPL and
the MFPL (a license similar to the MMPL) the LGPL 2.1 license, the MCP mappings bundled with it (for SRG<->Mojang
remapping) are under the MCP license, with Forge being given
explicit permission to redistribute them - that means you can’t. You can probably work around this by downloading the original Forge and extracting the MCP mapping file from there, but that’s a
very ugly move. You could also fork Forge and replace its mappings with ones you make yourself, which is great unless you want to support any existing Forge mods.
My recommendation? Instead of whining about Forge, if you don’t like it, go
help base your modding API on Meddle. It has great technology behind it and could use some support.
Oh, right! Don’t forget about all the people complaining you’re effectively ruining the community and splitting it in half over some petty nonsensical drama - from the perspective of the user, all the drama between modders is probably fairly petty, as they just want to enjoy their mods! To be honest, you’re probably better off making your own game.