Search in sources :

Example 36 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class ModuleProvider method sendStack.

// returns -1 on permanently failed, don't try another stack this tick
// returns 0 on "unable to do this delivery"
public int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return -1;
    ItemIdentifier item = stack.getItem();
    Iterator<Pair<IInventoryUtil, EnumFacing>> iterator = service.getAvailableAdjacent().inventories().stream().flatMap(neighbor -> {
        final IInventoryUtil invUtil = getInventoryUtilWithMode(neighbor);
        if (invUtil == null)
            return Stream.empty();
        return Stream.of(new Pair<>(invUtil, neighbor.getDirection()));
    }).iterator();
    while (iterator.hasNext()) {
        final Pair<IInventoryUtil, EnumFacing> current = iterator.next();
        int available = current.getValue1().itemCount(item);
        if (available == 0) {
            continue;
        }
        int wanted = Math.min(available, stack.getStackSize());
        wanted = Math.min(wanted, maxCount);
        wanted = Math.min(wanted, item.getMaxStackSize());
        IRouter dRtr = SimpleServiceLocator.routerManager.getServerRouter(destination);
        if (dRtr == null) {
            service.getItemOrderManager().sendFailed();
            return 0;
        }
        SinkReply reply = LogisticsManager.canSink(stack.makeNormalStack(), dRtr, null, true, stack.getItem(), null, true, false);
        boolean defersend = false;
        if (reply != null) {
            // some pipes are not aware of the space in the adjacent inventory, so they return null
            if (reply.maxNumberOfItems < wanted) {
                wanted = reply.maxNumberOfItems;
                if (wanted <= 0) {
                    service.getItemOrderManager().deferSend();
                    return 0;
                }
                defersend = true;
            }
        }
        if (!service.canUseEnergy(wanted * neededEnergy())) {
            return -1;
        }
        ItemStack removed = current.getValue1().getMultipleItems(item, wanted);
        if (removed.isEmpty()) {
            continue;
        }
        int sent = removed.getCount();
        service.useEnergy(sent * neededEnergy());
        final IRoutedItem routedItem = service.sendStack(removed, destination, itemSendMode(), info, current.getValue2());
        service.getItemOrderManager().sendSuccessfull(sent, defersend, routedItem);
        return sent;
    }
    service.getItemOrderManager().sendFailed();
    return 0;
}
Also used : ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) IRouter(logisticspipes.routing.IRouter) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) SneakyModuleDirectionUpdate(logisticspipes.network.packets.modules.SneakyModuleDirectionUpdate) Particles(logisticspipes.pipefxhandlers.Particles) CCType(logisticspipes.proxy.computers.interfaces.CCType) MainProxy(logisticspipes.proxy.MainProxy) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) SinkReply(logisticspipes.utils.SinkReply) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) Map(java.util.Map) CCCommand(logisticspipes.proxy.computers.interfaces.CCCommand) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) NewGuiHandler(logisticspipes.network.NewGuiHandler) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IModuleInventoryReceive(logisticspipes.interfaces.IModuleInventoryReceive) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) SneakyDirection(network.rs485.logisticspipes.module.SneakyDirection) ProviderModuleInHand(logisticspipes.network.guis.module.inhand.ProviderModuleInHand) Objects(java.util.Objects) NullableEnumProperty(network.rs485.logisticspipes.property.NullableEnumProperty) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) IFilter(logisticspipes.interfaces.routing.IFilter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BooleanProperty(network.rs485.logisticspipes.property.BooleanProperty) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) Gui(network.rs485.logisticspipes.module.Gui) EnumProperty(network.rs485.logisticspipes.property.EnumProperty) Property(network.rs485.logisticspipes.property.Property) ProviderMode(network.rs485.logisticspipes.inventory.ProviderMode) ItemResource(logisticspipes.request.resources.ItemResource) IItemIdentifierInventory(network.rs485.logisticspipes.inventory.IItemIdentifierInventory) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IClientInformationProvider(logisticspipes.interfaces.IClientInformationProvider) InventoryProperty(network.rs485.logisticspipes.property.InventoryProperty) ImmutableList(com.google.common.collect.ImmutableList) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ProviderModuleGuiProvider(logisticspipes.network.guis.module.inpipe.ProviderModuleGuiProvider) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) Nonnull(javax.annotation.Nonnull) Iterator(java.util.Iterator) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) EnumFacing(net.minecraft.util.EnumFacing) LogisticsPromise(logisticspipes.routing.LogisticsPromise) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) RequestTree(logisticspipes.request.RequestTree) HUDProviderModule(logisticspipes.gui.hud.modules.HUDProviderModule) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) ModuleInventory(logisticspipes.network.packets.module.ModuleInventory) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ILegacyActiveModule(logisticspipes.interfaces.ILegacyActiveModule) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) EnumFacing(net.minecraft.util.EnumFacing) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) ItemStack(net.minecraft.item.ItemStack) Pair(logisticspipes.utils.tuples.Pair)

