2023-05-02 10:24:48 +01:00
|
|
|
import { Chunk } from "../Chunk";
|
|
|
|
import { createWriter } from "../../bufferStuff/index";
|
2023-04-08 20:52:47 +01:00
|
|
|
import { deflate } from "zlib";
|
2023-05-02 10:24:48 +01:00
|
|
|
import { Endian } from "../../bufferStuff/Endian";
|
2023-04-08 20:52:47 +01:00
|
|
|
import { IPacket } from "./IPacket";
|
2023-05-02 10:24:48 +01:00
|
|
|
import { IReader } from "../../bufferStuff/readers/IReader";
|
|
|
|
import { Packet } from "../enums/Packet";
|
2023-04-08 20:52:47 +01:00
|
|
|
|
|
|
|
export class PacketMapChunk implements IPacket {
|
2023-04-10 21:52:30 +01:00
|
|
|
public packetId = Packet.MapChunk;
|
2023-04-08 20:52:47 +01:00
|
|
|
public x:number;
|
|
|
|
public y:number;
|
|
|
|
public z:number;
|
|
|
|
public sizeX:number;
|
|
|
|
public sizeY:number;
|
|
|
|
public sizeZ:number;
|
|
|
|
public chunk:Chunk;
|
|
|
|
|
|
|
|
public constructor(x:number, y:number, z:number, sizeX:number, sizeY:number, sizeZ:number, chunk:Chunk) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
this.sizeX = sizeX;
|
|
|
|
this.sizeY = sizeY;
|
|
|
|
this.sizeZ = sizeZ;
|
|
|
|
this.chunk = chunk;
|
|
|
|
}
|
|
|
|
|
2023-05-02 10:24:48 +01:00
|
|
|
public readData(reader:IReader) {
|
2023-04-09 04:51:30 +01:00
|
|
|
// TODO: Implement MapChunk reading
|
|
|
|
reader.readBool();
|
2023-04-08 20:52:47 +01:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public writeData() {
|
|
|
|
return new Promise<Buffer>((resolve, reject) => {
|
2023-05-02 08:50:49 +01:00
|
|
|
// TODO: Use block and sky nibble array buffers
|
2023-05-02 10:24:48 +01:00
|
|
|
const fakeLighting = createWriter(Endian.BE, 16384);
|
2023-05-02 08:50:49 +01:00
|
|
|
for (let i = 0; i < 16384; i++) {
|
|
|
|
fakeLighting.writeUByte(0xFF);
|
2023-04-08 20:52:47 +01:00
|
|
|
}
|
|
|
|
|
2023-05-02 10:24:48 +01:00
|
|
|
const data = createWriter(Endian.BE).writeBuffer(this.chunk.getBlockBuffer()).writeBuffer(this.chunk.getMetadataBuffer()).writeBuffer(fakeLighting.toBuffer()).writeBuffer(fakeLighting.toBuffer());//.writeBuffer(this.chunk.blockLight.toBuffer()).writeBuffer(this.chunk.skyLight.toBuffer());
|
2023-04-08 20:52:47 +01:00
|
|
|
|
2023-05-02 08:50:49 +01:00
|
|
|
deflate(data.toBuffer(), (err, data) => {
|
2023-04-08 20:52:47 +01:00
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
|
2023-05-02 10:24:48 +01:00
|
|
|
resolve(createWriter(Endian.BE, 18).writeUByte(this.packetId).writeInt(this.x << 4).writeShort(this.y).writeInt(this.z << 4).writeUByte(this.sizeX).writeUByte(this.sizeY).writeUByte(this.sizeZ).writeInt(data.length).writeBuffer(data).toBuffer());
|
2023-04-08 20:52:47 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|