Search in sources :

Example 1 with IRequireReliableFluidTransport

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;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) IRequireReliableFluidTransport(logisticspipes.interfaces.routing.IRequireReliableFluidTransport) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

IRequireReliableFluidTransport (logisticspipes.interfaces.routing.IRequireReliableFluidTransport)1 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)1 PipeFluidTransportLogistics (logisticspipes.transport.PipeFluidTransportLogistics)1 Pair (logisticspipes.utils.tuples.Pair)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1