Existing mod loaders such as Forge have a mechanism that allows you to directly decompile Minecraft to get the source code and easily add items etc. to the decompiled Minecraft. This method had the advantage (for modloader developers) that the modloader could mess with the entire Minecraft source code, but it had one major problem. Decompiling Minecraft is complicated and you can't even try to recompile the decompiled one. This is partly due to a bug by the decompiler itself, but it's unavoidable because some information is lost at compile time (such as Generics). This issue caused a delay in modloader development.
To put it simply, the Mixin framework is a group of functions that allow you to play with the source code without decompiling. The class file contains all the information about Java classes, but it's especially difficult to decompile the process inside the method. Conversely, if you can play with the source code without decompiling the process inside the method, there is no problem. The Mixin framework makes this possible with the following steps:
public class Player {
public void kill() {
...
}
}
public class Main {
public static void main(String[] args) {
Player player = new Player();
player.kill();
}
}
Suppose you have a player class (whose kill method is unknown) and a main class that uses it, as shown above. You are confident that killing the kill method will make the player immortal, and you want to take advantage of the Mixin framework to kill the kill method. At this point you will first "mixin" the Player class. The following class is created by "Mixin".
public class Player$1 extends Player {
private final Player player;
public Player$1(Player player) {
this.player = player;
}
public void kill() {
player.kill();
}
}
Also, the main class can be rewritten as follows by "Mixin".
public class Main {
public static void main(String[] args) {
Player$1 player = new Player$1(new Player());
player.kill();
}
}
You can see that the Player $ 1 class that wraps the Player class has been created, and new in the main class has been rewritten. So how do you get rid of the kill method? The answer is simple.
public class Player$1 extends Player {
private final Player player;
public Player$1(Player player) {
this.player = player;
}
public void kill() {
//player.kill();
}
}
I was able to delete the processing of the kill method just by commenting out one line. It's easy! Certainly, with this method, it seems easy to delete the processing of the method or add processing before and after the method.
The Fabric loader consists of the following two parts.
I said that you can easily change the processing of a method by "mixing", but there are actually some restrictions. One of the biggest restrictions is that loaded classes cannot be modified. So Fabric-loader modifies the Minecraft settings file (version .json) so that when you launch Minecraft from the launcher, Minecraft will not be executed directly, but the mod will go through Fabric-loader. Adjusts Minecraft to run after it has been loaded and "Mixined".
The Fabric API is a collection of common parts used in many mods such as adding blocks and adding items. The Fabric API also works using Fabric-loader. Also, there is no such thing as whether the Fabric API is absolutely necessary for mod creation, and famous mods such as Sodium, Phospher, Lithium, etc. will work without the Fabric API (on the contrary, if there is a Fabric API, they will interfere with each other and work. Some mods don't work).
Recommended Posts