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

33 lines
948 B
TypeScript
Raw Normal View History

import { createWriter } from "../../bufferStuff/index";
import { Endian } from "../../bufferStuff/Endian";
2023-04-10 21:52:30 +01:00
import { IPacket } from "./IPacket";
import { IReader } from "../../bufferStuff/readers/IReader";
import { Packet } from "../enums/Packet";
2023-04-10 21:52:30 +01:00
const EMPTY_BUFFER = Buffer.alloc(0);
export class PacketEntityMetadata implements IPacket {
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
}
}