Search in sources :

Example 1 with NeighborTileEntity

use of network.rs485.logisticspipes.connection.NeighborTileEntity in project LogisticsPipes by RS485.

the class PipeTransportLayer method itemArrived.

@Override
public EnumFacing itemArrived(IRoutedItem item, EnumFacing denied) {
    if (item.getItemIdentifierStack() != null) {
        _trackStatistics.recievedItem(item.getItemIdentifierStack().getStackSize());
    }
    // 1st prio, deliver to adjacent inventories
    LinkedList<EnumFacing> possibleEnumFacing = new LinkedList<>();
    for (NeighborTileEntity<TileEntity> adjacent : routedPipe.getAvailableAdjacent().inventories()) {
        if (_router.isRoutedExit(adjacent.getDirection())) {
            continue;
        }
        if (denied != null && denied.equals(adjacent.getDirection())) {
            continue;
        }
        CoreRoutedPipe pipe = _router.getPipe();
        if (pipe != null) {
            if (pipe.isLockedExit(adjacent.getDirection())) {
                continue;
            }
        }
        possibleEnumFacing.add(adjacent.getDirection());
    }
    if (possibleEnumFacing.size() != 0) {
        return possibleEnumFacing.get(routedPipe.getWorld().rand.nextInt(possibleEnumFacing.size()));
    }
    // 2nd prio, deliver to non-routed exit
    new WorldCoordinatesWrapper(routedPipe.container).connectedTileEntities().stream().filter(neighbor -> {
        if (_router.isRoutedExit(neighbor.getDirection()))
            return false;
        final CoreRoutedPipe routerPipe = _router.getPipe();
        return routerPipe == null || !routerPipe.isLockedExit(neighbor.getDirection());
    }).forEach(neighbor -> possibleEnumFacing.add(neighbor.getDirection()));
    if (possibleEnumFacing.size() == 0) {
        // last resort, drop item
        return null;
    } else {
        return possibleEnumFacing.get(routedPipe.getWorld().rand.nextInt(possibleEnumFacing.size()));
    }
}
Also used : NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IRouter(logisticspipes.routing.IRouter) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) EnumFacing(net.minecraft.util.EnumFacing) TileEntity(net.minecraft.tileentity.TileEntity) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) EnumFacing(net.minecraft.util.EnumFacing) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) LinkedList(java.util.LinkedList)

Example 2 with NeighborTileEntity

use of network.rs485.logisticspipes.connection.NeighborTileEntity in project LogisticsPipes by RS485.

the class ModuleCrafter method enabledUpdateEntity.

