send c:register packet for play phase instead of config (#3544)

This commit is contained in:
deirn 2024-01-23 00:57:22 +07:00 committed by GitHub
parent 31787236d2
commit 2e5ac54849
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 3 deletions

View file

@ -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.ServerConfigurationConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking; 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.ServerConfigurationNetworkAddon;
import net.fabricmc.fabric.impl.networking.server.ServerNetworkingImpl; import net.fabricmc.fabric.impl.networking.server.ServerNetworkingImpl;
@ -95,7 +96,7 @@ public class CommonPacketsImpl {
@Override @Override
public void sendPacket(Consumer<Packet<?>> sender) { public void sendPacket(Consumer<Packet<?>> sender) {
addon.sendPacket(addon.createRegisterPayload()); addon.sendPacket(new CommonRegisterPayload(addon.getNegotiatedVersion(), CommonRegisterPayload.PLAY_PHASE, ServerPlayNetworking.getGlobalReceivers()));
} }
@Override @Override

View file

@ -26,6 +26,7 @@ import java.util.UUID;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import org.apache.commons.lang3.Validate;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ClientPlayPacketListener; 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.FabricPacket;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PacketType; 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.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.test.networking.NetworkingTestmods; 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 { public record OverlayPacket(Text message) implements FabricPacket {

View file

@ -25,7 +25,6 @@ import net.minecraft.util.Identifier;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; 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.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.PacketSender;
@ -37,7 +36,7 @@ public final class NetworkingPlayPacketClientTest implements ClientModInitialize
@Override @Override
public void onInitializeClient() { 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( ClientCommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(
ClientCommandManager.literal("clientnetworktestcommand") ClientCommandManager.literal("clientnetworktestcommand")