Search in sources :

Example 1 with FluidLogisticsPromise

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);
    }
}
Also used : ISpecialTankHandler(logisticspipes.interfaces.ISpecialTankHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) FluidStack(net.minecraftforge.fluids.FluidStack) ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) FluidResource(logisticspipes.request.resources.FluidResource) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) FluidLogisticsPromise(logisticspipes.routing.FluidLogisticsPromise)

Aggregations

ISpecialTankAccessHandler (logisticspipes.interfaces.ISpecialTankAccessHandler)1 ISpecialTankHandler (logisticspipes.interfaces.ISpecialTankHandler)1 FluidResource (logisticspipes.request.resources.FluidResource)1 FluidLogisticsPromise (logisticspipes.routing.FluidLogisticsPromise)1 FluidIdentifier (logisticspipes.utils.FluidIdentifier)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1