use of logisticspipes.interfaces.routing.IRequireReliableFluidTransport in project LogisticsPipes by RS485.
the class FluidRoutedPipe method endReached.
public boolean endReached(LPTravelingItemServer arrivingItem, TileEntity tile) {
if (canInsertToTanks() && MainProxy.isServer(getWorld())) {
getCacheHolder().trigger(CacheTypes.Inventory);
if (arrivingItem.getItemIdentifierStack() == null || !(arrivingItem.getItemIdentifierStack().getItem().isFluidContainer())) {
return false;
}
if (getRouter().getSimpleID() != arrivingItem.getDestination()) {
return false;
}
int filled = 0;
FluidStack liquid = SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(arrivingItem.getItemIdentifierStack());
if (isConnectableTank(tile, arrivingItem.output, false)) {
List<Pair<TileEntity, ForgeDirection>> adjTanks = getAdjacentTanks(false);
//Try to put liquid into all adjacent tanks.
for (Pair<TileEntity, ForgeDirection> pair : adjTanks) {
IFluidHandler tank = (IFluidHandler) pair.getValue1();
ForgeDirection dir = pair.getValue2();
filled = tank.fill(dir.getOpposite(), liquid.copy(), true);
liquid.amount -= filled;
if (liquid.amount != 0) {
continue;
}
return true;
}
//Try inserting the liquid into the pipe side tank
filled = ((PipeFluidTransportLogistics) transport).sideTanks[arrivingItem.output.ordinal()].fill(liquid, true);
if (filled == liquid.amount) {
return true;
}
liquid.amount -= filled;
}
//Try inserting the liquid into the pipe internal tank
filled = ((PipeFluidTransportLogistics) transport).internalTank.fill(liquid, true);
if (filled == liquid.amount) {
return true;
}
//If liquids still exist,
liquid.amount -= filled;
//TODO: FIX THIS
if (this instanceof IRequireReliableFluidTransport) {
((IRequireReliableFluidTransport) this).liquidNotInserted(FluidIdentifier.get(liquid), liquid.amount);
}
IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(SimpleServiceLocator.logisticsFluidManager.getFluidContainer(liquid));
Pair<Integer, Integer> replies = SimpleServiceLocator.logisticsFluidManager.getBestReply(liquid, getRouter(), routedItem.getJamList());
int dest = replies.getValue1();
routedItem.setDestination(dest);
routedItem.setTransportMode(TransportMode.Passive);
this.queueRoutedItem(routedItem, arrivingItem.output.getOpposite());
return true;
}
return false;
}
Aggregations