WIP: Inventory support
This commit is contained in:
parent
b371521fda
commit
42cef0a838
6 changed files with 104 additions and 7 deletions
|
@ -5,15 +5,16 @@ export class Block {
|
||||||
this.blockId = blockId;
|
this.blockId = blockId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static stone = new Block(1);
|
// Define statics here
|
||||||
static grass = new Block(2);
|
static readonly stone = new Block(1);
|
||||||
static dirt = new Block(3);
|
static readonly grass = new Block(2);
|
||||||
|
static readonly dirt = new Block(3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static bedrock = new Block(7);
|
static readonly bedrock = new Block(7);
|
||||||
|
|
||||||
static waterStill = new Block(9);
|
static readonly waterStill = new Block(9);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +22,6 @@ export class Block {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static wood = new Block(17);
|
static readonly wood = new Block(17);
|
||||||
static leaves = new Block(18);
|
static readonly leaves = new Block(18);
|
||||||
}
|
}
|
13
server/containers/Container.ts
Normal file
13
server/containers/Container.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { FunkyArray } from "../../funkyArray";
|
||||||
|
import { ItemStack } from "./ItemStack";
|
||||||
|
import { ContainerSlot } from "./Slot";
|
||||||
|
|
||||||
|
export abstract class Container {
|
||||||
|
public itemSlots:Array<ContainerSlot>;
|
||||||
|
public itemStacks:Array<ItemStack>;
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
this.itemSlots = new Array<ContainerSlot>();
|
||||||
|
this.itemStacks = new Array<ItemStack>();
|
||||||
|
}
|
||||||
|
}
|
49
server/containers/ItemStack.ts
Normal file
49
server/containers/ItemStack.ts
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import { Block } from "../blocks/Block";
|
||||||
|
import { Item } from "../items/Item";
|
||||||
|
|
||||||
|
export class ItemStack {
|
||||||
|
public readonly itemID:number;
|
||||||
|
public stackSize:number;
|
||||||
|
public damage:number;
|
||||||
|
|
||||||
|
public constructor(blockOrItemOrItemID:Block|Item|number, stackSize?:number, damage?:number) {
|
||||||
|
if (blockOrItemOrItemID instanceof Block && stackSize === undefined && damage === undefined) {
|
||||||
|
this.itemID = blockOrItemOrItemID.blockId;
|
||||||
|
this.stackSize = 1;
|
||||||
|
this.damage = 0;
|
||||||
|
} else if (blockOrItemOrItemID instanceof Block && typeof(stackSize) === "number" && damage === undefined) {
|
||||||
|
this.itemID = blockOrItemOrItemID.blockId;
|
||||||
|
this.stackSize = stackSize;
|
||||||
|
this.damage = 0;
|
||||||
|
} else if (blockOrItemOrItemID instanceof Block && typeof(stackSize) === "number" && typeof(damage) === "number") {
|
||||||
|
this.itemID = blockOrItemOrItemID.blockId;
|
||||||
|
this.stackSize = stackSize;
|
||||||
|
this.damage = damage;
|
||||||
|
} else if (blockOrItemOrItemID instanceof Item && stackSize === undefined && damage === undefined) {
|
||||||
|
this.itemID = blockOrItemOrItemID.shiftedItemID;
|
||||||
|
this.stackSize = 1;
|
||||||
|
this.damage = 0;
|
||||||
|
} else if (blockOrItemOrItemID instanceof Item && typeof(stackSize) === "number" && damage === undefined) {
|
||||||
|
this.itemID = blockOrItemOrItemID.shiftedItemID;
|
||||||
|
this.stackSize = stackSize;
|
||||||
|
this.damage = 0;
|
||||||
|
} else if (blockOrItemOrItemID instanceof Item && typeof(stackSize) === "number" && typeof(damage) === "number") {
|
||||||
|
this.itemID = blockOrItemOrItemID.shiftedItemID;
|
||||||
|
this.stackSize = stackSize;
|
||||||
|
this.damage = damage;
|
||||||
|
} else if (typeof(blockOrItemOrItemID) === "number" && typeof(stackSize) === "number" && typeof(damage) === "number") {
|
||||||
|
this.itemID = blockOrItemOrItemID;
|
||||||
|
this.stackSize = stackSize;
|
||||||
|
this.damage = damage;
|
||||||
|
} else {
|
||||||
|
this.itemID = Number.MIN_VALUE;
|
||||||
|
this.stackSize = Number.MIN_VALUE;
|
||||||
|
this.damage = Number.MIN_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
split(amount:number) {
|
||||||
|
this.stackSize -= amount;
|
||||||
|
return new ItemStack(this.itemID, amount, this.damage);
|
||||||
|
}
|
||||||
|
}
|
11
server/containers/Slot.ts
Normal file
11
server/containers/Slot.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { IInventory } from "../inventories/IInventory";
|
||||||
|
|
||||||
|
export class ContainerSlot {
|
||||||
|
public inventory:IInventory;
|
||||||
|
public index:number;
|
||||||
|
|
||||||
|
public constructor(inventory:IInventory, index:number) {
|
||||||
|
this.inventory = inventory;
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
}
|
7
server/inventories/IInventory.ts
Normal file
7
server/inventories/IInventory.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { ItemStack } from "../containers/ItemStack";
|
||||||
|
|
||||||
|
export interface IInventory {
|
||||||
|
getInventoryName:() => string,
|
||||||
|
getInventorySize:() => number,
|
||||||
|
getSlotItemStack:(slotId:number) => ItemStack
|
||||||
|
}
|
16
server/items/Item.ts
Normal file
16
server/items/Item.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
export class Item {
|
||||||
|
public maxStackSize:number;
|
||||||
|
public shiftedItemID:number;
|
||||||
|
|
||||||
|
public constructor(itemID:number) {
|
||||||
|
this.shiftedItemID = 256 + itemID;
|
||||||
|
this.maxStackSize = 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setMaxStackSize(stackSize:number) {
|
||||||
|
this.maxStackSize = stackSize;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define statics here
|
||||||
|
}
|
Loading…
Reference in a new issue