User Tools

Site Tools


tutorial:side

This is an old revision of the document!


Side

Fabric allows mods to target the Minecraft client or dedicated server distributions of Minecraft, but more commonly both at the same time. A Minecraft client and a dedicated server are both instances of physical sides, referring to what code is “physically” present in the program environment. A physical side hosts one or multiple logical sides, called the logical client and logical server, referring to the kind of logic they are responsible for in the Client-server model.

For both types of “side”s, there are “client” and “server”. However, a logical client is not equivalent to a physical client, and a logical server is not equivalent to a physical server either. A logical client is instead hosted by a physical client, and a logical server is hosted by either a physical server or a physical client.

The logical sides are central in the architecture of both distributions of Minecraft. Therefore, an understanding of logical sides is vital for any kind of development with Fabric.

Logical Sides

Logical sides are mainly about the threads the game run on, including the Client (does rendering, sends player inputs to the server, handles resource packs, etc.) and the Server (calculates most core logic, handles data packs, keeps the world/game data, etc.) threads.

The packets (which https://wiki.vg documents) between minecraft sides are sent between logical clients and logical servers. Mods can add packets in order to transfer information between two logical sides.

In Minecraft, in order to reduce code, the logical client and servers share some logic classes, including

net.minecraft.world.World
net.minecraft.entity.Entity
net.minecraft.block.entity.BlockEntity

and a few more. These shared classes allow logical clients to shadow some common game logic from the logical server for easy rendering. (block entities are shadowed to the logical client optionally)

Usually, to identify the shadowed objects on the logical clients from the real ones on the logical server, vanilla and mod code access the World referenced in these objects and check the world's isClient field (in Fabric yarn) so that they do not possibly perform useless calculations on the logical client so as to avoid de-synchronization between the two logical sides and to reduce load on the logical client.

Logical Client

The logical client is where most displays to the player is done. Rendering (LWJGL), resource pack, player input handling, sounds, etc. all happen on the logical client.

The logical client runs on the main thread of the physical client exclusively. It is not present on the physical server. It is a singleton and always exists.

In yarn, the C2S packets are sent from the logical client (which calls write method in a network thread), and the S2C packets are received by the logical client (which calls read method in a network thread).

Logical Server

The logical server is where most of the game logic is going on. Data packs, world updates, block entity and entity ticks, mob AI, game/world saving, world generation, etc. all happen on the logical server.

The logical server on the physical client is called the “Integrated Server”, while the logical server on the physical server is called the “Dedicated Server” (which is also the name of the physical server itself).

The logical server never runs on the thread which went through the entrypoint of a physical side, even on physical servers. Still, it has its own thread, on which it handles its logic. It is a singleton that always exists on physical servers; on the physical client, it exists one instance at a time when the player is playing a local save, and a new instance is created every time the player loads a local save.

Most universal mods target the logical server so that they are applicable to both physical sides.

In yarn, the S2C packets are sent from the logical server (which calls write method in a network thread), and the C2S packets are received by the logical server (which calls read method in a network thread).

Physical Sides (EnvType)

The physical sides refer to the two distributions (jars) of Minecraft game, the client (what the vanilla launcher launches) and the server (download available on https://minecraft.net for free), which are launched in different ways.

In Fabric, you can often see annotations like

@Environment(EnvType.CLIENT)

This indicates that some code is present only on one physical side, in this case here, on the client.

In Fabric fabric.mod.json and the mixin config, the client/server refers to the physical side.

Each physical side ships classes used by its respective entry point and the data generator classes with entrypoint

net.minecraft.data.Main

Physical Client

The physical client is the minecraft jar downloaded by the vanilla launcher. It contains a logical client and a logical server (integrated server). Its entrypoint is

net.minecraft.client.main.Main

.

As a physical client can load worlds (launch integrated servers/its logical server) without a limit, but a previous logical server on a physical client must be stopped for a new one to launch.

Compared to the logical server of the physical server (dedicated server), the logical server of the physical client (integrated server) can be controlled by the logical client on the physical client (e.g. F3+T reloads data packs and shutting down the client shuts down the integrated server). It can also load resource packs bundled in a world to the logical client on the physical client.

All the logical client contents are exclusive to the physical client. Hence, you will see a lot of environment annotations on rendering, sound, and other logical client code.

Some mods target physical clients exclusively. For instance, Liteloader, Optifine, Minecraft PvP clients (Badlion, Hyperium, etc.) only run on the physical client.

Physical Server

The physical server is the java dedicated server. Compared to a physical client, it only has a logical server (dedicated server). Its entrypoint is

net.minecraft.server.MinecraftServer

Compared to the physical client, the physical server can only have one world/save as its logical server is a singlton.

Its logical server differs slightly from that of a physical client as only one logical server instance will be ever present when the physical server is ran. Moreover, the logical server of the physical server can be controlled remotely via Rcon, has server.properties, and can send server resource packs.

Despite these differences, most mods are fine and applicable to the logical servers of both the physical client and the physical server as long as they do not refer to logical client contents.

Its features of single world and resource pack sending, however, makes vanilla mod (data pack and resource pack combination) installation much easier compared to on clients, as vanilla physical clients will be set up when connecting to the server automatically.

Some mods target physical server exclusively. For instance, Bukkit and its derivatives (Spigot, Paper, Cauldron, Xxx-Bukkit hybrids) always run on the physical server.

Conclusion

Possible combinations of physical and logical sides:

Logical Client Logical Server
Physical Client Singleton Always Exists Exists when in local save; new instance for each play
Physical Server Does Not Exist Singleton Always Exists

Ultimately, the main confusion comes from the fact that logical servers exist on physical clients.

Logical Server in Physical Client

Most of the time, mods target physical server exclusively can be applied to logical servers in physical clients in theory.

However, modders for physical servers usually have incorrect assumptions of all logical servers, including but not limited to:

  • Only one logical server instance will ever exist on one game run
  • The world and entities should always calculate the game logic (i.e. the World.isClient field is always false)
  • Remote control, resource pack sending, and Favicon are present

These assumptions need to be corrected in order to make plugins that run on both singleplayer and dedicated servers, etc.

tutorial/side.1557347466.txt.gz · Last modified: 2019/05/08 20:31 by jamieswhiteshirt