Search in sources :

Example 56 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class EnderIOTransceiverConnection method getConnections.

@Override
public Collection<TileEntity> getConnections(TileEntity tile) {
    boolean onlyOnePipe = false;
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(tile), direction);
        TileEntity candidate = p.getTileEntity(tile.getWorldObj());
        if (candidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(tile, candidate, direction)) {
            if (onlyOnePipe) {
                onlyOnePipe = false;
                break;
            } else {
                onlyOnePipe = true;
            }
        }
    }
    if (!onlyOnePipe || !SimpleServiceLocator.enderIOProxy.isSendAndReceive(tile)) {
        return new ArrayList<>(0);
    }
    List<? extends TileEntity> connections = SimpleServiceLocator.enderIOProxy.getConnectedTransceivers(tile);
    Set<TileEntity> set = new HashSet<>();
    for (TileEntity connected : connections) {
        if (!SimpleServiceLocator.enderIOProxy.isSendAndReceive(connected)) {
            continue;
        }
        LogisticsTileGenericPipe pipe = null;
        for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
            DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(connected), direction);
            TileEntity candidate = p.getTileEntity(tile.getWorldObj());
            if (candidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(connected, candidate, direction)) {
                if (pipe != null) {
                    pipe = null;
                    break;
                } else {
                    pipe = (LogisticsTileGenericPipe) candidate;
                }
            }
        }
        if (pipe != null && pipe.pipe instanceof CoreRoutedPipe) {
            set.add(pipe);
        }
    }
    if (set.size() == 1) {
        return set;
    } else {
        return new ArrayList<>(0);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) HashSet(java.util.HashSet)

Example 57 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection 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 58 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class LogisticsNewRenderPipe method loadModels.

