Historically, Minecraft actually shipped with two completely separate programs -
- Dedicated Client - contained all the "client-side" code
- Dedicated Server - contained all the "server-side" code
This integrated server is used even when you're playing in single player mode.
The Dedicated Server is still available as a standalone program
- CombinedClient (which has both client-side code and server-side code in it)
- Dedicated Server (which has only server-side code).
The Forge authors wanted to make it easy to use the same Mod code in both the "Combined" Client and the Dedicated Server. (This is not trivial because the Dedicated Server is missing the client-side code, and if your Mod attempts to call any of the client-side code when it's installed in the DedicatedServer, it will crash.) Roughly half of the minecraft classes are in the client distribution only.
The way they do this is to call different events during startup.
- The FMLCommonSetupEvent is called during startup for both the CombinedClient and DedicatedServer.
- The FMLClientSetupEvent is called during startup of the CombinedClient only.
You just need to make sure that parts of your code which might run on the dedicated server never call any of the Client-code-only classes or methods. These objects are marked with the @OnlyIn(Dist.CLIENT) annotation, eg
@OnlyIn(Dist.CLIENT) public class Minecraft {
}
or
@OnlyIn(Dist.CLIENT) public boolean hasCustomBreakingProgress(BlockState state) { return true; }
A comment about @OnlyIn(Dist.CLIENT) objects - because of the way that Java loads classes, your server-side classes should not have any mention of @OnlyIn(Dist.CLIENT) vanilla objects whatsoever. It doesn't matter whether the code is ever executed- simply having a Dist.CLIENT definition somewhere in your class is often enough to cause a crash on a DedicatedServer. Create a dedicated client-side-only class to hold references to Dist.CLIENT class instances, and only instantiate your client-side-only class after checking whether you're on the server side or not. You can do this with inheritance if you prefer; similar to the way that Block classes refer to World, and not directly to ClientWorld or ServerWorld. The FMLClientSetupEvent (and FMLServerSetupEvent) can help to initialise these correctly.
Your Article is very usefull and explain step by stem to understand, Dedicated server is best than shared server
ReplyDelete"Interesting to see how Minecraft started with separate client and server programs! If you're diving into modding, choosing a dedicated server can make a huge difference. It ensures better performance and more control, especially when handling multiple mods. Have you tried using a dedicated server for your Minecraft projects?"
ReplyDeleteUnderstanding the differences between Minecraft client and dedicated server distributions has enhanced my gaming experience. qFlipper helped clarify the benefits of each for my setup!
ReplyDelete