Rework to use new bufferStuff submodule
This commit is contained in:
parent
ef1e7a278e
commit
15917f1533
|
@ -0,0 +1,3 @@
|
|||
[submodule "bufferStuff"]
|
||||
path = bufferStuff
|
||||
url = https://github.com/tgpholly/bufferStuff.git
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 02a44936ea99c3dec0f369f843882de67dccb93d
|
222
bufferStuff.ts
222
bufferStuff.ts
|
@ -1,222 +0,0 @@
|
|||
export class Reader {
|
||||
private buffer:Buffer;
|
||||
private offset:number;
|
||||
|
||||
public constructor(buffer:Buffer) {
|
||||
this.buffer = buffer;
|
||||
this.offset = 0;
|
||||
}
|
||||
|
||||
public readBuffer(bytes:number) {
|
||||
const value = this.buffer.subarray(this.offset, this.offset + bytes);
|
||||
this.offset += bytes;
|
||||
return value;
|
||||
}
|
||||
|
||||
// NOTE: This had to be a copy as the subarray is only cropped & offset
|
||||
public readUint8Array(bytes:number) {
|
||||
const croppedBuffer = this.readBuffer(bytes);
|
||||
const newArray = new Uint8Array(croppedBuffer.length);
|
||||
for (let i = 0; i < croppedBuffer.length; i++) {
|
||||
newArray[i] = croppedBuffer[i];
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
public readByte() {
|
||||
const value = this.buffer.readInt8(this.offset);
|
||||
this.offset++;
|
||||
return value;
|
||||
}
|
||||
|
||||
public readUByte() {
|
||||
const value = this.buffer.readUInt8(this.offset);
|
||||
this.offset++;
|
||||
return value;
|
||||
}
|
||||
|
||||
public readBool() {
|
||||
return Boolean(this.readUByte());
|
||||
}
|
||||
|
||||
public readShort() {
|
||||
const value = this.buffer.readInt16BE(this.offset);
|
||||
this.offset += 2
|
||||
return value;
|
||||
}
|
||||
|
||||
public readInt() {
|
||||
const value = this.buffer.readInt32BE(this.offset);
|
||||
this.offset += 4;
|
||||
return value;
|
||||
}
|
||||
|
||||
public readLong() {
|
||||
const value = this.buffer.readBigInt64BE(this.offset);
|
||||
this.offset += 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
public readFloat() {
|
||||
const value = this.buffer.readFloatBE(this.offset);
|
||||
this.offset += 4;
|
||||
return value;
|
||||
}
|
||||
|
||||
public readDouble() {
|
||||
const value = this.buffer.readDoubleBE(this.offset);
|
||||
this.offset += 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
public readString() {
|
||||
const length = this.readShort();
|
||||
let text:string = "";
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
text += String.fromCharCode(this.readShort());
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
export class Writer {
|
||||
private buffer:Buffer;
|
||||
private offset:number;
|
||||
private resizable:boolean;
|
||||
|
||||
public constructor(size:number = 0) {
|
||||
this.buffer = Buffer.alloc(size);
|
||||
this.offset = 0;
|
||||
this.resizable = size === 0;
|
||||
}
|
||||
|
||||
public toBuffer() {
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
public toString() {
|
||||
return this.buffer.toString();
|
||||
}
|
||||
|
||||
public writeBuffer(buffer:Buffer) {
|
||||
this.buffer = Buffer.concat([this.buffer, buffer], this.buffer.length + buffer.length);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeByte(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(1);
|
||||
buffer.writeInt8(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
this.buffer.writeInt8(value, this.offset);
|
||||
this.offset++;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeUByte(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(1);
|
||||
buffer.writeUInt8(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
this.buffer.writeUInt8(value, this.offset);
|
||||
this.offset++;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeBool(value:boolean|number) {
|
||||
if (typeof(value) === "number") {
|
||||
value = Boolean(value);
|
||||
}
|
||||
this.writeUByte(value ? 1 : 0);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeShort(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(2);
|
||||
buffer.writeInt16BE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
this.buffer.writeInt16BE(value, this.offset);
|
||||
this.offset += 2;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeInt(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(4);
|
||||
buffer.writeInt32BE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
this.buffer.writeInt32BE(value, this.offset);
|
||||
this.offset += 4;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeLong(value:number|bigint) {
|
||||
if (typeof(value) !== "bigint") {
|
||||
value = BigInt(value);
|
||||
}
|
||||
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(8);
|
||||
buffer.writeBigInt64BE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
this.buffer.writeBigInt64BE(value, this.offset);
|
||||
this.offset += 8;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeFloat(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(4);
|
||||
buffer.writeFloatBE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
this.buffer.writeFloatBE(value, this.offset);
|
||||
this.offset += 4;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeDouble(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(8);
|
||||
buffer.writeDoubleBE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
this.buffer.writeDoubleBE(value, this.offset);
|
||||
this.offset += 8;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeString(text:string) {
|
||||
this.writeShort(text.length);
|
||||
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
this.writeShort(text.charCodeAt(i));
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@ export class Chunk {
|
|||
this.metadata = new NibbleArray(metadata);
|
||||
this.skyLight = new NibbleArray(16 * 16 * this.MAX_HEIGHT);
|
||||
this.blockLight = new NibbleArray(16 * 16 * this.MAX_HEIGHT);
|
||||
this.calculateLighting();
|
||||
//this.calculateLighting();
|
||||
} else {
|
||||
this.blocks = new Uint8Array(16 * 16 * this.MAX_HEIGHT);
|
||||
this.metadata = new NibbleArray(16 * 16 * this.MAX_HEIGHT);
|
||||
|
@ -49,7 +49,7 @@ export class Chunk {
|
|||
|
||||
if (typeof(generateOrBlockData) === "boolean" && generateOrBlockData) {
|
||||
this.world.generator.generate(this);
|
||||
this.calculateLighting();
|
||||
//this.calculateLighting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
import { Socket } from "net";
|
||||
import { Reader, Writer } from "../bufferStuff";
|
||||
import { Console } from "../console";
|
||||
import { IReader } from "../bufferStuff/readers/IReader";
|
||||
import { MinecraftServer } from "./MinecraftServer";
|
||||
import { Packet } from "./enums/Packet";
|
||||
import { PacketAnimation } from "./packets/Animation";
|
||||
import { PacketChat } from "./packets/Chat"
|
||||
import { PacketEntityAction } from "./packets/EntityAction";
|
||||
import { PacketPlayer } from "./packets/Player";
|
||||
import { PacketPlayerPosition } from "./packets/PlayerPosition";
|
||||
import { PacketPlayerLook } from "./packets/PlayerLook";
|
||||
import { PacketPlayerPositionLook } from "./packets/PlayerPositionLook";
|
||||
import { Player } from "./entities/Player";
|
||||
import { PacketChat } from "./packets/Chat";
|
||||
import { MinecraftServer } from "./MinecraftServer";
|
||||
import { Vec3 } from "./Vec3";
|
||||
import { Console } from "../console";
|
||||
import { PacketPlayerDigging } from "./packets/PlayerDigging";
|
||||
import { PacketAnimation } from "./packets/Animation";
|
||||
import { PacketEntityAction } from "./packets/EntityAction";
|
||||
import { IPacket } from "./packets/IPacket";
|
||||
import { Animation } from "./enums/Animation";
|
||||
import { Player } from "./entities/Player";
|
||||
import { Socket } from "net";
|
||||
import { Vec3 } from "./Vec3";
|
||||
|
||||
export class MPClient {
|
||||
private readonly mcServer:MinecraftServer;
|
||||
|
@ -54,7 +52,7 @@ export class MPClient {
|
|||
}
|
||||
}
|
||||
|
||||
public handlePacket(reader:Reader) {
|
||||
public handlePacket(reader:IReader) {
|
||||
const packetId = reader.readUByte();
|
||||
|
||||
switch (packetId) {
|
||||
|
@ -161,11 +159,7 @@ export class MPClient {
|
|||
}
|
||||
}
|
||||
|
||||
public send(buffer:Buffer|Writer) {
|
||||
if (buffer instanceof Writer) {
|
||||
this.socket.write(buffer.toBuffer());
|
||||
} else {
|
||||
this.socket.write(buffer);
|
||||
}
|
||||
public send(buffer:Buffer) {
|
||||
this.socket.write(buffer);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import { Writer } from "../bufferStuff";
|
||||
import { createWriter } from "../bufferStuff/index";
|
||||
import { Endian } from "../bufferStuff/Endian";
|
||||
import { FunkyArray } from "../funkyArray";
|
||||
import { MetadataFieldType } from "./enums/MetadataFieldType";
|
||||
|
||||
|
@ -43,7 +44,7 @@ export class MetadataWriter {
|
|||
}
|
||||
|
||||
public writeBuffer() {
|
||||
const writer = new Writer(this.calculateBufferSize());
|
||||
const writer = createWriter(Endian.BE, this.calculateBufferSize());
|
||||
for (let key of this.entries.keys) {
|
||||
const entry = this.entries.get(key);
|
||||
if (entry instanceof MetadataEntry) {
|
||||
|
@ -56,7 +57,7 @@ export class MetadataWriter {
|
|||
case MetadataFieldType.Float: writer.writeFloat(entry.value); break;
|
||||
}
|
||||
} else if (typeof(entry.value) === "string") {
|
||||
writer.writeString(entry.value);
|
||||
writer.writeString16(entry.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
import { Config } from "../config";
|
||||
import { Console } from "../console";
|
||||
import { Server, Socket, SocketAddress } from "net";
|
||||
import { createReader } from "../bufferStuff/index";
|
||||
import { FunkyArray } from "../funkyArray";
|
||||
import { World } from "./World";
|
||||
import { Reader } from "../bufferStuff";
|
||||
import { Packet } from "./enums/Packet";
|
||||
import { PacketHandshake } from "./packets/Handshake";
|
||||
import { IReader } from "../bufferStuff/readers/IReader";
|
||||
import { Server, Socket, SocketAddress } from "net";
|
||||
import { MPClient } from "./MPClient";
|
||||
import { Packet } from "./enums/Packet";
|
||||
import { PacketKeepAlive } from "./packets/KeepAlive";
|
||||
import { PacketHandshake } from "./packets/Handshake";
|
||||
import { PacketLoginRequest } from "./packets/LoginRequest";
|
||||
import { PacketDisconnectKick } from "./packets/DisconnectKick";
|
||||
import { Player } from "./entities/Player";
|
||||
import { PacketChat } from "./packets/Chat";
|
||||
import { PacketSpawnPosition } from "./packets/SpawnPosition";
|
||||
import { PacketPlayerPositionLook } from "./packets/PlayerPositionLook";
|
||||
import { PacketChat } from "./packets/Chat";
|
||||
import { PacketNamedEntitySpawn } from "./packets/NamedEntitySpawn";
|
||||
import { WorldSaveManager } from "./WorldSaveManager";
|
||||
import { PacketDisconnectKick } from "./packets/DisconnectKick";
|
||||
import { Player } from "./entities/Player";
|
||||
import { SaveCompressionType } from "./enums/SaveCompressionType";
|
||||
import { WorldSaveManager } from "./WorldSaveManager";
|
||||
import { World } from "./World";
|
||||
import { Endian } from "../bufferStuff/Endian";
|
||||
|
||||
export class MinecraftServer {
|
||||
private static readonly PROTOCOL_VERSION = 14;
|
||||
|
@ -111,7 +113,7 @@ export class MinecraftServer {
|
|||
});
|
||||
}
|
||||
|
||||
handleLoginRequest(reader:Reader, socket:Socket, setMPClient:(mpclient:MPClient) => void) {
|
||||
handleLoginRequest(reader:IReader, socket:Socket, setMPClient:(mpclient:MPClient) => void) {
|
||||
const loginPacket = new PacketLoginRequest().readData(reader);
|
||||
if (loginPacket.protocolVersion !== MinecraftServer.PROTOCOL_VERSION) {
|
||||
if (loginPacket.protocolVersion > MinecraftServer.PROTOCOL_VERSION) {
|
||||
|
@ -151,7 +153,7 @@ export class MinecraftServer {
|
|||
}
|
||||
}
|
||||
|
||||
handleHandshake(reader:Reader, socket:Socket) {
|
||||
handleHandshake(reader:IReader, socket:Socket) {
|
||||
const handshakePacket = new PacketHandshake().readData(reader);
|
||||
socket.write(handshakePacket.writeData());
|
||||
}
|
||||
|
@ -174,7 +176,7 @@ export class MinecraftServer {
|
|||
socket.on("error", playerDisconnect.bind(this));
|
||||
|
||||
socket.on("data", chunk => {
|
||||
const reader = new Reader(chunk);
|
||||
const reader = createReader(Endian.BE, chunk);
|
||||
|
||||
// Let mpClient take over if it exists
|
||||
if (mpClient instanceof MPClient) {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { readFileSync, readFile, writeFile, existsSync, mkdirSync, writeFileSync, readdirSync } from "fs";
|
||||
import { Reader, Writer } from "../bufferStuff";
|
||||
import { createWriter, createReader } from "../bufferStuff/index";
|
||||
import { Config } from "../config";
|
||||
import { Chunk } from "./Chunk";
|
||||
import { SaveCompressionType } from "./enums/SaveCompressionType";
|
||||
import { deflate, inflate } from "zlib";
|
||||
import { World } from "./World";
|
||||
import { Endian } from "../bufferStuff/Endian";
|
||||
|
||||
export class WorldSaveManager {
|
||||
private readonly worldFolderPath;
|
||||
|
@ -61,7 +62,7 @@ export class WorldSaveManager {
|
|||
}
|
||||
|
||||
private createInfoFile(numericalSeed:number) {
|
||||
const infoFileWriter = new Writer(26);
|
||||
const infoFileWriter = createWriter(Endian.BE, 26);
|
||||
infoFileWriter.writeUByte(0xFD); // Info File Magic
|
||||
infoFileWriter.writeUByte(0); // File Version
|
||||
infoFileWriter.writeLong(this.worldCreationDate.getTime()); // World creation date
|
||||
|
@ -71,7 +72,7 @@ export class WorldSaveManager {
|
|||
}
|
||||
|
||||
private readInfoFile() {
|
||||
const infoFileReader = new Reader(readFileSync(this.infoFilePath));
|
||||
const infoFileReader = createReader(Endian.BE, readFileSync(this.infoFilePath));
|
||||
const fileMagic = infoFileReader.readUByte();
|
||||
if (fileMagic !== 0xFD) {
|
||||
throw new Error("World info file is invalid");
|
||||
|
@ -88,7 +89,7 @@ export class WorldSaveManager {
|
|||
public writeChunkToDisk(chunk:Chunk) {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
const saveType = this.config.saveCompression;
|
||||
const chunkFileWriter = new Writer(10);
|
||||
const chunkFileWriter = createWriter(Endian.BE, 10);
|
||||
chunkFileWriter.writeUByte(0xFC); // Chunk File Magic
|
||||
// TODO: Change to 1 when lighting actually works
|
||||
chunkFileWriter.writeUByte(0); // File Version
|
||||
|
@ -97,7 +98,7 @@ export class WorldSaveManager {
|
|||
chunkFileWriter.writeUByte(128); // Chunk Y
|
||||
chunkFileWriter.writeUByte(16); // Chunk Z
|
||||
|
||||
const chunkData = new Writer()
|
||||
const chunkData = createWriter(Endian.BE)
|
||||
.writeBuffer(Buffer.from(chunk.getData()))
|
||||
.writeBuffer(chunk.getMetadataBuffer()).toBuffer()
|
||||
//.writeBuffer(chunk.getBlockLightBuffer())
|
||||
|
@ -146,7 +147,7 @@ export class WorldSaveManager {
|
|||
return reject(err);
|
||||
}
|
||||
|
||||
const chunkFileReader = new Reader(data);
|
||||
const chunkFileReader = createReader(Endian.BE, data);
|
||||
|
||||
// Check file validity
|
||||
if (chunkFileReader.readUByte() !== 0xFC) {
|
||||
|
@ -163,7 +164,7 @@ export class WorldSaveManager {
|
|||
|
||||
const contentLength = chunkFileReader.readInt();
|
||||
if (saveCompressionType === SaveCompressionType.NONE) {
|
||||
const chunkData = new Reader(chunkFileReader.readBuffer(contentLength));
|
||||
const chunkData = createReader(Endian.BE, chunkFileReader.readBuffer(contentLength));
|
||||
const chunk = new Chunk(world, x, z, chunkData.readUint8Array(totalByteSize), chunkData.readUint8Array(totalByteSize / 2));
|
||||
resolve(chunk);
|
||||
} else if (saveCompressionType === SaveCompressionType.DEFLATE) {
|
||||
|
@ -172,7 +173,7 @@ export class WorldSaveManager {
|
|||
return reject(err);
|
||||
}
|
||||
|
||||
const chunkData = new Reader(data);
|
||||
const chunkData = createReader(Endian.BE, data);
|
||||
const chunk = new Chunk(world, x, z, chunkData.readUint8Array(totalByteSize), chunkData.readUint8Array(totalByteSize / 2));
|
||||
resolve(chunk);
|
||||
});
|
||||
|
@ -186,7 +187,7 @@ export class WorldSaveManager {
|
|||
|
||||
const contentLength = chunkFileReader.readInt();
|
||||
if (saveCompressionType === SaveCompressionType.NONE) {
|
||||
const chunkData = new Reader(chunkFileReader.readBuffer(contentLength));
|
||||
const chunkData = createReader(Endian.BE, chunkFileReader.readBuffer(contentLength));
|
||||
const chunk = new Chunk(world, x, z, chunkData.readUint8Array(totalByteSize), chunkData.readUint8Array(totalByteSize / 2));
|
||||
resolve(chunk);
|
||||
} else if (saveCompressionType === SaveCompressionType.DEFLATE) {
|
||||
|
@ -195,7 +196,7 @@ export class WorldSaveManager {
|
|||
return reject(err);
|
||||
}
|
||||
|
||||
const chunkData = new Reader(data);
|
||||
const chunkData = createReader(Endian.BE, data);
|
||||
const chunk = new Chunk(world, x, z, chunkData.readUint8Array(totalByteSize), chunkData.readUint8Array(totalByteSize / 2), chunkData.readUint8Array(totalByteSize / 2), chunkData.readUint8Array(totalByteSize / 2));
|
||||
resolve(chunk);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketAnimation implements IPacket {
|
||||
public packetId = Packet.Animation;
|
||||
|
@ -17,7 +19,7 @@ export class PacketAnimation implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
this.animation = reader.readByte();
|
||||
|
||||
|
@ -25,6 +27,6 @@ export class PacketAnimation implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(6).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.animation).toBuffer();
|
||||
return createWriter(Endian.BE, 6).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.animation).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketBlockChange implements IPacket {
|
||||
public packetId = Packet.BlockChange;
|
||||
|
@ -26,7 +28,7 @@ export class PacketBlockChange implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.x = reader.readInt();
|
||||
this.y = reader.readByte();
|
||||
this.z = reader.readInt();
|
||||
|
@ -37,6 +39,6 @@ export class PacketBlockChange implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(12).writeUByte(this.packetId).writeInt(this.x).writeByte(this.y).writeInt(this.z).writeByte(this.blockType).writeByte(this.blockMetadata).toBuffer();
|
||||
return createWriter(Endian.BE, 12).writeUByte(this.packetId).writeInt(this.x).writeByte(this.y).writeInt(this.z).writeByte(this.blockType).writeByte(this.blockMetadata).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketChat implements IPacket {
|
||||
public packetId = Packet.Chat;
|
||||
|
@ -14,13 +16,13 @@ export class PacketChat implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
this.message = reader.readString();
|
||||
public readData(reader:IReader) {
|
||||
this.message = reader.readString16();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(3 + this.message.length * 2).writeUByte(this.packetId).writeString(this.message).toBuffer();
|
||||
return createWriter(Endian.BE, 3 + this.message.length * 2).writeUByte(this.packetId).writeString16(this.message).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketDisconnectKick implements IPacket {
|
||||
public packetId = Packet.DisconnectKick;
|
||||
|
@ -14,12 +16,12 @@ export class PacketDisconnectKick implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
this.reason = reader.readString();
|
||||
public readData(reader:IReader) {
|
||||
this.reason = reader.readString16();
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(3 + this.reason.length * 2).writeUByte(this.packetId).writeString(this.reason).toBuffer();
|
||||
return createWriter(Endian.BE, 3 + this.reason.length * 2).writeUByte(this.packetId).writeString16(this.reason).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketEntity implements IPacket {
|
||||
public packetId = Packet.Entity;
|
||||
|
@ -14,13 +16,13 @@ export class PacketEntity implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(5).writeUByte(this.packetId).writeInt(this.entityId).toBuffer();
|
||||
return createWriter(Endian.BE, 5).writeUByte(this.packetId).writeInt(this.entityId).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketEntityAction implements IPacket {
|
||||
public packetId = Packet.EntityAction;
|
||||
|
@ -17,7 +19,7 @@ export class PacketEntityAction implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
this.action = reader.readByte();
|
||||
|
||||
|
@ -25,6 +27,6 @@ export class PacketEntityAction implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(6).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.action).toBuffer();
|
||||
return createWriter(Endian.BE, 6).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.action).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketEntityEquipment implements IPacket {
|
||||
public packetId = Packet.EntityEquipment;
|
||||
|
@ -16,7 +18,7 @@ export class PacketEntityEquipment implements IPacket {
|
|||
this.damage = damage;
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
this.slot = reader.readShort();
|
||||
this.itemId = reader.readShort();
|
||||
|
@ -26,6 +28,6 @@ export class PacketEntityEquipment implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(10).writeUByte(this.packetId).writeInt(this.entityId).writeShort(this.slot).writeShort(this.itemId).writeShort(this.damage).toBuffer();
|
||||
return createWriter(Endian.BE, 10).writeUByte(this.packetId).writeInt(this.entityId).writeShort(this.slot).writeShort(this.itemId).writeShort(this.damage).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketEntityLook implements IPacket {
|
||||
public packetId = Packet.EntityLook;
|
||||
|
@ -20,7 +22,7 @@ export class PacketEntityLook implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
this.yaw = reader.readByte();
|
||||
this.pitch = reader.readByte();
|
||||
|
@ -29,6 +31,6 @@ export class PacketEntityLook implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(7).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.yaw).writeByte(this.pitch).toBuffer();
|
||||
return createWriter(Endian.BE, 7).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.yaw).writeByte(this.pitch).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketEntityLookRelativeMove implements IPacket {
|
||||
public packetId = Packet.EntityLookRelativeMove;
|
||||
|
@ -29,7 +31,7 @@ export class PacketEntityLookRelativeMove implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
this.dX = reader.readByte();
|
||||
this.dY = reader.readByte();
|
||||
|
@ -41,6 +43,6 @@ export class PacketEntityLookRelativeMove implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(10).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.dX).writeByte(this.dY).writeByte(this.dZ).writeByte(this.yaw).writeByte(this.pitch).toBuffer();
|
||||
return createWriter(Endian.BE, 10).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.dX).writeByte(this.dY).writeByte(this.dZ).writeByte(this.yaw).writeByte(this.pitch).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
const EMPTY_BUFFER = Buffer.alloc(0);
|
||||
|
||||
|
@ -19,13 +21,13 @@ export class PacketEntityMetadata implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
// TODO: EntityMetadata reading
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(5).writeUByte(this.packetId).writeInt(this.entityId).writeBuffer(this.metadata).toBuffer();
|
||||
return createWriter(Endian.BE, 5).writeUByte(this.packetId).writeInt(this.entityId).writeBuffer(this.metadata).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketEntityRelativeMove implements IPacket {
|
||||
public packetId = Packet.EntityRelativeMove;
|
||||
|
@ -23,7 +25,7 @@ export class PacketEntityRelativeMove implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
this.dX = reader.readByte();
|
||||
this.dY = reader.readByte();
|
||||
|
@ -33,6 +35,6 @@ export class PacketEntityRelativeMove implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(8).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.dX).writeByte(this.dY).writeByte(this.dZ).toBuffer();
|
||||
return createWriter(Endian.BE, 8).writeUByte(this.packetId).writeInt(this.entityId).writeByte(this.dX).writeByte(this.dY).writeByte(this.dZ).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketEntityTeleport implements IPacket {
|
||||
public packetId = Packet.EntityTeleport;
|
||||
|
@ -29,7 +31,7 @@ export class PacketEntityTeleport implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
this.x = reader.readInt();
|
||||
this.y = reader.readInt();
|
||||
|
@ -41,6 +43,6 @@ export class PacketEntityTeleport implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(19).writeUByte(this.packetId).writeInt(this.entityId).writeInt(this.x).writeInt(this.y).writeInt(this.z).writeByte(this.yaw).writeByte(this.pitch).toBuffer();
|
||||
return createWriter(Endian.BE, 19).writeUByte(this.packetId).writeInt(this.entityId).writeInt(this.x).writeInt(this.y).writeInt(this.z).writeByte(this.yaw).writeByte(this.pitch).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createReader, createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketHandshake implements IPacket {
|
||||
public packetId:Packet = Packet.Handshake;
|
||||
|
@ -14,13 +16,13 @@ export class PacketHandshake implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
this.username = reader.readString();
|
||||
public readData(reader:IReader) {
|
||||
this.username = reader.readString16();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(5).writeUByte(this.packetId).writeString("-").toBuffer();
|
||||
return createWriter(Endian.BE, 5).writeUByte(this.packetId).writeString16("-").toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import { Reader } from "../../bufferStuff";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export interface IPacket {
|
||||
packetId: Packet,
|
||||
readData: (reader:Reader) => IPacket,
|
||||
readData: (reader:IReader) => IPacket,
|
||||
writeData: () => Buffer|Promise<Buffer>
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketKeepAlive implements IPacket {
|
||||
public packetId = Packet.KeepAlive;
|
||||
private static readonly KeepAliveBuffer:Buffer = new Writer(1).writeByte(Packet.KeepAlive).toBuffer();
|
||||
private static readonly KeepAliveBuffer:Buffer = createWriter(Endian.BE, 1).writeByte(Packet.KeepAlive).toBuffer();
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
reader;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketLoginRequest implements IPacket {
|
||||
public packetId = Packet.LoginRequest;
|
||||
|
@ -23,9 +25,9 @@ export class PacketLoginRequest implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.protocolVersion = reader.readInt();
|
||||
this.username = reader.readString();
|
||||
this.username = reader.readString16();
|
||||
this.mapSeed = Number(reader.readLong());
|
||||
this.dimension = reader.readByte();
|
||||
|
||||
|
@ -33,6 +35,6 @@ export class PacketLoginRequest implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(16 + (2 * this.username.length)).writeUByte(this.packetId).writeInt(this.protocolVersion).writeString(this.username).writeLong(this.mapSeed).writeByte(this.dimension).toBuffer();
|
||||
return createWriter(Endian.BE, 16 + (2 * this.username.length)).writeUByte(this.packetId).writeInt(this.protocolVersion).writeString16(this.username).writeLong(this.mapSeed).writeByte(this.dimension).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
import { deflate } from "zlib";
|
||||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { Chunk } from "../Chunk";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { deflate } from "zlib";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketMapChunk implements IPacket {
|
||||
public packetId = Packet.MapChunk;
|
||||
|
@ -24,7 +26,7 @@ export class PacketMapChunk implements IPacket {
|
|||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
// TODO: Implement MapChunk reading
|
||||
reader.readBool();
|
||||
|
||||
|
@ -34,19 +36,19 @@ export class PacketMapChunk implements IPacket {
|
|||
public writeData() {
|
||||
return new Promise<Buffer>((resolve, reject) => {
|
||||
// TODO: Use block and sky nibble array buffers
|
||||
const fakeLighting = new Writer(16384);
|
||||
const fakeLighting = createWriter(Endian.BE, 16384);
|
||||
for (let i = 0; i < 16384; i++) {
|
||||
fakeLighting.writeUByte(0xFF);
|
||||
}
|
||||
|
||||
const data = new Writer().writeBuffer(this.chunk.getBlockBuffer()).writeBuffer(this.chunk.getMetadataBuffer()).writeBuffer(fakeLighting.toBuffer()).writeBuffer(fakeLighting.toBuffer());//.writeBuffer(this.chunk.blockLight.toBuffer()).writeBuffer(this.chunk.skyLight.toBuffer());
|
||||
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());
|
||||
|
||||
deflate(data.toBuffer(), (err, data) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
resolve(new Writer(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());
|
||||
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());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketNamedEntitySpawn implements IPacket {
|
||||
public packetId = Packet.NamedEntitySpawn;
|
||||
|
@ -35,9 +37,9 @@ export class PacketNamedEntitySpawn implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.entityId = reader.readInt();
|
||||
this.playerName = reader.readString();
|
||||
this.playerName = reader.readString16();
|
||||
this.x = reader.readInt();
|
||||
this.y = reader.readInt();
|
||||
this.z = reader.readInt();
|
||||
|
@ -48,6 +50,6 @@ export class PacketNamedEntitySpawn implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(23 + this.playerName.length * 2).writeUByte(this.packetId).writeInt(this.entityId).writeString(this.playerName).writeInt(this.x).writeInt(this.y).writeInt(this.z).writeByte(this.yaw).writeByte(this.pitch).writeShort(this.currentItem).toBuffer();
|
||||
return createWriter(Endian.BE, 23 + this.playerName.length * 2).writeUByte(this.packetId).writeInt(this.entityId).writeString16(this.playerName).writeInt(this.x).writeInt(this.y).writeInt(this.z).writeByte(this.yaw).writeByte(this.pitch).writeShort(this.currentItem).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketPlayer implements IPacket {
|
||||
public packetId = Packet.Player;
|
||||
|
@ -14,13 +16,13 @@ export class PacketPlayer implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.onGround = reader.readBool();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(2).writeUByte(this.packetId).writeBool(this.onGround).toBuffer();
|
||||
return createWriter(Endian.BE, 2).writeUByte(this.packetId).writeBool(this.onGround).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketPlayerDigging implements IPacket {
|
||||
public packetId = Packet.PlayerDigging;
|
||||
|
@ -26,7 +28,7 @@ export class PacketPlayerDigging implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.status = reader.readByte();
|
||||
this.x = reader.readInt();
|
||||
this.y = reader.readByte();
|
||||
|
@ -37,6 +39,6 @@ export class PacketPlayerDigging implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(12).writeUByte(this.packetId).writeByte(this.status).writeInt(this.x).writeByte(this.y).writeInt(this.z).writeByte(this.face).toBuffer();
|
||||
return createWriter(Endian.BE, 12).writeUByte(this.packetId).writeByte(this.status).writeInt(this.x).writeByte(this.y).writeInt(this.z).writeByte(this.face).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketPlayerLook implements IPacket {
|
||||
public packetId = Packet.Player;
|
||||
|
@ -20,7 +22,7 @@ export class PacketPlayerLook implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.yaw = reader.readFloat();
|
||||
this.pitch = reader.readFloat();
|
||||
this.onGround = reader.readBool();
|
||||
|
@ -29,6 +31,6 @@ export class PacketPlayerLook implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(10).writeUByte(this.packetId).writeFloat(this.yaw).writeFloat(this.pitch).writeBool(this.onGround).toBuffer();
|
||||
return createWriter(Endian.BE, 10).writeUByte(this.packetId).writeFloat(this.yaw).writeFloat(this.pitch).writeBool(this.onGround).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketPlayerPosition implements IPacket {
|
||||
public packetId = Packet.PlayerPosition;
|
||||
|
@ -26,7 +28,7 @@ export class PacketPlayerPosition implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.x = reader.readDouble();
|
||||
this.y = reader.readDouble();
|
||||
this.stance = reader.readDouble();
|
||||
|
@ -37,6 +39,6 @@ export class PacketPlayerPosition implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(34).writeUByte(this.packetId).writeDouble(this.x).writeDouble(this.y).writeDouble(this.stance).writeDouble(this.z).writeBool(this.onGround).toBuffer();
|
||||
return createWriter(Endian.BE, 34).writeUByte(this.packetId).writeDouble(this.x).writeDouble(this.y).writeDouble(this.stance).writeDouble(this.z).writeBool(this.onGround).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketPlayerPositionLook implements IPacket {
|
||||
public packetId = Packet.PlayerPosition;
|
||||
|
@ -32,7 +34,7 @@ export class PacketPlayerPositionLook implements IPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.x = reader.readDouble();
|
||||
this.y = reader.readDouble();
|
||||
this.stance = reader.readDouble();
|
||||
|
@ -45,6 +47,6 @@ export class PacketPlayerPositionLook implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(42).writeUByte(this.packetId).writeDouble(this.x).writeDouble(this.y).writeDouble(this.stance).writeDouble(this.z).writeFloat(this.yaw).writeFloat(this.pitch).writeBool(this.onGround).toBuffer();
|
||||
return createWriter(Endian.BE, 42).writeUByte(this.packetId).writeDouble(this.x).writeDouble(this.y).writeDouble(this.stance).writeDouble(this.z).writeFloat(this.yaw).writeFloat(this.pitch).writeBool(this.onGround).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketPreChunk implements IPacket {
|
||||
public packetId = Packet.PreChunk;
|
||||
|
@ -14,7 +16,7 @@ export class PacketPreChunk implements IPacket {
|
|||
this.mode = mode;
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.x = reader.readInt();
|
||||
this.z = reader.readInt();
|
||||
this.mode = reader.readBool();
|
||||
|
@ -23,6 +25,6 @@ export class PacketPreChunk implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(10).writeUByte(this.packetId).writeInt(this.x).writeInt(this.z).writeBool(this.mode).toBuffer();
|
||||
return createWriter(Endian.BE, 10).writeUByte(this.packetId).writeInt(this.x).writeInt(this.z).writeBool(this.mode).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketRespawn implements IPacket {
|
||||
public packetId = Packet.Respawn;
|
||||
|
@ -10,13 +12,13 @@ export class PacketRespawn implements IPacket {
|
|||
this.health = health;
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.health = reader.readShort();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(3).writeUByte(this.packetId).writeShort(this.health).toBuffer();
|
||||
return createWriter(Endian.BE, 3).writeUByte(this.packetId).writeShort(this.health).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketSpawnPosition implements IPacket {
|
||||
public packetId = Packet.SpawnPosition;
|
||||
|
@ -14,7 +16,7 @@ export class PacketSpawnPosition implements IPacket {
|
|||
this.z = z;
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.x = reader.readInt();
|
||||
this.y = reader.readInt();
|
||||
this.z = reader.readInt();
|
||||
|
@ -23,6 +25,6 @@ export class PacketSpawnPosition implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(13).writeUByte(this.packetId).writeInt(this.x).writeInt(this.y).writeInt(this.z).toBuffer();
|
||||
return createWriter(Endian.BE, 13).writeUByte(this.packetId).writeInt(this.x).writeInt(this.y).writeInt(this.z).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketTimeUpdate implements IPacket {
|
||||
public packetId = Packet.TimeUpdate;
|
||||
|
@ -10,13 +12,13 @@ export class PacketTimeUpdate implements IPacket {
|
|||
this.time = time;
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.time = reader.readLong();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(9).writeUByte(this.packetId).writeLong(this.time).toBuffer();
|
||||
return createWriter(Endian.BE, 9).writeUByte(this.packetId).writeLong(this.time).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketUpdateHealth implements IPacket {
|
||||
public packetId = Packet.UpdateHealth;
|
||||
|
@ -10,13 +12,13 @@ export class PacketUpdateHealth implements IPacket {
|
|||
this.health = health;
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.health = reader.readShort();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(3).writeUByte(this.packetId).writeShort(this.health).toBuffer();
|
||||
return createWriter(Endian.BE, 3).writeUByte(this.packetId).writeShort(this.health).toBuffer();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import { Reader, Writer } from "../../bufferStuff";
|
||||
import { Packet } from "../enums/Packet";
|
||||
import { createWriter } from "../../bufferStuff/index";
|
||||
import { Endian } from "../../bufferStuff/Endian";
|
||||
import { IPacket } from "./IPacket";
|
||||
import { IReader } from "../../bufferStuff/readers/IReader";
|
||||
import { Packet } from "../enums/Packet";
|
||||
|
||||
export class PacketUseEntity implements IPacket {
|
||||
public packetId = Packet.UseEntity;
|
||||
|
@ -14,7 +16,7 @@ export class PacketUseEntity implements IPacket {
|
|||
this.leftClick = leftClick;
|
||||
}
|
||||
|
||||
public readData(reader:Reader) {
|
||||
public readData(reader:IReader) {
|
||||
this.userId = reader.readInt();
|
||||
this.targetId = reader.readInt();
|
||||
this.leftClick = reader.readBool();
|
||||
|
@ -23,6 +25,6 @@ export class PacketUseEntity implements IPacket {
|
|||
}
|
||||
|
||||
public writeData() {
|
||||
return new Writer(10).writeUByte(this.packetId).writeInt(this.userId).writeInt(this.targetId).writeBool(this.leftClick).toBuffer();
|
||||
return createWriter(Endian.BE, 10).writeUByte(this.packetId).writeInt(this.userId).writeInt(this.targetId).writeBool(this.leftClick).toBuffer();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue