-
-
Notifications
You must be signed in to change notification settings - Fork 67
Description
I ran into a crash while testing my mod on a Fabric Dedicated Server (1.21.1) and wanted to report it as an inconsistency between loaders.
When I use NetworkManager.registerReceiver for S2C (Server to Client) packets in my common code, the Fabric Dedicated Server crashes on startup (AbstractMethodError).
It seems that registerS2C in the Fabric implementation is annotated with @Environment(EnvType.CLIENT), so it doesn't exist on the server.
On NeoForge, however, this works perfectly fine out of the box, the server likely just registers the payload type and ignores the receiver.
The Workaround
I had to manually split my logic to prevent the server from trying to register a receiver for S2C packets. Basically, the server only needs to know the Codec (Payload Type) to send the packet, but Architectury tries to register the full receiver and fails.
Here is the code I had to write to make it work on Fabric:
// S2C Packets (Server -> Client)
if (side == NetworkManager.Side.S2C) {
if (Platform.getEnv() == Env.CLIENT) {
// Client needs the receiver
NetworkManager.registerReceiver(side, payloadType, codec, receiver);
} else {
// Server only needs to know HOW to send it (Codec), but can't have a receiver
NetworkManager.registerS2CPayloadType(payloadType, codec);
}
} else {
// C2S Packets are fine
NetworkManager.registerReceiver(side, payloadType, codec, receiver);
}It would be great if NetworkManager.registerReceiver handled this automatically on Fabric (like it seems to do on NeoForge). If I register a S2C receiver on the server, it should probably just fallback to registerS2CPayloadType instead of crashing.