public static void loadModels() {
    if (!SimpleServiceLocator.cclProxy.isActivated())
        return;
    try {
        Map<String, IModel3D> pipePartModels = SimpleServiceLocator.cclProxy.parseObjModels(LogisticsPipes.class.getResourceAsStream("/logisticspipes/models/PipeModel_moved.obj"), 7, new LPScale(1 / 100f));
        List<IModel3D> highlightList = new ArrayList<>();
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            LogisticsNewRenderPipe.sideNormal.put(dir, new ArrayList<>());
            String grp = "Side_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.sideNormal.get(dir).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.sideNormal.get(dir).size() != 4) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideNormal.get(dir).size());
            }
        }
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            LogisticsNewRenderPipe.sideBC.put(dir, new ArrayList<>());
            String grp = "Side_BC_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.sideBC.get(dir).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.sideBC.get(dir).size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideBC.get(dir).size());
            }
        }
        for (Edge edge : Edge.values()) {
            String grp;
            if (edge.part1 == ForgeDirection.UP || edge.part1 == ForgeDirection.DOWN) {
                grp = "Edge_M_" + LogisticsNewRenderPipe.getDirAsString_Type1(edge.part1) + "_" + LogisticsNewRenderPipe.getDirAsString_Type1(edge.part2);
            } else {
                grp = "Edge_M_S_" + LogisticsNewRenderPipe.getDirAsString_Type1(edge.part1) + LogisticsNewRenderPipe.getDirAsString_Type1(edge.part2);
            }
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)) {
                    LogisticsNewRenderPipe.edges.put(edge, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.edges.get(edge) == null) {
                throw new RuntimeException("Couldn't load " + edge.name() + " (" + grp + ")");
            }
            highlightList.add(LogisticsNewRenderPipe.edges.get(edge));
        }
        for (Corner corner : Corner.values()) {
            LogisticsNewRenderPipe.corners_M.put(corner, new ArrayList<>());
            String grp = "Corner_M_" + corner.ud.s + "_" + corner.ns.s + corner.ew.s;
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.corners_M.get(corner).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.corners_M.get(corner).size() != 2) {
                throw new RuntimeException("Couldn't load " + corner.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.corners_M.get(corner).size());
            }
            highlightList.addAll(LogisticsNewRenderPipe.corners_M.get(corner));
        }
        for (Corner corner : Corner.values()) {
            LogisticsNewRenderPipe.corners_I3.put(corner, new ArrayList<>());
            String grp = "Corner_I3_" + corner.ud.s + "_" + corner.ns.s + corner.ew.s;
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.corners_I3.get(corner).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.corners_I3.get(corner).size() != 2) {
                throw new RuntimeException("Couldn't load " + corner.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.corners_I3.get(corner).size());
            }
        }
        for (PipeSupport support : PipeSupport.values()) {
            String grp = "Support_" + LogisticsNewRenderPipe.getDirAsString_Type1(support.dir) + "_" + support.ori.s;
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)) {
                    LogisticsNewRenderPipe.supports.put(support, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.supports.get(support) == null) {
                throw new RuntimeException("Couldn't load " + support.name() + " (" + grp + ")");
            }
        }
        for (PipeTurnCorner corner : PipeTurnCorner.values()) {
            String grp = "Corner_I_" + corner.corner.ud.s + "_" + corner.corner.ns.s + corner.corner.ew.s;
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp)) {
                    char c = ' ';
                    if (!entry.getKey().endsWith(" " + grp)) {
                        c = entry.getKey().charAt(entry.getKey().indexOf(" " + grp) + (" " + grp).length());
                    }
                    if (Character.isDigit(c)) {
                        if (c == '2') {
                            if (corner.turn != Turn.NORTH_SOUTH) {
                                continue;
                            }
                        } else if (c == '1') {
                            if (corner.turn != Turn.EAST_WEST) {
                                continue;
                            }
                        } else {
                            throw new UnsupportedOperationException();
                        }
                    } else {
                        if (corner.turn != Turn.UP_DOWN) {
                            continue;
                        }
                    }
                    LogisticsNewRenderPipe.corners_I.put(corner, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.corners_I.get(corner) == null) {
                throw new RuntimeException("Couldn't load " + corner.name() + " (" + grp + ")");
            }
        }
        for (PipeTurnCorner corner : PipeTurnCorner.values()) {
            String grp = "Spacer" + corner.number;
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)) {
                    LogisticsNewRenderPipe.spacers.put(corner, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.spacers.get(corner) == null) {
                throw new RuntimeException("Couldn't load " + corner.name() + " (" + grp + ")");
            }
        }
        for (PipeMount mount : PipeMount.values()) {
            String grp = "Mount_" + LogisticsNewRenderPipe.getDirAsString_Type1(mount.dir) + "_" + LogisticsNewRenderPipe.getDirAsString_Type1(mount.side);
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)) {
                    LogisticsNewRenderPipe.mounts.put(mount, LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0))));
                    break;
                }
            }
            if (LogisticsNewRenderPipe.mounts.get(mount) == null) {
                throw new RuntimeException("Couldn't load " + mount.name() + " (" + grp + ")");
            }
        }
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            LogisticsNewRenderPipe.texturePlate_Inner.put(dir, new ArrayList<>());
            String grp = "Inner_Plate_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.texturePlate_Inner.get(dir).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.texturePlate_Inner.get(dir).size() != 2) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.texturePlate_Inner.get(dir).size());
            }
        }
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            LogisticsNewRenderPipe.texturePlate_Outer.put(dir, new ArrayList<>());
            String grp = "Texture_Plate_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.texturePlate_Outer.get(dir).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)).apply(new LPTranslation(-0.5, -0.5, -0.5)).apply(new LPScale(1.001D)).apply(new LPTranslation(0.5, 0.5, 0.5)))));
            if (LogisticsNewRenderPipe.texturePlate_Outer.get(dir).size() != 2) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.texturePlate_Outer.get(dir).size());
            }
        }
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            LogisticsNewRenderPipe.sideTexturePlate.put(dir, new Quartet<>(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()));
            String grp = "Texture_Side_" + LogisticsNewRenderPipe.getDirAsString_Type1(dir);
            for (Entry<String, IModel3D> entry : pipePartModels.entrySet()) {
                if (entry.getKey().contains(" " + grp)) {
                    IModel3D model = LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)));
                    double sizeA = (model.bounds().max().x() - model.bounds().min().x()) + (model.bounds().max().y() - model.bounds().min().y()) + (model.bounds().max().z() - model.bounds().min().z());
                    double dis = Math.pow(model.bounds().min().x() - 0.5D, 2) + Math.pow(model.bounds().min().y() - 0.5D, 2) + Math.pow(model.bounds().min().z() - 0.5D, 2);
                    if (sizeA < 0.5D) {
                        if ((dis > 0.22 && dis < 0.24) || (dis > 0.38 && dis < 0.40)) {
                            LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue4().add(model);
                        } else if ((dis < 0.2 && dis > 0.18) || (dis < 0.36 && dis > 0.34)) {
                            LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue2().add(model);
                        } else {
                            throw new UnsupportedOperationException("Dis: " + dis);
                        }
                    } else {
                        if ((dis > 0.22 && dis < 0.24) || (dis > 0.38 && dis < 0.40)) {
                            LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue3().add(model);
                        } else if ((dis < 0.2 && dis > 0.18) || (dis < 0.36 && dis > 0.34)) {
                            LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().add(model);
                        } else {
                            throw new UnsupportedOperationException("Dis: " + dis);
                        }
                    }
                }
            }
            if (LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().size());
            }
            if (LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue2().size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue2().size());
            }
            if (LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue3().size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue3().size());
            }
            if (LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue4().size() != 8) {
                throw new RuntimeException("Couldn't load " + dir.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue4().size());
            }
        }
        for (PipeMount mount : PipeMount.values()) {
            LogisticsNewRenderPipe.textureConnectorPlate.put(mount, new ArrayList<>());
            String grp = "Texture_Connector_" + LogisticsNewRenderPipe.getDirAsString_Type1(mount.dir) + "_" + LogisticsNewRenderPipe.getDirAsString_Type1(mount.side);
            pipePartModels.entrySet().stream().filter(entry -> entry.getKey().contains(" " + grp + " ") || entry.getKey().endsWith(" " + grp)).forEach(entry -> LogisticsNewRenderPipe.textureConnectorPlate.get(mount).add(LogisticsNewRenderPipe.compute(entry.getValue().backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)))));
            if (LogisticsNewRenderPipe.textureConnectorPlate.get(mount).size() != 4) {
                throw new RuntimeException("Couldn't load " + mount.name() + " (" + grp + "). Only loaded " + LogisticsNewRenderPipe.textureConnectorPlate.get(mount).size());
            }
        }
        highlight = SimpleServiceLocator.cclProxy.combine(highlightList);
        pipePartModels = SimpleServiceLocator.cclProxy.parseObjModels(LogisticsPipes.class.getResourceAsStream("/logisticspipes/models/PipeModel_Transport_Box.obj"), 7, new LPScale(1 / 100f));
        LogisticsNewRenderPipe.innerTransportBox = LogisticsNewRenderPipe.compute(pipePartModels.get("InnerTransportBox").backfacedCopy().apply(new LPTranslation(0.0, 0.0, 1.0)).apply(new LPTranslation(-0.5, -0.5, -0.5)).apply(new LPScale(0.99D)).apply(new LPTranslation(0.5, 0.5, 0.5)));
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
Also used : java.util(java.util) IVec3(logisticspipes.proxy.object3d.interfaces.IVec3) IModel3D(logisticspipes.proxy.object3d.interfaces.IModel3D) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) Textures(logisticspipes.textures.Textures) LogisticsPipes(logisticspipes.LogisticsPipes) IIconTransformation(logisticspipes.proxy.object3d.interfaces.IIconTransformation) Quartet(logisticspipes.utils.tuples.Quartet) logisticspipes.proxy.object3d.operation(logisticspipes.proxy.object3d.operation) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) IBounds(logisticspipes.proxy.object3d.interfaces.IBounds) PipeBlockRequestTable(logisticspipes.pipes.PipeBlockRequestTable) GL11(org.lwjgl.opengl.GL11) LPConstants(logisticspipes.LPConstants) I3DOperation(logisticspipes.proxy.object3d.interfaces.I3DOperation) IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) EffectRenderer(net.minecraft.client.particle.EffectRenderer) World(net.minecraft.world.World) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) CoordinateUtils(network.rs485.logisticspipes.world.CoordinateUtils) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Collectors(java.util.stream.Collectors) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Entry(java.util.Map.Entry) ResourceLocation(net.minecraft.util.ResourceLocation) Data(lombok.Data) TileEntity(net.minecraft.tileentity.TileEntity) PlayerConfig(logisticspipes.config.PlayerConfig) PipeRenderState(logisticspipes.renderer.state.PipeRenderState) AllArgsConstructor(lombok.AllArgsConstructor) EntityModelFX(logisticspipes.pipefxhandlers.EntityModelFX) IModel3D(logisticspipes.proxy.object3d.interfaces.IModel3D) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsPipes(logisticspipes.LogisticsPipes)