Example 37 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class ModuleCrafter method spaceFor.

protected int spaceFor(@Nonnull ItemStack stack, ItemIdentifier item, boolean includeInTransit) {
    Pair<String, ItemIdentifier> key = new Pair<>("spaceFor", item);
    final IPipeServiceProvider service = _service;
    if (service == null)
        return 0;
    Object cache = service.getCacheHolder().getCacheFor(CacheTypes.Inventory, key);
    int onRoute = 0;
    if (includeInTransit) {
        onRoute = service.countOnRoute(item);
    }
    if (cache != null) {
        return ((Integer) cache) - onRoute;
    }
    if (includeInTransit) {
        stack = stack.copy();
        stack.grow(onRoute);
    }
    final ISlotUpgradeManager upgradeManager = Objects.requireNonNull(getUpgradeManager());
    final ItemStack finalStack = stack;
    final Integer count = AdjacentUtilKt.sneakyInventoryUtils(service.getAvailableAdjacent(), upgradeManager).stream().map(invUtil -> invUtil.roomForItem(finalStack)).reduce(Integer::sum).orElse(0);
    service.getCacheHolder().setCache(CacheTypes.Inventory, key, count);
    return count - onRoute;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) ItemStack(net.minecraft.item.ItemStack) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) Pair(logisticspipes.utils.tuples.Pair)

Example 38 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class ModuleCrafter method importFromCraftingTable.

