Additional Enchanted Miner

Additional Enchanted Miner

23M Downloads

[1.21 Fabric] Server disconnect due to ClientSyncMessage payload not registered

smehringer1 opened this issue · 4 comments

commented

Fabric 1.21 Client and Dedicated Server
Fabric Loader 16.0.0 on both, QuarryPlus build 21.1.97

Happened whenever I would try to interact with the quarry block.

Server logs:
[Server thread/INFO]: Player lost connection: Internal Exception: io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:custom_payload' (quarryplus:client_sync_message)

[Netty Server IO #4/ERROR]: Error sending packet clientbound/minecraft:custom_payload io.netty.handler.codec.EncoderException: Failed to encode packet 'clientbound/minecraft:custom_payload' (quarryplus:client_sync_message)

Caused by: java.lang.ClassCastException: class com.yogpc.qp.packet.ClientSyncMessage cannot be cast to class net.minecraft.class_8711 (com.yogpc.qp.packet.ClientSyncMessage and net.minecraft.class_8711 are in unnamed module of loader net.fabricmc.loader.impl.launch.knot.KnotClassLoader @13deb50e) at net.minecraft.class_9139$6.encode(class_9139.java:42) ~[server-intermediary.jar:?]

Fix

ClientSyncMessage payload is never registered when running as dedicated Fabric server. All payloads need to be registered during common initialization. Moving ClientSyncMessage registration from initClient() to initServer() resolved this issue.

public static void initServer() {
PayloadTypeRegistry.playC2S().register(YSetterMessage.TYPE, YSetterMessage.STREAM_CODEC);
PayloadTypeRegistry.playC2S().register(MoverMessage.TYPE, MoverMessage.STREAM_CODEC);
PayloadTypeRegistry.playC2S().register(QuarryConfigSyncMessage.TYPE, QuarryConfigSyncMessage.STREAM_CODEC);
ServerPlayNetworking.registerGlobalReceiver(YSetterMessage.TYPE, Server::onReceive);

public static void initClient() {
PayloadTypeRegistry.playS2C().register(ClientSyncMessage.TYPE, ClientSyncMessage.STREAM_CODEC);
ClientPlayNetworking.registerGlobalReceiver(ClientSyncMessage.TYPE, Client::onReceive);

Related:
emilyploszaj/emi#586 (comment)

commented

Seems not working.

commented

Try removing the registrations that are done in initClient(). They're already registered via ModInitializer's call to initServer(). Duplicate registrations cause a crash.

public static void initClient() {
messages().forEach(p -> PayloadTypeRegistry.playS2C().register(p.getKey(), p.getValue()));

commented

Try removing the registrations that are done in initClient(). They're already registered via ModInitializer's call to initServer(). Duplicate registrations cause a crash.

This is not the point. I should have shared the registration code to register packet to PayloadTypeRegistry.playS2C() (NOT C2S) entry point.

I started the publish workflow.

commented
スクリーンショット 2024-08-24 9 44 17 Seems working in my development server