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
No known key found for this signature in database
GPG key ID: 547D90BC6FF753CF
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

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

View file

@ -1,20 +0,0 @@
--- a/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
+++ b/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
@@ -2,7 +2,6 @@
import com.google.common.collect.Lists;
import java.util.List;
-import net.minecraft.Util;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.Packet;
@@ -16,8 +15,7 @@
private static final int MAX_PAYLOAD_SIZE = 32767;
public static final StreamCodec<FriendlyByteBuf, ServerboundCustomPayloadPacket> STREAM_CODEC = CustomPacketPayload.codec((minecraftkey) -> {
return DiscardedPayload.codec(minecraftkey, 32767);
- }, (List) Util.make(Lists.newArrayList(new CustomPacketPayload.TypeAndCodec[]{new CustomPacketPayload.TypeAndCodec<>(BrandPayload.TYPE, BrandPayload.STREAM_CODEC)}), (arraylist) -> {
- })).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() {