Search in sources :

Example 6 with PipeFluidTransportLogistics

use of logisticspipes.transport.PipeFluidTransportLogistics in project LogisticsPipes by RS485.

the class FluidRoutedPipe method enabledUpdateEntity.

@Override
public void enabledUpdateEntity() {
    super.enabledUpdateEntity();
    if (canInsertFromSideToTanks()) {
        int validDirections = 0;
        final List<Pair<NeighborTileEntity<TileEntity>, ITankUtil>> list = PipeFluidUtil.INSTANCE.getAdjacentTanks(this, true);
        for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> pair : list) {
            if (pair.getValue2() instanceof LogisticsTileGenericPipe) {
                if (((LogisticsTileGenericPipe) pair.getValue2()).pipe instanceof CoreRoutedPipe) {
                    continue;
                }
            }
            FluidTank internalTank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue1().getDirection().ordinal()];
            validDirections++;
            if (internalTank.getFluid() == null) {
                continue;
            }
            int filled = pair.getValue2().fill(FluidIdentifierStack.getFromStack(internalTank.getFluid()), true);
            if (filled == 0) {
                continue;
            }
            FluidStack drain = internalTank.drain(filled, true);
            if (drain == null || filled != drain.amount) {
                if (LogisticsPipes.isDEBUG()) {
                    throw new UnsupportedOperationException("Fluid Multiplication");
                }
            }
        }
        if (validDirections == 0) {
            return;
        }
        FluidTank tank = ((PipeFluidTransportLogistics) transport).internalTank;
        FluidStack stack = tank.getFluid();
        if (stack == null) {
            return;
        }
        for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> pair : list) {
            if (pair.getValue1().isLogisticsPipe()) {
                if (((LogisticsTileGenericPipe) pair.getValue1().getTileEntity()).pipe instanceof CoreRoutedPipe) {
                    continue;
                }
            }
            FluidTank tankSide = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue1().getDirection().ordinal()];
            stack = tank.getFluid();
            if (stack == null) {
                continue;
            }
            stack = stack.copy();
            int filled = tankSide.fill(stack, true);
            if (filled == 0) {
                continue;
            }
            FluidStack drain = tank.drain(filled, true);
            if (drain == null || filled != drain.amount) {
                if (LogisticsPipes.isDEBUG()) {
                    throw new UnsupportedOperationException("Fluid Multiplication");
                }
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) FluidTank(net.minecraftforge.fluids.FluidTank) ITankUtil(logisticspipes.interfaces.ITankUtil) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) Pair(logisticspipes.utils.tuples.Pair)

Example 7 with PipeFluidTransportLogistics

use of logisticspipes.transport.PipeFluidTransportLogistics in project LogisticsPipes by RS485.

the class PipeFluidExtractor method extractFrom.

private void extractFrom(ITankUtil container, EnumFacing side) {
    int sideID = side.ordinal();
    FluidStack contained = ((PipeFluidTransportLogistics) transport).getTankProperties(side)[0].getContents();
    int amountMissing = ((PipeFluidTransportLogistics) transport).getSideCapacity() - (contained != null ? contained.amount : 0);
    if (liquidToExtract[sideID] < Math.min(PipeFluidExtractor.flowRate, amountMissing)) {
        if (this.useEnergy(PipeFluidExtractor.energyPerFlow)) {
            liquidToExtract[sideID] += Math.min(PipeFluidExtractor.flowRate, amountMissing);
        }
    }
    FluidIdentifierStack extracted = container.drain(Math.min(liquidToExtract[sideID], PipeFluidExtractor.flowRate), false);
    int inserted = 0;
    if (extracted != null) {
        inserted = ((PipeFluidTransportLogistics) transport).fill(side, extracted.makeFluidStack(), true);
        container.drain(inserted, true);
    }
    liquidToExtract[sideID] -= inserted;
}
Also used : FluidIdentifierStack(logisticspipes.utils.FluidIdentifierStack) FluidStack(net.minecraftforge.fluids.FluidStack) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics)

Example 8 with PipeFluidTransportLogistics

use of logisticspipes.transport.PipeFluidTransportLogistics in project LogisticsPipes by RS485.

the class PipeFluidInsertion method enabledUpdateEntity.

