2024-10-18 21:47:03 +01:00
|
|
|
import { createWriter, IReader, Endian } from "bufferstuff";
|
2024-10-26 14:24:38 +01:00
|
|
|
import IPacket from "./IPacket";
|
|
|
|
import Packet from "../enums/Packet";
|
2024-10-18 21:47:03 +01:00
|
|
|
|
2024-10-26 14:24:38 +01:00
|
|
|
export default class PacketWindowClick implements IPacket {
|
2024-10-18 21:47:03 +01:00
|
|
|
public packetId = Packet.WindowClick;
|
|
|
|
public windowId:number;
|
|
|
|
public slot:number;
|
|
|
|
public rightClick:boolean;
|
|
|
|
public actionNumber:number;
|
|
|
|
public shift:boolean;
|
|
|
|
public itemId:number;
|
|
|
|
public itemCount:number;
|
|
|
|
public itemUses:number;
|
|
|
|
|
|
|
|
public constructor(windowId?:number, slot?:number, rightClick?:boolean, actionNumber?:number, shift?:boolean, itemId?:number, itemCount?:number, itemUses?:number) {
|
|
|
|
if (typeof(windowId) === "number" && typeof(slot) === "number" && typeof(rightClick) === "boolean" && typeof(actionNumber) === "number" && typeof(shift) === "boolean" && typeof(itemId) === "number" && typeof(itemCount) === "number" && typeof(itemUses) === "number") {
|
|
|
|
this.windowId = windowId;
|
|
|
|
this.slot = slot;
|
|
|
|
this.rightClick = rightClick;
|
|
|
|
this.actionNumber = actionNumber;
|
|
|
|
this.shift = shift;
|
|
|
|
this.itemId = itemId;
|
|
|
|
this.itemCount = itemCount;
|
|
|
|
this.itemUses = itemUses;
|
|
|
|
} else {
|
|
|
|
this.windowId = Number.MIN_VALUE;
|
|
|
|
this.slot = Number.MIN_VALUE;
|
|
|
|
this.rightClick = false;
|
|
|
|
this.actionNumber = Number.MIN_VALUE;
|
|
|
|
this.shift = false;
|
|
|
|
this.itemId = Number.MIN_VALUE;
|
|
|
|
this.itemCount = Number.MIN_VALUE;
|
|
|
|
this.itemUses = Number.MIN_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public readData(reader:IReader) {
|
|
|
|
this.windowId = reader.readByte();
|
|
|
|
this.slot = reader.readShort();
|
|
|
|
this.rightClick = reader.readBool();
|
|
|
|
this.actionNumber = reader.readShort();
|
|
|
|
this.shift = reader.readBool();
|
|
|
|
this.itemId = reader.readShort();
|
2024-11-29 15:00:48 +00:00
|
|
|
if (this.itemId !== -1) {
|
|
|
|
this.itemCount = reader.readByte();
|
|
|
|
this.itemUses = reader.readShort();
|
|
|
|
}
|
2024-10-18 21:47:03 +01:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public writeData() {
|
2024-11-29 15:00:48 +00:00
|
|
|
const writer = createWriter(Endian.BE, 4).writeUByte(this.packetId).writeByte(this.windowId).writeShort(this.slot).writeBool(this.rightClick).writeShort(this.actionNumber).writeShort(this.itemId);
|
|
|
|
if (this.itemId !== -1) {
|
|
|
|
writer.writeByte(this.itemCount).writeShort(this.itemUses);
|
|
|
|
}
|
|
|
|
return writer.toBuffer();
|
2024-10-18 21:47:03 +01:00
|
|
|
}
|
|
|
|
}
|