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 266a11a85a..3c8faedd01 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 @@ -19,9 +19,9 @@ import java.util.Objects; import java.util.Set; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.CustomPayload; import net.minecraft.util.Identifier; import net.minecraft.util.thread.ThreadExecutor; @@ -57,14 +57,14 @@ public final class ClientConfigurationNetworking { * A global receiver is registered to all connections, in the present and future. * *

If a handler is already registered for the {@code type}, this method will return {@code false}, and no change will be made. - * Use {@link #unregisterGlobalReceiver(CustomPayload.Type)} to unregister the existing handler. + * Use {@link #unregisterGlobalReceiver(CustomPayload.Id)} to unregister the existing handler. * * @param type the packet type * @param handler the handler * @return false if a handler is already registered to the channel * @throws IllegalArgumentException if the codec for {@code type} has not been {@linkplain PayloadTypeRegistry#configurationS2C() registered} yet - * @see ClientConfigurationNetworking#unregisterGlobalReceiver(CustomPayload.Type) - * @see ClientConfigurationNetworking#registerReceiver(CustomPayload.Type, ConfigurationPayloadHandler) + * @see ClientConfigurationNetworking#unregisterGlobalReceiver(CustomPayload.Id) + * @see ClientConfigurationNetworking#registerReceiver(CustomPayload.Id, ConfigurationPayloadHandler) */ public static boolean registerGlobalReceiver(CustomPayload.Id type, ConfigurationPayloadHandler handler) { return ClientNetworkingImpl.CONFIGURATION.registerGlobalReceiver(type.id(), handler); @@ -76,15 +76,15 @@ public static boolean registerGlobalReceiver(CustomPay * *

The {@code type} is guaranteed not to have an associated handler after this call. * - * @param type the packet type + * @param id the packet id * @return the previous handler, or {@code null} if no handler was bound to the channel, * or it was not registered using {@link #registerGlobalReceiver(CustomPayload.Id, ConfigurationPayloadHandler)} * @see ClientConfigurationNetworking#registerGlobalReceiver(CustomPayload.Id, ConfigurationPayloadHandler) * @see ClientConfigurationNetworking#unregisterReceiver(Identifier) */ @Nullable - public static ClientConfigurationNetworking.ConfigurationPayloadHandler unregisterGlobalReceiver(CustomPayload.Type type) { - return ClientNetworkingImpl.CONFIGURATION.unregisterGlobalReceiver(type.id().id()); + public static ClientConfigurationNetworking.ConfigurationPayloadHandler unregisterGlobalReceiver(CustomPayload.Id id) { + return ClientNetworkingImpl.CONFIGURATION.unregisterGlobalReceiver(id.id()); } /** @@ -106,18 +106,18 @@ public static Set getGlobalReceivers() { *

For example, if you only register a receiver using this method when a {@linkplain ClientLoginNetworking#registerGlobalReceiver(Identifier, ClientLoginNetworking.LoginQueryRequestHandler)} * login query has been received, you should use {@link ClientPlayConnectionEvents#INIT} to register the channel handler. * - * @param type the packet type + * @param id the payload id * @param handler the handler * @return {@code false} if a handler is already registered for the type * @throws IllegalArgumentException if the codec for {@code type} has not been {@linkplain PayloadTypeRegistry#configurationS2C() registered} yet * @throws IllegalStateException if the client is not connected to a server * @see ClientPlayConnectionEvents#INIT */ - public static boolean registerReceiver(CustomPayload.Type type, ConfigurationPayloadHandler handler) { + public static boolean registerReceiver(CustomPayload.Id id, ConfigurationPayloadHandler handler) { final ClientConfigurationNetworkAddon addon = ClientNetworkingImpl.getClientConfigurationAddon(); if (addon != null) { - return addon.registerChannel(type.id().id(), handler); + return addon.registerChannel(id.id(), handler); } throw new IllegalStateException("Cannot register receiver while not configuring!"); @@ -130,7 +130,7 @@ public static boolean registerReceiver(CustomPayload.T * * @param id the payload id to unregister * @return the previous handler, or {@code null} if no handler was bound to the channel, - * or it was not registered using {@link #registerReceiver(CustomPayload.Type, ConfigurationPayloadHandler)} + * or it was not registered using {@link #registerReceiver(CustomPayload.Id, ConfigurationPayloadHandler)} * @throws IllegalStateException if the client is not connected to a server */ @Nullable @@ -265,9 +265,17 @@ public interface ConfigurationPayloadHandler { * } * * @param payload the packet payload - * @param responseSender the packet sender + * @param context the configuration networking context * @see CustomPayload */ - void receive(T payload, PacketSender responseSender); + void receive(T payload, Context context); + } + + @ApiStatus.NonExtendable + public interface Context { + /** + * @return The packet sender + */ + PacketSender responseSender(); } } diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java index 1c7fa1a5ce..7601a6f287 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientPlayNetworking.java @@ -19,6 +19,7 @@ import java.util.Objects; import java.util.Set; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import net.minecraft.client.MinecraftClient; @@ -274,10 +275,27 @@ public interface PlayPayloadHandler { *

The network handler can be accessed via {@link ClientPlayerEntity#networkHandler}. * * @param payload the packet payload - * @param player the player that received the payload - * @param responseSender the payload sender + * @param context the play networking context * @see CustomPayload */ - void receive(T payload, ClientPlayerEntity player, PacketSender responseSender); + void receive(T payload, Context context); + } + + @ApiStatus.NonExtendable + public interface Context { + /** + * @return The MinecraftClient instance + */ + MinecraftClient client(); + + /** + * @return The player that received the payload + */ + ClientPlayerEntity player(); + + /** + * @return The packet sender + */ + PacketSender responseSender(); } } diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientConfigurationNetworkAddon.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientConfigurationNetworkAddon.java index 59357f01ec..16cc1e99d0 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientConfigurationNetworkAddon.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientConfigurationNetworkAddon.java @@ -30,6 +30,7 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.impl.networking.AbstractChanneledNetworkAddon; import net.fabricmc.fabric.impl.networking.ChannelInfoHolder; import net.fabricmc.fabric.impl.networking.NetworkingImpl; @@ -40,12 +41,14 @@ public final class ClientConfigurationNetworkAddon extends AbstractChanneledNetworkAddon> { private final ClientConfigurationNetworkHandler handler; private final MinecraftClient client; + private final ContextImpl context; private boolean sentInitialRegisterPacket; public ClientConfigurationNetworkAddon(ClientConfigurationNetworkHandler handler, MinecraftClient client) { super(ClientNetworkingImpl.CONFIGURATION, ((ClientCommonNetworkHandlerAccessor) handler).getConnection(), "ClientPlayNetworkAddon for " + ((ClientConfigurationNetworkHandlerAccessor) handler).getProfile().getName()); this.handler = handler; this.client = client; + this.context = new ContextImpl(this); // Must register pending channels via lateinit this.registerPendingChannels((ChannelInfoHolder) this.connection, NetworkPhase.CONFIGURATION); @@ -72,7 +75,7 @@ protected void receiveRegistration(boolean register, RegistrationPayload payload @Override protected void receive(ClientConfigurationNetworking.ConfigurationPayloadHandler handler, CustomPayload payload) { - ((ClientConfigurationNetworking.ConfigurationPayloadHandler) handler).receive(payload, this); + ((ClientConfigurationNetworking.ConfigurationPayloadHandler) handler).receive(payload, this.context); } // impl details @@ -139,4 +142,7 @@ protected boolean isReservedChannel(Identifier channelName) { public ChannelInfoHolder getChannelInfoHolder() { return (ChannelInfoHolder) ((ClientCommonNetworkHandlerAccessor) handler).getConnection(); } + + private record ContextImpl(PacketSender responseSender) implements ClientConfigurationNetworking.Context { + } } diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientNetworkingImpl.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientNetworkingImpl.java index ddb1ec7ca0..68d628e188 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientNetworkingImpl.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientNetworkingImpl.java @@ -142,13 +142,13 @@ public static void clientInit() { }); // Version packet - ClientConfigurationNetworking.registerGlobalReceiver(CommonVersionPayload.ID, (payload, responseSender) -> { - int negotiatedVersion = handleVersionPacket(payload, responseSender); + ClientConfigurationNetworking.registerGlobalReceiver(CommonVersionPayload.ID, (payload, context) -> { + int negotiatedVersion = handleVersionPacket(payload, context.responseSender()); ClientNetworkingImpl.getClientConfigurationAddon().onCommonVersionPacket(negotiatedVersion); }); // Register packet - ClientConfigurationNetworking.registerGlobalReceiver(CommonRegisterPayload.ID, (payload, responseSender) -> { + ClientConfigurationNetworking.registerGlobalReceiver(CommonRegisterPayload.ID, (payload, context) -> { ClientConfigurationNetworkAddon addon = ClientNetworkingImpl.getClientConfigurationAddon(); if (CommonRegisterPayload.PLAY_PHASE.equals(payload.phase())) { @@ -158,10 +158,10 @@ public static void clientInit() { addon.getChannelInfoHolder().getPendingChannelsNames(NetworkPhase.PLAY).addAll(payload.channels()); NetworkingImpl.LOGGER.debug("Received accepted channels from the server"); - responseSender.sendPacket(new CommonRegisterPayload(addon.getNegotiatedVersion(), CommonRegisterPayload.PLAY_PHASE, ClientPlayNetworking.getGlobalReceivers())); + context.responseSender().sendPacket(new CommonRegisterPayload(addon.getNegotiatedVersion(), CommonRegisterPayload.PLAY_PHASE, ClientPlayNetworking.getGlobalReceivers())); } else { addon.onCommonRegisterPacket(payload); - responseSender.sendPacket(addon.createRegisterPayload()); + context.responseSender().sendPacket(addon.createRegisterPayload()); } }); } diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java index 38af88547b..a4c3ed3ae7 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java @@ -24,6 +24,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.network.NetworkPhase; import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.Packet; @@ -32,6 +33,7 @@ import net.fabricmc.fabric.api.client.networking.v1.C2SPlayChannelEvents; 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.PacketSender; import net.fabricmc.fabric.impl.networking.AbstractChanneledNetworkAddon; import net.fabricmc.fabric.impl.networking.ChannelInfoHolder; import net.fabricmc.fabric.impl.networking.NetworkingImpl; @@ -40,6 +42,7 @@ public final class ClientPlayNetworkAddon extends AbstractChanneledNetworkAddon> { private final ClientPlayNetworkHandler handler; private final MinecraftClient client; + private final ClientPlayNetworking.Context context; private boolean sentInitialRegisterPacket; private static final Logger LOGGER = LogUtils.getLogger(); @@ -48,6 +51,7 @@ public ClientPlayNetworkAddon(ClientPlayNetworkHandler handler, MinecraftClient super(ClientNetworkingImpl.PLAY, handler.getConnection(), "ClientPlayNetworkAddon for " + handler.getProfile().getName()); this.handler = handler; this.client = client; + this.context = new ContextImpl(client, client.player, this); // Must register pending channels via lateinit this.registerPendingChannels((ChannelInfoHolder) this.connection, NetworkPhase.PLAY); @@ -73,7 +77,7 @@ public void onServerReady() { @Override protected void receive(ClientPlayNetworking.PlayPayloadHandler handler, CustomPayload payload) { this.client.execute(() -> { - ((ClientPlayNetworking.PlayPayloadHandler) handler).receive(payload, client.player, ClientPlayNetworkAddon.this); + ((ClientPlayNetworking.PlayPayloadHandler) handler).receive(payload, context); }); } @@ -132,4 +136,7 @@ protected void invokeDisconnectEvent() { protected boolean isReservedChannel(Identifier channelName) { return NetworkingImpl.isReservedCommonChannel(channelName); } + + private record ContextImpl(MinecraftClient client, ClientPlayerEntity player, PacketSender responseSender) implements ClientPlayNetworking.Context { + } } diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerConfigurationNetworking.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerConfigurationNetworking.java index 04e5d4c94c..a83495ca36 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerConfigurationNetworking.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerConfigurationNetworking.java @@ -19,6 +19,7 @@ import java.util.Objects; import java.util.Set; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import net.minecraft.network.listener.ClientCommonPacketListener; @@ -259,10 +260,22 @@ public interface ConfigurationPacketHandler { * * * @param payload the packet payload - * @param networkHandler the network handler - * @param responseSender the packet sender + * @param context the configuration networking context * @see CustomPayload */ - void receive(T payload, ServerConfigurationNetworkHandler networkHandler, PacketSender responseSender); + void receive(T payload, Context context); + } + + @ApiStatus.NonExtendable + public interface Context { + /** + * @return The ServerConfigurationNetworkHandler instance + */ + ServerConfigurationNetworkHandler networkHandler(); + + /** + * @return The packet sender + */ + PacketSender responseSender(); } } diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java index 1f42dae85b..addf7991a0 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/ServerPlayNetworking.java @@ -19,9 +19,9 @@ import java.util.Objects; import java.util.Set; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.listener.ClientCommonPacketListener; import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.Packet; @@ -43,7 +43,7 @@ * *

Packet object-based API

* - *

This class provides a registration method, utilizing packet objects, {@link #registerGlobalReceiver(CustomPayload.Type, PlayPayloadHandler)}. + *

This class provides a registration method, utilizing packet objects, {@link #registerGlobalReceiver(CustomPayload.Id, PlayPayloadHandler)}. * This handler executes the callback in the server thread, ensuring thread safety. * *

This payload object-based API involves three classes: @@ -73,8 +73,8 @@ public final class ServerPlayNetworking { * @throws IllegalArgumentException if the codec for {@code type} has not been {@linkplain PayloadTypeRegistry#playC2S() registered} yet * @see ServerPlayNetworking#unregisterGlobalReceiver(Identifier) */ - public static boolean registerGlobalReceiver(CustomPayload.Type type, PlayPayloadHandler handler) { - return ServerNetworkingImpl.PLAY.registerGlobalReceiver(type.id().id(), handler); + public static boolean registerGlobalReceiver(CustomPayload.Id type, PlayPayloadHandler handler) { + return ServerNetworkingImpl.PLAY.registerGlobalReceiver(type.id(), handler); } /** @@ -85,8 +85,8 @@ public static boolean registerGlobalReceiver(CustomPay * * @param id the payload id * @return the previous handler, or {@code null} if no handler was bound to the channel, - * or it was not registered using {@link #registerGlobalReceiver(CustomPayload.Type, PlayPayloadHandler)} - * @see ServerPlayNetworking#registerGlobalReceiver(CustomPayload.Type, PlayPayloadHandler) + * or it was not registered using {@link #registerGlobalReceiver(CustomPayload.Id, PlayPayloadHandler)} + * @see ServerPlayNetworking#registerGlobalReceiver(CustomPayload.Id, PlayPayloadHandler) * @see ServerPlayNetworking#unregisterReceiver(ServerPlayNetworkHandler, Identifier) */ @Nullable @@ -106,7 +106,7 @@ public static Set getGlobalReceivers() { /** * Registers a handler for a payload type. - * This method differs from {@link ServerPlayNetworking#registerGlobalReceiver(CustomPayload.Type, PlayPayloadHandler)} since + * This method differs from {@link ServerPlayNetworking#registerGlobalReceiver(CustomPayload.Id, PlayPayloadHandler)} since * the channel handler will only be applied to the player represented by the {@link ServerPlayNetworkHandler}. * *

For example, if you only register a receiver using this method when a {@linkplain ServerLoginNetworking#registerGlobalReceiver(Identifier, ServerLoginNetworking.LoginQueryResponseHandler)} @@ -317,10 +317,22 @@ public interface PlayPayloadHandler { * and {@link ServerPlayerEntity#networkHandler}, respectively. * * @param payload the packet payload - * @param player the player that received the packet - * @param responseSender the packet sender + * @param context the play networking context * @see CustomPayload */ - void receive(T payload, ServerPlayerEntity player, PacketSender responseSender); + void receive(T payload, Context context); + } + + @ApiStatus.NonExtendable + public interface Context { + /** + * @return The player that received the packet + */ + ServerPlayerEntity player(); + + /** + * @return The packet sender + */ + PacketSender responseSender(); } } diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/AbstractNetworkAddon.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/AbstractNetworkAddon.java index c4057f878a..3ce0a675c9 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/AbstractNetworkAddon.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/AbstractNetworkAddon.java @@ -102,6 +102,8 @@ public boolean registerChannel(Identifier channelName, H handler) { Objects.requireNonNull(handler, "Packet handler cannot be null"); assertNotReserved(channelName); + receiver.assertPayloadType(channelName); + Lock lock = this.lock.writeLock(); lock.lock(); 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 83d914e791..b4ef08f3b1 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 @@ -43,14 +43,14 @@ public static void init() { PayloadTypeRegistry.playC2S().register(CommonRegisterPayload.ID, CommonRegisterPayload.CODEC); PayloadTypeRegistry.playS2C().register(CommonRegisterPayload.ID, CommonRegisterPayload.CODEC); - ServerConfigurationNetworking.registerGlobalReceiver(CommonVersionPayload.ID, (payload, handler, responseSender) -> { - ServerConfigurationNetworkAddon addon = ServerNetworkingImpl.getAddon(handler); + ServerConfigurationNetworking.registerGlobalReceiver(CommonVersionPayload.ID, (payload, context) -> { + ServerConfigurationNetworkAddon addon = ServerNetworkingImpl.getAddon(context.networkHandler()); addon.onCommonVersionPacket(getNegotiatedVersion(payload)); - handler.completeTask(CommonVersionConfigurationTask.KEY); + context.networkHandler().completeTask(CommonVersionConfigurationTask.KEY); }); - ServerConfigurationNetworking.registerGlobalReceiver(CommonRegisterPayload.ID, (payload, handler, responseSender) -> { - ServerConfigurationNetworkAddon addon = ServerNetworkingImpl.getAddon(handler); + ServerConfigurationNetworking.registerGlobalReceiver(CommonRegisterPayload.ID, (payload, context) -> { + ServerConfigurationNetworkAddon addon = ServerNetworkingImpl.getAddon(context.networkHandler()); if (CommonRegisterPayload.PLAY_PHASE.equals(payload.phase())) { if (payload.version() != addon.getNegotiatedVersion()) { @@ -64,7 +64,7 @@ public static void init() { addon.onCommonRegisterPacket(payload); } - handler.completeTask(CommonRegisterConfigurationTask.KEY); + context.networkHandler().completeTask(CommonRegisterConfigurationTask.KEY); }); // Create a configuration task to send and receive the common packets diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/GlobalReceiverRegistry.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/GlobalReceiverRegistry.java index 9ecd4e2506..5cbc025f21 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/GlobalReceiverRegistry.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/GlobalReceiverRegistry.java @@ -76,11 +76,7 @@ public boolean registerGlobalReceiver(Identifier channelName, H handler) { throw new IllegalArgumentException(String.format("Cannot register handler for reserved channel with name \"%s\"", channelName)); } - if (payloadTypeRegistry != null) { - if (payloadTypeRegistry.get(channelName) == null) { - throw new IllegalArgumentException(String.format("Cannot register handler as no payload type has been registered with name \"%s\" for %s %s", channelName, side, phase)); - } - } + assertPayloadType(channelName); Lock lock = this.lock.writeLock(); lock.lock(); @@ -212,6 +208,16 @@ private void handleUnregistration(Identifier channelName) { } } + public void assertPayloadType(Identifier channelName) { + if (payloadTypeRegistry == null) { + return; + } + + if (payloadTypeRegistry.get(channelName) == null) { + throw new IllegalArgumentException(String.format("Cannot register handler as no payload type has been registered with name \"%s\" for %s %s", channelName, side, phase)); + } + } + public NetworkPhase getPhase() { return phase; } diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerConfigurationNetworkAddon.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerConfigurationNetworkAddon.java index 761a231a16..75085bdcd6 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerConfigurationNetworkAddon.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerConfigurationNetworkAddon.java @@ -28,6 +28,7 @@ import net.minecraft.server.network.ServerConfigurationNetworkHandler; import net.minecraft.util.Identifier; +import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.S2CConfigurationChannelEvents; import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking; @@ -41,12 +42,14 @@ public final class ServerConfigurationNetworkAddon extends AbstractChanneledNetworkAddon> { private final ServerConfigurationNetworkHandler handler; private final MinecraftServer server; + private final ServerConfigurationNetworking.Context context; private RegisterState registerState = RegisterState.NOT_SENT; public ServerConfigurationNetworkAddon(ServerConfigurationNetworkHandler handler, MinecraftServer server) { super(ServerNetworkingImpl.CONFIGURATION, ((ServerCommonNetworkHandlerAccessor) handler).getConnection(), "ServerConfigurationNetworkAddon for " + handler.getDebugProfile().getName()); this.handler = handler; this.server = server; + this.context = new ContextImpl(handler, this); // Must register pending channels via lateinit this.registerPendingChannels((ChannelInfoHolder) this.connection, NetworkPhase.CONFIGURATION); @@ -102,7 +105,7 @@ public void onPong(int parameter) { @Override protected void receive(ServerConfigurationNetworking.ConfigurationPacketHandler handler, CustomPayload payload) { - ((ServerConfigurationNetworking.ConfigurationPacketHandler) handler).receive(payload, this.handler, this); + ((ServerConfigurationNetworking.ConfigurationPacketHandler) handler).receive(payload, this.context); } // impl details @@ -176,4 +179,7 @@ private enum RegisterState { public ChannelInfoHolder getChannelInfoHolder() { return (ChannelInfoHolder) ((ServerCommonNetworkHandlerAccessor) handler).getConnection(); } + + private record ContextImpl(ServerConfigurationNetworkHandler networkHandler, PacketSender responseSender) implements ServerConfigurationNetworking.Context { + } } diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java index 78b5c06e00..abf09c0a4a 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerPlayNetworkAddon.java @@ -25,8 +25,10 @@ import net.minecraft.network.packet.Packet; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; +import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.S2CPlayChannelEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -39,11 +41,13 @@ public final class ServerPlayNetworkAddon extends AbstractChanneledNetworkAddon< private final ServerPlayNetworkHandler handler; private final MinecraftServer server; private boolean sentInitialRegisterPacket; + private final ServerPlayNetworking.Context context; public ServerPlayNetworkAddon(ServerPlayNetworkHandler handler, ClientConnection connection, MinecraftServer server) { super(ServerNetworkingImpl.PLAY, connection, "ServerPlayNetworkAddon for " + handler.player.getDisplayName()); this.handler = handler; this.server = server; + this.context = new ContextImpl(handler.player, this); // Must register pending channels via lateinit this.registerPendingChannels((ChannelInfoHolder) this.connection, NetworkPhase.PLAY); @@ -64,7 +68,7 @@ public void onClientReady() { @Override protected void receive(ServerPlayNetworking.PlayPayloadHandler payloadHandler, CustomPayload payload) { this.server.execute(() -> { - ((ServerPlayNetworking.PlayPayloadHandler) payloadHandler).receive(payload, ServerPlayNetworkAddon.this.handler.player, ServerPlayNetworkAddon.this); + ((ServerPlayNetworking.PlayPayloadHandler) payloadHandler).receive(payload, ServerPlayNetworkAddon.this.context); }); } @@ -123,4 +127,7 @@ protected void invokeDisconnectEvent() { protected boolean isReservedChannel(Identifier channelName) { return NetworkingImpl.isReservedCommonChannel(channelName); } + + private record ContextImpl(ServerPlayerEntity player, PacketSender responseSender) implements ServerPlayNetworking.Context { + } } diff --git a/fabric-networking-api-v1/src/test/java/net/fabricmc/fabric/test/networking/unit/CommonPacketTests.java b/fabric-networking-api-v1/src/test/java/net/fabricmc/fabric/test/networking/unit/CommonPacketTests.java index 5d379babcc..b69f1d2899 100644 --- a/fabric-networking-api-v1/src/test/java/net/fabricmc/fabric/test/networking/unit/CommonPacketTests.java +++ b/fabric-networking-api-v1/src/test/java/net/fabricmc/fabric/test/networking/unit/CommonPacketTests.java @@ -78,6 +78,9 @@ public class CommonPacketTests { private ServerConfigurationNetworkHandler serverNetworkHandler; private ServerConfigurationNetworkAddon serverAddon; + private ClientConfigurationNetworking.Context clientContext; + private ServerConfigurationNetworking.Context serverContext; + @BeforeAll static void beforeAll() { CommonPacketsImpl.init(); @@ -87,7 +90,7 @@ static void beforeAll() { PayloadTypeRegistry.playS2C().register(TestPayload.ID, TestPayload.CODEC); // Listen for the payload on the client - ClientPlayNetworking.registerGlobalReceiver(TestPayload.ID, (payload, player, responseSender) -> { + ClientPlayNetworking.registerGlobalReceiver(TestPayload.ID, (payload, context) -> { System.out.println(payload.data()); }); } @@ -126,6 +129,19 @@ void setUp() { when(serverAddon.getChannelInfoHolder()).thenReturn(channelInfoHolder); ClientNetworkingImpl.setClientConfigurationAddon(clientAddon); + + clientContext = () -> packetSender; + serverContext = new ServerConfigurationNetworking.Context() { + @Override + public ServerConfigurationNetworkHandler networkHandler() { + return serverNetworkHandler; + } + + @Override + public PacketSender responseSender() { + return packetSender; + } + }; } // Test handling the version packet on the client @@ -139,7 +155,7 @@ void handleVersionPacketClient() { buf.writeIntArray(new int[]{1, 2, 3}); CommonVersionPayload payload = CommonVersionPayload.CODEC.decode(buf); - packetHandler.receive(payload, packetSender); + packetHandler.receive(payload, clientContext); // Assert the entire packet was read assertEquals(0, buf.readableBytes()); @@ -164,7 +180,7 @@ void handleVersionPacketClientUnsupported() { assertThrows(UnsupportedOperationException.class, () -> { CommonVersionPayload payload = CommonVersionPayload.CODEC.decode(buf); - packetHandler.receive(payload, packetSender); + packetHandler.receive(payload, clientContext); }); // Assert the entire packet was read @@ -182,7 +198,7 @@ void handleVersionPacketServer() { buf.writeIntArray(new int[]{1, 2, 3}); CommonVersionPayload payload = CommonVersionPayload.CODEC.decode(buf); - packetHandler.receive(payload, serverNetworkHandler, packetSender); + packetHandler.receive(payload, serverContext); // Assert the entire packet was read assertEquals(0, buf.readableBytes()); @@ -201,7 +217,7 @@ void handleVersionPacketServerUnsupported() { assertThrows(UnsupportedOperationException.class, () -> { CommonVersionPayload payload = CommonVersionPayload.CODEC.decode(buf); - packetHandler.receive(payload, serverNetworkHandler, packetSender); + packetHandler.receive(payload, serverContext); }); // Assert the entire packet was read @@ -223,7 +239,7 @@ void handlePlayRegistryClient() { buf.writeCollection(List.of(new Identifier("fabric", "test")), PacketByteBuf::writeIdentifier); CommonRegisterPayload payload = CommonRegisterPayload.CODEC.decode(buf); - packetHandler.receive(payload, packetSender); + packetHandler.receive(payload, clientContext); // Assert the entire packet was read assertEquals(0, buf.readableBytes()); @@ -253,7 +269,7 @@ void handleConfigurationRegistryClient() { buf.writeCollection(List.of(new Identifier("fabric", "test")), PacketByteBuf::writeIdentifier); CommonRegisterPayload payload = CommonRegisterPayload.CODEC.decode(buf); - packetHandler.receive(payload, packetSender); + packetHandler.receive(payload, clientContext); // Assert the entire packet was read assertEquals(0, buf.readableBytes()); @@ -282,7 +298,7 @@ void handlePlayRegistryServer() { buf.writeCollection(List.of(new Identifier("fabric", "test")), PacketByteBuf::writeIdentifier); CommonRegisterPayload payload = CommonRegisterPayload.CODEC.decode(buf); - packetHandler.receive(payload, serverNetworkHandler, packetSender); + packetHandler.receive(payload, serverContext); // Assert the entire packet was read assertEquals(0, buf.readableBytes()); @@ -304,7 +320,7 @@ void handleConfigurationRegistryServer() { buf.writeCollection(List.of(new Identifier("fabric", "test")), PacketByteBuf::writeIdentifier); CommonRegisterPayload payload = CommonRegisterPayload.CODEC.decode(buf); - packetHandler.receive(payload, serverNetworkHandler, packetSender); + packetHandler.receive(payload, serverContext); // Assert the entire packet was read assertEquals(0, buf.readableBytes()); diff --git a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/channeltest/NetworkingChannelTest.java b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/channeltest/NetworkingChannelTest.java index 7a8d58f6b6..f75d09d3e3 100644 --- a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/channeltest/NetworkingChannelTest.java +++ b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/channeltest/NetworkingChannelTest.java @@ -107,7 +107,7 @@ private static int registerChannel(CommandContext context, CustomPayload.Type payloadType = PayloadTypeRegistryImpl.PLAY_C2S.get(channel); if (payloadType != null) { - ServerPlayNetworking.registerReceiver(executor.networkHandler, payloadType.id(), (payload, player, sender) -> { + ServerPlayNetworking.registerReceiver(executor.networkHandler, payloadType.id(), (payload, ctx) -> { System.out.printf("Received packet on channel %s%n", payloadType.id().id()); }); context.getSource().sendFeedback(() -> Text.literal(String.format("Registered channel %s for %s", channel, executor.getDisplayName())), false); diff --git a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/configuration/NetworkingConfigurationTest.java b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/configuration/NetworkingConfigurationTest.java index 513c526abe..5191d1e99c 100644 --- a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/configuration/NetworkingConfigurationTest.java +++ b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/configuration/NetworkingConfigurationTest.java @@ -51,8 +51,8 @@ public void onInitialize() { } }); - ServerConfigurationNetworking.registerGlobalReceiver(ConfigurationCompletePacket.ID, (packet, networkHandler, responseSender) -> { - networkHandler.completeTask(TestConfigurationTask.KEY); + ServerConfigurationNetworking.registerGlobalReceiver(ConfigurationCompletePacket.ID, (packet, context) -> { + context.networkHandler().completeTask(TestConfigurationTask.KEY); }); } diff --git a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/keybindreciever/NetworkingKeybindPacketTest.java b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/keybindreciever/NetworkingKeybindPacketTest.java index 2ae78718e0..0c4c865998 100644 --- a/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/keybindreciever/NetworkingKeybindPacketTest.java +++ b/fabric-networking-api-v1/src/testmod/java/net/fabricmc/fabric/test/networking/keybindreciever/NetworkingKeybindPacketTest.java @@ -16,12 +16,10 @@ package net.fabricmc.fabric.test.networking.keybindreciever; -import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -29,8 +27,8 @@ // Listens for a packet from the client which is sent to the server when a keybinding is pressed. // In response the server will send a message containing the keybind text letting the client know it pressed that key. public final class NetworkingKeybindPacketTest implements ModInitializer { - private static void receive(KeybindPayload payload, ServerPlayerEntity player, PacketSender responseSender) { - player.server.execute(() -> player.sendMessage(Text.literal("So you pressed ").append(Text.keybind("fabric-networking-api-v1-testmod-keybind").styled(style -> style.withFormatting(Formatting.BLUE))), false)); + private static void receive(KeybindPayload payload, ServerPlayNetworking.Context context) { + context.player().server.execute(() -> context.player().sendMessage(Text.literal("So you pressed ").append(Text.keybind("fabric-networking-api-v1-testmod-keybind").styled(style -> style.withFormatting(Formatting.BLUE))), false)); } @Override 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 29c595c301..01055ab12c 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,11 +23,11 @@ public class NetworkingConfigurationClientTest implements ClientModInitializer { @Override public void onInitializeClient() { - ClientConfigurationNetworking.registerGlobalReceiver(NetworkingConfigurationTest.ConfigurationPacket.ID, (packet, responseSender) -> { + ClientConfigurationNetworking.registerGlobalReceiver(NetworkingConfigurationTest.ConfigurationPacket.ID, (packet, context) -> { // Handle stuff here // Respond back to the server that the task is complete - responseSender.sendPacket(NetworkingConfigurationTest.ConfigurationCompletePacket.INSTANCE); + context.responseSender().sendPacket(NetworkingConfigurationTest.ConfigurationCompletePacket.INSTANCE); }); } } 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 e20ae8c9df..112c6cc95c 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 @@ -18,8 +18,6 @@ import com.mojang.brigadier.Command; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; @@ -30,18 +28,17 @@ 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.PacketSender; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.test.networking.NetworkingTestmods; import net.fabricmc.fabric.test.networking.play.NetworkingPlayPacketTest; -public final class NetworkingPlayPacketClientTest implements ClientModInitializer, ClientPlayNetworking.PlayPayloadHandler { +public final class NetworkingPlayPacketClientTest implements ClientModInitializer { @Override public void onInitializeClient() { // Register the payload only on the client. PayloadTypeRegistry.playC2S().register(UnknownPayload.ID, UnknownPayload.CODEC); - ClientPlayConnectionEvents.INIT.register((handler, client) -> ClientPlayNetworking.registerReceiver(NetworkingPlayPacketTest.OverlayPacket.ID, this)); + ClientPlayConnectionEvents.INIT.register((handler, client) -> ClientPlayNetworking.registerReceiver(NetworkingPlayPacketTest.OverlayPacket.ID, (payload, context) -> context.client().inGameHud.setOverlayMessage(payload.message(), true))); ClientCommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register( ClientCommandManager.literal("clientnetworktestcommand") @@ -52,11 +49,6 @@ public void onInitializeClient() { )))); } - @Override - public void receive(NetworkingPlayPacketTest.OverlayPacket payload, ClientPlayerEntity player, PacketSender sender) { - MinecraftClient.getInstance().inGameHud.setOverlayMessage(payload.message(), true); - } - private record UnknownPayload(String data) implements CustomPayload { private static final CustomPayload.Id ID = new Id<>(NetworkingTestmods.id("unknown_test_channel_c2s")); private static final PacketCodec CODEC = PacketCodecs.STRING.xmap(UnknownPayload::new, UnknownPayload::data).cast(); diff --git a/fabric-recipe-api-v1/src/client/java/net/fabricmc/fabric/impl/recipe/ingredient/client/CustomIngredientSyncClient.java b/fabric-recipe-api-v1/src/client/java/net/fabricmc/fabric/impl/recipe/ingredient/client/CustomIngredientSyncClient.java index 2baa4cb656..513775dcda 100644 --- a/fabric-recipe-api-v1/src/client/java/net/fabricmc/fabric/impl/recipe/ingredient/client/CustomIngredientSyncClient.java +++ b/fabric-recipe-api-v1/src/client/java/net/fabricmc/fabric/impl/recipe/ingredient/client/CustomIngredientSyncClient.java @@ -27,8 +27,8 @@ public class CustomIngredientSyncClient implements ClientModInitializer { @Override public void onInitializeClient() { - ClientConfigurationNetworking.registerGlobalReceiver(CustomIngredientPayloadS2C.ID, (payload, responseSender) -> { - responseSender.sendPacket(CustomIngredientSync.createResponsePayload(payload.protocolVersion())); + ClientConfigurationNetworking.registerGlobalReceiver(CustomIngredientPayloadS2C.ID, (payload, context) -> { + context.responseSender().sendPacket(CustomIngredientSync.createResponsePayload(payload.protocolVersion())); }); } } diff --git a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/CustomIngredientSync.java b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/CustomIngredientSync.java index 3403963bd1..e3620677fc 100644 --- a/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/CustomIngredientSync.java +++ b/fabric-recipe-api-v1/src/main/java/net/fabricmc/fabric/impl/recipe/ingredient/CustomIngredientSync.java @@ -88,15 +88,15 @@ public void onInitialize() { } }); - ServerConfigurationNetworking.registerGlobalReceiver(CustomIngredientPayloadC2S.ID, (payload, handler, responseSender) -> { + ServerConfigurationNetworking.registerGlobalReceiver(CustomIngredientPayloadC2S.ID, (payload, context) -> { Set supportedCustomIngredients = decodeResponsePayload(payload); - ChannelHandler packetEncoder = ((ServerCommonNetworkHandlerAccessor) handler).getConnection().channel.pipeline().get("encoder"); + ChannelHandler packetEncoder = ((ServerCommonNetworkHandlerAccessor) context.networkHandler()).getConnection().channel.pipeline().get("encoder"); if (packetEncoder != null) { // Null in singleplayer ((SupportedIngredientsPacketEncoder) packetEncoder).fabric_setSupportedCustomIngredients(supportedCustomIngredients); } - handler.completeTask(IngredientSyncTask.KEY); + context.networkHandler().completeTask(IngredientSyncTask.KEY); }); } diff --git a/fabric-registry-sync-v0/src/client/java/net/fabricmc/fabric/impl/client/registry/sync/FabricRegistryClientInit.java b/fabric-registry-sync-v0/src/client/java/net/fabricmc/fabric/impl/client/registry/sync/FabricRegistryClientInit.java index ea8d891e2a..5fe4a864fa 100644 --- a/fabric-registry-sync-v0/src/client/java/net/fabricmc/fabric/impl/client/registry/sync/FabricRegistryClientInit.java +++ b/fabric-registry-sync-v0/src/client/java/net/fabricmc/fabric/impl/client/registry/sync/FabricRegistryClientInit.java @@ -40,19 +40,19 @@ public void onInitializeClient() { } private void registerSyncPacketReceiver(RegistryPacketHandler packetHandler) { - ClientConfigurationNetworking.registerGlobalReceiver(packetHandler.getPacketId(), (payload, responseSender) -> { + ClientConfigurationNetworking.registerGlobalReceiver(packetHandler.getPacketId(), (payload, context) -> { MinecraftClient client = MinecraftClient.getInstance(); RegistrySyncManager.receivePacket(client, packetHandler, payload, RegistrySyncManager.DEBUG || !client.isInSingleplayer()) .whenComplete((complete, throwable) -> { if (throwable != null) { LOGGER.error("Registry remapping failed!", throwable); - client.execute(() -> responseSender.disconnect(getText(throwable))); + client.execute(() -> context.responseSender().disconnect(getText(throwable))); return; } if (complete) { - responseSender.sendPacket(SyncCompletePayload.INSTANCE); + context.responseSender().sendPacket(SyncCompletePayload.INSTANCE); } }); }); diff --git a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/FabricRegistryInit.java b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/FabricRegistryInit.java index 772a36bf5c..acf23e7246 100644 --- a/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/FabricRegistryInit.java +++ b/fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync/FabricRegistryInit.java @@ -33,8 +33,8 @@ public void onInitialize() { PayloadTypeRegistry.configurationS2C().register(DirectRegistryPacketHandler.Payload.ID, DirectRegistryPacketHandler.Payload.CODEC); ServerConfigurationConnectionEvents.BEFORE_CONFIGURE.register(RegistrySyncManager::configureClient); - ServerConfigurationNetworking.registerGlobalReceiver(SyncCompletePayload.ID, (payload, handler, responseSender) -> { - handler.completeTask(RegistrySyncManager.SyncConfigurationTask.KEY); + ServerConfigurationNetworking.registerGlobalReceiver(SyncCompletePayload.ID, (payload, context) -> { + context.networkHandler().completeTask(RegistrySyncManager.SyncConfigurationTask.KEY); }); // Synced in PlaySoundS2CPacket. diff --git a/fabric-screen-handler-api-v1/src/client/java/net/fabricmc/fabric/impl/screenhandler/client/ClientNetworking.java b/fabric-screen-handler-api-v1/src/client/java/net/fabricmc/fabric/impl/screenhandler/client/ClientNetworking.java index 29471a949f..c02e269f06 100644 --- a/fabric-screen-handler-api-v1/src/client/java/net/fabricmc/fabric/impl/screenhandler/client/ClientNetworking.java +++ b/fabric-screen-handler-api-v1/src/client/java/net/fabricmc/fabric/impl/screenhandler/client/ClientNetworking.java @@ -39,7 +39,7 @@ public final class ClientNetworking implements ClientModInitializer { @Override public void onInitializeClient() { - ClientPlayNetworking.registerGlobalReceiver(Networking.OpenScreenPayload.ID, (payload, player, responseSender) -> { + ClientPlayNetworking.registerGlobalReceiver(Networking.OpenScreenPayload.ID, (payload, context) -> { this.openScreen(payload); }); }