This commit is contained in:
parent
cb9b124ec7
commit
5decd39cdc
73
src/main/ts/src/minecraft/inventory.ts
Normal file
73
src/main/ts/src/minecraft/inventory.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { useBridge } from 'scriptcraft-core';
|
||||
import { ItemStack } from './item';
|
||||
|
||||
/**
|
||||
* Inventory
|
||||
*/
|
||||
export class Inventory {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
readonly javaObject: JavaObject;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(object: JavaObject) {
|
||||
this.javaObject = object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Size
|
||||
* @returns Inventory Size
|
||||
*/
|
||||
size(): number {
|
||||
return useBridge('Inventory.size', this.javaObject) as number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Maximum Stack Size
|
||||
* @returns Inventory Maximum Stack Size
|
||||
*/
|
||||
getMaxStackSize(): number {
|
||||
return useBridge('Inventory.getMaxStackSize', this.javaObject) as number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Stack In Slot
|
||||
* @param slot Inventory Slot
|
||||
* @returns Item Stack
|
||||
*/
|
||||
get(slot: number): ItemStack {
|
||||
const obj = useBridge('Inventory.get', this.javaObject, slot) as JavaObject;
|
||||
if (obj !== null) {
|
||||
return new ItemStack(obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take Item From Slot
|
||||
* @param slot Inventory Slot
|
||||
* @param count Amount To Take
|
||||
* @returns Item Stack
|
||||
*/
|
||||
take(slot: number, count: number): ItemStack {
|
||||
const obj = useBridge('Inventory.take', this.javaObject, slot, count) as JavaObject;
|
||||
if (obj !== null) {
|
||||
return new ItemStack(obj);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Item In Slot
|
||||
* @param slot Inventory Slot
|
||||
* @param item Item Stack
|
||||
*/
|
||||
set(slot: number, item: ItemStack): void {
|
||||
useBridge('Inventory.set', this.javaObject, slot, item.javaObject);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user