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

26 lines
629 B
TypeScript
Raw Normal View History

2023-10-29 05:08:26 +00:00
import { createWriter, IReader, Endian } from "bufferstuff";
import IPacket from "./IPacket";
import Packet from "../enums/Packet";
2023-10-29 05:08:26 +00:00
export default class PacketHoldingChange implements IPacket {
2023-10-29 05:08:26 +00:00
public packetId = Packet.HoldingChange;
public slotId:number;
public constructor(slotId?:number) {
if (typeof(slotId) === "number") {
this.slotId = slotId;
} else {
this.slotId = Number.MIN_VALUE;
}
}
public readData(reader:IReader) {
this.slotId = reader.readShort();
return this;
}
public writeData() {
return createWriter(Endian.BE, 3).writeUByte(this.packetId).writeShort(this.slotId).toBuffer();
}
}