use of blusunrize.immersiveengineering.common.blocks.metal.TileEntityFluidPipe.DirectionalFluidOutput in project ImmersiveEngineering by BluSunrize.
the class TileEntityFluidPump method outputFluid.
public int outputFluid(FluidStack fs, boolean simulate) {
if (fs == null)
return 0;
int canAccept = fs.amount;
if (canAccept <= 0)
return 0;
int accelPower = IEConfig.Machines.pump_consumption_accelerate;
final int fluidForSort = canAccept;
int sum = 0;
HashMap<DirectionalFluidOutput, Integer> sorting = new HashMap<DirectionalFluidOutput, Integer>();
for (EnumFacing f : EnumFacing.values()) if (sideConfig[f.ordinal()] == 1) {
TileEntity tile = worldObj.getTileEntity(getPos().offset(f));
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, f.getOpposite())) {
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, f.getOpposite());
FluidStack insertResource = new FluidStack(fs.getFluid(), fs.amount);
if (tile instanceof TileEntityFluidPipe && this.energyStorage.extractEnergy(accelPower, true) >= accelPower) {
insertResource.tag = new NBTTagCompound();
insertResource.tag.setBoolean("pressurized", true);
}
int temp = handler.fill(insertResource, false);
if (temp > 0) {
sorting.put(new DirectionalFluidOutput(handler, tile, f), temp);
sum += temp;
}
}
}
if (sum > 0) {
int f = 0;
int i = 0;
for (DirectionalFluidOutput output : sorting.keySet()) {
float prio = sorting.get(output) / (float) sum;
int amount = (int) (fluidForSort * prio);
if (i++ == sorting.size() - 1)
amount = canAccept;
FluidStack insertResource = new FluidStack(fs.getFluid(), amount);
if (output.containingTile instanceof TileEntityFluidPipe && this.energyStorage.extractEnergy(accelPower, true) >= accelPower) {
this.energyStorage.extractEnergy(accelPower, false);
insertResource.tag = new NBTTagCompound();
insertResource.tag.setBoolean("pressurized", true);
}
int r = output.output.fill(insertResource, !simulate);
f += r;
canAccept -= r;
if (canAccept <= 0)
break;
}
return f;
}
return 0;
}
Aggregations