Example 59 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class LogisticsPipeWorldRenderer method renderPipe.

public static boolean renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, LogisticsBlockGenericPipe block, LogisticsTileGenericPipe pipe, int x, int y, int z) {
    if (pipe.pipe instanceof PipeBlockRequestTable) {
        if (LogisticsPipeWorldRenderer.renderPass != 0) {
            return false;
        }
        PipeRenderState state = pipe.renderState;
        IIconProvider icons = pipe.getPipeIcons();
        if (icons == null) {
            return false;
        }
        state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN));
        block.setRenderAllSides();
        block.setBlockBounds(0, 0, 0, 1, 1, 1);
        renderblocks.setRenderBoundsFromBlock(block);
        renderblocks.renderStandardBlock(block, x, y, z);
        return true;
    }
    // Here to prevent Minecraft from crashing when nothing renders on render pass zero
    // This is likely a bug, and has been submitted as an issue to the Forge team
    renderblocks.setRenderBounds(0, 0, 0, 0, 0, 0);
    renderblocks.renderStandardBlock(Blocks.stone, x, y, z);
    renderblocks.setRenderBoundsFromBlock(block);
    PipeRenderState state = pipe.renderState;
    IIconProvider icons = pipe.getPipeIcons();
    if (icons == null) {
        return false;
    }
    if (LogisticsPipeWorldRenderer.renderPass == 0) {
        int connectivity = state.pipeConnectionMatrix.getMask();
        float[] dim = new float[6];
        if (!pipe.isOpaque()) {
            // render the unconnected pipe faces of the center block (if any)
            if (connectivity != 0x3f) {
                // note: 0x3f = 0x111111 = all sides
                LogisticsPipeWorldRenderer.resetToCenterDimensions(dim);
                state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN));
                LogisticsPipeWorldRenderer.renderTwoWayBlock(renderblocks, block, x, y, z, dim, connectivity ^ 0x3f);
            }
            // render the connecting pipe faces
            for (int dir = 0; dir < 6; dir++) {
                int mask = 1 << dir;
                if ((connectivity & mask) == 0) {
                    // no connection towards dir
                    continue;
                }
                // center piece offsets
                LogisticsPipeWorldRenderer.resetToCenterDimensions(dim);
                // extend block towards dir as it's connected to there
                dim[dir / 2] = dir % 2 == 0 ? 0 : LPConstants.BC_PIPE_MAX_POS;
                dim[dir / 2 + 3] = dir % 2 == 0 ? LPConstants.BC_PIPE_MIN_POS : 1;
                // the mask points to all faces perpendicular to dir, i.e. dirs 0+1 -> mask 111100, 1+2 -> 110011, 3+5 -> 001111
                int renderMask = (3 << (dir / 2 * 2)) ^ 0x3f;
                //workaround for 1.6 texture weirdness, rotate texture for N/S/E/W connections
                renderblocks.uvRotateEast = renderblocks.uvRotateNorth = renderblocks.uvRotateWest = renderblocks.uvRotateSouth = (dir < 2) ? 0 : 1;
                // render sub block
                state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.VALID_DIRECTIONS[dir]));
                LogisticsPipeWorldRenderer.renderTwoWayBlock(renderblocks, block, x, y, z, dim, renderMask);
                renderblocks.uvRotateEast = renderblocks.uvRotateNorth = renderblocks.uvRotateWest = renderblocks.uvRotateSouth = 0;
            }
        } else {
            // render the unconnected pipe faces of the center block (if any)
            if (connectivity != 0x3f) {
                // note: 0x3f = 0x111111 = all sides
                LogisticsPipeWorldRenderer.resetToCenterDimensions(dim);
                //Render opaque Layer
                state.currentTexture = icons.getIcon(Textures.LOGISTICSPIPE_OPAQUE_TEXTURE.normal);
                LogisticsPipeWorldRenderer.renderOneWayBlock(renderblocks, block, x, y, z, dim, connectivity ^ 0x3f);
                //Render Pipe Texture
                state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN));
                LogisticsPipeWorldRenderer.renderOneWayBlock(renderblocks, block, x, y, z, dim, connectivity ^ 0x3f);
            }
            // render the connecting pipe faces
            for (int dir = 0; dir < 6; dir++) {
                int mask = 1 << dir;
                if ((connectivity & mask) == 0) {
                    // no connection towards dir
                    continue;
                }
                // center piece offsets
                LogisticsPipeWorldRenderer.resetToCenterDimensions(dim);
                // extend block towards dir as it's connected to there
                dim[dir / 2] = dir % 2 == 0 ? 0 : LPConstants.BC_PIPE_MAX_POS;
                dim[dir / 2 + 3] = dir % 2 == 0 ? LPConstants.BC_PIPE_MIN_POS : 1;
                // the mask points to all faces perpendicular to dir, i.e. dirs 0+1 -> mask 111100, 1+2 -> 110011, 3+5 -> 001111
                int renderMask = (3 << (dir / 2 * 2)) ^ 0x3f;
                //workaround for 1.6 texture weirdness, rotate texture for N/S/E/W connections
                renderblocks.uvRotateEast = renderblocks.uvRotateNorth = renderblocks.uvRotateWest = renderblocks.uvRotateSouth = (dir < 2) ? 0 : 1;
                //Render opaque Layer
                state.currentTexture = icons.getIcon(Textures.LOGISTICSPIPE_OPAQUE_TEXTURE.normal);
                LogisticsPipeWorldRenderer.renderOneWayBlock(renderblocks, block, x, y, z, dim, 0x3f);
                // render sub block
                state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.VALID_DIRECTIONS[dir]));
                LogisticsPipeWorldRenderer.renderOneWayBlock(renderblocks, block, x, y, z, dim, renderMask);
                renderblocks.uvRotateEast = renderblocks.uvRotateNorth = renderblocks.uvRotateWest = renderblocks.uvRotateSouth = 0;
            }
        }
    }
    renderblocks.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (pipe.tilePart.hasPipePluggable(dir)) {
            IBCPipePluggable p = pipe.tilePart.getBCPipePluggable(dir);
            p.renderPluggable(renderblocks, dir, LogisticsPipeWorldRenderer.renderPass, x, y, z);
        }
    }
    return true;
}
Also used : PipeRenderState(logisticspipes.renderer.state.PipeRenderState) PipeBlockRequestTable(logisticspipes.pipes.PipeBlockRequestTable) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IBCPipePluggable(logisticspipes.proxy.buildcraft.subproxies.IBCPipePluggable)