public void importFromCraftingTable(@Nullable EntityPlayer player) {
    if (MainProxy.isClient(getWorld())) {
        // Send packet asking for import
        final CoordinatesPacket packet = PacketHandler.getPacket(CPipeSatelliteImport.class).setModulePos(this);
        MainProxy.sendPacketToServer(packet);
    } else {
        final IPipeServiceProvider service = _service;
        if (service == null)
            return;
        service.getAvailableAdjacent().neighbors().keySet().stream().flatMap(neighbor -> SimpleServiceLocator.craftingRecipeProviders.stream().filter(provider -> provider.importRecipe(neighbor.getTileEntity(), dummyInventory)).map(provider1 -> new Pair<>(neighbor, provider1))).findFirst().ifPresent(neighborProviderPair -> {
            if (neighborProviderPair.getValue2() instanceof IFuzzyRecipeProvider) {
                ((IFuzzyRecipeProvider) neighborProviderPair.getValue2()).importFuzzyFlags(neighborProviderPair.getValue1().getTileEntity(), dummyInventory.getSlotAccess(), fuzzyFlags);
            }
        });
        // Send inventory as packet
        final CoordinatesPacket packet = PacketHandler.getPacket(CPipeSatelliteImportBack.class).setInventory(dummyInventory).setModulePos(this);
        if (player != null) {
            MainProxy.sendPacketToPlayer(packet, player);
        }
        MainProxy.sendPacketToAllWatchingChunk(this, packet);
    }
}
Also used : CPipeSatelliteImportBack(logisticspipes.network.packets.cpipe.CPipeSatelliteImportBack) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassis.ChassiTargetInformation) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) BitSetProperty(network.rs485.logisticspipes.property.BitSetProperty) Constants(net.minecraftforge.common.util.Constants) EnumHand(net.minecraft.util.EnumHand) MainProxy(logisticspipes.proxy.MainProxy) FluidCraftingAmount(logisticspipes.network.packets.pipe.FluidCraftingAmount) SinkReply(logisticspipes.utils.SinkReply) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) ItemCraftingTemplate(logisticspipes.request.ItemCraftingTemplate) Map(java.util.Map) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) NewGuiHandler(logisticspipes.network.NewGuiHandler) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise) LogisticsManager(logisticspipes.logistics.LogisticsManager) PacketHandler(logisticspipes.network.PacketHandler) ExitRoute(logisticspipes.routing.ExitRoute) UUIDPropertyKt(network.rs485.logisticspipes.property.UUIDPropertyKt) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) BooleanProperty(network.rs485.logisticspipes.property.BooleanProperty) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) BufferMode(logisticspipes.utils.SinkReply.BufferMode) CraftingModuleInHand(logisticspipes.network.guis.module.inhand.CraftingModuleInHand) IItemIdentifierInventory(network.rs485.logisticspipes.inventory.IItemIdentifierInventory) UUIDListProperty(network.rs485.logisticspipes.property.UUIDListProperty) CraftingPipeOpenConnectedGuiPacket(logisticspipes.network.packets.cpipe.CraftingPipeOpenConnectedGuiPacket) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CraftingModuleSlot(logisticspipes.network.guis.module.inpipe.CraftingModuleSlot) InventoryProperty(network.rs485.logisticspipes.property.InventoryProperty) IWorldProvider(logisticspipes.interfaces.IWorldProvider) LogisticsDictPromise(logisticspipes.routing.LogisticsDictPromise) FuzzyUtil(network.rs485.logisticspipes.util.FuzzyUtil) Nullable(javax.annotation.Nullable) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) BlockPos(net.minecraft.util.math.BlockPos) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) DelayedGeneric(logisticspipes.utils.DelayedGeneric) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) CPipeSatelliteImport(logisticspipes.network.packets.cpipe.CPipeSatelliteImport) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) IBlockState(net.minecraft.block.state.IBlockState) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) TileEntity(net.minecraft.tileentity.TileEntity) ItemBlock(net.minecraft.item.ItemBlock) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) ItemUpgrade(logisticspipes.items.ItemUpgrade) ICraftingTemplate(logisticspipes.request.ICraftingTemplate) LogisticsPipes(logisticspipes.LogisticsPipes) Particles(logisticspipes.pipefxhandlers.Particles) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DictCraftingTemplate(logisticspipes.request.DictCraftingTemplate) NBTTagList(net.minecraft.nbt.NBTTagList) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ICraftItems(logisticspipes.interfaces.routing.ICraftItems) LPNeighborTileEntityKt(network.rs485.logisticspipes.connection.LPNeighborTileEntityKt) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) Collection(java.util.Collection) FluidResource(logisticspipes.request.resources.FluidResource) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IFuzzyRecipeProvider(logisticspipes.proxy.interfaces.IFuzzyRecipeProvider) UUID(java.util.UUID) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) Objects(java.util.Objects) IItemSpaceControl(logisticspipes.interfaces.routing.IItemSpaceControl) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) CacheTypes(logisticspipes.utils.CacheHolder.CacheTypes) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Gui(network.rs485.logisticspipes.module.Gui) Property(network.rs485.logisticspipes.property.Property) IPromise(logisticspipes.request.IPromise) AdjacentUtilKt(network.rs485.logisticspipes.connection.AdjacentUtilKt) ItemResource(logisticspipes.request.resources.ItemResource) Getter(lombok.Getter) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IReqCraftingTemplate(logisticspipes.request.IReqCraftingTemplate) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) CoordinatesPacket(logisticspipes.network.abstractpackets.CoordinatesPacket) IBitSet(network.rs485.logisticspipes.property.IBitSet) IntListProperty(network.rs485.logisticspipes.property.IntListProperty) IntegerProperty(network.rs485.logisticspipes.property.IntegerProperty) ImmutableList(com.google.common.collect.ImmutableList) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) DelayQueue(java.util.concurrent.DelayQueue) WeakReference(java.lang.ref.WeakReference) PipeFluidSatellite(logisticspipes.pipes.PipeFluidSatellite) Nonnull(javax.annotation.Nonnull) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) IGuiOpenControler(logisticspipes.interfaces.IGuiOpenControler) FixedPriority(logisticspipes.utils.SinkReply.FixedPriority) CraftingPipeUpdatePacket(logisticspipes.network.packets.pipe.CraftingPipeUpdatePacket) EnumFacing(net.minecraft.util.EnumFacing) LogisticsPromise(logisticspipes.routing.LogisticsPromise) RequestTree(logisticspipes.request.RequestTree) UUIDProperty(network.rs485.logisticspipes.property.UUIDProperty) BitSet(java.util.BitSet) IFuzzyRecipeProvider(logisticspipes.proxy.interfaces.IFuzzyRecipeProvider) CPipeSatelliteImport(logisticspipes.network.packets.cpipe.CPipeSatelliteImport) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) CoordinatesPacket(logisticspipes.network.abstractpackets.CoordinatesPacket) Pair(logisticspipes.utils.tuples.Pair)

Example 39 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class PowerSupplierHandler method requestICPower.

