one chunk
This commit is contained in:
@@ -9,30 +9,62 @@ import lombok.ToString;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_125.ByteArrayOutputNetStream;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
@Setter
|
||||
@ToString
|
||||
public class ChunkDataPacket implements SCPacket {
|
||||
private static final byte[] data = new byte[65536 + 32768 + 32768 + 32768/* + 0*/ + 256];
|
||||
private static byte[] compressData = null;
|
||||
private static byte[] compressData;
|
||||
|
||||
private int x, z;
|
||||
private boolean needInitChunk;
|
||||
private int yMin,yMax;
|
||||
|
||||
static {
|
||||
byte[] blocktype = new byte[4096];
|
||||
Arrays.fill(blocktype, 0, 256, (byte)7);
|
||||
Arrays.fill(blocktype, 256, 768, (byte)3);
|
||||
Arrays.fill(blocktype, 768, 1024, (byte)2);
|
||||
Arrays.fill(blocktype, 1024, 4096, (byte)0);
|
||||
|
||||
byte[] blockmeta = new byte[2048];
|
||||
Arrays.fill(blockmeta, (byte)0);
|
||||
|
||||
byte[] blocklight = new byte[2048];
|
||||
Arrays.fill(blocklight, (byte)0);
|
||||
|
||||
byte[] skylight = new byte[2048];
|
||||
Arrays.fill(skylight, 0, 512, (byte) 0);
|
||||
Arrays.fill(skylight, 512, 2048, (byte)-1);
|
||||
|
||||
byte[] addition = new byte[2048];
|
||||
Arrays.fill(addition, 0, 256, (byte)1);
|
||||
Arrays.fill(addition, 256, 2048, (byte)0);
|
||||
|
||||
byte[] biometype = new byte[256];
|
||||
Arrays.fill(biometype, (byte)0);
|
||||
|
||||
byte[] chunkData = new byte[blocktype.length + blockmeta.length + blocklight.length + skylight.length + addition.length + biometype.length];
|
||||
System.arraycopy(blocktype, 0, chunkData, 0, blocktype.length);
|
||||
System.arraycopy(blockmeta, 0, chunkData, blocktype.length, blockmeta.length);
|
||||
System.arraycopy(blocklight, 0, chunkData, blockmeta.length, blocklight.length);
|
||||
System.arraycopy(skylight, 0, chunkData, blocklight.length, skylight.length);
|
||||
System.arraycopy(addition, 0, chunkData, skylight.length, addition.length);
|
||||
System.arraycopy(biometype, 0, chunkData, addition.length, biometype.length);
|
||||
|
||||
Deflater zlib = new Deflater(Deflater.DEFAULT_COMPRESSION);
|
||||
zlib.setInput(chunkData);
|
||||
zlib.finish();
|
||||
byte[] preCompileData = new byte[chunkData.length];
|
||||
int compressSize = zlib.deflate(preCompileData);
|
||||
|
||||
compressData = new byte[compressSize];
|
||||
System.arraycopy(preCompileData, 0, compressData, 0, compressSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
if (compressData == null) {
|
||||
Deflater zlib = new Deflater();
|
||||
zlib.setInput(data);
|
||||
byte[] preCompress = new byte[data.length];
|
||||
int len = zlib.deflate(preCompress);
|
||||
|
||||
compressData = new byte[len];
|
||||
System.arraycopy(preCompress, 0, compressData, 0, len);
|
||||
}
|
||||
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
netStream.writeInt(x);
|
||||
|
||||
Reference in New Issue
Block a user