public void enabledUpdateEntity() {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return;
    if (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
        if (service.isNthTick(6)) {
            cacheAreAllOrderesToBuffer();
        }
        if (service.getItemOrderManager().isFirstOrderWatched()) {
            TileEntity tile = lastAccessedCrafter.get();
            if (tile != null) {
                service.getItemOrderManager().setMachineProgress(SimpleServiceLocator.machineProgressProvider.getProgressForTile(tile));
            } else {
                service.getItemOrderManager().setMachineProgress((byte) 0);
            }
        }
    } else {
        cachedAreAllOrderesToBuffer = false;
    }
    if (!service.isNthTick(6)) {
        return;
    }
    final List<NeighborTileEntity<TileEntity>> adjacentInventories = service.getAvailableAdjacent().inventories();
    if (!service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
        final ISlotUpgradeManager upgradeManager = Objects.requireNonNull(getUpgradeManager());
        if (upgradeManager.getCrafterCleanup() > 0) {
            adjacentInventories.stream().map(neighbor -> extractFiltered(neighbor, cleanupInventory, cleanupModeIsExclude.getValue(), upgradeManager.getCrafterCleanup() * 3)).filter(stack -> !stack.isEmpty()).findFirst().ifPresent(extracted -> {
                service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(extracted), EnumFacing.UP);
                service.getCacheHolder().trigger(CacheTypes.Inventory);
            });
        }
        return;
    }
    if (adjacentInventories.size() < 1) {
        if (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
            service.getItemOrderManager().sendFailed();
        }
        return;
    }
    List<ItemIdentifierStack> wanteditem = getCraftedItems();
    if (wanteditem == null || wanteditem.isEmpty()) {
        return;
    }
    service.spawnParticle(Particles.VioletParticle, 2);
    int itemsleft = itemsToExtract();
    int stacksleft = stacksToExtract();
    while (itemsleft > 0 && stacksleft > 0 && (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
        LogisticsItemOrder nextOrder = service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, // fetch but not remove.
        ResourceType.EXTRA);
        int maxtosend = Math.min(itemsleft, nextOrder.getResource().stack.getStackSize());
        maxtosend = Math.min(nextOrder.getResource().getItem().getMaxStackSize(), maxtosend);
        // retrieve the new crafted items
        ItemStack extracted = ItemStack.EMPTY;
        // there has to be at least one adjacentCrafter at this point; adjacent wont stay null
        NeighborTileEntity<TileEntity> adjacent = null;
        for (NeighborTileEntity<TileEntity> adjacentCrafter : adjacentInventories) {
            adjacent = adjacentCrafter;
            extracted = extract(adjacent, nextOrder.getResource(), maxtosend);
            if (!extracted.isEmpty()) {
                break;
            }
        }
        if (extracted.isEmpty()) {
            service.getItemOrderManager().deferSend();
            break;
        }
        service.getCacheHolder().trigger(CacheTypes.Inventory);
        Objects.requireNonNull(adjacent);
        lastAccessedCrafter = new WeakReference<>(adjacent.getTileEntity());
        // send the new crafted items to the destination
        ItemIdentifier extractedID = ItemIdentifier.get(extracted);
        while (!extracted.isEmpty()) {
            if (isExtractedMismatch(nextOrder, extractedID)) {
                LogisticsItemOrder startOrder = nextOrder;
                if (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                    do {
                        service.getItemOrderManager().deferSend();
                        nextOrder = service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
                    } while (isExtractedMismatch(nextOrder, extractedID) && startOrder != nextOrder);
                }
                if (startOrder == nextOrder) {
                    int numtosend = Math.min(extracted.getCount(), extractedID.getMaxStackSize());
                    if (numtosend == 0) {
                        break;
                    }
                    stacksleft -= 1;
                    itemsleft -= numtosend;
                    ItemStack stackToSend = extracted.splitStack(numtosend);
                    // Route the unhandled item
                    service.sendStack(stackToSend, -1, ItemSendMode.Normal, null, adjacent.getDirection());
                    continue;
                }
            }
            int numtosend = Math.min(extracted.getCount(), extractedID.getMaxStackSize());
            numtosend = Math.min(numtosend, nextOrder.getResource().stack.getStackSize());
            if (numtosend == 0) {
                break;
            }
            stacksleft -= 1;
            itemsleft -= numtosend;
            ItemStack stackToSend = extracted.splitStack(numtosend);
            if (nextOrder.getDestination() != null) {
                SinkReply reply = LogisticsManager.canSink(stackToSend, nextOrder.getDestination().getRouter(), null, true, ItemIdentifier.get(stackToSend), null, true, false);
                boolean defersend = (reply == null || reply.bufferMode != BufferMode.NONE || reply.maxNumberOfItems < 1);
                IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
                item.setDestination(nextOrder.getDestination().getRouter().getSimpleID());
                item.setTransportMode(TransportMode.Active);
                item.setAdditionalTargetInformation(nextOrder.getInformation());
                service.queueRoutedItem(item, adjacent.getDirection());
                service.getItemOrderManager().sendSuccessfull(stackToSend.getCount(), defersend, item);
            } else {
                service.sendStack(stackToSend, -1, ItemSendMode.Normal, nextOrder.getInformation(), adjacent.getDirection());
                service.getItemOrderManager().sendSuccessfull(stackToSend.getCount(), false, null);
            }
            if (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                nextOrder = service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, // fetch but not remove.
                ResourceType.EXTRA);
            }
        }
    }
}
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) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) SinkReply(logisticspipes.utils.SinkReply) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager)

Example 3 with NeighborTileEntity

use of network.rs485.logisticspipes.connection.NeighborTileEntity in project LogisticsPipes by RS485.

the class PowerSupplierHandler method requestRFPower.

