Forge Dedicated Server Crash
Mattabase opened this issue · 7 comments
- Install the latest version on a Forge dedicated server
- launch the server
- crash
Please fix this. Other client side only mods such as Mouse Tweaks just gracefully dont load instead of crashing the server.
Its incredibly annoying when you are trying to quickly start up a server to test smthn and you have to go through an extra three or four boot cycles to weed out bad client side mods.
The Forge documentation on sides can be found here: https://docs.minecraftforge.net/en/1.19.x/concepts/sides/#sides-in-minecraft
It should be as simple as adding a classloading barrier and registering it to ignore server side versions when clients connect
The Forge documentation on sides can be found here: https://docs.minecraftforge.net/en/1.19.x/concepts/sides/#sides-in-minecraft
In recent versions, Minecraft Forge has removed a “sidedness” attribute from the mods.toml.
This is an exclusive problem to Forge, and so far no one was able to give me an example on how to prevent it(the main class has, for example, a field for the keybind, which prevents the class from loading on the server and causing the crash. So it's not an issue of trying to register events on the wrong side or whatever, but an overall issue that the class is loaded in the first place, unlike Fabric/Quilt).
It should be as simple as adding a classloading barrier
If you have an example of how I can prevent the mod from loading at all, be my guest. I'm not going to restructure all my mods entire class layout, just because Forge was so stupid and removed the side field from the toml. Maybe having some forge bootstrap around the mod could work.
registering it to ignore server side versions when clients connect
That part is already done for all of my mods, otherwise, the server would be flagged as incompatible.
Gave the bootstrap idea a try and it works. It's such a stupid workaround, only required because Forge messed up for some reason. d622339#diff-abed0af7066774f8dd8b9e877214b61e8ac9213e7070bbdb79a4a014ef938563R17
It happens because Java loads the Minecraft class, because you are calling instance methods on it. (I don't know the details as to why)
Something like this should also work
public class MyMod {
public MyMod() {
}
public void onInitialize() {
if (!serverSide)
ClientBarrier.registerKeybind()
}
private class ClientBarrier {
private static void registerKeybind() {
Minecraft.getInstance().doStuff()
}
}
}
The ClientBarrier class will not be loaded until the static method in it is actually called, and therefore the Minecraft class will not be loaded till then.
It happens because Java loads the Minecraft class, because you are calling instance methods on it. (I don't know the details as to why)
I know that, but like I wrote above, not going to rewrite the entire mod main class, just because Forge is too stupid to support clientsided mods, unlike Fabric/Quilt. In my comment above I linked how I did fix it now, but IMO this really shouldn't be required, if Forge would just maintain a simple condition on load.