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/08 21:00] – [Logical Server] Expand abbreviations for S2C and C2S jamieswhiteshirttutorial: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-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. 
  
-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 [[https://en.wikipedia.org/wiki/Client%E2%80%93server_model|Client-server model]].+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 "physicalsides. Howevera Minecraft client hosts its own integrated server for singleplayer and LAN sessions, which means that a Minecraft client also contains server logic. Thereforeclient/server may also be used to distinguish parts of the game logic which are called "logical" sides.
  
-For both types of "side"s, there are "clientand "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 kind of 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.
  
-===== Logical Sides =====+===== Physical Sides  =====
  
-Logical sides are mainly about the threads the game run onincluding the Client (does rendering, sends player inputs to the serverhandles resource packs, etc.) and the Server (calculates most core logic, handles data packs,  keeps the world/game data, etc.) threads.+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 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.+The client and server environment are minified distributions of the same program, containing only the required parts of the code
  
-In Minecraft, in order to reduce code, the logical client and servers share some logic classes, including<code> +In Fabricyou can often see annotations like ''@Environment(EnvType.CLIENT)''. This indicates that some code is present only in one environment; in this example, the client.
-net.minecraft.world.World +
-net.minecraft.entity.Entity +
-net.minecraft.block.entity.BlockEntity +
-</code> +
-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.+In Fabric fabric.mod.json and the mixin config, the client/server refers to the environment.
  
-==== Logical Client ==== +Each physical side ships classes used by its entry point and the data generator classes with entrypoint ''net.minecraft.data.Main''.
-The logical client is where most displays to the player is doneRendering (LWJGL), resource pack, player input handling, sounds, etcall 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.+===== Logical Sides =====
  
-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).+The logical sides are responsible for the actual game logic.  
 +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.
  
-==== Logical Server ==== +The client maintains a partial replica of the server's world, with copies of objects such as:<yarncode> 
-The logical server is where most of the game logic is going onData packs, world updates, block entity and entity ticks, mob AI, game/world saving, world generation, etcall happen on the logical server.+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 syncUsuallyto 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'' fieldThis can be used to perform authoritative actions on the server such as spawning entities, and to simulate actions on the clientThis technique is necessary to avoid desynchronization between the two logical sides. 
 +===== Detailed look into all sides =====
  
-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).+With an understanding of which sides there are and how to distinguish between them, we can now look at each side in detail.
  
-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 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.+==== Physical Client ==== 
 +The physical client is the minecraft jar downloaded by the vanilla launcher. It contains logical client and a logical server (integrated server). Its entrypoint is ''net.minecraft.client.main.Main''.
  
-Most universal mods target the logical server so that they are applicable to both physical sides.+A physical client can load several different worlds, each within a separate logical server, but only one at a time.
  