private boolean requestRFPower() {
    // 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.powerProxy.isEnergyReceiver(adjacent.getTileEntity(), adjacent.getOurDirection())) {
            if (pipe.canPipeConnect(adjacent.getTileEntity(), adjacent.getDirection())) {
                ICoFHEnergyReceiver energyReceiver = SimpleServiceLocator.powerProxy.getEnergyReceiver(adjacent.getTileEntity(), adjacent.getOurDirection());
                globalNeed += need[i] = (energyReceiver.getMaxEnergyStored() - energyReceiver.getEnergyStored());
            }
        }
        ++i;
    }
    if (globalNeed != 0 && !Double.isNaN(globalNeed)) {
        double fullfillable = Math.min(1, internalBufferRF / globalNeed);
        i = 0;
        for (NeighborTileEntity<TileEntity> adjacent : adjacentTileEntities) {
            if (SimpleServiceLocator.powerProxy.isEnergyReceiver(adjacent.getTileEntity(), adjacent.getOurDirection())) {
                if (pipe.canPipeConnect(adjacent.getTileEntity(), adjacent.getDirection())) {
                    EnumFacing oppositeDir = adjacent.getOurDirection();
                    ICoFHEnergyReceiver energyReceiver = SimpleServiceLocator.powerProxy.getEnergyReceiver(adjacent.getTileEntity(), oppositeDir);
                    if (internalBufferRF + 1 < need[i] * fullfillable) {
                        return true;
                    }
                    int used = energyReceiver.receiveEnergy(oppositeDir, (int) (need[i] * fullfillable), false);
                    if (used > 0) {
                        pipe.container.addLaser(adjacent.getDirection(), 0.5F, LogisticsPowerProviderTileEntity.RF_COLOR, false, true);
                        internalBufferRF -= used;
                    }
                    if (internalBufferRF < 0) {
                        internalBufferRF = 0;
                        return true;
                    }
                }
            }
            ++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("RF")) {
            continue;
        }
        available += pair.getValue1().getPowerLevel();
    }
    if (available > 0) {
        double neededPower = PowerSupplierHandler.INTERNAL_RF_BUFFER_MAX - internalBufferRF;
        if (neededPower > 0) {
            if (pipe.useEnergy((int) (neededPower / 100), 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("RF")) {
                        continue;
                    }
                    double requestamount = neededPower * (pair.getValue1().getPowerLevel() / available);
                    pair.getValue1().requestPower(pipe.getRouterId(), requestamount);
                }
            }
        }
    }
    return false;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) 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) ICoFHEnergyReceiver(logisticspipes.proxy.cofh.subproxies.ICoFHEnergyReceiver) Pair(logisticspipes.utils.tuples.Pair)

Example 4 with NeighborTileEntity

use of network.rs485.logisticspipes.connection.NeighborTileEntity 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;
        FluidIdentifierStack liquid = SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(arrivingItem.getItemIdentifierStack());
        if (isConnectableTank(tile, arrivingItem.output, false)) {
            // Try to put liquid into all adjacent tanks.
            for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> util : PipeFluidUtil.INSTANCE.getAdjacentTanks(this, false)) {
                filled = util.getValue2().fill(liquid, true);
                liquid.lowerAmount(filled);
                if (liquid.getAmount() != 0) {
                    continue;
                }
                return true;
            }
            // Try inserting the liquid into the pipe side tank
            filled = ((PipeFluidTransportLogistics) transport).sideTanks[arrivingItem.output.ordinal()].fill(liquid.makeFluidStack(), true);
            if (filled == liquid.getAmount()) {
                return true;
            }
            liquid.lowerAmount(filled);
        }
        // Try inserting the liquid into the pipe internal tank
        filled = ((PipeFluidTransportLogistics) transport).internalTank.fill(liquid.makeFluidStack(), true);
        if (filled == liquid.getAmount()) {
            return true;
        }
        // If liquids still exist,
        liquid.lowerAmount(filled);
        // TODO: FIX THIS
        if (this instanceof IRequireReliableFluidTransport) {
            ((IRequireReliableFluidTransport) this).liquidNotInserted(liquid.getFluid(), liquid.getAmount());
        }
        IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(SimpleServiceLocator.logisticsFluidManager.getFluidContainer(liquid));
        Pair<Integer, FluidSinkReply> replies = SimpleServiceLocator.logisticsFluidManager.getBestReply(liquid, getRouter(), routedItem.getJamList());
        if (replies == null) {
            // clear destination without marking item as lost
            routedItem.setDestination(0);
        } else {
            int dest = replies.getValue1();
            routedItem.setDestination(dest);
        }
        routedItem.setTransportMode(TransportMode.Passive);
        this.queueRoutedItem(routedItem, arrivingItem.output.getOpposite());
        return true;
    }
    return false;
}
Also used : FluidIdentifierStack(logisticspipes.utils.FluidIdentifierStack) ITankUtil(logisticspipes.interfaces.ITankUtil) FluidSinkReply(logisticspipes.utils.FluidSinkReply) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) IRequireReliableFluidTransport(logisticspipes.interfaces.routing.IRequireReliableFluidTransport)

Example 5 with NeighborTileEntity

use of network.rs485.logisticspipes.connection.NeighborTileEntity in project LogisticsPipes by RS485.

the class LogisticsEventListener method onPlayerLeftClickBlock.

