|
| 1 | +/// <reference path="./core-engine.d.ts" /> |
| 2 | +declare type Container = NativeTileEntity | UI.Container | ItemContainer; |
1 | 3 | interface StorageDescriptor { |
2 | 4 | slots?: { |
3 | | - [key: string]: SlotInterface; |
| 5 | + [key: string]: SlotData; |
4 | 6 | }; |
| 7 | + liquidUnitRatio?: number; |
5 | 8 | isValidInput?(item: ItemInstance, side: number, tileEntity: TileEntity): boolean; |
6 | | - addItem?(item: ItemInstance, side: number, maxCount: number): number; |
7 | | - getOutputSlots?(side: number): string[] | number[]; |
8 | | - canReceiveLiquid?(liquid: string, side?: number): boolean; |
9 | | - canTransportLiquid?(liquid: string, side?: number): boolean; |
10 | | - addLiquid?(liquid: string, amount: number): number; |
11 | | - getLiquid?(liquid: string, amount: number): number; |
12 | | - getLiquidStored?(storage: string, side: number): string; |
| 9 | + addItem?(item: ItemInstance, side?: number, maxCount?: number): number; |
| 10 | + getInputSlots?(side?: number): string[] | number[]; |
| 11 | + getOutputSlots?(side?: number): string[] | number[]; |
| 12 | + canReceiveLiquid?(liquid: string, side: number): boolean; |
| 13 | + canTransportLiquid?(liquid: string, side: number): boolean; |
| 14 | + receiveLiquid?(liquidStorage: ILiquidStorage, liquid: string, amount: number): number; |
| 15 | + extractLiquid?(liquidStorage: ILiquidStorage, liquid: string, amount: number): number; |
| 16 | + getInputTank?(side: number): ILiquidStorage; |
| 17 | + getOutputTank?(side: number): ILiquidStorage; |
13 | 18 | } |
14 | | -interface IStorage extends StorageDescriptor { |
15 | | - isNativeContainer(): boolean; |
| 19 | +interface Storage extends StorageDescriptor { |
| 20 | + container: Container; |
| 21 | + isNativeContainer: boolean; |
16 | 22 | getSlot(name: string | number): ItemInstance; |
17 | 23 | setSlot(name: string | number, id: number, count: number, data: number, extra?: ItemExtraData): void; |
| 24 | + getContainerSlots(): string[] | number[]; |
| 25 | + getInputSlots(side?: number): string[] | number[]; |
| 26 | + getOutputSlots(side?: number): string[] | number[]; |
| 27 | + getReceivingItemCount(item: ItemInstance, side?: number): number; |
| 28 | + addItemToSlot(name: string | number, item: ItemInstance, maxCount?: number): number; |
| 29 | + addItem(item: ItemInstance, side?: number, maxCount?: number): number; |
| 30 | + clearContainer(): void; |
18 | 31 | } |
19 | | -interface SlotInterface { |
| 32 | +interface SlotData { |
20 | 33 | input?: boolean; |
21 | 34 | output?: boolean; |
22 | | - side?: number | "horizontal" | "down" | "up"; |
| 35 | + side?: number | "horizontal" | "verctical" | "down" | "up"; |
| 36 | + maxStack?: number; |
23 | 37 | isValid?(item: ItemInstance, side: number, tileEntity: TileEntity): boolean; |
24 | 38 | canOutput?(item: ItemInstance, side: number, tileEntity: TileEntity): boolean; |
25 | 39 | } |
26 | | -declare class NativeContainerInterface implements IStorage { |
27 | | - container: NativeTileEntity; |
| 40 | +interface ILiquidStorage { |
| 41 | + getLiquidStored(): string; |
| 42 | + getLimit(liquid: string): number; |
| 43 | + getAmount(liquid: string): number; |
| 44 | + getLiquid(liquid: string, amount: number): number; |
| 45 | + addLiquid(liquid: string, amount: number): number; |
| 46 | + isFull(): boolean; |
| 47 | + isEmpty(): boolean; |
| 48 | +} |
| 49 | +declare class NativeContainerInterface implements Storage { |
| 50 | + readonly container: NativeTileEntity; |
| 51 | + readonly isNativeContainer = true; |
28 | 52 | constructor(container: NativeTileEntity); |
29 | | - isNativeContainer(): boolean; |
30 | 53 | getSlot(index: number): ItemInstance; |
31 | 54 | setSlot(index: number, id: number, count: number, data: number, extra?: ItemExtraData): void; |
32 | | - private isValidInputSlot; |
33 | | - addItem(item: ItemInstance, side: number, maxCount: number): number; |
34 | | - getOutputSlots(side: number): number[]; |
| 55 | + getContainerSlots(): any[]; |
| 56 | + getInputSlots(side: number): number[]; |
| 57 | + getReceivingItemCount(item: ItemInstance, side: number): number; |
| 58 | + addItemToSlot(index: number, item: ItemInstance, maxCount?: number): number; |
| 59 | + addItem(item: ItemInstance, side: number, maxCount?: number): number; |
| 60 | + getOutputSlots(): number[]; |
| 61 | + clearContainer(): void; |
35 | 62 | } |
36 | | -declare class TileEntityInterface implements IStorage { |
37 | | - slots?: { |
38 | | - [key: string]: SlotInterface; |
| 63 | +declare class TileEntityInterface implements Storage { |
| 64 | + readonly liquidUnitRatio: number; |
| 65 | + readonly slots?: { |
| 66 | + [key: string]: SlotData; |
39 | 67 | }; |
40 | | - container: UI.Container | ItemContainer; |
41 | | - tileEntity: TileEntity; |
42 | | - liquidStorage: any; |
| 68 | + readonly container: UI.Container | ItemContainer; |
| 69 | + readonly tileEntity: TileEntity; |
| 70 | + readonly isNativeContainer = false; |
43 | 71 | constructor(tileEntity: TileEntity); |
44 | | - isNativeContainer(): boolean; |
45 | 72 | getSlot(name: string): ItemInstance; |
46 | 73 | setSlot(name: string, id: number, count: number, data: number, extra?: ItemExtraData): void; |
| 74 | + getSlotData(name: string): SlotData; |
| 75 | + getSlotMaxStack(name: string): number; |
| 76 | + private isValidSlotSide; |
| 77 | + private isValidSlotInput; |
| 78 | + getContainerSlots(): string[]; |
| 79 | + private getDefaultSlots; |
| 80 | + getInputSlots(side?: number): string[]; |
| 81 | + getReceivingItemCount(item: ItemInstance, side?: number): number; |
47 | 82 | isValidInput(item: ItemInstance, side: number, tileEntity: TileEntity): boolean; |
48 | | - checkSide(slotSideTag: string | number, side: number): boolean; |
49 | | - addItem(item: ItemInstance, side: number, maxCount?: number): number; |
50 | | - getOutputSlots(side: number): string[]; |
51 | | - canReceiveLiquid(liquid: string, side?: number): boolean; |
52 | | - canTransportLiquid(liquid: string, side?: number): boolean; |
53 | | - addLiquid(liquid: string, amount: number): number; |
54 | | - getLiquid(liquid: string, amount: number): number; |
55 | | - getLiquidStored(storage?: string, side?: number): string; |
| 83 | + addItemToSlot(name: string, item: ItemInstance, maxCount?: number): number; |
| 84 | + addItem(item: ItemInstance, side?: number, maxCount?: number): number; |
| 85 | + getOutputSlots(side?: number): string[]; |
| 86 | + clearContainer(): void; |
| 87 | + canReceiveLiquid(liquid: string, side: number): boolean; |
| 88 | + canTransportLiquid(liquid: string, side: number): boolean; |
| 89 | + receiveLiquid(liquidStorage: ILiquidStorage, liquid: string, amount: number): number; |
| 90 | + extractLiquid(liquidStorage: ILiquidStorage, liquid: string, amount: number): number; |
| 91 | + getInputTank(side: number): ILiquidStorage; |
| 92 | + getOutputTank(side: number): ILiquidStorage; |
56 | 93 | } |
57 | | -declare let LIQUID_STORAGE_MAX_LIMIT: number; |
58 | | -declare type Container = NativeTileEntity | UI.Container | ItemContainer; |
59 | 94 | declare namespace StorageInterface { |
60 | | - var data: {}; |
61 | | - var directionsBySide: { |
| 95 | + type ContainersMap = { |
| 96 | + [key: number]: Container; |
| 97 | + }; |
| 98 | + type StoragesMap = { |
| 99 | + [key: number]: Storage; |
| 100 | + }; |
| 101 | + export var data: { |
| 102 | + [key: number]: StorageDescriptor; |
| 103 | + }; |
| 104 | + export function getData(id: number): StorageDescriptor; |
| 105 | + export var directionsBySide: { |
62 | 106 | x: number; |
63 | 107 | y: number; |
64 | 108 | z: number; |
65 | 109 | }[]; |
66 | | - function getRelativeCoords(coords: Vector, side: number): Vector; |
67 | | - function setSlotMaxStackPolicy(container: ItemContainer, slotName: string, maxCount: number): void; |
68 | | - function setSlotValidatePolicy(container: ItemContainer, slotName: string, func: (name: string, id: number, amount: number, data: number, extra: ItemExtraData, container: ItemContainer, playerUid: number) => boolean): void; |
69 | | - function setGlobalValidatePolicy(container: ItemContainer, func: (name: string, id: number, amount: number, data: number, extra: ItemExtraData, container: ItemContainer, playerUid: number) => boolean): void; |
70 | | - function newInstance(storage: TileEntity | Container): IStorage; |
71 | | - function createInterface(id: number, interface: StorageDescriptor): void; |
72 | | - function addItemToSlot(item: ItemInstance, slot: ItemInstance, count: number): number; |
73 | | - function getStorage(region: BlockSource, x: number, y: number, z: number): IStorage; |
74 | | - function getNearestContainers(coords: Vector, side: number, excludeSide?: boolean): object; |
75 | | - function getNearestLiquidStorages(coords: Vector, side: number, excludeSide?: boolean): object; |
76 | | - function getContainerSlots(container: Container): string[] | number[]; |
77 | | - function putItems(items: ItemInstance[], containers: object): void; |
78 | | - function putItemToContainer(item: ItemInstance, container: Container, side: number, maxCount?: number): number; |
79 | | - function extractItemsFromContainer(inputContainer: TileEntity | Container, outputContainer: Container, side: number, maxCount?: number, oneStack?: boolean): number; |
80 | | - function extractLiquid(liquid: string, maxAmount: number, input: TileEntity, output: TileEntity, inputSide: number): void; |
81 | | - function transportLiquid(liquid: string, maxAmount: number, output: TileEntity, input: TileEntity, outputSide: number): void; |
82 | | - function checkHoppers(tile: TileEntity): void; |
| 110 | + export function getRelativeCoords(coords: Vector, side: number): Vector; |
| 111 | + export function setSlotMaxStackPolicy(container: ItemContainer, slotName: string, maxCount: number): void; |
| 112 | + export function setSlotValidatePolicy(container: ItemContainer, slotName: string, func: (name: string, id: number, amount: number, data: number, extra: ItemExtraData, container: ItemContainer, playerUid: number) => boolean): void; |
| 113 | + export function setGlobalValidatePolicy(container: ItemContainer, func: (name: string, id: number, amount: number, data: number, extra: ItemExtraData, container: ItemContainer, playerUid: number) => boolean): void; |
| 114 | + /** Creates new interface instance for TileEntity or Container */ |
| 115 | + export function getInterface(storage: TileEntity | Container): Storage; |
| 116 | + /** Registers interface for block container */ |
| 117 | + export function createInterface(id: number, descriptor: StorageDescriptor): void; |
| 118 | + /** Trasfers item to slot |
| 119 | + * @count amount to transfer. Default is 64. |
| 120 | + * @returns transfered amount |
| 121 | + */ |
| 122 | + export function addItemToSlot(item: ItemInstance, slot: ItemInstance, count?: number): number; |
| 123 | + /** Returns storage interface for container in the world */ |
| 124 | + export function getStorage(region: BlockSource, x: number, y: number, z: number): Nullable<Storage>; |
| 125 | + /** Returns storage interface for TileEntity with liquid storage */ |
| 126 | + export function getLiquidStorage(region: BlockSource, x: number, y: number, z: number): Nullable<TileEntityInterface>; |
| 127 | + /** Returns storage interface for neighbour container on specified side */ |
| 128 | + export function getNeighbourStorage(region: BlockSource, coords: Vector, side: number): Nullable<Storage>; |
| 129 | + /** Returns storage interface for neighbour TileEntity with liquid storage on specified side */ |
| 130 | + export function getNeighbourLiquidStorage(region: BlockSource, coords: Vector, side: number): Nullable<TileEntityInterface>; |
| 131 | + /** |
| 132 | + * Returns object containing neigbour containers where keys are block side numbers |
| 133 | + * @coords position from which check neighbour blocks |
| 134 | + */ |
| 135 | + export function getNearestContainers(coords: Vector, region: BlockSource): ContainersMap; |
| 136 | + /** |
| 137 | + * Returns object containing neigbour liquid storages where keys are block side numbers |
| 138 | + * @coords position from which check neighbour blocks |
| 139 | + */ |
| 140 | + export function getNearestLiquidStorages(coords: Vector, region: BlockSource): StoragesMap; |
| 141 | + /** |
| 142 | + * Returns array of slot indexes for vanilla container or array of slot names for mod container |
| 143 | + */ |
| 144 | + export function getContainerSlots(container: Container): string[] | number[]; |
| 145 | + /** Puts items to containers */ |
| 146 | + export function putItems(items: ItemInstance[], containers: ContainersMap): void; |
| 147 | + /** |
| 148 | + * @side block side of container which receives item |
| 149 | + * @maxCount max count of item to transfer (optional) |
| 150 | + */ |
| 151 | + export function putItemToContainer(item: ItemInstance, container: TileEntity | Container, side?: number, maxCount?: number): number; |
| 152 | + /** |
| 153 | + * Extracts items from one container to another |
| 154 | + * @inputContainer container to receive items |
| 155 | + * @outputContainer container to extract items |
| 156 | + * @inputSide block side of input container which is receiving items |
| 157 | + * @maxCount max total count of extracted items (optional) |
| 158 | + * @oneStack if true, will extract only 1 item |
| 159 | + */ |
| 160 | + export function extractItemsFromContainer(inputContainer: TileEntity | Container, outputContainer: TileEntity | Container, inputSide: number, maxCount?: number, oneStack?: boolean): number; |
| 161 | + /** |
| 162 | + * Extracts items from one container to another |
| 163 | + * @inputStorage container interface to receive items |
| 164 | + * @outputStorage container interface to extract items |
| 165 | + * @inputSide block side of input container which is receiving items |
| 166 | + * @maxCount max total count of extracted items (optional) |
| 167 | + * @oneStack if true, will extract only 1 item |
| 168 | + */ |
| 169 | + export function extractItemsFromStorage(inputStorage: Storage, outputStorage: Storage, inputSide: number, maxCount?: number, oneStack?: boolean): number; |
| 170 | + /** |
| 171 | + * Extract liquid from one storage to another |
| 172 | + * @liquid liquid to extract. If null, will extract liquid stored in output storage |
| 173 | + * @maxAmount max amount of liquid that can be transfered |
| 174 | + * @inputStorage storage to input liquid |
| 175 | + * @outputStorage storage to extract liquid |
| 176 | + * @inputSide block side of input storage which is receiving |
| 177 | + * @returns left liquid amount |
| 178 | + */ |
| 179 | + export function extractLiquid(liquid: Nullable<string>, maxAmount: number, inputStorage: TileEntity | Storage, outputStorage: Storage, inputSide: number): number; |
| 180 | + /** Similar to StorageInterface.extractLiquid, but liquid must be specified */ |
| 181 | + export function transportLiquid(liquid: string, maxAmount: number, outputStorage: TileEntity | Storage, inputStorage: Storage, outputSide: number): number; |
| 182 | + /** |
| 183 | + * Every 8 ticks checks neigbour hoppers and transfers items. |
| 184 | + * Use it in tick function of TileEntity |
| 185 | + */ |
| 186 | + export function checkHoppers(tile: TileEntity): void; |
| 187 | + export {}; |
83 | 188 | } |
0 commit comments