WIP: Inventory support
This commit is contained in:
parent
b371521fda
commit
42cef0a838
|
@ -5,15 +5,16 @@ export class Block {
|
|||
this.blockId = blockId;
|
||||
}
|
||||
|
||||
static stone = new Block(1);
|
||||
static grass = new Block(2);
|
||||
static dirt = new Block(3);
|
||||
// Define statics here
|
||||
static readonly stone = new Block(1);
|
||||
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 leaves = new Block(18);
|
||||
static readonly wood = new Block(17);
|
||||
static readonly leaves = new Block(18);
|
||||
}
|
|
@ -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>();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import { ItemStack } from "../containers/ItemStack";
|
||||
|
||||
export interface IInventory {
|
||||
getInventoryName:() => string,
|
||||
getInventorySize:() => number,
|
||||
getSlotItemStack:(slotId:number) => ItemStack
|
||||
}
|
|
@ -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 New Issue