@SubscribeEvent
public void onPlayerLeftClickBlock(final PlayerInteractEvent.RightClickBlock event) {
    if (MainProxy.isServer(event.getEntityPlayer().world)) {
        WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(event.getEntityPlayer().world, event.getPos());
        TileEntity tileEntity = worldCoordinates.getTileEntity();
        if (tileEntity instanceof TileEntityChest || SimpleServiceLocator.ironChestProxy.isIronChest(tileEntity)) {
            List<WeakReference<AsyncQuicksortModule>> list = worldCoordinates.allNeighborTileEntities().stream().filter(NeighborTileEntity::isLogisticsPipe).filter(adjacent -> ((LogisticsTileGenericPipe) adjacent.getTileEntity()).pipe instanceof PipeLogisticsChassis).filter(adjacent -> ((PipeLogisticsChassis) ((LogisticsTileGenericPipe) adjacent.getTileEntity()).pipe).getPointedOrientation() == adjacent.getOurDirection()).map(adjacent -> (PipeLogisticsChassis) ((LogisticsTileGenericPipe) adjacent.getTileEntity()).pipe).flatMap(chassis -> chassis.getModules().getModules()).filter(logisticsModule -> logisticsModule instanceof AsyncQuicksortModule).map(logisticsModule -> new WeakReference<>((AsyncQuicksortModule) logisticsModule)).collect(Collectors.toList());
            if (!list.isEmpty()) {
                LogisticsEventListener.chestQuickSortConnection.put(event.getEntityPlayer(), list);
            }
        }
    }
}
Also used : NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) PipeLogisticsChassis(logisticspipes.pipes.PipeLogisticsChassis) PlayerEvent(net.minecraftforge.fml.common.gameevent.PlayerEvent) MainProxy(logisticspipes.proxy.MainProxy) VersionChecker(logisticspipes.ticks.VersionChecker) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Configs(logisticspipes.config.Configs) TEControl(logisticspipes.routing.pathfinder.changedetection.TEControl) ChestGuiOpened(logisticspipes.network.packets.chassis.ChestGuiOpened) PlayerConfiguration(network.rs485.logisticspipes.config.PlayerConfiguration) Side(net.minecraftforge.fml.relauncher.Side) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) ClientConfiguration(network.rs485.logisticspipes.config.ClientConfiguration) LogisticsGuiOverrenderer(logisticspipes.renderer.LogisticsGuiOverrenderer) Map(java.util.Map) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) EntityItem(net.minecraft.entity.item.EntityItem) ChestGuiClosed(logisticspipes.network.packets.chassis.ChestGuiClosed) BlockEvent(net.minecraftforge.event.world.BlockEvent) UnWatch(net.minecraftforge.event.world.ChunkWatchEvent.UnWatch) WorldEvent(net.minecraftforge.event.world.WorldEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AsyncQuicksortModule(network.rs485.logisticspipes.module.AsyncQuicksortModule) ChunkPos(net.minecraft.util.math.ChunkPos) LPTickHandler(logisticspipes.ticks.LPTickHandler) PacketHandler(logisticspipes.network.PacketHandler) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) PlayerLoggedOutEvent(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent) List(java.util.List) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemTooltipEvent(net.minecraftforge.event.entity.player.ItemTooltipEvent) PlayerIdentifier(logisticspipes.utils.PlayerIdentifier) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Queue(java.util.Queue) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ClientConnectedToServerEvent(net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent) PlayerLoggedInEvent(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent) Setter(lombok.Setter) TextUtil(network.rs485.logisticspipes.util.TextUtil) Getter(lombok.Getter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) GuiReopenPacket(logisticspipes.network.packets.gui.GuiReopenPacket) HashMap(java.util.HashMap) PlayerConfigToClientPacket(logisticspipes.network.packets.PlayerConfigToClientPacket) Watch(net.minecraftforge.event.world.ChunkWatchEvent.Watch) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemStack(net.minecraft.item.ItemStack) IItemAdvancedExistance(logisticspipes.interfaces.IItemAdvancedExistance) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) WeakHashMap(java.util.WeakHashMap) ChatColor(logisticspipes.utils.string.ChatColor) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) GuiChest(net.minecraft.client.gui.inventory.GuiChest) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) GuiOpenEvent(net.minecraftforge.client.event.GuiOpenEvent) QuickSortChestMarkerStorage(logisticspipes.utils.QuickSortChestMarkerStorage) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) AllArgsConstructor(lombok.AllArgsConstructor) TileEntityChest(net.minecraft.tileentity.TileEntityChest) AsyncQuicksortModule(network.rs485.logisticspipes.module.AsyncQuicksortModule) WeakReference(java.lang.ref.WeakReference) PipeLogisticsChassis(logisticspipes.pipes.PipeLogisticsChassis) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

NeighborTileEntity (network.rs485.logisticspipes.connection.NeighborTileEntity)14 TileEntity (net.minecraft.tileentity.TileEntity)11 Pair (logisticspipes.utils.tuples.Pair)9 IFilter (logisticspipes.interfaces.routing.IFilter)8 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 ITankUtil (logisticspipes.interfaces.ITankUtil)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 Nonnull (javax.annotation.Nonnull)6 FluidIdentifier (logisticspipes.utils.FluidIdentifier)6 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)6 FluidStack (net.minecraftforge.fluids.FluidStack)6 Collection (java.util.Collection)5 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)5 IRequestFluid (logisticspipes.interfaces.routing.IRequestFluid)5 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)5 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)5 WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)5 Entry (java.util.Map.Entry)4