net.minecraft.network.protocol.common(.custom)

This commit is contained in:
Noah van der Aa
2024-12-14 18:52:05 +01:00
parent 1a214aed6a
commit 902965e66a
3 changed files with 24 additions and 34 deletions

View File

@@ -0,0 +1,13 @@
--- a/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
+++ b/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
@@ -14,9 +_,7 @@
private static final int MAX_PAYLOAD_SIZE = 32767;
public static final StreamCodec<FriendlyByteBuf, ServerboundCustomPayloadPacket> STREAM_CODEC = CustomPacketPayload.<FriendlyByteBuf>codec(
id -> DiscardedPayload.codec(id, 32767),
- Util.make(Lists.newArrayList(new CustomPacketPayload.TypeAndCodec<>(BrandPayload.TYPE, BrandPayload.STREAM_CODEC)), list -> {})
- )
- .map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload);
+ java.util.Collections.emptyList()).map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload); // CraftBukkit - treat all packets the same
@Override
public PacketType<ServerboundCustomPayloadPacket> type() {

View File

@@ -0,0 +1,21 @@
--- a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
+++ b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
@@ -4,13 +_,15 @@
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
-public record DiscardedPayload(ResourceLocation id) implements CustomPacketPayload {
+public record DiscardedPayload(ResourceLocation id, io.netty.buffer.ByteBuf data) implements CustomPacketPayload { // CraftBukkit - store data
public static <T extends FriendlyByteBuf> StreamCodec<T, DiscardedPayload> codec(ResourceLocation id, int maxSize) {
- return CustomPacketPayload.codec((value, output) -> {}, buffer -> {
+ return CustomPacketPayload.codec((value, output) -> {
+ output.writeBytes(value.data); // CraftBukkit - serialize
+ }, buffer -> {
int i = buffer.readableBytes();
if (i >= 0 && i <= maxSize) {
buffer.skipBytes(i);
- return new DiscardedPayload(id);
+ return new DiscardedPayload(id, buffer.readBytes(i)); // CraftBukkit
} else {
throw new IllegalArgumentException("Payload may not be larger than " + maxSize + " bytes");
}