use of buildcraft.api.power.IPowerReceptor in project MineFactoryReloaded by powercrystals.
the class TileEntityGenerator method producePower.
protected final int producePower(int mj) {
BlockPosition ourbp = BlockPosition.fromFactoryTile(this);
for (BlockPosition bp : ourbp.getAdjacent(true)) {
TileEntity te = worldObj.getBlockTileEntity(bp.x, bp.y, bp.z);
if (te == null || !(te instanceof IPowerReceptor)) {
continue;
}
IPowerReceptor ipr = ((IPowerReceptor) te);
IPowerProvider pp = ipr.getPowerProvider();
if (pp != null && pp.preConditions(ipr) && pp.getMinEnergyReceived() <= mj) {
int mjUsed = Math.min(Math.min(pp.getMaxEnergyReceived(), mj), pp.getMaxEnergyStored() - (int) Math.floor(pp.getEnergyStored()));
pp.receiveEnergy(mjUsed, bp.orientation);
mj -= mjUsed;
if (mj <= 0) {
return 0;
}
}
}
return mj;
}
Aggregations