Search in sources :

Example 1 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class LogisticsPipes method createPipe.

protected Item createPipe(Class<? extends CoreUnroutedPipe> clas, String descr, Side side) {
    final ItemLogisticsPipe res = LogisticsBlockGenericPipe.registerPipe(clas);
    res.setCreativeTab(LogisticsPipes.LPCreativeTab);
    res.setUnlocalizedName(clas.getSimpleName());
    final CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.createPipe(res);
    if (pipe instanceof CoreRoutedPipe) {
        postInitRun.add(() -> res.setPipeIconIndex(((CoreRoutedPipe) pipe).getTextureType(ForgeDirection.UNKNOWN).normal, ((CoreRoutedPipe) pipe).getTextureType(ForgeDirection.UNKNOWN).newTexture));
    }
    if (side.isClient()) {
        if (pipe instanceof PipeBlockRequestTable) {
            MinecraftForgeClient.registerItemRenderer(res, new LogisticsPipeItemRenderer(true));
        } else {
            MinecraftForgeClient.registerItemRenderer(res, MainProxy.proxy.getPipeItemRenderer());
        }
    }
    if (clas != PipeItemsBasicLogistics.class && CoreRoutedPipe.class.isAssignableFrom(clas)) {
        if (clas != PipeFluidBasic.class && PipeFluidBasic.class.isAssignableFrom(clas)) {
            registerShapelessResetRecipe(res, 0, LogisticsPipes.LogisticsFluidBasicPipe, 0);
        } else {
            registerShapelessResetRecipe(res, 0, LogisticsPipes.LogisticsBasicPipe, 0);
        }
    }
    return res;
}
Also used : CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) PipeBlockRequestTable(logisticspipes.pipes.PipeBlockRequestTable) PipeItemsBasicLogistics(logisticspipes.pipes.PipeItemsBasicLogistics) ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) PipeFluidBasic(logisticspipes.pipes.PipeFluidBasic) LogisticsPipeItemRenderer(logisticspipes.renderer.LogisticsPipeItemRenderer)

Example 2 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class LogisticsPowerProviderTileEntity method sendPowerLaserPackets.

private void sendPowerLaserPackets(IRouter sourceRouter, IRouter destinationRouter, ForgeDirection exitOrientation, boolean addBall) {
    if (sourceRouter == destinationRouter) {
        return;
    }
    LinkedList<Triplet<IRouter, ForgeDirection, Boolean>> todo = new LinkedList<>();
    todo.add(new Triplet<>(sourceRouter, exitOrientation, addBall));
    while (!todo.isEmpty()) {
        Triplet<IRouter, ForgeDirection, Boolean> part = todo.pollFirst();
        List<ExitRoute> exits = part.getValue1().getRoutersOnSide(part.getValue2());
        for (ExitRoute exit : exits) {
            if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                // Find only result (caused by only straight connections)
                int distance = part.getValue1().getDistanceToNextPowerPipe(exit.exitOrientation);
                CoreRoutedPipe pipe = part.getValue1().getPipe();
                if (pipe != null && pipe.isInitialized()) {
                    pipe.container.addLaser(exit.exitOrientation, distance, getLaserColor(), false, part.getValue3());
                }
                // Use new sourceRouter
                IRouter nextRouter = exit.destination;
                if (nextRouter == destinationRouter) {
                    return;
                }
                outerRouters: for (ExitRoute newExit : nextRouter.getDistanceTo(destinationRouter)) {
                    if (newExit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                        for (IFilter filter : newExit.filters) {
                            if (filter.blockPower()) {
                                continue outerRouters;
                            }
                        }
                        todo.addLast(new Triplet<>(nextRouter, newExit.exitOrientation, newExit.exitOrientation != exit.exitOrientation));
                    }
                }
            }
        }
    }
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) LinkedList(java.util.LinkedList) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute)

