mc-beta-server/server/items/Item.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

import { MaxUses } from "../enums/MaxUses";
2023-04-11 01:53:33 +01:00
export class Item {
2023-11-02 08:31:43 +00:00
public static items:Array<Item> = new Array<Item>();
2023-04-11 01:53:33 +01:00
public maxStackSize:number;
public maxDamage:number;
2023-04-11 01:53:33 +01:00
public shiftedItemID:number;
2023-11-02 08:31:43 +00:00
public name:string;
2023-04-11 01:53:33 +01:00
public constructor(itemID:number) {
this.shiftedItemID = 256 + itemID;
this.maxDamage = 0;
2023-04-11 01:53:33 +01:00
this.maxStackSize = 64;
2023-11-02 08:31:43 +00:00
this.name = "UNNAMED";
Item.items[itemID] = this;
}
public static getByShiftedItemId(shiftedItemID:number) {
return Item.items[shiftedItemID - 256];
2023-04-11 01:53:33 +01:00
}
public setMaxStackSize(stackSize:number) {
this.maxStackSize = stackSize;
return this;
}
public getMaxDamage() {
return this.maxDamage;
}
public setMaxDamage(value:number) {
this.maxDamage = value;
return this;
}
2023-11-02 08:31:43 +00:00
public setName(name:string) {
this.name = name;
return this;
}
public getName() {
return this.name;
}
2023-04-11 01:53:33 +01:00
// Define statics here
static ironShovel = new Item(0).setMaxDamage(MaxUses.IRON).setName("Iron Shovel");
static ironPickaxe = new Item(1).setMaxDamage(MaxUses.IRON).setName("Iron Pickaxe");
static ironAxe = new Item(2).setMaxDamage(MaxUses.IRON).setName("Iron Axe");
static ironSword = new Item(11).setMaxDamage(MaxUses.IRON).setName("Iron Sword");
2023-04-11 01:53:33 +01:00
}