Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 73 additions & 22 deletions declarations/lib/StorageInterface.d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,83 @@


interface StorageDescriptor {
slots?: {
[key: string]: SlotInterface;
};
isValidInput?(item: ItemInstance, side: number, tileEntity: TileEntity): boolean;
addItem?(item: ItemInstance, side: number, maxCount: number): number;
getOutputSlots?(side: number): string[] | number[];
canReceiveLiquid?(liquid: string, side?: number): boolean;
canTransportLiquid?(liquid: string, side?: number): boolean;
addLiquid?(liquid: string, amount: number): number;
getLiquid?(liquid: string, amount: number): number;
getLiquidStored?(storage: string, side: number): string;
}
interface IStorage extends StorageDescriptor {
isNativeContainer(): boolean;
getSlot(name: string | number): ItemInstance;
setSlot(name: string | number, id: number, count: number, data: number, extra?: ItemExtraData): void;
}
interface SlotInterface {
input?: boolean;
output?: boolean;
side?: number | "horizontal" | "down" | "up";
isValid?(item: ItemInstance, side: number, tileEntity: TileEntity): boolean;
canOutput?(item: ItemInstance, side: number, tileEntity: TileEntity): boolean;
}
declare class NativeContainerInterface implements IStorage {
container: NativeTileEntity;
constructor(container: NativeTileEntity);
isNativeContainer(): boolean;
getSlot(index: number): ItemInstance;
setSlot(index: number, id: number, count: number, data: number, extra?: ItemExtraData): void;
private isValidInputSlot;
addItem(item: ItemInstance, side: number, maxCount: number): number;
getOutputSlots(side: number): number[];
}
declare class TileEntityInterface implements IStorage {
slots?: {
[key: string]: SlotInterface;
};
container: UI.Container | ItemContainer;
tileEntity: TileEntity;
liquidStorage: any;
constructor(tileEntity: TileEntity);
isNativeContainer(): boolean;
getSlot(name: string): ItemInstance;
setSlot(name: string, id: number, count: number, data: number, extra?: ItemExtraData): void;
isValidInput(item: ItemInstance, side: number, tileEntity: TileEntity): boolean;
checkSide(slotSideTag: string | number, side: number): boolean;
addItem(item: ItemInstance, side: number, maxCount?: number): number;
getOutputSlots(side: number): string[];
canReceiveLiquid(liquid: string, side?: number): boolean;
canTransportLiquid(liquid: string, side?: number): boolean;
addLiquid(liquid: string, amount: number): number;
getLiquid(liquid: string, amount: number): number;
getLiquidStored(storage?: string, side?: number): string;
}
declare let LIQUID_STORAGE_MAX_LIMIT: number;
declare type Container = NativeTileEntity | UI.Container | ItemContainer;
declare namespace StorageInterface {
const data: {};
const directionsBySide: {
var data: {};
var directionsBySide: {
x: number;
y: number;
z: number;
}[];
function getRelativeCoords(coords: Vector | TileEntity, side: number): {
x: number;
y: number;
z: number;
};
function newInstance(id: number, tileEntity: TileEntity): {
tileEntity: TileEntity;
container: UI.Container;
liquidStorage: any;
};
function createInterface(id: number, interface: any): void;
function getRelativeCoords(coords: Vector, side: number): Vector;
function setSlotMaxStackPolicy(container: ItemContainer, slotName: string, maxCount: number): void;
function setSlotValidatePolicy(container: ItemContainer, slotName: string, func: (name: string, id: number, amount: number, data: number, extra: ItemExtraData, container: ItemContainer, playerUid: number) => boolean): void;
function setGlobalValidatePolicy(container: ItemContainer, func: (name: string, id: number, amount: number, data: number, extra: ItemExtraData, container: ItemContainer, playerUid: number) => boolean): void;
function newInstance(storage: TileEntity | Container): IStorage;
function createInterface(id: number, interface: StorageDescriptor): void;
function addItemToSlot(item: ItemInstance, slot: ItemInstance, count: number): number;
function getNearestContainers(coords: Vector | TileEntity, side: number, excludeSide?: boolean): {};
function getNearestLiquidStorages(coords: Vector | TileEntity, side: number, excludeSide?: boolean): {};
function putItems(items: ItemInstance[], containers: any): void;
function putItemToContainer(item: ItemInstance, container: NativeTileEntity | UI.Container | ItemContainer, side: number, maxCount?: number): number;
function extractItemsFromContainer(inputTile: TileEntity, container: NativeTileEntity | UI.Container, side: number, maxCount?: number, oneStack?: boolean): number;
function getStorage(region: BlockSource, x: number, y: number, z: number): IStorage;
function getNearestContainers(coords: Vector, side: number, excludeSide?: boolean): object;
function getNearestLiquidStorages(coords: Vector, side: number, excludeSide?: boolean): object;
function getContainerSlots(container: Container): string[] | number[];
function putItems(items: ItemInstance[], containers: object): void;
function putItemToContainer(item: ItemInstance, container: Container, side: number, maxCount?: number): number;
function extractItemsFromContainer(inputContainer: TileEntity | Container, outputContainer: Container, side: number, maxCount?: number, oneStack?: boolean): number;
function extractLiquid(liquid: string, maxAmount: number, input: TileEntity, output: TileEntity, inputSide: number): void;
function transportLiquid(liquid: string, maxAmount: number, output: TileEntity, input: TileEntity, outputSide: number): void;
function getContainerSlots(container: any, mode: number, side: number): (string | number)[];
function checkHoppers(tile: TileEntity): void;
function extractItems(items: ItemInstance[], containers: any, tile: TileEntity): void;
}
6 changes: 3 additions & 3 deletions make.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"name": "BuildCraft PE",
"author": "Nikolay Savenko",
"version": "1.0",
"version": "1.0.1",
"description": "Port of PC version of BuildCraft"
},
"api": "CoreEngine"
Expand Down Expand Up @@ -53,8 +53,8 @@
"language": "javascript"
},
{
"source": "src/dev",
"target": "main.js",
"source": "src/dev",
"target": "main.js",
"type": "main",
"language": "typescript"
},
Expand Down
4 changes: 0 additions & 4 deletions src/dev/core/engine/Engines.ts