Example 3 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class LogisticsPowerProviderTileEntity method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    pauseRequesting = false;
    if (!init) {
        if (MainProxy.isClient(getWorld())) {
            LogisticsHUDRenderer.instance().add(this);
        }
        init = true;
    }
    double globalRequest = orders.values().stream().reduce(Double::sum).orElse(0.0);
    if (globalRequest > 0) {
        double fullfillRatio = Math.min(1, Math.min(internalStorage, getMaxProvidePerTick()) / globalRequest);
        if (fullfillRatio > 0) {
            for (Entry<Integer, Double> order : orders.entrySet()) {
                double toSend = order.getValue() * fullfillRatio;
                if (toSend > internalStorage) {
                    toSend = internalStorage;
                }
                IRouter destinationRouter = SimpleServiceLocator.routerManager.getRouter(order.getKey());
                if (destinationRouter != null && destinationRouter.getPipe() != null) {
                    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(this);
                    outerTiles: for (AdjacentTileEntity adjacent : worldCoordinates.getAdjacentTileEntities().collect(Collectors.toList())) {
                        if (adjacent.tileEntity instanceof LogisticsTileGenericPipe) {
                            if (((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof CoreRoutedPipe) {
                                if (((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).stillNeedReplace()) {
                                    continue;
                                }
                                IRouter sourceRouter = ((CoreRoutedPipe) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getRouter();
                                if (sourceRouter != null) {
                                    outerRouters: for (ExitRoute exit : sourceRouter.getDistanceTo(destinationRouter)) {
                                        if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                                            for (IFilter filter : exit.filters) {
                                                if (filter.blockPower()) {
                                                    continue outerRouters;
                                                }
                                            }
                                            CoreRoutedPipe pipe = sourceRouter.getPipe();
                                            if (pipe != null && pipe.isInitialized()) {
                                                pipe.container.addLaser(adjacent.direction.getOpposite(), 1, getLaserColor(), true, true);
                                            }
                                            sendPowerLaserPackets(sourceRouter, destinationRouter, exit.exitOrientation, exit.exitOrientation != adjacent.direction);
                                            internalStorage -= toSend;
                                            handlePower(destinationRouter.getPipe(), toSend);
                                            break outerTiles;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    orders.clear();
    if (MainProxy.isServer(worldObj)) {
        if (internalStorage != lastUpdateStorage) {
            updateClients();
            lastUpdateStorage = internalStorage;
        }
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ExitRoute(logisticspipes.routing.ExitRoute) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Example 4 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class ModuleCrafter method isSatelliteConnected.

public boolean isSatelliteConnected() {
    final List<ExitRoute> routes = getRouter().getIRoutersByCost();
    if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
        if (satelliteId == 0) {
            return true;
        }
        for (final PipeItemsSatelliteLogistics satellite : PipeItemsSatelliteLogistics.AllSatellites) {
            if (satellite.satelliteId == satelliteId) {
                CoreRoutedPipe satPipe = satellite;
                if (satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null) {
                    continue;
                }
                IRouter satRouter = satPipe.getRouter();
                for (ExitRoute route : routes) {
                    if (route.destination == satRouter) {
                        return true;
                    }
                }
            }
        }
    } else {
        boolean foundAll = true;
        for (int i = 0; i < 9; i++) {
            boolean foundOne = false;
            if (advancedSatelliteIdArray[i] == 0) {
                continue;
            }
            for (final PipeItemsSatelliteLogistics satellite : PipeItemsSatelliteLogistics.AllSatellites) {
                if (satellite.satelliteId == advancedSatelliteIdArray[i]) {
                    CoreRoutedPipe satPipe = satellite;
                    if (satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null) {
                        continue;
                    }
                    IRouter satRouter = satPipe.getRouter();
                    for (ExitRoute route : routes) {
                        if (route.destination == satRouter) {
                            foundOne = true;
                            break;
                        }
                    }
                }
            }
            foundAll &= foundOne;
        }
        return foundAll;
    }
    //TODO check for FluidCrafter
    return false;
}
Also used : PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute)

Example 5 with CoreRoutedPipe

use of logisticspipes.pipes.basic.CoreRoutedPipe in project LogisticsPipes by RS485.

the class PipeTransportLayer method itemArrived.

@Override
public ForgeDirection itemArrived(IRoutedItem item, ForgeDirection denyed) {
    if (item.getItemIdentifierStack() != null) {
        _trackStatistics.recievedItem(item.getItemIdentifierStack().getStackSize());
    }
    List<AdjacentTileEntity> adjacentEntities = new WorldCoordinatesWrapper(routedPipe.container).getConnectedAdjacentTileEntities(IPipeInformationProvider.ConnectionPipeType.ITEM).collect(Collectors.toList());
    LinkedList<ForgeDirection> possibleForgeDirection = new LinkedList<>();
    for (AdjacentTileEntity adjacent : adjacentEntities) {
        if (SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)) {
            continue;
        }
        if (_router.isRoutedExit(adjacent.direction)) {
            continue;
        }
        if (denyed != null && denyed.equals(adjacent.direction)) {
            continue;
        }
        CoreRoutedPipe pipe = _router.getPipe();
        if (pipe != null) {
            if (pipe.isLockedExit(adjacent.direction)) {
                continue;
            }
        }
        possibleForgeDirection.add(adjacent.direction);
    }
    if (possibleForgeDirection.size() != 0) {
        return possibleForgeDirection.get(routedPipe.getWorld().rand.nextInt(possibleForgeDirection.size()));
    }
    // 2nd prio, deliver to non-routed exit
    for (AdjacentTileEntity adjacent : adjacentEntities) {
        if (_router.isRoutedExit(adjacent.direction)) {
            continue;
        }
        CoreRoutedPipe pipe = _router.getPipe();
        if (pipe != null) {
            if (pipe.isLockedExit(adjacent.direction)) {
                continue;
            }
        }
        possibleForgeDirection.add(adjacent.direction);
    }
    if (possibleForgeDirection.size() == 0) {
        return null;
    }
    return possibleForgeDirection.get(routedPipe.getWorld().rand.nextInt(possibleForgeDirection.size()));
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) LinkedList(java.util.LinkedList) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Aggregations

CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)68 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)43 TileEntity (net.minecraft.tileentity.TileEntity)22 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)16 ExitRoute (logisticspipes.routing.ExitRoute)15 ArrayList (java.util.ArrayList)14 LinkedList (java.util.LinkedList)13 IRouter (logisticspipes.routing.IRouter)11 Pair (logisticspipes.utils.tuples.Pair)10 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)10 List (java.util.List)9 HashMap (java.util.HashMap)8 IFilter (logisticspipes.interfaces.routing.IFilter)8 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 Map (java.util.Map)6 PipeRoutingConnectionType (logisticspipes.routing.PipeRoutingConnectionType)6 World (net.minecraft.world.World)6 BitSet (java.util.BitSet)5 Collections (java.util.Collections)5 EnumSet (java.util.EnumSet)5