Example 60 with ForgeDirection

use of net.minecraftforge.common.util.ForgeDirection in project LogisticsPipes by RS485.

the class ThermalDynamicsProxy method renderPipeConnections.

@Override
@SideOnly(Side.CLIENT)
public void renderPipeConnections(LogisticsTileGenericPipe pipeTile, RenderBlocks renderer) {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (pipeTile.renderState.pipeConnectionMatrix.isTDConnected(dir)) {
            IconTransformation texture = connectionTextureBasic;
            if (pipeTile.renderState.textureMatrix.isRouted()) {
                if (pipeTile.renderState.textureMatrix.isRoutedInDir(dir)) {
                    texture = connectionTextureActive;
                } else {
                    texture = connectionTextureInactive;
                }
            }
            double move = 0.25;
            Translation localTranslation = new Translation(pipeTile.xCoord + 0.5D + dir.offsetX * move, pipeTile.yCoord + 0.5D + dir.offsetY * move, pipeTile.zCoord + 0.5D + dir.offsetZ * move);
            RenderDuct.modelConnection[2][dir.ordinal()].render(new CCRenderState.IVertexOperation[] { localTranslation, texture });
        }
    }
}
Also used : Translation(cofh.repack.codechicken.lib.vec.Translation) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) CCRenderState(cofh.repack.codechicken.lib.render.CCRenderState) IconTransformation(cofh.repack.codechicken.lib.render.uv.IconTransformation) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

ForgeDirection (net.minecraftforge.common.util.ForgeDirection)242 TileEntity (net.minecraft.tileentity.TileEntity)80 ItemStack (net.minecraft.item.ItemStack)47 ArrayList (java.util.ArrayList)29 Block (net.minecraft.block.Block)28 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)24 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)21 IInventory (net.minecraft.inventory.IInventory)19 FluidStack (net.minecraftforge.fluids.FluidStack)18 SideOnly (cpw.mods.fml.relauncher.SideOnly)17 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)17 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)16 HashMap (java.util.HashMap)12 Pair (logisticspipes.utils.tuples.Pair)11 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)10 World (net.minecraft.world.World)10 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)9 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)9 List (java.util.List)8