@Override
public void enabledUpdateEntity() {
    super.enabledUpdateEntity();
    List<Integer> tempJamList = new ArrayList<>();
    if (!localJamList.isEmpty()) {
        List<Pair<Integer, Integer>> toRemove = new ArrayList<>();
        for (Pair<Integer, Integer> part : localJamList) {
            part.setValue2(part.getValue2() - 1);
            if (part.getValue2() <= 0) {
                toRemove.add(part);
            } else {
                tempJamList.add(part.getValue1());
            }
        }
        if (!toRemove.isEmpty()) {
            localJamList.removeAll(toRemove);
        }
    }
    PipeFluidTransportLogistics transport = (PipeFluidTransportLogistics) this.transport;
    for (EnumFacing dir : EnumFacing.VALUES) {
        FluidStack stack = transport.sideTanks[dir.ordinal()].getFluid();
        if (stack == null) {
            continue;
        }
        stack = stack.copy();
        if (nextSendMax[dir.ordinal()] > 0 && stack.amount < transport.sideTanks[dir.ordinal()].getCapacity()) {
            nextSendMax[dir.ordinal()]--;
            continue;
        }
        if (nextSendMin[dir.ordinal()] > 0) {
            nextSendMin[dir.ordinal()]--;
            continue;
        }
        Pair<Integer, FluidSinkReply> result = SimpleServiceLocator.logisticsFluidManager.getBestReply(FluidIdentifierStack.getFromStack(stack), getRouter(), tempJamList);
        if (result == null || result.getValue2().sinkAmount <= 0) {
            nextSendMax[dir.ordinal()] = 100;
            nextSendMin[dir.ordinal()] = 10;
            continue;
        }
        if (!useEnergy((int) (0.01 * result.getValue2().getSinkAmountInt()))) {
            nextSendMax[dir.ordinal()] = 100;
            nextSendMin[dir.ordinal()] = 10;
            continue;
        }
        FluidStack toSend = transport.sideTanks[dir.ordinal()].drain(result.getValue2().getSinkAmountInt(), true);
        ItemIdentifierStack liquidContainer = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(FluidIdentifierStack.getFromStack(toSend));
        IRoutedItem routed = SimpleServiceLocator.routedItemHelper.createNewTravelItem(liquidContainer);
        routed.setDestination(result.getValue1());
        routed.setTransportMode(TransportMode.Passive);
        this.queueRoutedItem(routed, dir);
        nextSendMax[dir.ordinal()] = 100;
        nextSendMin[dir.ordinal()] = 5;
    }
}
Also used : PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) FluidSinkReply(logisticspipes.utils.FluidSinkReply) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Pair(logisticspipes.utils.tuples.Pair)

Example 9 with PipeFluidTransportLogistics

use of logisticspipes.transport.PipeFluidTransportLogistics in project LogisticsPipes by RS485.

the class PipeFluidSupplierMk2 method throttledUpdateEntity.

