Search in sources :

Example 1 with IEngine

use of buildcraft.api.power.IEngine in project BuildCraft by BuildCraft.

the class TileEngineBase method sendPower.

protected void sendPower() {
    Object tile = getEnergyProvider(orientation);
    if (isPoweredTile(tile, orientation)) {
        int extracted = getPowerToExtract();
        if (extracted <= 0) {
            setPumping(false);
            return;
        }
        setPumping(true);
        if (tile instanceof IEngine) {
            IEngine engine = (IEngine) tile;
            int neededRF = engine.receiveEnergyFromEngine(orientation.getOpposite(), extracted, false);
            extractEnergy(neededRF, true);
        } else if (tile instanceof IEnergyReceiver) {
            IEnergyReceiver handler = (IEnergyReceiver) tile;
            int neededRF = handler.receiveEnergy(orientation.getOpposite(), extracted, false);
            extractEnergy(neededRF, true);
        }
    }
}
Also used : IEngine(buildcraft.api.power.IEngine) IEnergyReceiver(cofh.api.energy.IEnergyReceiver)

Example 2 with IEngine

use of buildcraft.api.power.IEngine in project BuildCraft by BuildCraft.

the class TileEngineBase method getPowerToExtract.

private int getPowerToExtract() {
    Object tile = getEnergyProvider(orientation);
    if (tile instanceof IEngine) {
        IEngine engine = (IEngine) tile;
        int maxEnergy = engine.receiveEnergyFromEngine(orientation.getOpposite(), this.energy, true);
        return extractEnergy(maxEnergy, false);
    } else if (tile instanceof IEnergyReceiver) {
        IEnergyReceiver handler = (IEnergyReceiver) tile;
        int maxEnergy = handler.receiveEnergy(orientation.getOpposite(), this.energy, true);
        return extractEnergy(maxEnergy, false);
    } else {
        return 0;
    }
}
Also used : IEngine(buildcraft.api.power.IEngine) IEnergyReceiver(cofh.api.energy.IEnergyReceiver)

Example 3 with IEngine

use of buildcraft.api.power.IEngine in project BuildCraft by BuildCraft.

the class Utils method addToRandomInventoryAround.

/**
 * Tries to add the passed stack to any valid inventories around the given coordinates.
 *
 * @param stack
 * @param world
 * @param x
 * @param y
 * @param z
 * @return amount used
 */
public static int addToRandomInventoryAround(World world, BlockPos pos, ItemStack stack) {
    Collections.shuffle(directions);
    for (EnumFacing orientation : directions) {
        BlockPos newpos = pos.offset(orientation);
        TileEntity tile = world.getTileEntity(newpos);
        ITransactor transactor = Transactor.getTransactorFor(tile, orientation.getOpposite());
        if (transactor != null && !(tile instanceof IEngine) && transactor.insert(stack, false).stackSize > 0) {
            // UP!
            return transactor.insert(stack, true).stackSize;
        }
    }
    return 0;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IEngine(buildcraft.api.power.IEngine) ITransactor(buildcraft.core.lib.inventory.ITransactor)

Aggregations

IEngine (buildcraft.api.power.IEngine)3 IEnergyReceiver (cofh.api.energy.IEnergyReceiver)2 ITransactor (buildcraft.core.lib.inventory.ITransactor)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1