use of logisticspipes.routing.FluidLogisticsPromise in project LogisticsPipes by RS485.
the class PipeFluidProvider method canProvide.
@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filter) {
if (tree.isDone()) {
return;
}
if (!(tree.getRequestType() instanceof FluidResource)) {
return;
}
FluidIdentifier fluid = ((FluidResource) tree.getRequestType()).getFluid();
int containedAmount = 0;
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
boolean fallback = true;
if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
if (handler instanceof ISpecialTankAccessHandler) {
fallback = false;
Map<FluidIdentifier, Long> map = ((ISpecialTankAccessHandler) handler).getAvailableLiquid(pair.getValue1());
if (map.containsKey(fluid)) {
long addition = (containedAmount) + map.get(fluid);
containedAmount = addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition;
}
}
}
if (fallback) {
FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
if (tanks != null) {
for (FluidTankInfo tank : tanks) {
if (tank == null) {
continue;
}
FluidStack liquid;
if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
if (fluid.equals(FluidIdentifier.get(liquid))) {
if (((IFluidHandler) pair.getValue1()).canDrain(pair.getValue2().getOpposite(), liquid.getFluid())) {
if (((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), 1, false) != null) {
long addition = ((long) containedAmount) + liquid.amount;
containedAmount = addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition;
}
}
}
}
}
}
}
}
FluidLogisticsPromise promise = new FluidLogisticsPromise();
promise.liquid = fluid;
promise.amount = Math.min(tree.getMissingAmount(), containedAmount - root.getAllPromissesFor(this, fluid.getItemIdentifier()));
promise.sender = this;
promise.type = ResourceType.PROVIDER;
if (promise.amount > 0) {
tree.addPromise(promise);
}
}
Aggregations