Flat world
This commit is contained in:
@@ -8,55 +8,37 @@ import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_125.ByteArrayOutputNetStream;
|
||||
import mc.core.world.Chunk;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
@Setter
|
||||
@ToString
|
||||
public class ChunkDataPacket implements SCPacket {
|
||||
private static byte[] compressData;
|
||||
private static final int dataSize = 4096 + 2048 + 2048 + 2048 + 2048 + 256;
|
||||
|
||||
private int x, z;
|
||||
private boolean needInitChunk;
|
||||
private int yMin,yMax;
|
||||
private byte[] compressData;
|
||||
|
||||
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);
|
||||
public void setChunk(Chunk chunk) {
|
||||
ByteBuffer chunkData = ByteBuffer.allocate(dataSize);
|
||||
|
||||
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);
|
||||
Arrays.stream(chunk.getBlockTypeAsArray()).forEach(i -> chunkData.put((byte) i));
|
||||
Arrays.stream(chunk.getBlockMetadataAsArray()).forEach(i -> chunkData.put((byte) i));
|
||||
Arrays.stream(chunk.getBlockLightAsArray()).forEach(i -> chunkData.put((byte) i));
|
||||
Arrays.stream(chunk.getSkyLightAsArray()).forEach(i -> chunkData.put((byte) i));
|
||||
Arrays.stream(chunk.getAdditionAsArray()).forEach(i -> chunkData.put((byte) i));
|
||||
Arrays.stream(chunk.getBiomeAsArray()).forEach(i -> chunkData.put((byte) i));
|
||||
|
||||
Deflater zlib = new Deflater(Deflater.DEFAULT_COMPRESSION);
|
||||
zlib.setInput(chunkData);
|
||||
zlib.setInput(chunkData.array());
|
||||
zlib.finish();
|
||||
byte[] preCompileData = new byte[chunkData.length];
|
||||
byte[] preCompileData = new byte[dataSize];
|
||||
int compressSize = zlib.deflate(preCompileData);
|
||||
|
||||
compressData = new byte[compressSize];
|
||||
|
||||
Reference in New Issue
Block a user