Search in sources :

Example 6 with Triplet

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

the class TDDuctInformationProvider method acceptItem.

@Override
public boolean acceptItem(LPTravelingItem item, TileEntity from) {
    if (item instanceof LPTravelingItemServer) {
        LPTravelingItemServer serverItem = (LPTravelingItemServer) item;
        int id = serverItem.getInfo().destinationint;
        if (id == -1) {
            id = SimpleServiceLocator.routerManager.getIDforUUID(serverItem.getInfo().destinationUUID);
        }
        IRouter destination = SimpleServiceLocator.routerManager.getRouter(id);
        if (destination == null) {
            return false;
        }
        RouteCache routes = duct.getCache(true);
        Iterable<Route> paramIterable = routes.outputRoutes;
        Route route = null;
        Object cache = null;
        Triplet<Integer, ItemIdentifier, Boolean> key = new Triplet<>(id, item.getItemIdentifierStack().getItem(), serverItem.getInfo()._transportMode == TransportMode.Active);
        if (duct instanceof ILPTEInformation && ((ILPTEInformation) duct).getObject() != null) {
            cache = ((ILPTEInformation) duct).getObject().getCacheHolder().getCacheFor(CacheTypes.Routing, key);
        }
        if (cache instanceof Route) {
            route = (Route) cache;
            if (!routes.outputRoutes.contains(route)) {
                route = null;
            }
        }
        if (route == null) {
            Pair<Double, Route> closesedConnection = null;
            List<DoubleCoordinates> visited = new ArrayList<>();
            visited.add(new DoubleCoordinates(from));
            for (Route localRoute1 : paramIterable) {
                if (localRoute1.endPoint instanceof LPItemDuct) {
                    LPItemDuct lpDuct = (LPItemDuct) localRoute1.endPoint;
                    double max = Integer.MAX_VALUE;
                    if (closesedConnection != null) {
                        max = closesedConnection.getValue1();
                    }
                    DoubleCoordinates pos = new DoubleCoordinates((TileEntity) lpDuct.pipe);
                    if (visited.contains(pos)) {
                        continue;
                    }
                    visited.add(pos);
                    double distance = lpDuct.pipe.getDistanceTo(id, ForgeDirection.getOrientation(localRoute1.pathDirections.get(localRoute1.pathDirections.size() - 1)).getOpposite(), item.getItemIdentifierStack().getItem(), serverItem.getInfo()._transportMode == TransportMode.Active, localRoute1.pathWeight, max, visited);
                    visited.remove(pos);
                    if (distance != Integer.MAX_VALUE && (closesedConnection == null || distance + localRoute1.pathDirections.size() < closesedConnection.getValue1())) {
                        closesedConnection = new Pair<>(distance + localRoute1.pathWeight, localRoute1);
                    }
                }
            }
            if (closesedConnection != null) {
                route = closesedConnection.getValue2();
            }
        }
        if (route != null) {
            if (duct instanceof ILPTEInformation && ((ILPTEInformation) duct).getObject() != null) {
                ((ILPTEInformation) duct).getObject().getCacheHolder().setCache(CacheTypes.Routing, key, route);
            }
            TravelingItem travelItem = new TravelingItem(item.getItemIdentifierStack().makeNormalStack(), duct, route.copy(), (byte) serverItem.output.ordinal(), (byte) 1);
            travelItem.lpRoutingInformation = serverItem.getInfo();
            duct.insertNewItem(travelItem);
            return true;
        }
    } else {
        return true;
    }
    return false;
}
Also used : ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) Triplet(logisticspipes.utils.tuples.Triplet) ArrayList(java.util.ArrayList) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRouter(logisticspipes.routing.IRouter) TravelingItem(cofh.thermaldynamics.duct.item.TravelingItem) LPTravelingItem(logisticspipes.transport.LPTravelingItem) RouteCache(cofh.thermaldynamics.multiblock.RouteCache) Route(cofh.thermaldynamics.multiblock.Route) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 7 with Triplet

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

the class ReflectionHelper method invokePrivateMethod.

@SuppressWarnings("unchecked")
public static <T> T invokePrivateMethod(Class<T> type, Class<?> clazz, Object target, String name, Class<?>[] classes, Object[] objects) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Triplet<Class<?>, String, List<Class<?>>> key = new Triplet<>(clazz, name, Arrays.asList(classes));
    Method method = ReflectionHelper.methodCache.get(key);
    if (method == null) {
        try {
            method = clazz.getDeclaredMethod(name, classes);
        } catch (NoSuchMethodException e1) {
            try {
                method = clazz.getMethod(name, classes);
            } catch (NoSuchMethodException e2) {
                method = clazz.getDeclaredMethod(name, classes);
            }
        }
        method.setAccessible(true);
        ReflectionHelper.methodCache.put(key, method);
    }
    Object result = method.invoke(target, objects);
    return (T) result;
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) List(java.util.List) Method(java.lang.reflect.Method)

Aggregations

Triplet (logisticspipes.utils.tuples.Triplet)7 IRouter (logisticspipes.routing.IRouter)3 ArrayList (java.util.ArrayList)2 IFilter (logisticspipes.interfaces.routing.IFilter)2 ExitRoute (logisticspipes.routing.ExitRoute)2 ItemRoutingInformation (logisticspipes.routing.ItemRoutingInformation)2 LPTravelingItemServer (logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)2 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 TravelingItem (cofh.thermaldynamics.duct.item.TravelingItem)1 Route (cofh.thermaldynamics.multiblock.Route)1 RouteCache (cofh.thermaldynamics.multiblock.RouteCache)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ILPTEInformation (logisticspipes.asm.te.ILPTEInformation)1 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)1 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)1 CCSinkResponder (logisticspipes.proxy.computers.objects.CCSinkResponder)1 LPTravelingItem (logisticspipes.transport.LPTravelingItem)1