@Override
public void throttledUpdateEntity() {
    if (!isEnabled()) {
        return;
    }
    if (MainProxy.isClient(Objects.requireNonNull(container).getWorld())) {
        return;
    }
    super.throttledUpdateEntity();
    if (dummyInventory.getIDStackInSlot(0) == null) {
        return;
    }
    PipeFluidUtil.INSTANCE.getAdjacentTanks(this, false).forEach(fluidHandlerDirectionPair -> {
        if (!fluidHandlerDirectionPair.getValue2().containsTanks()) {
            return;
        }
        // How much do I want?
        Map<FluidIdentifier, Integer> wantFluids = new HashMap<>();
        ItemIdentifierStack stack = dummyInventory.getIDStackInSlot(0);
        if (stack == null)
            return;
        FluidIdentifier fIdent = FluidIdentifier.get(stack.getItem());
        wantFluids.put(fIdent, amount);
        // How much do I have?
        HashMap<FluidIdentifier, Integer> haveFluids = new HashMap<>();
        // Check what is inside the connected tank
        fluidHandlerDirectionPair.getValue2().tanks().map(tank -> FluidIdentifierStack.getFromStack(tank.getContents())).filter(Objects::nonNull).forEach(fluid -> haveFluids.merge(fluid.getFluid(), fluid.getAmount(), Integer::sum));
        // What does our sided internal tank have
        int directionOrdinal = fluidHandlerDirectionPair.getValue1().getDirection().ordinal();
        if (directionOrdinal < ((PipeFluidTransportLogistics) transport).sideTanks.length) {
            FluidTank sideTank = ((PipeFluidTransportLogistics) transport).sideTanks[directionOrdinal];
            if (sideTank != null && sideTank.getFluid() != null && wantFluids.containsKey(FluidIdentifier.get(sideTank.getFluid()))) {
                haveFluids.merge(FluidIdentifier.get(sideTank.getFluid()), sideTank.getFluid().amount, Integer::sum);
            }
        }
        // What does our center internal tank have
        FluidTank centerTank = ((PipeFluidTransportLogistics) transport).internalTank;
        if (centerTank != null && centerTank.getFluid() != null && wantFluids.containsKey(FluidIdentifier.get(centerTank.getFluid()))) {
            haveFluids.merge(FluidIdentifier.get(centerTank.getFluid()), centerTank.getFluid().amount, Integer::sum);
        }
        // Reduce what I have and what have been requested already
        for (Entry<FluidIdentifier, Integer> liquidId : wantFluids.entrySet()) {
            Integer haveCount = haveFluids.get(liquidId.getKey());
            if (haveCount != null) {
                liquidId.setValue(liquidId.getValue() - haveCount);
            }
            // @formatter:off
            _requestedItems.entrySet().stream().filter(requestedItem -> requestedItem.getKey().equals(liquidId.getKey())).forEach(requestedItem -> liquidId.setValue(liquidId.getValue() - requestedItem.getValue()));
        // @formatter:on
        }
        setRequestFailed(false);
        for (FluidIdentifier need : wantFluids.keySet()) {
            int countToRequest = wantFluids.get(need);
            if (countToRequest < 1) {
                continue;
            }
            if (_bucketMinimum.getAmount() != 0 && countToRequest < _bucketMinimum.getAmount()) {
                continue;
            }
            if (!useEnergy(11)) {
                break;
            }
            boolean success = false;
            if (_requestPartials) {
                countToRequest = RequestTree.requestFluidPartial(need, countToRequest, this, null);
                if (countToRequest > 0) {
                    success = true;
                }
            } else {
                success = RequestTree.requestFluid(need, countToRequest, this, null);
            }
            if (success) {
                Integer currentRequest = _requestedItems.get(need);
                if (currentRequest == null) {
                    _requestedItems.put(need, countToRequest);
                } else {
                    _requestedItems.put(need, currentRequest + countToRequest);
                }
            } else {
                setRequestFailed(true);
            }
        }
    });
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) Getter(lombok.Getter) IRequireReliableFluidTransport(logisticspipes.interfaces.routing.IRequireReliableFluidTransport) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) LogisticsPipes(logisticspipes.LogisticsPipes) HashMap(java.util.HashMap) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) MainProxy(logisticspipes.proxy.MainProxy) FluidIdentifier(logisticspipes.utils.FluidIdentifier) FluidIdentifierStack(logisticspipes.utils.FluidIdentifierStack) Map(java.util.Map) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) TextureType(logisticspipes.textures.Textures.TextureType) PacketHandler(logisticspipes.network.PacketHandler) RequestTree(logisticspipes.request.RequestTree) Objects(java.util.Objects) FluidSupplierAmount(logisticspipes.network.packets.pipe.FluidSupplierAmount) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IInventory(net.minecraft.inventory.IInventory) Entry(java.util.Map.Entry) FluidTank(net.minecraftforge.fluids.FluidTank) GuiIDs(logisticspipes.network.GuiIDs) FluidRoutedPipe(logisticspipes.pipes.basic.fluid.FluidRoutedPipe) HashMap(java.util.HashMap) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Aggregations

PipeFluidTransportLogistics (logisticspipes.transport.PipeFluidTransportLogistics)9 FluidStack (net.minecraftforge.fluids.FluidStack)5 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)3 FluidIdentifierStack (logisticspipes.utils.FluidIdentifierStack)3 ITankUtil (logisticspipes.interfaces.ITankUtil)2 IRequireReliableFluidTransport (logisticspipes.interfaces.routing.IRequireReliableFluidTransport)2 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)2 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)2 FluidSinkReply (logisticspipes.utils.FluidSinkReply)2 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)2 Pair (logisticspipes.utils.tuples.Pair)2 FluidTank (net.minecraftforge.fluids.FluidTank)2 NeighborTileEntity (network.rs485.logisticspipes.connection.NeighborTileEntity)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 LogisticsPipes (logisticspipes.LogisticsPipes)1 IRequestFluid (logisticspipes.interfaces.routing.IRequestFluid)1