From 1f3375faf80201755faf0e239b3374c75aa6e951 Mon Sep 17 00:00:00 2001 From: Alemiz Date: Thu, 27 Jun 2024 18:03:27 +0200 Subject: [PATCH] Increase sub chunk request limit --- .../v486/serializer/SubChunkRequestSerializer_v486.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v486/serializer/SubChunkRequestSerializer_v486.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v486/serializer/SubChunkRequestSerializer_v486.java index 5df4004a9..2759caa0e 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v486/serializer/SubChunkRequestSerializer_v486.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v486/serializer/SubChunkRequestSerializer_v486.java @@ -11,6 +11,11 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class SubChunkRequestSerializer_v486 extends SubChunkRequestSerializer_v471 { + // A limit of how many sub chunks can client request within a single packet + // It seems that client does not have any cap on how many sub chunks it can request, + // and in some edge cases it requests all sub chunks within the view distance + // The limit set here is based on maximum view distance vanilla client supports (96 chunks) + private static final int MAX_SUB_CHUNKS = (int) (0.785 * 96 * 96 * 24); // circle area * 96 chunks * 24 sub chunks per chunk public static final SubChunkRequestSerializer_v486 INSTANCE = new SubChunkRequestSerializer_v486(); @@ -25,7 +30,7 @@ public void serialize(ByteBuf buffer, BedrockCodecHelper helper, SubChunkRequest public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SubChunkRequestPacket packet) { packet.setDimension(VarInts.readInt(buffer)); packet.setSubChunkPosition(helper.readVector3i(buffer)); - helper.readArray(buffer, packet.getPositionOffsets(), ByteBuf::readIntLE, this::readSubChunkOffset, 3072); // Somehow client sometimes requests over 1000 sub chunks + helper.readArray(buffer, packet.getPositionOffsets(), ByteBuf::readIntLE, this::readSubChunkOffset, MAX_SUB_CHUNKS); } protected void writeSubChunkOffset(ByteBuf buffer, Vector3i offsetPosition) {