User Tools

Site Tools


tutorial:side

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:side [2019/05/12 12:22] tyra314tutorial:side [2022/04/13 04:32] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Side ====== ====== Side ======
-Minecraft uses the [[https://en.wikipedia.org/wiki/Client%E2%80%93server_model|Client-server model]], that is users install the game client and connect to a server to play the game. Fabric allows mods to target either the Minecraft client or the Minecraft server, but also both at the same time. +Minecraft uses the [[https://en.wikipedia.org/wiki/Client-server_model|Client-server model]], that is users install the game client and connect to a server to play the game. Fabric allows mods to target either the Minecraft client or the Minecraft server, but also both at the same time. 
  
-In the past, there used to be a simple division into the client and the server, but with the switch of the single player game mode to an internal dedicated server, this simple model doesn't fit anymoreThuswe have two dimensions when distinguishing between client and server in Minecraft. These are the physical and logical sides.+The concept of client/server in Minecraft is ambiguous and may refer to either physical or logical sides. The terms client/server may be used to distinguish the different distributions of Minecraft (the Minecraft client vs. a dedicated Minecraft server) which are called "physical" sidesHowevera Minecraft client hosts its own integrated server for singleplayer and LAN sessions, which means that a Minecraft client also contains server logicTherefore, client/server may also be used to distinguish parts of the game logic which are called "logicalsides.
  
-For both types of sides, 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.+For both types of sides, there is a 'clientand a '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 mod development with Fabric. The logical sides are central in the architecture of both distributions of Minecraft. Therefore, an understanding of logical sides is vital for any mod development with Fabric.
Line 10: Line 10:
 ===== Physical Sides  ===== ===== Physical Sides  =====
  
-The physical sides or the environment 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). A physical side refers to which code is available in the current environment.+The physical sides or the environment refer to the two distributions (jars) of Minecraft, the client (what the vanilla launcher launches)and the server (download available on [[https://minecraft.net]] for free). A physical side refers to which code is available in the current environment.
  
 The client and server environment are minified distributions of the same program, containing only the required parts of the code.  The client and server environment are minified distributions of the same program, containing only the required parts of the code. 
Line 22: Line 22:
 ===== Logical Sides ===== ===== Logical Sides =====
  
-Logical sides are about the actual logic running during the execution.  +The logical sides are responsible for the actual game logic.  
-The client does rendering, sends player inputs to the server, handles resource packs, and the server calculates most core logic, handles data packs, keeps the world/game data. +The logical client does rendering, sends player inputs to the server, handles resource packs, and partially simulates the game world. The server handles the core game logic, data packs, and maintains the true state of the game world.
- +
-The logical client and server share some logic classes, including:<code> +
-net.minecraft.world.World +
-net.minecraft.entity.Entity +
-net.minecraft.block.entity.BlockEntity +
-</code> +
-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) +
- +
-Usuallyto distinguish the shadowed objects on the logical clients from the real ones on the logical servervanilla and mod code access the world referenced in these objects and check the state of the isClient field. A calculation is then only down on the logical server so that they do not perform useless calculations on the logical client. This technique avoids desynchronization between the two logical sides and reduces the load on the logical client.+
  
 +The client maintains a partial replica of the server's world, with copies of objects such as:<yarncode>
 +net.minecraft.class_1937
 +net.minecraft.class_1297
 +net.minecraft.class_2586
 +</yarncode>
 +These replicated objects allow clients and servers to perform some common game logic. The client can interact with these objects while the server is responsible for keeping them in sync. Usually, to distinguish objects on the logical clients from the ones on the logical server you would access the world of the object and check its ''isClient'' field. This can be used to perform authoritative actions on the server such as spawning entities, and to simulate actions on the client. This technique is necessary to avoid desynchronization between the two logical sides.
 ===== Detailed look into all sides ===== ===== Detailed look into all sides =====
  
-With an understanding of which sides there are and how to distingish between them, we can now look into every single side with a detailed look.+With an understanding of which sides there are and how to distinguish between them, we can now look at each side in detail.
  
 ==== Physical Client ==== ==== 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''. 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 several different worlds each within a separate logical server, but only one at a time.+physical client can load several different worldseach within a separate logical server, but only one at a time.
  
 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 also shuts down the integrated server). It can also load resource packs bundled in a world to the logical client on the physical client. 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 also 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 see many environment annotations on rendering, sound, and other logical client code.+All the logical client content is exclusive to the physical client, therefore you see many environment annotations on rendering, sound, and other logical client code.
  
 Some mods target physical clients exclusively, for instance, Liteloader, Optifine, and Minecraft PvP clients (Badlion, Hyperium). Some mods target physical clients exclusively, for instance, Liteloader, Optifine, and Minecraft PvP clients (Badlion, Hyperium).
Line 55: Line 52:
 Its logical server differs slightly from that of a physical client as only one logical server instance is ever present when the physical server is running. Moreover, the logical server of the physical server can be controlled remotely via Rcon, has a config file called server.properties, and can send server resource packs. Its logical server differs slightly from that of a physical client as only one logical server instance is ever present when the physical server is running. Moreover, the logical server of the physical server can be controlled remotely via Rcon, has a config file called server.properties, and can send server resource packs.
  
-Despite these differences, most mods are applicable with problems to the logical servers of both the physical client and the physical server as long as they do not refer to logical client contents.+Despite these differences, most mods are applicable without problems to the logical servers of both the physical client and the physical server as long as they do not refer to logical client content.
  
 Its features of single world and resource pack sending, however, make vanilla mod (data pack and resource pack combination) installation much easier compared to on clients, as vanilla physical clients set up when connecting to the server automatically. Its features of single world and resource pack sending, however, make vanilla mod (data pack and resource pack combination) installation much easier compared to on clients, as vanilla physical clients set up when connecting to the server automatically.
Line 62: Line 59:
  
 ==== Logical Client ==== ==== Logical Client ====
-The logical client is the interface to the player. Rendering (LWJGL), resource pack, player input handling, and soundshappen on the logical client. It is not present on the physical server.+The logical client is the interface to the player. Rendering (LWJGL), resource pack, player input handling, and sounds happen on the logical client. It is not present on the physical server.
  
 ==== Logical Server ==== ==== 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,  and world generation, happen on the logical server.+The logical server is where most of the game logic is executed. Data packs, world updates, block entity and entity ticks, mob AI, game/world-saving,  and world generation, 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 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 entry point of a physical side, even on physical servers. Stillit has its thread, on which it handles its logicIt is 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 saveand a new instance is created every time the player loads a local save+The logical server runs in its own main thread, even on physical servers, and has a few worker threadsThe lifetime of logical server depends on the physical side it is hosted on. On a physical server, a logical server exists for as long as the process is running. On a physical client, multiple logical servers may be created, but only one logical server may exist at a time. A new logical server is created when the player loads a local save and closed when the player closes the local save.
- +
-Most universal mods target the logical server so that they can work on physical sides.+
  
 +Most universal mods target the logical server so that they can work both in single player and multi player scenarios.
 ===== Communication===== ===== Communication=====
  
-The only correct way to exchange data between a client and a server are packets. The packets (which [[https://wiki.vg]] documents) are sent between logical clients and logical servers, not physical sides. Mods can add packets to transfer custom information between two logical sides.+The only correct way to exchange data between logical clients and servers is by exchanging packets. The packets (as documented on [[https://wiki.vg]]) are sent between logical clients and logical servers, not physical sides. Mods can add packets to transfer custom information between two logical sides. Packets are exchanged in-memory for a logical client connected to its own integrated server, and exchanged over a networking protocol otherwise.
  
 Logical clients send C2S (Client-To-Server) packets to the logical server. Logical clients send C2S (Client-To-Server) packets to the logical server.
 The logical server sends S2C (Server-To-Client) packets the logical clients. The logical server sends S2C (Server-To-Client) packets the logical clients.
-Packets are sent be a write method in a network thread and received by a call to a read method in a network thread.+Packets are sent by a write method in a network thread and received by a call to a read method in a network thread.
  
 For more details on how to handle networking, see [[tutorial:networking|this article]]. For more details on how to handle networking, see [[tutorial:networking|this article]].
tutorial/side.1557663748.txt.gz · Last modified: 2019/05/12 12:22 by tyra314