private void requestICPower() {
    // Use Buffer
    final List<LPNeighborTileEntity<TileEntity>> adjacentTileEntities = new WorldCoordinatesWrapper(pipe.container).allNeighborTileEntities();
    double globalNeed = 0;
    double[] need = new double[adjacentTileEntities.size()];
    int i = 0;
    for (NeighborTileEntity<TileEntity> adjacent : adjacentTileEntities) {
        if (SimpleServiceLocator.IC2Proxy.isEnergySink(adjacent.getTileEntity())) {
            if (pipe.canPipeConnect(adjacent.getTileEntity(), adjacent.getDirection())) {
                if (SimpleServiceLocator.IC2Proxy.acceptsEnergyFrom(adjacent.getTileEntity(), pipe.container, adjacent.getOurDirection())) {
                    // TODO pipe.container must be IEnergySource
                    globalNeed += need[i] = SimpleServiceLocator.IC2Proxy.demandedEnergyUnits(adjacent.getTileEntity());
                }
            }
        }
        ++i;
    }
    if (globalNeed != 0 && !Double.isNaN(globalNeed)) {
        double fullfillable = Math.min(1, internalBufferIC2 / globalNeed);
        i = 0;
        for (NeighborTileEntity<TileEntity> adjacent : adjacentTileEntities) {
            if (SimpleServiceLocator.IC2Proxy.isEnergySink(adjacent.getTileEntity()) && pipe.canPipeConnect(adjacent.getTileEntity(), adjacent.getDirection()) && SimpleServiceLocator.IC2Proxy.acceptsEnergyFrom(adjacent.getTileEntity(), pipe.container, adjacent.getOurDirection())) {
                // TODO pipe.container must be IEnergySource
                if (internalBufferIC2 + 1 < need[i] * fullfillable) {
                    return;
                }
                double toUse = Math.min(pipe.getUpgradeManager().getIC2PowerLevel(), need[i] * fullfillable);
                double unUsed = SimpleServiceLocator.IC2Proxy.injectEnergyUnits(adjacent.getTileEntity(), adjacent.getOurDirection(), toUse);
                double used = toUse - unUsed;
                if (used > 0) {
                    // MainProxy.sendPacketToAllWatchingChunk(this.pipe.getX(), this.pipe.getZ(), MainProxy.getDimensionForWorld(this.pipe.getWorld()), PacketHandler.getPacket(PowerPacketLaser.class).setColor(LogisticsPowerProviderTileEntity.IC2_COLOR).setPos(this.pipe.getLPPosition()).setRenderBall(true).setDir(adTile.orientation).setLength(0.5F));
                    pipe.container.addLaser(adjacent.getDirection(), 0.5F, LogisticsPowerProviderTileEntity.IC2_COLOR, false, true);
                    internalBufferIC2 -= used;
                }
                if (internalBufferIC2 < 0) {
                    internalBufferIC2 = 0;
                    return;
                }
            }
            ++i;
        }
    }
    // Rerequest Buffer
    List<Pair<ISubSystemPowerProvider, List<IFilter>>> provider = pipe.getRouter().getSubSystemPowerProvider();
    double available = 0;
    outer: for (Pair<ISubSystemPowerProvider, List<IFilter>> pair : provider) {
        for (IFilter filter : pair.getValue2()) {
            if (filter.blockPower()) {
                continue outer;
            }
        }
        if (pair.getValue1().usePaused()) {
            continue;
        }
        if (!pair.getValue1().getBrand().equals("EU")) {
            continue;
        }
        available += pair.getValue1().getPowerLevel();
    }
    if (available > 0) {
        double neededPower = PowerSupplierHandler.INTERNAL_IC2_BUFFER_MAX - internalBufferIC2;
        if (neededPower > 0) {
            if (pipe.useEnergy((int) (neededPower / 10000), false)) {
                outer: for (Pair<ISubSystemPowerProvider, List<IFilter>> pair : provider) {
                    for (IFilter filter : pair.getValue2()) {
                        if (filter.blockPower()) {
                            continue outer;
                        }
                    }
                    if (pair.getValue1().usePaused()) {
                        continue;
                    }
                    if (!pair.getValue1().getBrand().equals("EU")) {
                        continue;
                    }
                    double requestamount = neededPower * (pair.getValue1().getPowerLevel() / available);
                    pair.getValue1().requestPower(pipe.getRouterId(), requestamount);
                }
            }
        }
    }
}
Also used : LogisticsPowerProviderTileEntity(logisticspipes.blocks.powertile.LogisticsPowerProviderTileEntity) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) LPNeighborTileEntity(network.rs485.logisticspipes.connection.LPNeighborTileEntity) IFilter(logisticspipes.interfaces.routing.IFilter) LPNeighborTileEntity(network.rs485.logisticspipes.connection.LPNeighborTileEntity) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Pair(logisticspipes.utils.tuples.Pair)

Example 40 with Pair

use of logisticspipes.utils.tuples.Pair 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)

Aggregations

Pair (logisticspipes.utils.tuples.Pair)42 List (java.util.List)21 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)19 IFilter (logisticspipes.interfaces.routing.IFilter)18 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)18 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)18 Map (java.util.Map)16 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)16 TileEntity (net.minecraft.tileentity.TileEntity)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)13 Collection (java.util.Collection)12 ExitRoute (logisticspipes.routing.ExitRoute)12 ItemStack (net.minecraft.item.ItemStack)12 Nonnull (javax.annotation.Nonnull)11 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)11 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)11 MainProxy (logisticspipes.proxy.MainProxy)11 IRouter (logisticspipes.routing.IRouter)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11