From 459c9cc18d66bbd5b54b7346b908806e2c28d9a1 Mon Sep 17 00:00:00 2001 From: deirn Date: Wed, 14 Feb 2024 00:07:50 +0700 Subject: [PATCH] don't sent `minecraft:register` on quilt --- .../java/lol/bai/badpackets/impl/fabric/FabricProxy.java | 6 ++++++ .../bai/badpackets/impl/handler/AbstractPacketHandler.java | 3 ++- .../lol/bai/badpackets/impl/platform/PlatformProxy.java | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/platform/fabric/src/main/java/lol/bai/badpackets/impl/fabric/FabricProxy.java b/platform/fabric/src/main/java/lol/bai/badpackets/impl/fabric/FabricProxy.java index 5d017d7..7462d52 100644 --- a/platform/fabric/src/main/java/lol/bai/badpackets/impl/fabric/FabricProxy.java +++ b/platform/fabric/src/main/java/lol/bai/badpackets/impl/fabric/FabricProxy.java @@ -13,6 +13,12 @@ public class FabricProxy extends PlatformProxy { private static final boolean HAS_FABRIC_API = FabricLoader.getInstance().isModLoaded("fabric-networking-api-v1"); + private static final boolean HAS_QUILT_STD = FabricLoader.getInstance().isModLoaded("quilt_networking"); + + @Override + public boolean canSendVanillaRegisterPackets() { + return !HAS_QUILT_STD; + } @Override public Packet createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) { diff --git a/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java index 7dadc9c..ee442aa 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java @@ -13,6 +13,7 @@ import lol.bai.badpackets.api.PacketSender; import lol.bai.badpackets.impl.Constants; import lol.bai.badpackets.impl.payload.UntypedPayload; +import lol.bai.badpackets.impl.platform.PlatformProxy; import lol.bai.badpackets.impl.registry.ChannelRegistry; import net.minecraft.network.Connection; import net.minecraft.network.FriendlyByteBuf; @@ -143,7 +144,7 @@ public void remove() { } private void sendVanillaChannelRegisterPacket(Set channels) { - if (!channels.isEmpty()) { + if (PlatformProxy.INSTANCE.canSendVanillaRegisterPackets() && !channels.isEmpty()) { FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); boolean first = true; for (ResourceLocation channel : channels) { diff --git a/src/main/java/lol/bai/badpackets/impl/platform/PlatformProxy.java b/src/main/java/lol/bai/badpackets/impl/platform/PlatformProxy.java index 34304c4..f84fb01 100644 --- a/src/main/java/lol/bai/badpackets/impl/platform/PlatformProxy.java +++ b/src/main/java/lol/bai/badpackets/impl/platform/PlatformProxy.java @@ -13,6 +13,10 @@ public class PlatformProxy { public static final PlatformProxy INSTANCE = ServiceLoader.load(PlatformProxy.class).findFirst().orElseGet(PlatformProxy::new); + public boolean canSendVanillaRegisterPackets() { + return true; + } + public Packet createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) { return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf)); }