Allow ItemStack(s) to be compared

This commit is contained in:
Holly Stubbs 2023-11-05 10:55:15 +00:00
parent 83f37a0621
commit bb733ff2af
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E

View file

@ -4,6 +4,9 @@ import { Player } from "../entities/Player";
import { Item } from "../items/Item"; import { Item } from "../items/Item";
export class ItemStack { export class ItemStack {
private static ITEMSTACK_ID_ADDER = 0;
private readonly itemStackId:number;
public readonly itemID:number; public readonly itemID:number;
public readonly isBlock:boolean; public readonly isBlock:boolean;
public size:number; public size:number;
@ -58,6 +61,16 @@ export class ItemStack {
this.maxSize = this.isBlock ? 64 : Item.getByShiftedItemId(this.itemID).maxStackSize; this.maxSize = this.isBlock ? 64 : Item.getByShiftedItemId(this.itemID).maxStackSize;
this.maxDamage = this.isBlock ? 0 : Item.getByShiftedItemId(this.itemID).maxDamage; this.maxDamage = this.isBlock ? 0 : Item.getByShiftedItemId(this.itemID).maxDamage;
this.canBeDamaged = this.maxDamage > 0; 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) { public insert(itemStack:ItemStack) {