Skip to content

Commit 5154df1

Browse files
committed
Change chunk compression back to default java as chunks are serialized on heap byte arrays so native compression has no use
1 parent 9cf34ae commit 5154df1

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

common/src/main/java/com/viaversion/viarewind/api/type/chunk/BulkChunkType1_7_6.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.netty.buffer.Unpooled;
2525

2626
import java.util.zip.DataFormatException;
27+
import java.util.zip.Deflater;
2728

2829
public class BulkChunkType1_7_6 extends Type<Chunk[]> {
2930

@@ -83,21 +84,22 @@ public void write(ByteBuf buffer, Chunk[] chunks) {
8384
}
8485

8586
buffer.writeShort(chunkCount);
86-
final int sizeIndex = buffer.writerIndex();
87-
buffer.writerIndex(sizeIndex + 4);
8887

89-
buffer.writeBoolean(anySkyLight);
90-
91-
final int startCompressIndex = buffer.writerIndex();
88+
final Deflater deflater = new Deflater();
89+
byte[] compressedData;
90+
int compressedSize;
9291
try {
93-
CompressorUtil.getCompressor().deflate(Unpooled.wrappedBuffer(data), buffer);
94-
} catch (DataFormatException e) {
95-
throw new RuntimeException(e);
92+
deflater.setInput(data, 0, data.length);
93+
deflater.finish();
94+
compressedData = new byte[data.length];
95+
compressedSize = deflater.deflate(compressedData);
96+
} finally {
97+
deflater.end();
9698
}
97-
final int endCompressIndex = buffer.writerIndex();
98-
final int compressedSize = endCompressIndex - startCompressIndex;
9999

100-
buffer.setInt(sizeIndex, compressedSize);
100+
buffer.writeInt(compressedSize);
101+
buffer.writeBoolean(anySkyLight);
102+
buffer.writeBytes(compressedData, 0, compressedSize);;
101103

102104
for (int i = 0; i < chunkCount; i++) {
103105
Chunk chunk = chunks[i];

common/src/main/java/com/viaversion/viarewind/api/type/chunk/ChunkType1_7_6.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.netty.buffer.Unpooled;
2828

2929
import java.util.zip.DataFormatException;
30+
import java.util.zip.Deflater;
3031

3132
import static com.viaversion.viaversion.api.minecraft.chunks.ChunkSection.SIZE;
3233
import static com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLight.LIGHT_LENGTH;
@@ -62,20 +63,20 @@ public void write(ByteBuf buffer, Chunk chunk) {
6263
buffer.writeShort(bitmask);
6364
buffer.writeShort(addBitmask);
6465

65-
final int sizeIndex = buffer.writerIndex();
66-
buffer.writerIndex(sizeIndex + 4);
67-
68-
final int startCompressIndex = buffer.writerIndex();
66+
final Deflater deflater = new Deflater();
67+
byte[] compressedData;
68+
int compressedSize;
6969
try {
70-
CompressorUtil.getCompressor().deflate(Unpooled.wrappedBuffer(data), buffer);
71-
} catch (DataFormatException e) {
72-
throw new RuntimeException(e);
70+
deflater.setInput(data, 0, data.length);
71+
deflater.finish();
72+
compressedData = new byte[data.length];
73+
compressedSize = deflater.deflate(compressedData);
74+
} finally {
75+
deflater.end();
7376
}
7477

75-
final int endCompressIndex = buffer.writerIndex();
76-
final int compressedSize = endCompressIndex - startCompressIndex;
77-
78-
buffer.setInt(sizeIndex, compressedSize);
78+
buffer.writeInt(compressedSize);
79+
buffer.writeBytes(compressedData, 0, compressedSize);
7980
}
8081

8182
public static int serialize(Chunk chunk, byte[] output, int offset, int addBitmask, boolean writeSkyLight, boolean biomes) {

0 commit comments

Comments
 (0)