Search in sources :

Example 11 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class PipeLogisticsChassi method canProvide.

/*** IProvideItems ***/
@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
    if (!isEnabled()) {
        return;
    }
    for (IFilter filter : filters) {
        if (filter.isBlocked() == filter.isFilteredItem(tree.getRequestType()) || filter.blockProvider()) {
            return;
        }
    }
    for (int i = 0; i < getChassiSize(); i++) {
        LogisticsModule x = _module.getSubModule(i);
        if (x instanceof ILegacyActiveModule) {
            ILegacyActiveModule y = (ILegacyActiveModule) x;
            y.canProvide(tree, root, filters);
        }
    }
}
Also used : ILegacyActiveModule(logisticspipes.interfaces.ILegacyActiveModule) IFilter(logisticspipes.interfaces.routing.IFilter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule)

Example 12 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class ServerRouter method recheckAdjacent.

/**
	 * Rechecks the piped connection to all adjacent routers as well as discover
	 * new ones.
	 */
private boolean recheckAdjacent() {
    connectionNeedsChecking = 0;
    if (LPConstants.DEBUG) {
        causedBy.clear();
    }
    if (getPipe() != null) {
        /*
			if (getPipe().getDebug() != null && getPipe().getDebug().debugThisPipe) {
				Info info = StackTraceUtil.addTraceInformation("(" + getPipe().getX() + ", " + getPipe().getY() + ", " + getPipe().getZ() + ")");
				StackTraceUtil.printTrace();
				info.end();
			}
			*/
        getPipe().spawnParticle(Particles.LightRedParticle, 5);
    }
    LPTickHandler.adjChecksDone++;
    boolean adjacentChanged = false;
    CoreRoutedPipe thisPipe = getPipe();
    if (thisPipe == null) {
        return false;
    }
    HashMap<CoreRoutedPipe, ExitRoute> adjacent;
    List<Pair<ILogisticsPowerProvider, List<IFilter>>> power;
    List<Pair<ISubSystemPowerProvider, List<IFilter>>> subSystemPower;
    PathFinder finder = new PathFinder(thisPipe.container, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, localChangeListener);
    power = finder.powerNodes;
    subSystemPower = finder.subPowerProvider;
    adjacent = finder.result;
    Map<ForgeDirection, List<CoreRoutedPipe>> pipeDirections = new HashMap<>();
    for (Entry<CoreRoutedPipe, ExitRoute> entry : adjacent.entrySet()) {
        List<CoreRoutedPipe> list = pipeDirections.get(entry.getValue().exitOrientation);
        if (list == null) {
            list = new ArrayList<>();
            pipeDirections.put(entry.getValue().exitOrientation, list);
        }
        list.add(entry.getKey());
    }
    pipeDirections.entrySet().stream().filter(entry -> entry.getValue().size() > Configs.MAX_UNROUTED_CONNECTIONS).forEach(entry -> entry.getValue().forEach(adjacent::remove));
    listenedPipes.stream().filter(list -> !finder.listenedPipes.contains(list)).forEach(list -> list.remove(localChangeListener));
    listenedPipes = finder.listenedPipes;
    for (CoreRoutedPipe pipe : adjacent.keySet()) {
        if (pipe.stillNeedReplace()) {
            return false;
        }
    }
    boolean[] oldSideDisconnected = sideDisconnected;
    sideDisconnected = new boolean[6];
    checkSecurity(adjacent);
    boolean changed = false;
    for (int i = 0; i < 6; i++) {
        changed |= sideDisconnected[i] != oldSideDisconnected[i];
    }
    if (changed) {
        CoreRoutedPipe pipe = getPipe();
        if (pipe != null) {
            pipe.getWorld().notifyBlocksOfNeighborChange(pipe.getX(), pipe.getY(), pipe.getZ(), pipe.getWorld().getBlock(pipe.getX(), pipe.getY(), pipe.getZ()));
            pipe.refreshConnectionAndRender(false);
        }
        adjacentChanged = true;
    }
    if (_adjacent.size() != adjacent.size()) {
        adjacentChanged = true;
    }
    for (CoreRoutedPipe pipe : _adjacent.keySet()) {
        if (!adjacent.containsKey(pipe)) {
            adjacentChanged = true;
        }
    }
    if (_powerAdjacent != null) {
        if (power == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : _powerAdjacent) {
                if (!power.contains(provider)) {
                    adjacentChanged = true;
                }
            }
        }
    }
    if (power != null) {
        if (_powerAdjacent == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : power) {
                if (!_powerAdjacent.contains(provider)) {
                    adjacentChanged = true;
                }
            }
        }
    }
    if (_subSystemPowerAdjacent != null) {
        if (subSystemPower == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : _subSystemPowerAdjacent) {
                if (!subSystemPower.contains(provider)) {
                    adjacentChanged = true;
                }
            }
        }
    }
    if (subSystemPower != null) {
        if (_subSystemPowerAdjacent == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : subSystemPower) {
                if (!_subSystemPowerAdjacent.contains(provider)) {
                    adjacentChanged = true;
                }
            }
        }
    }
    for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
        ExitRoute oldExit = _adjacent.get(pipe.getKey());
        if (oldExit == null) {
            adjacentChanged = true;
            break;
        }
        ExitRoute newExit = pipe.getValue();
        if (!newExit.equals(oldExit)) {
            adjacentChanged = true;
            break;
        }
    }
    if (!oldTouchedPipes.equals(finder.touchedPipes)) {
        CacheHolder.clearCache(oldTouchedPipes);
        CacheHolder.clearCache(finder.touchedPipes);
        oldTouchedPipes = finder.touchedPipes;
        BitSet visited = new BitSet(ServerRouter.getBiggestSimpleID());
        visited.set(getSimpleID());
        act(visited, new floodClearCache());
    }
    if (adjacentChanged) {
        HashMap<IRouter, ExitRoute> adjacentRouter = new HashMap<>();
        EnumSet<ForgeDirection> routedexits = EnumSet.noneOf(ForgeDirection.class);
        EnumMap<ForgeDirection, Integer> subpowerexits = new EnumMap<>(ForgeDirection.class);
        for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
            adjacentRouter.put(pipe.getKey().getRouter(), pipe.getValue());
            if ((pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRouteTo) || pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && !routedexits.contains(pipe.getValue().exitOrientation))) {
                routedexits.add(pipe.getValue().exitOrientation);
            }
            if (!subpowerexits.containsKey(pipe.getValue().exitOrientation) && pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                subpowerexits.put(pipe.getValue().exitOrientation, PathFinder.messureDistanceToNextRoutedPipe(getLPPosition(), pipe.getValue().exitOrientation, pipe.getKey().getWorld()));
            }
        }
        _adjacent = Collections.unmodifiableMap(adjacent);
        _adjacentRouter_Old = _adjacentRouter;
        _adjacentRouter = Collections.unmodifiableMap(adjacentRouter);
        if (power != null) {
            _powerAdjacent = Collections.unmodifiableList(power);
        } else {
            _powerAdjacent = null;
        }
        if (subSystemPower != null) {
            _subSystemPowerAdjacent = Collections.unmodifiableList(subSystemPower);
        } else {
            _subSystemPowerAdjacent = null;
        }
        _routedExits = routedexits;
        _subPowerExits = subpowerexits;
        SendNewLSA();
    }
    return adjacentChanged;
}
Also used : LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) PriorityQueue(java.util.PriorityQueue) Quartet(logisticspipes.utils.tuples.Quartet) Particles(logisticspipes.pipefxhandlers.Particles) MainProxy(logisticspipes.proxy.MainProxy) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) Configs(logisticspipes.config.Configs) StackTraceUtil(logisticspipes.utils.StackTraceUtil) Map(java.util.Map) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) EnumSet(java.util.EnumSet) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) EnumMap(java.util.EnumMap) FluidResource(logisticspipes.request.resources.FluidResource) CacheHolder(logisticspipes.utils.CacheHolder) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Set(java.util.Set) LPTickHandler(logisticspipes.ticks.LPTickHandler) UUID(java.util.UUID) DictResource(logisticspipes.request.resources.DictResource) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Collectors(java.util.stream.Collectors) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Info(logisticspipes.utils.StackTraceUtil.Info) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ItemResource(logisticspipes.request.resources.ItemResource) Setter(lombok.Setter) Getter(lombok.Getter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) AccessLevel(lombok.AccessLevel) IRoutingDebugAdapter(logisticspipes.interfaces.IRoutingDebugAdapter) LPTileEntityObject(logisticspipes.asm.te.LPTileEntityObject) PathFinder(logisticspipes.routing.pathfinder.PathFinder) OneList(logisticspipes.utils.OneList) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) LPConstants(logisticspipes.LPConstants) DimensionManager(net.minecraftforge.common.DimensionManager) RoutingTableUpdateThread(logisticspipes.ticks.RoutingTableUpdateThread) Iterator(java.util.Iterator) World(net.minecraft.world.World) IResource(logisticspipes.request.resources.IResource) Lock(java.util.concurrent.locks.Lock) PipeItemsFirewall(logisticspipes.pipes.PipeItemsFirewall) TileEntity(net.minecraft.tileentity.TileEntity) BitSet(java.util.BitSet) Collections(java.util.Collections) HashMap(java.util.HashMap) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) List(java.util.List) ArrayList(java.util.ArrayList) OneList(logisticspipes.utils.OneList) LinkedList(java.util.LinkedList) EnumMap(java.util.EnumMap) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) Pair(logisticspipes.utils.tuples.Pair) BitSet(java.util.BitSet) PathFinder(logisticspipes.routing.pathfinder.PathFinder) IFilter(logisticspipes.interfaces.routing.IFilter)

