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);
}
}
}
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;
}
}
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;
}
Aggregations