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;
|
||||
|
||||
@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);
|
||||
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);
|
||||
|
||||
compressData = new byte[len];
|
||||
System.arraycopy(preCompress, 0, compressData, 0, len);
|
||||
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() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
netStream.writeInt(x);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
}
|
||||
|
||||
public void onLoginPacket(Channel channel, LoginPacket packet) {
|
||||
final Location spawnLoc = new Location(0, 65, 0);
|
||||
final Location spawnLoc = new Location(0, 6, 0);
|
||||
Player player;
|
||||
|
||||
Optional<Player> optPlayer = playerManager.getPlayer(packet.getPlayerName());
|
||||
@@ -120,41 +120,15 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
chInitPkt.setInitChunk(true);
|
||||
channel.write(chInitPkt);
|
||||
|
||||
for (int x = -17; x <= 17; x++) {
|
||||
for (int z = -17; z <= 17; z++) {
|
||||
if (x == 0 && z == 0) continue;
|
||||
|
||||
chInitPkt = new ChunkAllocationPacket();
|
||||
chInitPkt.setX(x);
|
||||
chInitPkt.setZ(z);
|
||||
chInitPkt.setInitChunk(true);
|
||||
channel.write(chInitPkt);
|
||||
}
|
||||
}
|
||||
|
||||
// send Chunk data
|
||||
ChunkDataPacket chDataPkt = new ChunkDataPacket();
|
||||
chDataPkt.setX(0);
|
||||
chDataPkt.setZ(0);
|
||||
chDataPkt.setNeedInitChunk(false);
|
||||
chDataPkt.setYMin(0);
|
||||
chDataPkt.setNeedInitChunk(true);
|
||||
chDataPkt.setYMin(1);
|
||||
chDataPkt.setYMax(0);
|
||||
channel.write(chDataPkt);
|
||||
|
||||
for (int x = -17; x <= 17; x++) {
|
||||
for (int z = -17; z <= 17; z++) {
|
||||
if (x == 0 && z == 0) continue;
|
||||
|
||||
chDataPkt = new ChunkDataPacket();
|
||||
chDataPkt.setX(x);
|
||||
chDataPkt.setZ(z);
|
||||
chDataPkt.setNeedInitChunk(false);
|
||||
chDataPkt.setYMin(0);
|
||||
chDataPkt.setYMax(0);
|
||||
channel.write(chDataPkt);
|
||||
}
|
||||
}
|
||||
|
||||
// send Position and look
|
||||
PositionAndLookPacket posLookPkt = new PositionAndLookPacket();
|
||||
posLookPkt.setLocation(player.getLocation());
|
||||
|
||||
Reference in New Issue
Block a user