Simplify custom payload handling (#12347)

This commit is contained in:
Nassim Jahnke
2025-03-27 14:22:38 +01:00
committed by GitHub
parent c467df95a2
commit 9b1798d643
5 changed files with 59 additions and 55 deletions

View File

@@ -1,21 +1,26 @@
--- a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
+++ b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
@@ -4,13 +_,14 @@
@@ -4,13 +_,19 @@
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 record DiscardedPayload(ResourceLocation id, byte[] data) implements CustomPacketPayload { // Paper - 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
+ // Paper start
+ // Always write data
+ output.writeBytes(value.data);
+ }, 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
+ final byte[] data = new byte[i];
+ buffer.readBytes(data);
+ return new DiscardedPayload(id, data);
+ // Paper end
} else {
throw new IllegalArgumentException("Payload may not be larger than " + maxSize + " bytes");
}