Skip to content

Commit a0b1e85

Browse files
Merge pull request #10 from mineprogramming/develop
Version 1.0.1 Merge
2 parents 8edf9e8 + f7646b0 commit a0b1e85

File tree

23 files changed

+581
-536
lines changed

23 files changed

+581
-536
lines changed
Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,83 @@
1-
2-
1+
interface StorageDescriptor {
2+
slots?: {
3+
[key: string]: SlotInterface;
4+
};
5+
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;
13+
}
14+
interface IStorage extends StorageDescriptor {
15+
isNativeContainer(): boolean;
16+
getSlot(name: string | number): ItemInstance;
17+
setSlot(name: string | number, id: number, count: number, data: number, extra?: ItemExtraData): void;
18+
}
19+
interface SlotInterface {
20+
input?: boolean;
21+
output?: boolean;
22+
side?: number | "horizontal" | "down" | "up";
23+
isValid?(item: ItemInstance, side: number, tileEntity: TileEntity): boolean;
24+
canOutput?(item: ItemInstance, side: number, tileEntity: TileEntity): boolean;
25+
}
26+
declare class NativeContainerInterface implements IStorage {
27+
container: NativeTileEntity;
28+
constructor(container: NativeTileEntity);
29+
isNativeContainer(): boolean;
30+
getSlot(index: number): ItemInstance;
31+
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[];
35+
}
36+
declare class TileEntityInterface implements IStorage {
37+
slots?: {
38+
[key: string]: SlotInterface;
39+
};
40+
container: UI.Container | ItemContainer;
41+
tileEntity: TileEntity;
42+
liquidStorage: any;
43+
constructor(tileEntity: TileEntity);
44+
isNativeContainer(): boolean;
45+
getSlot(name: string): ItemInstance;
46+
setSlot(name: string, id: number, count: number, data: number, extra?: ItemExtraData): void;
47+
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;
56+
}
57+
declare let LIQUID_STORAGE_MAX_LIMIT: number;
58+
declare type Container = NativeTileEntity | UI.Container | ItemContainer;
359
declare namespace StorageInterface {
4-
const data: {};
5-
const directionsBySide: {
60+
var data: {};
61+
var directionsBySide: {
662
x: number;
763
y: number;
864
z: number;
965
}[];
10-
function getRelativeCoords(coords: Vector | TileEntity, side: number): {
11-
x: number;
12-
y: number;
13-
z: number;
14-
};
15-
function newInstance(id: number, tileEntity: TileEntity): {
16-
tileEntity: TileEntity;
17-
container: UI.Container;
18-
liquidStorage: any;
19-
};
20-
function createInterface(id: number, interface: any): void;
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;
2172
function addItemToSlot(item: ItemInstance, slot: ItemInstance, count: number): number;
22-
function getNearestContainers(coords: Vector | TileEntity, side: number, excludeSide?: boolean): {};
23-
function getNearestLiquidStorages(coords: Vector | TileEntity, side: number, excludeSide?: boolean): {};
24-
function putItems(items: ItemInstance[], containers: any): void;
25-
function putItemToContainer(item: ItemInstance, container: NativeTileEntity | UI.Container | ItemContainer, side: number, maxCount?: number): number;
26-
function extractItemsFromContainer(inputTile: TileEntity, container: NativeTileEntity | UI.Container, side: number, maxCount?: number, oneStack?: boolean): 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;
2780
function extractLiquid(liquid: string, maxAmount: number, input: TileEntity, output: TileEntity, inputSide: number): void;
2881
function transportLiquid(liquid: string, maxAmount: number, output: TileEntity, input: TileEntity, outputSide: number): void;
29-
function getContainerSlots(container: any, mode: number, side: number): (string | number)[];
3082
function checkHoppers(tile: TileEntity): void;
31-
function extractItems(items: ItemInstance[], containers: any, tile: TileEntity): void;
3283
}

make.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"info": {
44
"name": "BuildCraft PE",
55
"author": "Nikolay Savenko",
6-
"version": "1.0",
6+
"version": "1.0.1",
77
"description": "Port of PC version of BuildCraft"
88
},
99
"api": "CoreEngine"
@@ -53,8 +53,8 @@
5353
"language": "javascript"
5454
},
5555
{
56-
"source": "src/dev",
57-
"target": "main.js",
56+
"source": "src/dev",
57+
"target": "main.js",
5858
"type": "main",
5959
"language": "typescript"
6060
},