Example 13 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class RequestTreeNode method getCrafters.

private static List<Pair<ICraftingTemplate, List<IFilter>>> getCrafters(IResource iRequestType, List<ExitRoute> validDestinations) {
    List<Pair<ICraftingTemplate, List<IFilter>>> crafters = new ArrayList<>(validDestinations.size());
    for (ExitRoute r : validDestinations) {
        CoreRoutedPipe pipe = r.destination.getPipe();
        if (r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            if (pipe instanceof ICraft) {
                ICraftingTemplate craftable = ((ICraft) pipe).addCrafting(iRequestType);
                if (craftable != null) {
                    for (IFilter filter : r.filters) {
                        if (filter.isBlocked() == filter.isFilteredItem(craftable.getResultItem()) || filter.blockCrafting()) {
                            continue;
                        }
                    }
                    List<IFilter> list = new LinkedList<>();
                    list.addAll(r.filters);
                    crafters.add(new Pair<>(craftable, list));
                }
            }
        }
    }
    //		Collections.sort(crafters,new CraftingTemplate.PairPrioritizer());
    return crafters;
}
Also used : ICraft(logisticspipes.interfaces.routing.ICraft) IFilter(logisticspipes.interfaces.routing.IFilter) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) LinkedList(java.util.LinkedList) Pair(logisticspipes.utils.tuples.Pair)

