diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java index a6e4fe0d25..829a76d8a4 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java @@ -27,6 +27,7 @@ import net.minecraft.network.PacketByteBuf; import net.minecraft.network.listener.ServerCommonPacketListener; import net.minecraft.network.packet.Packet; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.thread.ThreadExecutor; @@ -105,10 +106,10 @@ public void receive(MinecraftClient client, ClientConfigurationNetworkHandler ne // Normally, packets are handled on the network IO thread - though it is // not guaranteed (for example, with 1.19.4 S2C packet bundling) // Since we're handling it right now, connection check is redundant. - handler.receive(packet, sender); + handler.receive(packet, networkHandler, sender); } else { client.execute(() -> { - if (((ClientCommonNetworkHandlerAccessor) networkHandler).getConnection().isOpen()) handler.receive(packet, sender); + if (((ClientCommonNetworkHandlerAccessor) networkHandler).getConnection().isOpen()) handler.receive(packet, networkHandler, sender); }); } } @@ -218,10 +219,10 @@ public void receive(MinecraftClient client, ClientConfigurationNetworkHandler ne // Normally, packets are handled on the network IO thread - though it is // not guaranteed (for example, with 1.19.4 S2C packet bundling) // Since we're handling it right now, connection check is redundant. - handler.receive(packet, sender); + handler.receive(packet, networkHandler, sender); } else { client.execute(() -> { - if (((ClientCommonNetworkHandlerAccessor) networkHandler).getConnection().isOpen()) handler.receive(packet, sender); + if (((ClientCommonNetworkHandlerAccessor) networkHandler).getConnection().isOpen()) handler.receive(packet, networkHandler, sender); }); } } @@ -393,6 +394,14 @@ public static void send(T packet) { throw new IllegalStateException("Cannot send packet while not configuring!"); } + /** + * Disconnects from the server. + * @param handler the network handler + */ + public static void disconnect(ClientConfigurationNetworkHandler handler, Text reason) { + ((ClientCommonNetworkHandlerAccessor) handler).getConnection().disconnect(reason); + } + private ClientConfigurationNetworking() { } @@ -451,9 +460,10 @@ public interface ConfigurationPacketHandler { * * * @param packet the packet + * @param networkHandler the network handler * @param responseSender the packet sender * @see FabricPacket */ - void receive(T packet, PacketSender responseSender); + void receive(T packet, ClientConfigurationNetworkHandler networkHandler, PacketSender responseSender); } } diff --git a/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/configuration/NetworkingConfigurationClientTest.java b/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/configuration/NetworkingConfigurationClientTest.java index 3a1d4acb13..560ca70363 100644 --- a/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/configuration/NetworkingConfigurationClientTest.java +++ b/fabric-networking-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/networking/client/configuration/NetworkingConfigurationClientTest.java @@ -23,7 +23,7 @@ public class NetworkingConfigurationClientTest implements ClientModInitializer { @Override public void onInitializeClient() { - ClientConfigurationNetworking.registerGlobalReceiver(NetworkingConfigurationTest.ConfigurationPacket.PACKET_TYPE, (packet, responseSender) -> { + ClientConfigurationNetworking.registerGlobalReceiver(NetworkingConfigurationTest.ConfigurationPacket.PACKET_TYPE, (packet, handler, responseSender) -> { // Handle stuff here // Respond back to the server that the task is complete