src/dev/core/engine/Engines.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/dev/core/engine/abstract/BCEngineTileEntity.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
/// <reference path="../../energy.ts" />
33
/// <reference path="../interface/IHeatable.ts" />
44
/// <reference path="../interface/IEngine.ts" />
5+
/**
6+
* !WARNING
7+
* this code adapted from JAVA source of PC mod
8+
* this structure created not by me
9+
* dont punch me pls
10+
*/
511
abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHeatable, IEngine {
612
public readonly MIN_HEAT: number = 20;
713
public readonly IDEAL_HEAT: number = 100;
@@ -18,7 +24,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
1824
// How many ticks ago it gave out power, capped to 4.
1925
private lastTick: number = 0;
2026

21-
constructor(protected texture: EngineTexture){}
27+
constructor(protected texture: EngineTexture) { }
2228
protected data: any = {// * it will be rewriten during runtime
2329
meta: null, // * this.orientation in PC version
2430
energy: 0, // * this.energy in PC version
@@ -53,7 +59,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
5359
}
5460

5561
public setOrientation(value: number) {
56-
if (typeof(value) == "number") {
62+
if (typeof (value) == "number") {
5763
const { x, y, z } = this;
5864
this.blockSource.setBlock(x, y, z, this.blockSource.getBlockId(x, y, z), value);
5965
this.updateClientOrientation();
@@ -65,7 +71,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
6571
this.networkData.sendChanges();
6672
}
6773

68-
private setProgress(value: number){
74+
private setProgress(value: number) {
6975
this.data.progress = value;
7076
this.networkData.putFloat("progress", value);
7177
}
@@ -74,15 +80,15 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
7480
return this.data.progress;
7581
}
7682

77-
private setProgressPart(value: number){
83+
private setProgressPart(value: number) {
7884
this.progressPart = value;
7985
}
8086

8187
private getProgressPart(): number {
8288
return this.progressPart;
8389
}
8490

85-
private setEnergyStage(value: EngineHeat){
91+
private setEnergyStage(value: EngineHeat) {
8692
this.energyStage = value;
8793
this.networkData.putInt("energyStageIndex", HeatOrder.indexOf(this.energyStage));
8894
this.networkData.sendChanges();
@@ -92,7 +98,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
9298
return this.isPumping;
9399
}
94100

95-
public setPumping(value: boolean){
101+
public setPumping(value: boolean) {
96102
if (this.isPumping == value) return;
97103
this.isPumping = value;
98104
this.lastTick = 0;
@@ -173,24 +179,24 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
173179
}
174180

175181
// !TileEntity event
176-
public init(){
182+
public init() {
177183
this.checkOrientation = true;
178184
}
179185

180186
// !TileEntity event
181-
public redstone(params){
187+
public redstone(params) {
182188
this.isRedstonePowered = params.signal > 0;
183189
}
184190

185191
// !TileEntity event
186-
public tick(){
192+
public tick() {
187193
if (this.checkOrientation) this.updateConnectionSide();
188194
if (this.lastTick < 4) this.lastTick++;
189195

190196
this.updateHeat();
191197
this.getEnergyStage();
192198

193-
if (this.getEnergyStage() === EngineHeat.OVERHEAT){
199+
if (this.getEnergyStage() === EngineHeat.OVERHEAT) {
194200
this.data.energy = Math.max(this.data.energy - 50, 0);
195201
return;
196202
}
@@ -234,7 +240,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
234240
}
235241

236242
public click(id, count, data) {
237-
if(id != ItemID.bc_wrench) return false;
243+
if (id != ItemID.bc_wrench) return false;
238244
if (this.getEnergyStage() == EngineHeat.OVERHEAT) {
239245
this.setEnergyStage(this.computeEnergyStage());
240246
}
@@ -249,21 +255,21 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
249255
// ! @MineExplorer PLEASE make EnergyTileRegistry BlockSource support
250256
// TODO move to blockSource getConnectionSide
251257
/** @param findNext - use true value if you want to rerotate engine like a wrench */
252-
protected getConnectionSide(findNext : boolean = false){
258+
protected getConnectionSide(findNext: boolean = false) {
253259
// * In common situation ends when i gets max in 5 index
254260
// * But if fhis function calling by wrench index can go beyound
255261
// * I think this code is poor, but maybe i fix it in future
256262
const orientation = this.getOrientation();
257-
for(let t = 0; t < 12; t++){
263+
for (let t = 0; t < 12; t++) {
258264
const i = t % 6;
259-
if(findNext) {
260-
if(orientation == t) findNext = false;
265+
if (findNext) {
266+
if (orientation == t) findNext = false;
261267
continue;
262268
}
263269
const relCoords = World.getRelativeCoords(this.x, this.y, this.z, i);
264270
// * ?. is new ESNext feature. Its amazing!
265271
const energyTypes = EnergyTileRegistry.accessMachineAtCoords(relCoords.x, relCoords.y, relCoords.z)?.__energyTypes;
266-
if(energyTypes?.RF) return i;
272+
if (energyTypes?.RF) return i;
267273
}
268274
return null;
269275
}
@@ -273,7 +279,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
273279
const orientation = this.getOrientation();
274280
if (!this.isPoweredTile(this.getEnergyProvider(orientation), orientation)) {
275281
const side = this.getConnectionSide();
276-
if (typeof(side) == "number") {
282+
if (typeof (side) == "number") {
277283
this.setOrientation(side);
278284
} else this.updateClientOrientation();
279285
} else this.updateClientOrientation();
@@ -310,7 +316,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
310316

311317
private getPowerToExtract(): number {
312318
const tile = this.getEnergyProvider(this.getOrientation());
313-
if(!tile) return 0;
319+
if (!tile) return 0;
314320

315321
const oppositeSide = World.getInverseBlockSide(this.getOrientation());
316322

@@ -327,7 +333,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
327333
}
328334

329335
public isPoweredTile(tile: any, side: number): boolean {
330-
if(!tile) return false;
336+
if (!tile) return false;
331337
const oppositeSide = World.getInverseBlockSide(this.getOrientation());
332338

333339
if (tile.isEngine) {
@@ -442,7 +448,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
442448
}
443449

444450
// ? why we need it? ask PC author about it. Maybe it should be overrided in future
445-
protected burn(): void {}
451+
protected burn(): void { }
446452

447453
// abstract methods
448454
public abstract isBurning(): boolean

src/dev/core/engine/creative/CreativeEngine.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/// <reference path="../components/recipe/EngineIngredients.ts" />
44
/// <reference path="CreativeEngineTileEntity.ts" />
55
/// <reference path="../EngineTextures.ts" />
6+
// * only for engine order in creative tab
7+
/// <reference path="../wood/WoodEngine.ts" />
68
class CreativeEngine extends BCEngine {
79

810
public get engineType(): string {
@@ -24,4 +26,5 @@ class CreativeEngine extends BCEngine {
2426
protected getIngredientsForRecipe(): EngineIngredients {
2527
return null;
2628
}
27-
}
29+
}
30+
const creativeEngine = new CreativeEngine();

src/dev/core/engine/wood/WoodEngine.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// <reference path="../components/recipe/EngineIngredients.ts" />
44
/// <reference path="WoodEngineTileEntity.ts" />
55
/// <reference path="../EngineTextures.ts" />
6+
/// <reference path="../../../item/gears.ts" />
67

78
class WoodEngine extends BCEngine {
89
public get engineType(): string {
@@ -20,4 +21,5 @@ class WoodEngine extends BCEngine {
2021
protected getIngredientsForRecipe(): EngineIngredients {
2122
return new EngineIngredients({ id: ItemID.gear_wood, count: 1, data: 0 }, { id: VanillaBlockID.planks, count: 1, data: -1 });
2223
}
23-
}
24+
}
25+
const woodenEngine = new WoodEngine();

src/dev/core/pipe/components/PipeBlock.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const BlockTypePipe: Block.SpecialType = {
22
base: 1,
33
destroytime: 0.2,
4-
explosionres: 0.5,
5-
renderlayer: 1
4+
explosionres: 0.5
65
};
76

87
class PipeBlock {

src/dev/core/pipe/item/ItemMachines.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,12 @@ const transportConnector = new TransportPipeConnector();
55
const basicRule = transportConnector.getConnectionRules()[0];
66

77
for (const instance of ITEM_MACHINES) {
8-
ICRender.getGroup(basicRule.name).add(instance.id, instance.data);
8+
ICRender.getGroup(basicRule.name).add(instance.id, instance.data);
9+
}
10+
11+
// For StorageInterface containers
12+
// @ts-ignore
13+
for (const blockID in StorageInterface.data) {
14+
// @ts-ignore
15+
ICRender.getGroup(basicRule.name).add(blockID, -1);
916
}

src/dev/core/pipe/item/ItemPipes.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/dev/core/pipe/item/cobble/PipeCobble.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ class PipeCobble extends BCTransportPipe {
2626
protected getIngredientForRecipe(): ItemInstance {
2727
return { id: VanillaBlockID.cobblestone, count: 1, data: 0 }
2828
}
29-
}
29+
}
30+
const cobblePipe = new PipeCobble();

0 commit comments

Comments
 (0)