diff --git a/patches/net/minecraft/client/multiplayer/ClientConfigurationPacketListenerImpl.java.patch b/patches/net/minecraft/client/multiplayer/ClientConfigurationPacketListenerImpl.java.patch index a0d17df2cf..21481c42c8 100644 --- a/patches/net/minecraft/client/multiplayer/ClientConfigurationPacketListenerImpl.java.patch +++ b/patches/net/minecraft/client/multiplayer/ClientConfigurationPacketListenerImpl.java.patch @@ -55,7 +55,7 @@ @Override public boolean hasInfiniteMaterials() { return true; -@@ -206,6 +_,59 @@ +@@ -206,6 +_,61 @@ public void onDisconnect(DisconnectionDetails reason) { super.onDisconnect(reason); this.minecraft.clearDownloadedResourcePacks(); @@ -65,6 +65,8 @@ + public void handleCustomPayload(net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket packet) { + // Handle the initial registration payload by responding with the client's set of supported channels. + if (!this.initializedConnection && packet.payload() instanceof net.neoforged.neoforge.network.payload.MinecraftRegisterPayload) { ++ // Handle the registration packet before we respond, so that implementations like fabric that only send it once, don't have the values ignored ++ super.handleCustomPayload(packet); + net.neoforged.neoforge.client.network.registration.ClientNetworkRegistry.sendInitialListeningChannels(this); + return; + } diff --git a/src/client/java/net/neoforged/neoforge/client/network/registration/ClientNetworkRegistry.java b/src/client/java/net/neoforged/neoforge/client/network/registration/ClientNetworkRegistry.java index 93ee900e83..bc130dc10f 100644 --- a/src/client/java/net/neoforged/neoforge/client/network/registration/ClientNetworkRegistry.java +++ b/src/client/java/net/neoforged/neoforge/client/network/registration/ClientNetworkRegistry.java @@ -10,7 +10,6 @@ import com.mojang.logging.LogUtils; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; import net.minecraft.network.ConnectionProtocol; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.PacketFlow; @@ -255,6 +254,16 @@ public final class ClientNetworkRegistry extends NetworkRegistry { NetworkFilters.injectIfNecessary(listener.getConnection()); + sendInitialListeningChannels(listener); + } + + /// Invoked by the client when it receives a [MinecraftRegisterPayload] during negotiation in the configuration phase. + /// This will respond to the server with the client's set of builtin and optional channels to indicate it supports the common protocol. + /// + /// Invoked on the network thread. + /// + /// @param listener The listener which received the brand payload. + public static void sendInitialListeningChannels(ClientConfigurationPacketListener listener) { ImmutableSet.Builder nowListeningOn = ImmutableSet.builder(); nowListeningOn.addAll(getInitialListeningChannels(listener.flow())); PAYLOAD_REGISTRATIONS.get(ConnectionProtocol.CONFIGURATION).entrySet().stream() @@ -264,19 +273,6 @@ public final class ClientNetworkRegistry extends NetworkRegistry { listener.send(new MinecraftRegisterPayload(nowListeningOn.build())); } - /** - * Invoked by the client when it receives a {@link MinecraftRegisterPayload} during negotiation in the configuration phase. - * This will respond to the server with the client's set of builtin channels to indicate it supports the common protocol. - *

- * Invoked on the network thread. - * - * @param listener The listener which received the brand payload. - */ - public static void sendInitialListeningChannels(ClientConfigurationPacketListener listener) { - Set nowListeningOn = ImmutableSet.copyOf(getInitialListeningChannels(listener.flow())); - listener.send(new MinecraftRegisterPayload(nowListeningOn)); - } - /** * Used in place of {@link Thread#dumpStack()} as that logs to {@link System#err}. */ diff --git a/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java b/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java index 93fdbb84a6..bed0f17aed 100644 --- a/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java +++ b/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java @@ -429,11 +429,11 @@ public class NetworkRegistry { return; } - if (hasChannel(listener, customPayloadPacket.payload().type().id())) { + if (hasChannel(listener, id)) { return; } - throw new UnsupportedOperationException("Payload %s may not be sent to the client!".formatted(customPayloadPacket.payload().type().id())); + throw new UnsupportedOperationException("Payload %s may not be sent to the client!".formatted(id)); } } @@ -451,11 +451,11 @@ public class NetworkRegistry { return; } - if (hasChannel(listener, customPayloadPacket.payload().type().id())) { + if (hasChannel(listener, id)) { return; } - throw new UnsupportedOperationException("Payload %s may not be sent to the server!".formatted(customPayloadPacket.payload().type().id())); + throw new UnsupportedOperationException("Payload %s may not be sent to the server!".formatted(id)); } } @@ -541,10 +541,10 @@ public class NetworkRegistry { return; } - NetworkChannel channel = payloadSetup.getChannel(ConnectionProtocol.PLAY, customPayloadPacket.payload().type().id()); + NetworkChannel channel = payloadSetup.getChannel(ConnectionProtocol.PLAY, id); if (channel == null) { - LOGGER.trace("Somebody tried to send: {} to a client which cannot accept it. Not sending packet.", customPayloadPacket.payload().type().id()); + LOGGER.trace("Somebody tried to send: {} to a client which cannot accept it. Not sending packet.", id); return; } @@ -612,7 +612,7 @@ public class NetworkRegistry { nowForgottenChannels.add(MinecraftRegisterPayload.ID); nowForgottenChannels.add(MinecraftUnregisterPayload.ID); PAYLOAD_REGISTRATIONS.get(ConnectionProtocol.PLAY).entrySet().stream() - .filter(registration -> registration.getValue().flow().isEmpty() || registration.getValue().flow().get() == PacketFlow.SERVERBOUND) + .filter(registration -> registration.getValue().matchesFlow(PacketFlow.SERVERBOUND)) .filter(registration -> registration.getValue().optional()) .forEach(registration -> nowForgottenChannels.add(registration.getKey())); return nowForgottenChannels.build();