Developing multiplayer compatible mods

Section

MCreator's mods are multiplayer compatible by default, but there are still some things you need to keep your eye on while developing your mods for multiplayer situations.

Even single-player gameplay has a built-in server running in the background, so many of these can apply even to a single-player scenario.

Testing server first

If you plan to make mods for multiplayer situations, consider regularly testing mod on the server while developing using an integrated Run server feature that sets up a server and client and adds said server on your server list in integrated test Minecraft client.

Client-side procedure triggers

Some procedure triggers are client-side only. One example of such a procedure trigger is the Random tick update event. Such triggers are marked with a computer icon. These procedure triggers will execute independently for each client and will not execute on the server at all. Their purpose is to handle client effects such as random block particles or sounds so the network communication is not flooded with updates for effects that can be handled on the client-side.

Using such procedure triggers for any other purpose such as modifying blocks, containers, entities or any other tasks that require server-side communication and synchronization between clients will cause unexpected effects such as ghost entities, blocks, and items in inventory.

Random chance procedures

If not marked with client or server icon next to the trigger, the procedure triggers trigger procedure on both server and client-side. This is generally not a problem as the procedure will do the same action on both sides. But some procedures use random chance when executing and these procedures can cause different outcomes when they run on both server and client-side.  Examples of such procedures are:

  • Explosions
  • Any procedure involving a random number procedure block
  • Any other procedure that causes strange glitches in the game

For such procedures to work, you need to wrap your procedure (the whole part that depends on random condition) with if statement that checks if the current world is server-side:

if NOT "Is provided world remote (client-side)"

    (your existing procedure)

You can find "Is provided world remote (client-side)" procedure block in the "World data" procedure blocks section.

Using GLOBAL_SESSION variables

Another important thing to keep in mind is that GLOBAL_SESSION variables are specific per Java runtime instance and as client and world run on different Java runtime instances or even different computers and locations, these two variables will hold different value for each client connected to the server and another different value for the server.

This limits the usability of GLOBAL_SESSION variable type for multiplayer scenarios. If you do not have a good reason to use them, do not.



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.