[JAVA] [Modding] An important Side concept in Minecraft

Being addicted

When I executed world.createExplosion (), the so-called ** ghost block ** phenomenon that was not displayed but only the collision detection remained occurred. After a lot of research, it seems that the concept of ** side **, Server and Client, exists in Forge. So I found that the program was running on each side. I referred to the reference in here.

About the type of side

The general perception is that the client affects the player and the server is the one that connects when playing multiplayer.

Now, let's explain the ambiguity of these two sides.

Physical server

A physical server is often referred to as a * dedicated server *. A dedicated server is an entire program of a type like minecraft_server.jar and does not have a screen to operate.

Physical client

A physical client is the entire program that launches Minecraft from the launcher. It can be said that all threads, processes, and services that are responsible for drawing games and operating screens are part of the physical client.

Logical server

The logical server controls the game. It is responsible for all the mechanics of the game, including mob spawning, weather, inventory updates, and mob intelligence. The logical server is inside the physical server, but in single play it can be run with the logical client inside the physical client. This is done under the name Server Thread.

Logical client

The logical client is responsible for receiving input from the player and sending it to the logical server. In addition, the logical client receives information from the logical server and displays that information on the screen so that the player can see it. This is done with the name Client Thread.

Program execution tailored to the side

world.isRemote This boolean value checks which side the program is running on. This boolean can be checked for ** logical ** servers or ** logical ** clients. If it is a logical client, it returns true, and if it is a logical server, it returns false. This is because the physical server always returns false, so the value overlaps with the logical server of the physical client. In principle, you can't tell from this value whether it's a physical server or a logical server. The use of this boolean value is when you want to execute game rules and other mechanisms. For example

――While touching a block, you will continue to take damage --When you put soil in a machine, it turns it into a diamond.

And so on. These should be done when the value of world.isRemote is false. If these are executed by a logical client, it will be inconsistent with the logical server, and in the case of a minor bug, a mob ghost phenomenon or a physical strength mismatch will occur. In the case of heavy bugs, the game may crash.

getEffectiveSide FMLCommonHandler.getEffectiveSide () is used when world.isRemote cannot be used for some reason. ** Guess ** which side this is. The reason is that this is because the name of the thread (Server Thread or Client Thread) determines which side it is on. When world is available, try to use world.isRemote as much as possible, and this should be used as an alternative when that method is not available.

Solution

Well, it seems that it is the logical server that manages the world blocks etc., so if you execute world.createExplosion () on the logical client and the logical server, the block information on the server and the block on the client It seems that the ghost block phenomenon will occur because the information will be inconsistent. Since the blocks to be destroyed by the explosion are randomly determined, the blocks that are supposed to be destroyed by the client may have escaped the explosion by the server. Here, a collision detection was generated for a block that did not exist. So the solution to this problem is

if (!world.isRemote)
    world.createExplosion(...);

Will be. Modder, who is worried about collision detection and ghost entities, will be happy if he tries to run it only on the logical server and only on the logical client once.

Recommended Posts

[Modding] An important Side concept in Minecraft
Minecraft Modding 1.12.2
Site summary to be helpful in Minecraft modding 1.12.2