This file was deleted.

46 changes: 26 additions & 20 deletions src/dev/core/engine/abstract/BCEngineTileEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
/// <reference path="../../energy.ts" />
/// <reference path="../interface/IHeatable.ts" />
/// <reference path="../interface/IEngine.ts" />
/**
* !WARNING
* this code adapted from JAVA source of PC mod
* this structure created not by me
* dont punch me pls
*/
abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHeatable, IEngine {
public readonly MIN_HEAT: number = 20;
public readonly IDEAL_HEAT: number = 100;
Expand All @@ -18,7 +24,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
// How many ticks ago it gave out power, capped to 4.
private lastTick: number = 0;

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

public setOrientation(value: number) {
if (typeof(value) == "number") {
if (typeof (value) == "number") {
const { x, y, z } = this;
this.blockSource.setBlock(x, y, z, this.blockSource.getBlockId(x, y, z), value);
this.updateClientOrientation();
Expand All @@ -65,7 +71,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
this.networkData.sendChanges();
}

private setProgress(value: number){
private setProgress(value: number) {
this.data.progress = value;
this.networkData.putFloat("progress", value);
}
Expand All @@ -74,15 +80,15 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
return this.data.progress;
}

private setProgressPart(value: number){
private setProgressPart(value: number) {
this.progressPart = value;
}

private getProgressPart(): number {
return this.progressPart;
}

private setEnergyStage(value: EngineHeat){
private setEnergyStage(value: EngineHeat) {
this.energyStage = value;
this.networkData.putInt("energyStageIndex", HeatOrder.indexOf(this.energyStage));
this.networkData.sendChanges();
Expand All @@ -92,7 +98,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
return this.isPumping;
}

public setPumping(value: boolean){
public setPumping(value: boolean) {
if (this.isPumping == value) return;
this.isPumping = value;
this.lastTick = 0;
Expand Down Expand Up @@ -173,24 +179,24 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
}

// !TileEntity event
public init(){
public init() {
this.checkOrientation = true;
}

// !TileEntity event
public redstone(params){
public redstone(params) {
this.isRedstonePowered = params.signal > 0;
}

// !TileEntity event
public tick(){
public tick() {
if (this.checkOrientation) this.updateConnectionSide();
if (this.lastTick < 4) this.lastTick++;

this.updateHeat();
this.getEnergyStage();

if (this.getEnergyStage() === EngineHeat.OVERHEAT){
if (this.getEnergyStage() === EngineHeat.OVERHEAT) {
this.data.energy = Math.max(this.data.energy - 50, 0);
return;
}
Expand Down Expand Up @@ -234,7 +240,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
}

public click(id, count, data) {
if(id != ItemID.bc_wrench) return false;
if (id != ItemID.bc_wrench) return false;
if (this.getEnergyStage() == EngineHeat.OVERHEAT) {
this.setEnergyStage(this.computeEnergyStage());
}
Expand All @@ -249,21 +255,21 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
// ! @MineExplorer PLEASE make EnergyTileRegistry BlockSource support
// TODO move to blockSource getConnectionSide
/** @param findNext - use true value if you want to rerotate engine like a wrench */
protected getConnectionSide(findNext : boolean = false){
protected getConnectionSide(findNext: boolean = false) {
// * In common situation ends when i gets max in 5 index
// * But if fhis function calling by wrench index can go beyound
// * I think this code is poor, but maybe i fix it in future
const orientation = this.getOrientation();
for(let t = 0; t < 12; t++){
for (let t = 0; t < 12; t++) {
const i = t % 6;
if(findNext) {
if(orientation == t) findNext = false;
if (findNext) {
if (orientation == t) findNext = false;
continue;
}
const relCoords = World.getRelativeCoords(this.x, this.y, this.z, i);
// * ?. is new ESNext feature. Its amazing!
const energyTypes = EnergyTileRegistry.accessMachineAtCoords(relCoords.x, relCoords.y, relCoords.z)?.__energyTypes;
if(energyTypes?.RF) return i;
if (energyTypes?.RF) return i;
}
return null;
}
Expand All @@ -273,7 +279,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
const orientation = this.getOrientation();
if (!this.isPoweredTile(this.getEnergyProvider(orientation), orientation)) {
const side = this.getConnectionSide();
if (typeof(side) == "number") {
if (typeof (side) == "number") {
this.setOrientation(side);
} else this.updateClientOrientation();
} else this.updateClientOrientation();
Expand Down Expand Up @@ -310,7 +316,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe

private getPowerToExtract(): number {
const tile = this.getEnergyProvider(this.getOrientation());
if(!tile) return 0;
if (!tile) return 0;

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

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

public isPoweredTile(tile: any, side: number): boolean {
if(!tile) return false;
if (!tile) return false;
const oppositeSide = World.getInverseBlockSide(this.getOrientation());

if (tile.isEngine) {
Expand Down Expand Up @@ -442,7 +448,7 @@ abstract class BCEngineTileEntity implements TileEntity.TileEntityPrototype, IHe
}

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

// abstract methods
public abstract isBurning(): boolean
Expand Down
5 changes: 4 additions & 1 deletion src/dev/core/engine/creative/CreativeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/// <reference path="../components/recipe/EngineIngredients.ts" />
/// <reference path="CreativeEngineTileEntity.ts" />
/// <reference path="../EngineTextures.ts" />
// * only for engine order in creative tab
/// <reference path="../wood/WoodEngine.ts" />
class CreativeEngine extends BCEngine {

public get engineType(): string {
Expand All @@ -24,4 +26,5 @@ class CreativeEngine extends BCEngine {
protected getIngredientsForRecipe(): EngineIngredients {
return null;
}
}
}
const creativeEngine = new CreativeEngine();
4 changes: 3 additions & 1 deletion src/dev/core/engine/wood/WoodEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// <reference path="../components/recipe/EngineIngredients.ts" />
/// <reference path="WoodEngineTileEntity.ts" />
/// <reference path="../EngineTextures.ts" />
/// <reference path="../../../item/gears.ts" />

class WoodEngine extends BCEngine {
public get engineType(): string {
Expand All @@ -20,4 +21,5 @@ class WoodEngine extends BCEngine {
protected getIngredientsForRecipe(): EngineIngredients {
return new EngineIngredients({ id: ItemID.gear_wood, count: 1, data: 0 }, { id: VanillaBlockID.planks, count: 1, data: -1 });
}
}
}
const woodenEngine = new WoodEngine();
3 changes: 1 addition & 2 deletions src/dev/core/pipe/components/PipeBlock.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const BlockTypePipe: Block.SpecialType = {
base: 1,
destroytime: 0.2,
explosionres: 0.5,
renderlayer: 1
explosionres: 0.5
};

class PipeBlock {
Expand Down
9 changes: 8 additions & 1 deletion src/dev/core/pipe/item/ItemMachines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ const transportConnector = new TransportPipeConnector();
const basicRule = transportConnector.getConnectionRules()[0];

for (const instance of ITEM_MACHINES) {
ICRender.getGroup(basicRule.name).add(instance.id, instance.data);
ICRender.getGroup(basicRule.name).add(instance.id, instance.data);
}

// For StorageInterface containers
// @ts-ignore
for (const blockID in StorageInterface.data) {
// @ts-ignore
ICRender.getGroup(basicRule.name).add(blockID, -1);
}
21 changes: 0 additions & 21 deletions src/dev/core/pipe/item/ItemPipes.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/dev/core/pipe/item/cobble/PipeCobble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ class PipeCobble extends BCTransportPipe {
protected getIngredientForRecipe(): ItemInstance {
return { id: VanillaBlockID.cobblestone, count: 1, data: 0 }
}
}
}
const cobblePipe = new PipeCobble();
Loading