Search in sources :

Example 1 with IPowerReceptor

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPosition(powercrystals.core.position.BlockPosition) IPowerReceptor(buildcraft.api.power.IPowerReceptor) IPowerProvider(buildcraft.api.power.IPowerProvider)

Aggregations

IPowerProvider (buildcraft.api.power.IPowerProvider)1 IPowerReceptor (buildcraft.api.power.IPowerReceptor)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPosition (powercrystals.core.position.BlockPosition)1