int totalRequested = 0;
int numRequests = 0;
// Then to external connections
for (ForgeDirection dir : con.getExternalConnections()) {
if(con.canOutputToDir(dir)) {
IFluidHandler extCon = con.getExternalHandler(dir);
if(extCon != null) {
int amount = extCon.fill(dir.getOpposite(), available.copy(), false);
if(amount > 0) {
totalRequested += amount;
numRequests++;
}
}
}
}
if(numRequests > 0) {
int amountPerRequest = Math.min(totalAmount, totalRequested) / numRequests;
amountPerRequest = Math.min(maxFlowVolume, amountPerRequest);
FluidStack requestSource = available.copy();
requestSource.amount = amountPerRequest;
for (ForgeDirection dir : con.getExternalConnections()) {
if(con.canOutputToDir(dir)) {
IFluidHandler extCon = con.getExternalHandler(dir);
if(extCon != null) {
int amount = extCon.fill(dir.getOpposite(), requestSource.copy(), true);
if(amount > 0) {
outputedToExternal(amount);
tank.addAmount(-amount);
}
}