Background and mechanism of Fabric-loader

Target

How Fabric-loader was created

1. Problems with existing mod loaders

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.

2. Birth of SpongePowered / Mixin (Mixin framework)

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:

  1. Parse information in class files (classes, member variables, methods)
  2. Create a wrapper class for the parsed class.
  3. For the parsed class, replace all newly created objects with subclasses.
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.

What is Fabric-loader?

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".

What is Fabric API?

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

Background and mechanism of Fabric-loader
About the mechanism of the Web and HTTP
Learn the rudimentary mechanism and usage of Gradle 4.4
behavior of didSet and willSet
Overview of Docker and containers
Setup of JMeter and jEnv
Summary of FileInputStream and BufferedInputStream
Command mechanism and management tools
Combination of search and each_with_index
Judgment of JSONArray and JSONObject
Operator of remainder and exponentiation (exponentiation)
Advantages and disadvantages of Java
Mechanism and characteristics of Collection implementation class often used in Java
Basics of conditional branching and return
Understand the basic mechanism of log4j2.xml
About fastqc of Biocontainers and Java
Java reference mechanism (stack and heap)
Proper use of redirect_to and render
This and that of the JDK
[Swift] Advantages and disadvantages of Storyboard
Proper use of Mockito and PowerMock
[Java] Judgment of identity and equivalence
[Rails] Differences and usage of each_with_index and each.with_index
About removeAll and retainAll of ArrayList
This and that of Core Graphics
Default implementation of Object.equals () and Object.hashCode ()
Application of downcase and slice methods
This and that of exclusive control