From bb733ff2af99365e96b7344b00ab66b8390b1ae8 Mon Sep 17 00:00:00 2001 From: Holly Date: Sun, 5 Nov 2023 10:55:15 +0000 Subject: [PATCH] Allow ItemStack(s) to be compared --- server/inventories/ItemStack.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/inventories/ItemStack.ts b/server/inventories/ItemStack.ts index 38b4be3..c417cb5 100644 --- a/server/inventories/ItemStack.ts +++ b/server/inventories/ItemStack.ts @@ -4,6 +4,9 @@ import { Player } from "../entities/Player"; import { Item } from "../items/Item"; export class ItemStack { + private static ITEMSTACK_ID_ADDER = 0; + private readonly itemStackId:number; + public readonly itemID:number; public readonly isBlock:boolean; public size:number; @@ -58,6 +61,16 @@ export class ItemStack { this.maxSize = this.isBlock ? 64 : Item.getByShiftedItemId(this.itemID).maxStackSize; this.maxDamage = this.isBlock ? 0 : Item.getByShiftedItemId(this.itemID).maxDamage; this.canBeDamaged = this.maxDamage > 0; + + this.itemStackId = ItemStack.ITEMSTACK_ID_ADDER++; + } + + public static Compare(itemStack1:ItemStack, itemStack2:ItemStack) { + return itemStack1.itemStackId === itemStack2.itemStackId; + } + + public compare(itemStack:ItemStack) { + return this.itemStackId === itemStack.itemStackId; } public insert(itemStack:ItemStack) {