mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 12:20:11 +00:00
87 lines
3.1 KiB
Diff
87 lines
3.1 KiB
Diff
--- ../src_base/minecraft/net/minecraft/network/packet/Packet56MapChunks.java
|
|
+++ ../src_work/minecraft/net/minecraft/network/packet/Packet56MapChunks.java
|
|
@@ -6,6 +6,7 @@
|
|
import java.io.DataOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
+import java.util.concurrent.Semaphore;
|
|
import java.util.zip.DataFormatException;
|
|
import java.util.zip.Deflater;
|
|
import java.util.zip.Inflater;
|
|
@@ -26,6 +27,9 @@
|
|
private int dataLength;
|
|
private boolean field_92076_h;
|
|
private static byte[] chunkDataNotCompressed = new byte[0];
|
|
+ private int maxLen = 0;
|
|
+
|
|
+ private Semaphore deflateGate;
|
|
|
|
public Packet56MapChunks() {}
|
|
|
|
@@ -44,15 +48,6 @@
|
|
{
|
|
Chunk chunk = (Chunk)par1List.get(k);
|
|
Packet51MapChunkData packet51mapchunkdata = Packet51MapChunk.getMapChunkData(chunk, true, 65535);
|
|
-
|
|
- if (chunkDataNotCompressed.length < j + packet51mapchunkdata.compressedData.length)
|
|
- {
|
|
- byte[] abyte = new byte[j + packet51mapchunkdata.compressedData.length];
|
|
- System.arraycopy(chunkDataNotCompressed, 0, abyte, 0, chunkDataNotCompressed.length);
|
|
- chunkDataNotCompressed = abyte;
|
|
- }
|
|
-
|
|
- System.arraycopy(packet51mapchunkdata.compressedData, 0, chunkDataNotCompressed, j, packet51mapchunkdata.compressedData.length);
|
|
j += packet51mapchunkdata.compressedData.length;
|
|
this.chunkPostX[k] = chunk.xPosition;
|
|
this.chunkPosZ[k] = chunk.zPosition;
|
|
@@ -60,15 +55,29 @@
|
|
this.field_73588_b[k] = packet51mapchunkdata.chunkHasAddSectionFlag;
|
|
this.field_73584_f[k] = packet51mapchunkdata.compressedData;
|
|
}
|
|
+ deflateGate = new Semaphore(1);
|
|
+ maxLen = j;
|
|
+ }
|
|
+
|
|
+ private void deflate()
|
|
+ {
|
|
+ byte[] data = new byte[maxLen];
|
|
+ int offset = 0;
|
|
+ for (int x = 0; x < field_73584_f.length; x++)
|
|
+ {
|
|
+ System.arraycopy(field_73584_f[x], 0, data, offset, field_73584_f[x].length);
|
|
+ offset += field_73584_f[x].length;
|
|
+ }
|
|
|
|
Deflater deflater = new Deflater(-1);
|
|
|
|
try
|
|
{
|
|
- deflater.setInput(chunkDataNotCompressed, 0, j);
|
|
+ deflater.setInput(data, 0, maxLen);
|
|
deflater.finish();
|
|
- this.chunkDataBuffer = new byte[j];
|
|
- this.dataLength = deflater.deflate(this.chunkDataBuffer);
|
|
+ byte[] deflated = new byte[maxLen];
|
|
+ this.dataLength = deflater.deflate(deflated);
|
|
+ this.chunkDataBuffer = deflated;
|
|
}
|
|
finally
|
|
{
|
|
@@ -150,6 +159,16 @@
|
|
*/
|
|
public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
|
|
{
|
|
+ if (this.chunkDataBuffer == null)
|
|
+ {
|
|
+ deflateGate.acquireUninterruptibly();
|
|
+ if (this.chunkDataBuffer == null)
|
|
+ {
|
|
+ deflate();
|
|
+ }
|
|
+ deflateGate.release();
|
|
+ }
|
|
+
|
|
par1DataOutputStream.writeShort(this.chunkPostX.length);
|
|
par1DataOutputStream.writeInt(this.dataLength);
|
|
par1DataOutputStream.writeBoolean(this.field_92076_h);
|