use of cofh.api.energy.IEnergyReceiver in project PneumaticCraft by MineMaarten.
the class ProgWidgetRFCondition method getEvaluator.
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {
@Override
protected boolean evaluate(ChunkPosition pos) {
TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
int energy = 0;
if (te instanceof IEnergyReceiver) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (getSides()[d.ordinal()]) {
energy = Math.max(((IEnergyReceiver) te).getEnergyStored(d), energy);
}
}
}
if (te instanceof IEnergyProvider) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if (getSides()[d.ordinal()]) {
energy = Math.max(((IEnergyProvider) te).getEnergyStored(d), energy);
}
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? energy == ((ICondition) widget).getRequiredCount() : energy >= ((ICondition) widget).getRequiredCount();
}
};
}
Aggregations