Skip to content

Commit 2249d72

Browse files
committed
Update to reflect the use of fixed length long arrays in data palettes.
1 parent 6e60afe commit 2249d72

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftTypes.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ public static long[] readLongArray(ByteBuf buf, ToIntFunction<ByteBuf> reader) {
334334
}
335335

336336
long[] l = new long[length];
337-
for (int index = 0; index < length; index++) {
337+
return readFixedSizeLongArray(buf, l);
338+
}
339+
340+
public static long[] readFixedSizeLongArray(ByteBuf buf, long[] l) {
341+
for (int index = 0; index < l.length; index++) {
338342
l[index] = buf.readLong();
339343
}
340344

@@ -347,6 +351,10 @@ public static void writeLongArray(ByteBuf buf, long[] l) {
347351

348352
public static void writeLongArray(ByteBuf buf, long[] l, ObjIntConsumer<ByteBuf> writer) {
349353
writer.accept(buf, l.length);
354+
MinecraftTypes.writeFixedSizeLongArray(buf, l);
355+
}
356+
357+
public static void writeFixedSizeLongArray(ByteBuf buf, long[] l) {
350358
for (long value : l) {
351359
buf.writeLong(value);
352360
}
@@ -1268,7 +1276,8 @@ public static DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType)
12681276
Palette palette = MinecraftTypes.readPalette(buf, paletteType, bitsPerEntry);
12691277
BitStorage storage;
12701278
if (!(palette instanceof SingletonPalette)) {
1271-
storage = new BitStorage(bitsPerEntry, paletteType.getStorageSize(), MinecraftTypes.readLongArray(buf));
1279+
storage = new BitStorage(bitsPerEntry, paletteType.getStorageSize());
1280+
MinecraftTypes.readFixedSizeLongArray(buf, storage.getData());
12721281
} else {
12731282
// Eat up - can be seen on Hypixel as of 1.19.0
12741283
int length = MinecraftTypes.readVarInt(buf);
@@ -1308,7 +1317,7 @@ public static void writeDataPalette(ByteBuf buf, DataPalette palette) {
13081317
}
13091318

13101319
long[] data = palette.getStorage().getData();
1311-
MinecraftTypes.writeLongArray(buf, data);
1320+
MinecraftTypes.writeFixedSizeLongArray(buf, data);
13121321
}
13131322

13141323
private static Palette readPalette(ByteBuf buf, PaletteType paletteType, int bitsPerEntry) {

0 commit comments

Comments
 (0)