mc-beta-server/server/packets/PlayerDigging.ts

44 lines
1.3 KiB
TypeScript
Raw Normal View History

import { createWriter } from "../../bufferStuff/index";
import { Endian } from "../../bufferStuff/Endian";
2023-04-10 14:42:14 +01:00
import { IPacket } from "./IPacket";
import { IReader } from "../../bufferStuff/readers/IReader";
import { Packet } from "../enums/Packet";
2023-04-10 14:42:14 +01:00
export class PacketPlayerDigging implements IPacket {
2023-04-10 21:52:30 +01:00
public packetId = Packet.PlayerDigging;
2023-04-10 14:42:14 +01:00
public status:number;
public x:number;
public y:number;
public z:number;
public face:number;
public constructor(status?:number, x?:number, y?:number, z?:number, face?:number) {
if (typeof(status) == "number" && typeof(x) === "number" && typeof(y) === "number" && typeof(z) === "number" && typeof(face) === "number") {
this.status = status;
this.x = x;
this.y = y;
this.z = z;
this.face = face;
} else {
this.status = Number.MIN_VALUE;
this.x = Number.MIN_VALUE;
this.y = Number.MIN_VALUE;
this.z = Number.MIN_VALUE;
this.face = Number.MIN_VALUE;
}
}
public readData(reader:IReader) {
2023-04-10 14:42:14 +01:00
this.status = reader.readByte();
this.x = reader.readInt();
this.y = reader.readByte();
this.z = reader.readInt();
this.face = reader.readByte();
return this;
}
public writeData() {
return createWriter(Endian.BE, 12).writeUByte(this.packetId).writeByte(this.status).writeInt(this.x).writeByte(this.y).writeInt(this.z).writeByte(this.face).toBuffer();
2023-04-10 14:42:14 +01:00
}
}