-In yarn, the S2C (Server-To-Client) packets are sent from the logical server (which calls write method in a network thread), and the C2S (Client-To-Serverpackets are received by the logical server (which calls read method in a network thread).+Compared to the logical server of the physical server (dedicated server), the logical server of the physical client (integrated servercan 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.
  
-===== Physical Sides (EnvType) =====+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.
  
-The physical sides refer to the two distributions (jars) of Minecraft gamethe client (what the vanilla launcher launches) and the server (download available on [[https://minecraft.net]] for free), which are launched in different ways. A physical side refers to which code is "physically" available in the environment.+Some mods target physical clients exclusively, for instance, Liteloader, Optifine, and Minecraft PvP clients (Badlion, Hyperium).
  
-The physical client and server are minified distributions of the same program, containing only the specific parts of the code that they use. Only the physical client contains the code required to host the logical client. Historically, the dedicated server would also have its own unique code.+==== Physical Server ====
  
-In Fabricyou can often see annotations like <code>@Environment(EnvType.CLIENT)</code>This indicates that some code is present only on one physical sidein this case here, on the client.+The physical server is the java dedicated server. Compared to a physical clientit only has a logical server (dedicated server). Its entrypoint is ''net.minecraft.server.MinecraftServer'' and the physical server can only have one world during its runtime. If a server should switch to another worlda server restart is required.
  
-In Fabric fabric.mod.json and the mixin config, the client/server refers to the physical side.+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.
  
-Each physical side ships classes used by its respective entry point and the data generator classes with entrypoint<code>net.minecraft.data.Main</code>+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.
  
-==== Physical Client ==== +Its features of single world and resource pack sending, however, make vanilla mod (data pack and resource pack combinationinstallation much easier compared to on clients, as vanilla physical clients set up when connecting to the server automatically.
-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 <code>net.minecraft.client.main.Main</code>.+
  
-As a physical client can load worlds (launch integrated servers/its logical server) without a limitbut a previous logical server on physical client must be stopped for a new one to launch.+Some mods target physical server exclusively. For instanceBukkit and its derivatives (Spigot, Paper, Cauldron, Xxx-Bukkit hybrids) always run on the physical server.
  
-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.+==== Logical Client ==== 
 +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.
  
-All the logical client contents are exclusive to the physical clientHenceyou will see a lot of environment annotations on renderingsound, and other logical client code.+==== Logical Server ==== 
 +The logical server is where most of the game logic is executedData packsworld updatesblock entity and entity ticksmob AI, game/world-saving,  and world generation, happen on the logical server.
  
-Some mods target physical clients exclusively. For instanceLiteloader, Optifine, Minecraft PvP clients (Badlion, Hyperium, etc.) only run on the physical client.+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).
  
-==== Physical Server ==== +The logical server runs in its own main thread, even on physical servers, and has a few worker threads. The lifetime of a 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 runningOn a physical client, multiple logical servers may be created, but only one logical server may exist at a timeA new logical server is created when the player loads a local save and closed when the player closes the local save.
-The physical server is the java dedicated server. Compared to a physical client, it only has a logical server (dedicated server). Its entrypoint is <code>net.minecraft.server.MinecraftServer</code>+
  
-Compared to the physical client, the physical server can only have one world/save as its logical server is a singlton.+Most universal mods target the logical server so that they can work both in single player and multi player scenarios. 
 +===== Communication=====
  
-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 ranMoreoverthe logical server of the physical server can be controlled remotely via Rcon, has server.properties, and can send server resource packs.+The only correct way to exchange data between logical clients and servers is by exchanging packetsThe packets (as documented on [[https://wiki.vg]]) are sent between logical clients and logical serversnot 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.
  
-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.+Logical clients send C2S (Client-To-Server) packets to the logical server. 
 +The logical server sends S2C (Server-To-Client) packets the logical clients. 
 +Packets are sent by a write method in a network thread and received by a call to a read method in a network thread.
  
-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 clientsas vanilla physical clients will be set up when connecting to the server automatically.+For more details on how to handle networkingsee [[tutorial:networking|this article]].
  
-Some mods target physical server exclusivelyFor instanceBukkit and its derivatives (SpigotPaperCauldronXxx-Bukkit hybrids) always run on the physical server.+===== Common misconceptions about logical servers ===== 
 +Most of the time, mods exclusively targeting the physical server also work on logical servers inside of physical clients. 
 + 
 +Howevermodders for physical servers usually have assumptions which do not apply to integrated servers, including but not limited to: 
 +  * Only one logical server instance exists on one game run 
 +  * The world and entities should always calculate the game logic (i.e.the isClient field of the world object is always false) 
 +  * Remote controlresource pack sendingand Favicon are present 
 + 
 +These assumptions need to be corrected to make mods that run on logical servers.
  
 ===== Conclusion ===== ===== Conclusion =====
Line 83: Line 96:
  
 Ultimately, the main confusion comes from the fact that logical servers exist on physical clients. 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.1557349220.txt.gz · Last modified: 2019/05/08 21:00 by jamieswhiteshirt