2012-07-29 09:33:13 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.zip.DataFormatException;
|
|
|
|
import java.util.zip.Deflater;
|
|
|
|
import java.util.zip.Inflater;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public class PacketPlayOutMapChunkBulk extends Packet {
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
private int[] a;
|
|
|
|
private int[] b;
|
2012-07-29 09:33:13 +02:00
|
|
|
private int[] c;
|
|
|
|
private int[] d;
|
2012-11-06 13:05:28 +01:00
|
|
|
private byte[] buffer;
|
2012-07-29 09:33:13 +02:00
|
|
|
private byte[][] inflatedBuffers;
|
2012-11-06 13:05:28 +01:00
|
|
|
private int size;
|
2012-12-20 05:03:52 +01:00
|
|
|
private boolean h;
|
2012-11-06 13:05:28 +01:00
|
|
|
private byte[] buildBuffer = new byte[0]; // CraftBukkit - remove static
|
|
|
|
// CraftBukkit start
|
|
|
|
static final ThreadLocal<Deflater> localDeflater = new ThreadLocal<Deflater>() {
|
|
|
|
@Override
|
|
|
|
protected Deflater initialValue() {
|
2012-11-18 15:45:54 +01:00
|
|
|
// Don't use higher compression level, slows things down too much
|
|
|
|
return new Deflater(6);
|
2012-11-06 13:05:28 +01:00
|
|
|
}
|
|
|
|
};
|
2012-07-29 09:33:13 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public PacketPlayOutMapChunkBulk() {}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public PacketPlayOutMapChunkBulk(List list) {
|
2012-07-29 09:33:13 +02:00
|
|
|
int i = list.size();
|
|
|
|
|
|
|
|
this.a = new int[i];
|
|
|
|
this.b = new int[i];
|
2013-11-04 14:07:38 +01:00
|
|
|
this.c = new int[i];
|
|
|
|
this.d = new int[i];
|
2012-07-29 09:33:13 +02:00
|
|
|
this.inflatedBuffers = new byte[i][];
|
2013-07-01 13:03:00 +02:00
|
|
|
this.h = !list.isEmpty() && !((Chunk) list.get(0)).world.worldProvider.g;
|
2012-07-29 09:33:13 +02:00
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
for (int k = 0; k < i; ++k) {
|
|
|
|
Chunk chunk = (Chunk) list.get(k);
|
2013-11-04 14:07:38 +01:00
|
|
|
ChunkMap chunkmap = PacketPlayOutMapChunk.a(chunk, true, '\uffff');
|
2012-07-29 09:33:13 +02:00
|
|
|
|
|
|
|
if (buildBuffer.length < j + chunkmap.a.length) {
|
|
|
|
byte[] abyte = new byte[j + chunkmap.a.length];
|
|
|
|
|
|
|
|
System.arraycopy(buildBuffer, 0, abyte, 0, buildBuffer.length);
|
|
|
|
buildBuffer = abyte;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.arraycopy(chunkmap.a, 0, buildBuffer, j, chunkmap.a.length);
|
|
|
|
j += chunkmap.a.length;
|
2013-11-04 14:07:38 +01:00
|
|
|
this.a[k] = chunk.locX;
|
|
|
|
this.b[k] = chunk.locZ;
|
|
|
|
this.c[k] = chunkmap.b;
|
|
|
|
this.d[k] = chunkmap.c;
|
2012-07-29 09:33:13 +02:00
|
|
|
this.inflatedBuffers[k] = chunkmap.a;
|
|
|
|
}
|
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
/* CraftBukkit start - Moved to compress()
|
2012-07-29 09:33:13 +02:00
|
|
|
Deflater deflater = new Deflater(-1);
|
|
|
|
|
|
|
|
try {
|
|
|
|
deflater.setInput(buildBuffer, 0, j);
|
|
|
|
deflater.finish();
|
|
|
|
this.buffer = new byte[j];
|
|
|
|
this.size = deflater.deflate(this.buffer);
|
|
|
|
} finally {
|
|
|
|
deflater.end();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
// Add compression method
|
|
|
|
public void compress() {
|
|
|
|
if (this.buffer != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Deflater deflater = localDeflater.get();
|
|
|
|
deflater.reset();
|
|
|
|
deflater.setInput(this.buildBuffer);
|
|
|
|
deflater.finish();
|
|
|
|
|
|
|
|
this.buffer = new byte[this.buildBuffer.length + 100];
|
|
|
|
this.size = deflater.deflate(this.buffer);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public static int c() {
|
|
|
|
return 5;
|
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void a(PacketDataSerializer packetdataserializer) throws IOException { // CraftBukkit - throws IOException
|
|
|
|
short short1 = packetdataserializer.readShort();
|
|
|
|
|
|
|
|
this.size = packetdataserializer.readInt();
|
|
|
|
this.h = packetdataserializer.readBoolean();
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a = new int[short1];
|
|
|
|
this.b = new int[short1];
|
2013-11-04 14:07:38 +01:00
|
|
|
this.c = new int[short1];
|
|
|
|
this.d = new int[short1];
|
2012-07-29 09:33:13 +02:00
|
|
|
this.inflatedBuffers = new byte[short1][];
|
|
|
|
if (buildBuffer.length < this.size) {
|
|
|
|
buildBuffer = new byte[this.size];
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
packetdataserializer.readBytes(buildBuffer, 0, this.size);
|
|
|
|
byte[] abyte = new byte[PacketPlayOutMapChunk.c() * short1];
|
2012-07-29 09:33:13 +02:00
|
|
|
Inflater inflater = new Inflater();
|
|
|
|
|
|
|
|
inflater.setInput(buildBuffer, 0, this.size);
|
|
|
|
|
|
|
|
try {
|
|
|
|
inflater.inflate(abyte);
|
|
|
|
} catch (DataFormatException dataformatexception) {
|
|
|
|
throw new IOException("Bad compressed data format");
|
|
|
|
} finally {
|
|
|
|
inflater.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (int j = 0; j < short1; ++j) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.a[j] = packetdataserializer.readInt();
|
|
|
|
this.b[j] = packetdataserializer.readInt();
|
|
|
|
this.c[j] = packetdataserializer.readShort();
|
|
|
|
this.d[j] = packetdataserializer.readShort();
|
2012-07-29 09:33:13 +02:00
|
|
|
int k = 0;
|
2012-12-20 05:03:52 +01:00
|
|
|
int l = 0;
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
int i1;
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
for (i1 = 0; i1 < 16; ++i1) {
|
2013-11-04 14:07:38 +01:00
|
|
|
k += this.c[j] >> i1 & 1;
|
|
|
|
l += this.d[j] >> i1 & 1;
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
|
2012-12-20 05:03:52 +01:00
|
|
|
i1 = 2048 * 4 * k + 256;
|
|
|
|
i1 += 2048 * l;
|
|
|
|
if (this.h) {
|
|
|
|
i1 += 2048 * k;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.inflatedBuffers[j] = new byte[i1];
|
|
|
|
System.arraycopy(abyte, i, this.inflatedBuffers[j], 0, i1);
|
|
|
|
i += i1;
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void b(PacketDataSerializer packetdataserializer) throws IOException { // CraftBukkit - throws IOException
|
2012-11-06 13:05:28 +01:00
|
|
|
compress(); // CraftBukkit
|
2013-11-04 14:07:38 +01:00
|
|
|
packetdataserializer.writeShort(this.a.length);
|
|
|
|
packetdataserializer.writeInt(this.size);
|
|
|
|
packetdataserializer.writeBoolean(this.h);
|
|
|
|
packetdataserializer.writeBytes(this.buffer, 0, this.size);
|
|
|
|
|
|
|
|
for (int i = 0; i < this.a.length; ++i) {
|
|
|
|
packetdataserializer.writeInt(this.a[i]);
|
|
|
|
packetdataserializer.writeInt(this.b[i]);
|
|
|
|
packetdataserializer.writeShort((short) (this.c[i] & '\uffff'));
|
|
|
|
packetdataserializer.writeShort((short) (this.d[i] & '\uffff'));
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void a(PacketPlayOutListener packetplayoutlistener) {
|
|
|
|
packetplayoutlistener.a(this);
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public String b() {
|
|
|
|
StringBuilder stringbuilder = new StringBuilder();
|
|
|
|
|
|
|
|
for (int i = 0; i < this.a.length; ++i) {
|
|
|
|
if (i > 0) {
|
|
|
|
stringbuilder.append(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
stringbuilder.append(String.format("{x=%d, z=%d, sections=%d, adds=%d, data=%d}", new Object[] { Integer.valueOf(this.a[i]), Integer.valueOf(this.b[i]), Integer.valueOf(this.c[i]), Integer.valueOf(this.d[i]), Integer.valueOf(this.inflatedBuffers[i].length)}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return String.format("size=%d, chunks=%d[%s]", new Object[] { Integer.valueOf(this.size), Integer.valueOf(this.a.length), stringbuilder});
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void handle(PacketListener packetlistener) {
|
|
|
|
this.a((PacketPlayOutListener) packetlistener);
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
}
|