diff --git a/gradle.properties b/gradle.properties index 360e934..25b0983 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ majorVersion = 0 fabricLoader = 0.15.3 fabricApi = 0.93.1+1.20.4 forge = 49.0.19 -neo = 20.4.96-beta +neo = 20.4.171 cf.projectId = 615134 mr.projectId = ftdbN0KK 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 7462d52..97910b7 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 @@ -1,5 +1,8 @@ package lol.bai.badpackets.impl.fabric; +import java.util.Set; +import java.util.function.Supplier; + import lol.bai.badpackets.impl.Constants; import lol.bai.badpackets.impl.platform.PlatformProxy; import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking; @@ -9,6 +12,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.Packet; +import net.minecraft.resources.ResourceLocation; public class FabricProxy extends PlatformProxy { @@ -21,31 +25,31 @@ public boolean canSendVanillaRegisterPackets() { } @Override - public Packet createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) { + public Packet createVanillaRegisterConfigS2CPacket(Set channels, Supplier buf) { return HAS_FABRIC_API - ? ServerConfigurationNetworking.createS2CPacket(Constants.MC_REGISTER_CHANNEL, buf) - : super.createVanillaRegisterConfigS2CPacket(buf); + ? ServerConfigurationNetworking.createS2CPacket(Constants.MC_REGISTER_CHANNEL, buf.get()) + : super.createVanillaRegisterConfigS2CPacket(channels, buf); } @Override - public Packet createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) { + public Packet createVanillaRegisterConfigC2SPacket(Set channels, Supplier buf) { return HAS_FABRIC_API - ? ClientConfigurationNetworking.createC2SPacket(Constants.MC_REGISTER_CHANNEL, buf) - : super.createVanillaRegisterConfigC2SPacket(buf); + ? ClientConfigurationNetworking.createC2SPacket(Constants.MC_REGISTER_CHANNEL, buf.get()) + : super.createVanillaRegisterConfigC2SPacket(channels, buf); } @Override - public Packet createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) { + public Packet createVanillaRegisterPlayS2CPacket(Set channels, Supplier buf) { return HAS_FABRIC_API - ? ServerPlayNetworking.createS2CPacket(Constants.MC_REGISTER_CHANNEL, buf) - : super.createVanillaRegisterPlayS2CPacket(buf); + ? ServerPlayNetworking.createS2CPacket(Constants.MC_REGISTER_CHANNEL, buf.get()) + : super.createVanillaRegisterPlayS2CPacket(channels, buf); } @Override - public Packet createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) { + public Packet createVanillaRegisterPlayC2SPacket(Set channels, Supplier buf) { return HAS_FABRIC_API - ? ClientPlayNetworking.createC2SPacket(Constants.MC_REGISTER_CHANNEL, buf) - : super.createVanillaRegisterPlayC2SPacket(buf); + ? ClientPlayNetworking.createC2SPacket(Constants.MC_REGISTER_CHANNEL, buf.get()) + : super.createVanillaRegisterPlayC2SPacket(channels, buf); } } diff --git a/platform/forge/src/main/java/lol/bai/badpackets/impl/forge/ForgeProxy.java b/platform/forge/src/main/java/lol/bai/badpackets/impl/forge/ForgeProxy.java index 809b6a1..bb4ac90 100644 --- a/platform/forge/src/main/java/lol/bai/badpackets/impl/forge/ForgeProxy.java +++ b/platform/forge/src/main/java/lol/bai/badpackets/impl/forge/ForgeProxy.java @@ -1,5 +1,8 @@ package lol.bai.badpackets.impl.forge; +import java.util.Set; +import java.util.function.Supplier; + import lol.bai.badpackets.impl.Constants; import lol.bai.badpackets.impl.platform.PlatformProxy; import net.minecraft.network.FriendlyByteBuf; @@ -7,27 +10,28 @@ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.common.custom.DiscardedPayload; +import net.minecraft.resources.ResourceLocation; public class ForgeProxy extends PlatformProxy { @Override - public Packet createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) { - return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf)); + public Packet createVanillaRegisterConfigS2CPacket(Set channels, Supplier buf) { + return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf.get())); } @Override - public Packet createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) { - return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf)); + public Packet createVanillaRegisterConfigC2SPacket(Set channels, Supplier buf) { + return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf.get())); } @Override - public Packet createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) { - return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf)); + public Packet createVanillaRegisterPlayS2CPacket(Set channels, Supplier buf) { + return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf.get())); } @Override - public Packet createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) { - return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf)); + public Packet createVanillaRegisterPlayC2SPacket(Set channels, Supplier buf) { + return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf.get())); } } diff --git a/platform/neo/src/main/java/lol/bai/badpackets/impl/neo/NeoProxy.java b/platform/neo/src/main/java/lol/bai/badpackets/impl/neo/NeoProxy.java index 0ae5240..6a8e453 100644 --- a/platform/neo/src/main/java/lol/bai/badpackets/impl/neo/NeoProxy.java +++ b/platform/neo/src/main/java/lol/bai/badpackets/impl/neo/NeoProxy.java @@ -1,35 +1,36 @@ package lol.bai.badpackets.impl.neo; +import java.util.Set; +import java.util.function.Supplier; + import lol.bai.badpackets.impl.platform.PlatformProxy; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.payload.MinecraftRegisterPayload; -// TODO: NeoForge has different format for minecraft:register. Support it again when it reuse the old format. public class NeoProxy extends PlatformProxy { @Override - public boolean canSendVanillaRegisterPackets() { - return false; - } - - @Override - public Packet createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) { - throw new UnsupportedOperationException("Not yet implemented"); + public Packet createVanillaRegisterConfigS2CPacket(Set channels, Supplier buf) { + return new ClientboundCustomPayloadPacket(new MinecraftRegisterPayload(channels)); } @Override - public Packet createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) { - throw new UnsupportedOperationException("Not yet implemented"); + public Packet createVanillaRegisterConfigC2SPacket(Set channels, Supplier buf) { + return new ServerboundCustomPayloadPacket(new MinecraftRegisterPayload(channels)); } @Override - public Packet createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) { - throw new UnsupportedOperationException("Not yet implemented"); + public Packet createVanillaRegisterPlayS2CPacket(Set channels, Supplier buf) { + return new ClientboundCustomPayloadPacket(new MinecraftRegisterPayload(channels)); } @Override - public Packet createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) { - throw new UnsupportedOperationException("Not yet implemented"); + public Packet createVanillaRegisterPlayC2SPacket(Set channels, Supplier buf) { + return new ServerboundCustomPayloadPacket(new MinecraftRegisterPayload(channels)); } } 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 a15f794..112dfe5 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/AbstractPacketHandler.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; import io.netty.buffer.Unpooled; @@ -145,21 +146,23 @@ public void remove() { private void sendVanillaChannelRegisterPacket(Set channels) { if (PlatformProxy.INSTANCE.canSendVanillaRegisterPackets() && !channels.isEmpty()) { - FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - boolean first = true; - for (ResourceLocation channel : channels) { - if (first) { - first = false; - } else { - buf.writeByte(0); + connection.send(createVanillaRegisterPacket(channels, () -> { + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); + boolean first = true; + for (ResourceLocation channel : channels) { + if (first) { + first = false; + } else { + buf.writeByte(0); + } + buf.writeBytes(channel.toString().getBytes(StandardCharsets.US_ASCII)); } - buf.writeBytes(channel.toString().getBytes(StandardCharsets.US_ASCII)); - } - connection.send(createVanillaRegisterPacket(buf)); + return buf; + })); } } - protected abstract Packet createVanillaRegisterPacket(FriendlyByteBuf buf); + protected abstract Packet createVanillaRegisterPacket(Set channels, Supplier buf); @Override public void send(CustomPacketPayload payload, @Nullable PacketSendListener callback) { diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ClientConfigPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ClientConfigPacketHandler.java index 165aedb..77522c5 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ClientConfigPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ClientConfigPacketHandler.java @@ -1,5 +1,8 @@ package lol.bai.badpackets.impl.handler; +import java.util.Set; +import java.util.function.Supplier; + import lol.bai.badpackets.api.config.ClientConfigPacketReadyCallback; import lol.bai.badpackets.api.config.ClientConfigPacketReceiver; import lol.bai.badpackets.impl.platform.PlatformProxy; @@ -12,6 +15,7 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; public class ClientConfigPacketHandler extends AbstractPacketHandler> { @@ -26,8 +30,8 @@ public ClientConfigPacketHandler(Minecraft client, ClientConfigurationPacketList } @Override - protected Packet createVanillaRegisterPacket(FriendlyByteBuf buf) { - return PlatformProxy.INSTANCE.createVanillaRegisterConfigC2SPacket(buf); + protected Packet createVanillaRegisterPacket(Set channels, Supplier buf) { + return PlatformProxy.INSTANCE.createVanillaRegisterConfigC2SPacket(channels, buf); } @Override diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java index a7b0649..804015e 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ClientPlayPacketHandler.java @@ -1,5 +1,8 @@ package lol.bai.badpackets.impl.handler; +import java.util.Set; +import java.util.function.Supplier; + import lol.bai.badpackets.api.play.ClientPlayPacketReadyCallback; import lol.bai.badpackets.api.play.ClientPlayPacketReceiver; import lol.bai.badpackets.impl.platform.PlatformProxy; @@ -11,6 +14,7 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; public class ClientPlayPacketHandler extends AbstractPacketHandler> { @@ -34,8 +38,8 @@ public static ClientPlayPacketHandler get() { } @Override - protected Packet createVanillaRegisterPacket(FriendlyByteBuf buf) { - return PlatformProxy.INSTANCE.createVanillaRegisterPlayC2SPacket(buf); + protected Packet createVanillaRegisterPacket(Set channels, Supplier buf) { + return PlatformProxy.INSTANCE.createVanillaRegisterPlayC2SPacket(channels, buf); } @Override diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ServerConfigPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ServerConfigPacketHandler.java index e25af21..d6b6d6e 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ServerConfigPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ServerConfigPacketHandler.java @@ -2,7 +2,9 @@ import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.function.Consumer; +import java.util.function.Supplier; import lol.bai.badpackets.api.config.ConfigTaskExecutor; import lol.bai.badpackets.api.config.ServerConfigPacketReadyCallback; @@ -46,8 +48,8 @@ public CallbackTask createCallbackTask() { } @Override - protected Packet createVanillaRegisterPacket(FriendlyByteBuf buf) { - return PlatformProxy.INSTANCE.createVanillaRegisterConfigS2CPacket(buf); + protected Packet createVanillaRegisterPacket(Set channels, Supplier buf) { + return PlatformProxy.INSTANCE.createVanillaRegisterConfigS2CPacket(channels, buf); } @Override diff --git a/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java b/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java index b1c5188..b56763c 100644 --- a/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java +++ b/src/main/java/lol/bai/badpackets/impl/handler/ServerPlayPacketHandler.java @@ -1,5 +1,8 @@ package lol.bai.badpackets.impl.handler; +import java.util.Set; +import java.util.function.Supplier; + import lol.bai.badpackets.api.play.ServerPlayPacketReadyCallback; import lol.bai.badpackets.api.play.ServerPlayPacketReceiver; import lol.bai.badpackets.impl.platform.PlatformProxy; @@ -10,6 +13,7 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; @@ -30,8 +34,8 @@ public static ServerPlayPacketHandler get(ServerPlayer player) { } @Override - protected Packet createVanillaRegisterPacket(FriendlyByteBuf buf) { - return PlatformProxy.INSTANCE.createVanillaRegisterPlayS2CPacket(buf); + protected Packet createVanillaRegisterPacket(Set channels, Supplier buf) { + return PlatformProxy.INSTANCE.createVanillaRegisterPlayS2CPacket(channels, buf); } @Override 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 f84fb01..a723725 100644 --- a/src/main/java/lol/bai/badpackets/impl/platform/PlatformProxy.java +++ b/src/main/java/lol/bai/badpackets/impl/platform/PlatformProxy.java @@ -1,6 +1,8 @@ package lol.bai.badpackets.impl.platform; import java.util.ServiceLoader; +import java.util.Set; +import java.util.function.Supplier; import lol.bai.badpackets.impl.Constants; import lol.bai.badpackets.impl.payload.UntypedPayload; @@ -8,6 +10,7 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.resources.ResourceLocation; public class PlatformProxy { @@ -17,20 +20,20 @@ public boolean canSendVanillaRegisterPackets() { return true; } - public Packet createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) { - return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf)); + public Packet createVanillaRegisterConfigC2SPacket(Set channels, Supplier buf) { + return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf.get())); } - public Packet createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) { - return new ClientboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf)); + public Packet createVanillaRegisterConfigS2CPacket(Set channels, Supplier buf) { + return new ClientboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf.get())); } - public Packet createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) { - return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf)); + public Packet createVanillaRegisterPlayC2SPacket(Set channels, Supplier buf) { + return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf.get())); } - public Packet createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) { - return new ClientboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf)); + public Packet createVanillaRegisterPlayS2CPacket(Set channels, Supplier buf) { + return new ClientboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf.get())); } }