From 2e5ac54849046563971e7ebc9efc666e5326650a Mon Sep 17 00:00:00 2001 From: deirn Date: Tue, 23 Jan 2024 00:57:22 +0700 Subject: [PATCH] send `c:register` packet for play phase instead of config (#3544) --- .../fabricmc/fabric/impl/networking/CommonPacketsImpl.java | 3 ++- .../test/networking/play/NetworkingPlayPacketTest.java | 6 ++++++ .../client/play/NetworkingPlayPacketClientTest.java | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/CommonPacketsImpl.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/CommonPacketsImpl.java index 66a0052ef..60a99a9d3 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/CommonPacketsImpl.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/CommonPacketsImpl.java @@ -25,6 +25,7 @@ import net.minecraft.server.network.ServerPlayerConfigurationTask; import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.impl.networking.server.ServerConfigurationNetworkAddon; import net.fabricmc.fabric.impl.networking.server.ServerNetworkingImpl; @@ -95,7 +96,7 @@ public class CommonPacketsImpl { @Override public void sendPacket(Consumer> sender) { - addon.sendPacket(addon.createRegisterPayload()); + addon.sendPacket(new CommonRegisterPayload(addon.getNegotiatedVersion(), CommonRegisterPayload.PLAY_PHASE, ServerPlayNetworking.getGlobalReceivers())); } @Override diff --git a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/play/NetworkingPlayPacketTest.java b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/play/NetworkingPlayPacketTest.java index b9ada312d..c67ba7da7 100644 --- a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/play/NetworkingPlayPacketTest.java +++ b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/play/NetworkingPlayPacketTest.java @@ -26,6 +26,7 @@ import java.util.UUID; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import org.apache.commons.lang3.Validate; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.listener.ClientPlayPacketListener; @@ -43,6 +44,7 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.networking.v1.FabricPacket; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.test.networking.NetworkingTestmods; @@ -133,6 +135,10 @@ public final class NetworkingPlayPacketTest implements ModInitializer { } } }); + + ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { + Validate.isTrue(ServerPlayNetworking.canSend(handler, OverlayPacket.PACKET_TYPE)); + }); } public record OverlayPacket(Text message) implements FabricPacket { diff --git a/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/play/NetworkingPlayPacketClientTest.java b/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/play/NetworkingPlayPacketClientTest.java index e87babc83..0255034e0 100644 --- a/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/play/NetworkingPlayPacketClientTest.java +++ b/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/play/NetworkingPlayPacketClientTest.java @@ -25,7 +25,6 @@ import net.minecraft.util.Identifier; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PacketSender; @@ -37,7 +36,7 @@ public final class NetworkingPlayPacketClientTest implements ClientModInitialize @Override public void onInitializeClient() { - ClientPlayConnectionEvents.INIT.register((handler, client) -> ClientPlayNetworking.registerReceiver(NetworkingPlayPacketTest.OverlayPacket.PACKET_TYPE, this)); + ClientPlayNetworking.registerGlobalReceiver(NetworkingPlayPacketTest.OverlayPacket.PACKET_TYPE, this); ClientCommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register( ClientCommandManager.literal("clientnetworktestcommand")