2011-05-21 21:27:34 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.io.DataInputStream;
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.zip.DataFormatException;
|
|
|
|
import java.util.zip.Deflater;
|
|
|
|
import java.util.zip.Inflater;
|
|
|
|
|
|
|
|
public class Packet51MapChunk extends Packet {
|
|
|
|
|
|
|
|
public int a;
|
|
|
|
public int b;
|
|
|
|
public int c;
|
|
|
|
public int d;
|
2012-01-12 16:27:39 +01:00
|
|
|
public byte[] buffer;
|
2012-03-01 11:49:23 +01:00
|
|
|
public boolean f;
|
2012-01-12 16:27:39 +01:00
|
|
|
public int size; // CraftBukkit - private -> public
|
2012-03-01 11:49:23 +01:00
|
|
|
private int h;
|
|
|
|
public byte[] rawData = new byte[0]; // CraftBukkit
|
2011-05-21 21:27:34 +02:00
|
|
|
|
|
|
|
public Packet51MapChunk() {
|
2012-01-14 21:03:48 +01:00
|
|
|
this.lowPriority = true;
|
2011-05-21 21:27:34 +02:00
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
// CraftBukkit start
|
2012-03-01 11:49:23 +01:00
|
|
|
public Packet51MapChunk(Chunk chunk, boolean flag, int i) {
|
2012-01-14 21:03:48 +01:00
|
|
|
this.lowPriority = true;
|
2012-03-01 11:49:23 +01:00
|
|
|
this.a = chunk.x;
|
|
|
|
this.b = chunk.z;
|
|
|
|
this.f = flag;
|
|
|
|
if (flag) {
|
|
|
|
i = '\uffff';
|
2012-03-21 22:01:11 +01:00
|
|
|
chunk.sentToClient = true; // CraftBukkit - flag as seen
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ChunkSection[] achunksection = chunk.h();
|
|
|
|
int j = 0;
|
|
|
|
int k = 0;
|
|
|
|
|
|
|
|
int l;
|
|
|
|
|
|
|
|
for (l = 0; l < achunksection.length; ++l) {
|
|
|
|
if (achunksection[l] != null && (!flag || !achunksection[l].a()) && (i & 1 << l) != 0) {
|
|
|
|
this.c |= 1 << l;
|
|
|
|
++j;
|
|
|
|
if (achunksection[l].h() != null) {
|
|
|
|
this.d |= 1 << l;
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
l = 2048 * (5 * j + k);
|
|
|
|
if (flag) {
|
|
|
|
l += 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rawData.length < l) {
|
|
|
|
rawData = new byte[l];
|
|
|
|
}
|
|
|
|
|
|
|
|
byte[] abyte = rawData;
|
|
|
|
int i1 = 0;
|
|
|
|
|
|
|
|
int j1;
|
|
|
|
|
|
|
|
for (j1 = 0; j1 < achunksection.length; ++j1) {
|
|
|
|
if (achunksection[j1] != null && (!flag || !achunksection[j1].a()) && (i & 1 << j1) != 0) {
|
|
|
|
byte[] abyte1 = achunksection[j1].g();
|
|
|
|
|
|
|
|
System.arraycopy(abyte1, 0, abyte, i1, abyte1.length);
|
|
|
|
i1 += abyte1.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NibbleArray nibblearray;
|
|
|
|
|
|
|
|
for (j1 = 0; j1 < achunksection.length; ++j1) {
|
|
|
|
if (achunksection[j1] != null && (!flag || !achunksection[j1].a()) && (i & 1 << j1) != 0) {
|
|
|
|
nibblearray = achunksection[j1].i();
|
|
|
|
System.arraycopy(nibblearray.a, 0, abyte, i1, nibblearray.a.length);
|
|
|
|
i1 += nibblearray.a.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j1 = 0; j1 < achunksection.length; ++j1) {
|
|
|
|
if (achunksection[j1] != null && (!flag || !achunksection[j1].a()) && (i & 1 << j1) != 0) {
|
|
|
|
nibblearray = achunksection[j1].j();
|
|
|
|
System.arraycopy(nibblearray.a, 0, abyte, i1, nibblearray.a.length);
|
|
|
|
i1 += nibblearray.a.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j1 = 0; j1 < achunksection.length; ++j1) {
|
|
|
|
if (achunksection[j1] != null && (!flag || !achunksection[j1].a()) && (i & 1 << j1) != 0) {
|
|
|
|
nibblearray = achunksection[j1].k();
|
|
|
|
System.arraycopy(nibblearray.a, 0, abyte, i1, nibblearray.a.length);
|
|
|
|
i1 += nibblearray.a.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k > 0) {
|
|
|
|
for (j1 = 0; j1 < achunksection.length; ++j1) {
|
|
|
|
if (achunksection[j1] != null && (!flag || !achunksection[j1].a()) && achunksection[j1].h() != null && (i & 1 << j1) != 0) {
|
|
|
|
nibblearray = achunksection[j1].h();
|
|
|
|
System.arraycopy(nibblearray.a, 0, abyte, i1, nibblearray.a.length);
|
|
|
|
i1 += nibblearray.a.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
byte[] abyte2 = chunk.l();
|
|
|
|
|
|
|
|
System.arraycopy(abyte2, 0, abyte, i1, abyte2.length);
|
|
|
|
i1 += abyte2.length;
|
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
/* CraftBukkit start - Moved compression into its own method.
|
2011-05-21 21:27:34 +02:00
|
|
|
byte[] abyte = data; // CraftBukkit - uses data from above constructor
|
2011-06-12 00:02:58 +02:00
|
|
|
Deflater deflater = new Deflater(-1);
|
2011-05-21 21:27:34 +02:00
|
|
|
|
|
|
|
try {
|
2012-03-01 11:49:23 +01:00
|
|
|
deflater.setInput(abyte, 0, i1);
|
2011-05-21 21:27:34 +02:00
|
|
|
deflater.finish();
|
2012-03-01 11:49:23 +01:00
|
|
|
this.buffer = new byte[i1];
|
2012-01-14 21:03:48 +01:00
|
|
|
this.size = deflater.deflate(this.buffer);
|
2011-05-21 21:27:34 +02:00
|
|
|
} finally {
|
|
|
|
deflater.end();
|
2012-01-14 21:03:48 +01:00
|
|
|
} */
|
2012-03-01 11:49:23 +01:00
|
|
|
this.rawData = abyte;
|
2012-01-14 21:03:48 +01:00
|
|
|
// CraftBukkit end
|
2011-05-21 21:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(DataInputStream datainputstream) throws IOException { // CraftBukkit - throws IOEXception
|
|
|
|
this.a = datainputstream.readInt();
|
2012-03-01 11:49:23 +01:00
|
|
|
this.b = datainputstream.readInt();
|
|
|
|
this.f = datainputstream.readBoolean();
|
|
|
|
this.c = datainputstream.readShort();
|
|
|
|
this.d = datainputstream.readShort();
|
2012-01-12 16:27:39 +01:00
|
|
|
this.size = datainputstream.readInt();
|
2012-03-01 11:49:23 +01:00
|
|
|
this.h = datainputstream.readInt();
|
|
|
|
if (rawData.length < this.size) {
|
|
|
|
rawData = new byte[this.size];
|
|
|
|
}
|
|
|
|
|
|
|
|
datainputstream.readFully(rawData, 0, this.size);
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 16; ++j) {
|
|
|
|
i += this.c >> j & 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
j = 12288 * i;
|
|
|
|
if (this.f) {
|
|
|
|
j += 256;
|
|
|
|
}
|
2011-05-21 21:27:34 +02:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
this.buffer = new byte[j];
|
2011-05-21 21:27:34 +02:00
|
|
|
Inflater inflater = new Inflater();
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
inflater.setInput(rawData, 0, this.size);
|
2011-05-21 21:27:34 +02:00
|
|
|
|
|
|
|
try {
|
2012-01-12 16:27:39 +01:00
|
|
|
inflater.inflate(this.buffer);
|
2011-05-21 21:27:34 +02:00
|
|
|
} catch (DataFormatException dataformatexception) {
|
|
|
|
throw new IOException("Bad compressed data format");
|
|
|
|
} finally {
|
|
|
|
inflater.end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(DataOutputStream dataoutputstream) throws IOException { // CraftBukkit - throws IOException
|
|
|
|
dataoutputstream.writeInt(this.a);
|
2012-03-01 11:49:23 +01:00
|
|
|
dataoutputstream.writeInt(this.b);
|
|
|
|
dataoutputstream.writeBoolean(this.f);
|
|
|
|
dataoutputstream.writeShort((short) (this.c & '\uffff'));
|
|
|
|
dataoutputstream.writeShort((short) (this.d & '\uffff'));
|
2012-01-12 16:27:39 +01:00
|
|
|
dataoutputstream.writeInt(this.size);
|
2012-03-01 11:49:23 +01:00
|
|
|
dataoutputstream.writeInt(this.h);
|
2012-01-12 16:27:39 +01:00
|
|
|
dataoutputstream.write(this.buffer, 0, this.size);
|
2011-05-21 21:27:34 +02:00
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public void handle(NetHandler nethandler) {
|
2011-05-21 21:27:34 +02:00
|
|
|
nethandler.a(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int a() {
|
2012-01-12 16:27:39 +01:00
|
|
|
return 17 + this.size;
|
2011-05-21 21:27:34 +02:00
|
|
|
}
|
|
|
|
}
|