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

31 lines
841 B
TypeScript
Raw Permalink Normal View History

2023-06-22 12:43:28 +01:00
import { createWriter, IReader, Endian } from "bufferstuff";
import IPacket from "./IPacket";
import Packet from "../enums/Packet";
2023-04-10 21:52:30 +01:00
const EMPTY_BUFFER = Buffer.alloc(0);
export default class PacketEntityMetadata implements IPacket {
2023-04-10 21:52:30 +01:00
public packetId = Packet.EntityMetadata;
public entityId:number;
public metadata:Buffer;
public constructor(entityId?:number, metadata?:Buffer) {
if (typeof(entityId) == "number" && metadata instanceof Buffer) {
this.entityId = entityId;
this.metadata = metadata;
} else {
this.entityId = Number.MIN_VALUE;
this.metadata = EMPTY_BUFFER;
}
}
public readData(reader:IReader) {
2023-04-10 21:52:30 +01:00
// TODO: EntityMetadata reading
return this;
}
public writeData() {
return createWriter(Endian.BE, 5).writeUByte(this.packetId).writeInt(this.entityId).writeBuffer(this.metadata).toBuffer();
2023-04-10 21:52:30 +01:00
}
}