1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Implement tryTakeItem in EnergyConsumer

This commit is contained in:
isaisstillalive 2020-07-03 01:44:31 +09:00
parent 9ef0e77910
commit 7b60cc9420
3 changed files with 16 additions and 17 deletions

View File

@ -103,6 +103,7 @@ export class MetaAdvancedProcessorBuilding extends MetaBuilding {
directions: [enumDirection.top],
filter: enumItemType.positiveEnergy,
layer: enumLayer.wires,
processor: "EnergyConsumer",
},
],
})

View File

@ -59,6 +59,21 @@ export class EnergyConsumerComponent extends Component {
this.piledOutput = 0;
}
/**
*
* @param {BaseItem} item
* @param {number} slot
*/
tryTakeItem(item, slot) {
if (this.tryAcceptItem(item, slot)) {
// All good
return true;
}
// Energy consumer can have more components
return false;
}
/**
* Tries to accept a given item
* @param {BaseItem} item

View File

@ -267,23 +267,6 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
}
}
// Try figuring out how what to do with the item
// TODO: Kinda hacky. How to solve this properly? Don't want to go through inheritance hell.
// Also its just a few cases (hope it stays like this .. :x).
const slotIndex = slot.index;
const itemLayer = enumItemTypeToLayer[item.getItemType()];
const energyConsumerComp = receiver.components.EnergyConsumer;
if (energyConsumerComp) {
if (energyConsumerComp.tryAcceptItem(item, slotIndex)) {
// All good
return true;
}
// Energy consumer can have more components
}
return false;
}