Example 14 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class RoutingUpdateDebugFilters method writeData.

@Override
public void writeData(LPDataOutput output) {
    output.writeSerializable(pos);
    for (PipeRoutingConnectionType type : filters.keySet()) {
        output.writeShort(type.ordinal());
        for (List<IFilter> linkedFilter : filters.get(type)) {
            output.writeShort(linkedFilter.size());
            for (IFilter filter : linkedFilter) {
                output.writeSerializable(filter.getLPPosition());
            }
        }
        output.writeShort(-1);
    }
    output.writeShort(-1);
}
Also used : PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) IFilter(logisticspipes.interfaces.routing.IFilter)

Example 15 with IFilter

use of logisticspipes.interfaces.routing.IFilter in project LogisticsPipes by RS485.

the class PipeItemsProviderLogistics method canProvide.

@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
    if (!isEnabled()) {
        return;
    }
    if (tree.getRequestType() instanceof ItemResource) {
        ItemIdentifier item = ((ItemResource) tree.getRequestType()).getItem();
        for (IFilter filter : filters) {
            if (filter.isBlocked() == filter.isFilteredItem(item.getUndamaged()) || filter.blockProvider()) {
                return;
            }
        }
        // Check the transaction and see if we have helped already
        int canProvide = getAvailableItemCount(item);
        canProvide -= root.getAllPromissesFor(this, item);
        if (canProvide < 1) {
            return;
        }
        LogisticsPromise promise = new LogisticsPromise(item, Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
        tree.addPromise(promise);
    } else if (tree.getRequestType() instanceof DictResource) {
        DictResource dict = (DictResource) tree.getRequestType();
        HashMap<ItemIdentifier, Integer> available = new HashMap<>();
        getAllItems(available, filters);
        for (Entry<ItemIdentifier, Integer> item : available.entrySet()) {
            if (!dict.matches(item.getKey(), IResource.MatchSettings.NORMAL)) {
                continue;
            }
            int canProvide = getAvailableItemCount(item.getKey());
            canProvide -= root.getAllPromissesFor(this, item.getKey());
            if (canProvide < 1) {
                continue;
            }
            LogisticsPromise promise = new LogisticsPromise(item.getKey(), Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
            tree.addPromise(promise);
            if (tree.getMissingAmount() <= 0) {
                break;
            }
        }
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Entry(java.util.Map.Entry) IFilter(logisticspipes.interfaces.routing.IFilter) HashMap(java.util.HashMap) LogisticsPromise(logisticspipes.routing.LogisticsPromise) DictResource(logisticspipes.request.resources.DictResource) ItemResource(logisticspipes.request.resources.ItemResource)

Aggregations

IFilter (logisticspipes.interfaces.routing.IFilter)21 ArrayList (java.util.ArrayList)13 ExitRoute (logisticspipes.routing.ExitRoute)12 LinkedList (java.util.LinkedList)9 IRouter (logisticspipes.routing.IRouter)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8 BitSet (java.util.BitSet)7 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Entry (java.util.Map.Entry)6 Pair (logisticspipes.utils.tuples.Pair)6 DictResource (logisticspipes.request.resources.DictResource)5 IResource (logisticspipes.request.resources.IResource)5 Iterator (java.util.Iterator)4 Collectors (java.util.stream.Collectors)4 IProvideItems (logisticspipes.interfaces.routing.IProvideItems)4 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)4 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)4