2024-11-26 19:24:08 +00:00
|
|
|
import InventoryType from "../enums/InventoryType";
|
|
|
|
import Inventory from "../inventories/Inventory";
|
2024-11-29 15:00:48 +00:00
|
|
|
import ItemStack from "../inventories/ItemStack";
|
2024-12-01 00:19:32 +00:00
|
|
|
import PlayerCombinedInventory from "../inventories/PlayerCombinedInventory";
|
2024-11-26 19:24:08 +00:00
|
|
|
import MPClient from "../MPClient";
|
|
|
|
import PacketOpenWindow from "../packets/OpenWindow";
|
2024-12-01 00:19:32 +00:00
|
|
|
import PacketWindowItems from "../packets/WindowItems";
|
2024-11-26 19:24:08 +00:00
|
|
|
|
|
|
|
export default abstract class Window {
|
|
|
|
public static WINDOW_GLOBAL_COUNTER = 1;
|
|
|
|
|
2024-12-01 00:19:32 +00:00
|
|
|
public readonly inventorySize: number;
|
|
|
|
|
2024-11-26 19:24:08 +00:00
|
|
|
public windowId = Window.WINDOW_GLOBAL_COUNTER++;
|
|
|
|
public inventoryType: InventoryType;
|
2024-12-01 00:19:32 +00:00
|
|
|
public inventory: PlayerCombinedInventory;
|
|
|
|
|
|
|
|
public cursorItemStack: ItemStack | null;
|
2024-11-26 19:24:08 +00:00
|
|
|
|
2024-12-01 00:19:32 +00:00
|
|
|
public constructor(inventoryType: InventoryType, inventory: PlayerCombinedInventory, inventorySize: number) {
|
|
|
|
this.inventorySize = inventorySize;
|
2024-11-29 15:00:48 +00:00
|
|
|
|
2024-11-26 19:24:08 +00:00
|
|
|
this.inventoryType = inventoryType;
|
|
|
|
this.inventory = inventory;
|
2024-12-01 00:19:32 +00:00
|
|
|
|
|
|
|
this.cursorItemStack = null;
|
2024-11-26 19:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
openWindow(mpClient: MPClient) {
|
|
|
|
const windowPacket = new PacketOpenWindow(this.windowId, this.inventoryType, this.inventory.getInventoryName(), this.inventory.getInventorySize()).writeData();
|
2024-12-01 00:19:32 +00:00
|
|
|
const windowItems = new PacketWindowItems(this.windowId, this.inventorySize, this.inventory.constructInventoryPayload()).writeData();
|
|
|
|
mpClient.send(Buffer.concat([ windowPacket, windowItems ], windowPacket.length + windowItems.length));
|
|
|
|
//mpClient.send(windowPacket);
|
|
|
|
//mpClient.send(inventoryDataPayload);
|
|
|
|
}
|
|
|
|
|
|
|
|
clickedWindow(slotId: number, rightClick: boolean) {
|
|
|
|
if (this.cursorItemStack) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.cursorItemStack = this.inventory.getSlotItemStack(slotId);
|
|
|
|
}
|
2024-11-26 19:24:08 +00:00
|
|
|
}
|
|
|
|
}
|