Fix SplitPacketTransformer not saving enough space for packet id (#273)

This commit is contained in:
shedaniel
2022-06-09 19:16:14 +08:00
committed by GitHub
parent 23c5587442
commit 796ee4fc14

View File

@@ -35,6 +35,7 @@ import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
@ApiStatus.Experimental @ApiStatus.Experimental
@@ -179,7 +180,7 @@ public class SplitPacketTransformer implements PacketTransformer {
@Override @Override
public void outbound(NetworkManager.Side side, ResourceLocation id, FriendlyByteBuf buf, TransformationSink sink) { public void outbound(NetworkManager.Side side, ResourceLocation id, FriendlyByteBuf buf, TransformationSink sink) {
int maxSize = (side == NetworkManager.Side.C2S ? 32767 : 1048576) - 1 - 20; int maxSize = (side == NetworkManager.Side.C2S ? 32767 : 1048576) - 1 - 20 - id.toString().getBytes(StandardCharsets.UTF_8).length;
if (buf.readableBytes() <= maxSize) { if (buf.readableBytes() <= maxSize) {
ByteBuf stateBuf = Unpooled.buffer(1); ByteBuf stateBuf = Unpooled.buffer(1);
stateBuf.writeByte(ONLY); stateBuf.writeByte(ONLY);