Search in sources :

Example 91 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class HSTubeGain method addCollisionBoxesToList.

@Override
public void addCollisionBoxesToList(List<AxisAlignedBB> arraylist, AxisAlignedBB axisalignedbb) {
    if (boxes == null || boxes.isEmpty()) {
        boxes = new ArrayList<>();
        double x = getX();
        double y = getY();
        double z = getZ();
        for (int i = -1; i < 54; i++) {
            double xOne = x;
            double yOne = y;
            double zOne = z;
            double xTwo = x;
            double yTwo = y + 2;
            double zTwo = z;
            if (orientation.getRenderOrientation() == TubeGainRenderOrientation.SOUTH) {
                zOne += 4.0F * (i - 4) / 50;
                zTwo += 4.0F * (i + 4) / 50;
                xOne += 1;
                xTwo -= 2;
            } else if (orientation.getRenderOrientation() == TubeGainRenderOrientation.WEST) {
                xOne -= 3;
                xTwo -= 3;
                xOne += 4.0F * (i - 4) / 50;
                xTwo += 4.0F * (i + 4) / 50;
                zOne -= 1;
                zTwo += 2;
            } else if (orientation.getRenderOrientation() == TubeGainRenderOrientation.NORTH) {
                zOne += 1;
                zTwo += 1;
                zOne -= 4.0F * (i - 4) / 50;
                zTwo -= 4.0F * (i + 4) / 50;
                xOne -= 1;
                xTwo += 2;
            } else if (orientation.getRenderOrientation() == TubeGainRenderOrientation.EAST) {
                xOne += 4;
                xTwo += 4;
                xOne -= 4.0F * (i - 4) / 50;
                xTwo -= 4.0F * (i + 4) / 50;
                zOne -= 1;
                zTwo += 2;
            }
            AxisAlignedBB box = GainTubeRenderer.getObjectBoundsAt(new AxisAlignedBB(Math.min(xOne, xTwo), Math.min(yOne, yTwo), Math.min(zOne, zTwo), Math.max(xOne, xTwo), Math.max(yOne, yTwo), Math.max(zOne, zTwo)).offset(-x, -y, -z), orientation);
            if (box != null) {
                LPPositionSet<DoubleCoordinates> lpBox = new LPPositionSet<>(DoubleCoordinates.class);
                lpBox.addFrom(box);
                DoubleCoordinates center = lpBox.getCenter();
                box = new AxisAlignedBB(center.getXCoord() - 0.3D, center.getYCoord() - 0.3D, center.getZCoord() - 0.3D, center.getXCoord() + 0.3D, center.getYCoord() + 0.3D, center.getZCoord() + 0.3D);
                AxisAlignedBB cBox = getCompleteBox();
                double minX = Math.max(box.minX, cBox.minX);
                double minY = Math.max(box.minY, cBox.minY);
                double minZ = Math.max(box.minZ, cBox.minZ);
                double maxX = Math.min(box.maxX, cBox.maxX);
                double maxY = Math.min(box.maxY, cBox.maxY);
                double maxZ = Math.min(box.maxZ, cBox.maxZ);
                boxes.add(new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ).offset(x, y, z));
            }
        }
    }
    arraylist.addAll(boxes.stream().filter(box -> box != null && (axisalignedbb == null || axisalignedbb.intersects(box))).collect(Collectors.toList()));
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 92 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class CoreUnroutedPipe method getDistanceTo.

public double getDistanceTo(int destinationint, EnumFacing ignore, ItemIdentifier ident, boolean isActive, double travled, double max, List<DoubleCoordinates> visited) {
    double lowest = Integer.MAX_VALUE;
    for (EnumFacing dir : EnumFacing.VALUES) {
        if (ignore == dir) {
            continue;
        }
        IPipeInformationProvider information = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(container.getNextConnectedTile(dir));
        if (information != null) {
            DoubleCoordinates pos = new DoubleCoordinates(information);
            if (visited.contains(pos)) {
                continue;
            }
            visited.add(pos);
            lowest = information.getDistanceTo(destinationint, dir.getOpposite(), ident, isActive, travled, Math.min(max, lowest), visited);
            visited.remove(pos);
        }
    }
    return lowest;
}
Also used : IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider) EnumFacing(net.minecraft.util.EnumFacing) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 93 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class LogisticsNewRenderPipe method fillObjectsToRenderList.

private static void fillObjectsToRenderList(List<RenderEntry> objectsToRender, LogisticsTileGenericPipe pipeTile, PipeRenderState renderState) {
    List<Edge> edgesToRender = new ArrayList<>(Arrays.asList(Edge.values()));
    Map<Corner, Integer> connectionAtCorner = new HashMap<>();
    List<PipeMount> mountCanidates = new ArrayList<>(Arrays.asList(PipeMount.values()));
    int connectionCount = 0;
    for (EnumFacing dir : EnumFacing.VALUES) {
        if (renderState.pipeConnectionMatrix.isConnected(dir) || pipeTile.pipe.hasSpecialPipeEndAt(dir)) {
            connectionCount++;
            if (renderState.pipeConnectionMatrix.isTDConnected(dir) || renderState.pipeConnectionMatrix.isBCConnected(dir)) {
                I3DOperation[] texture = new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture };
                if (renderState.textureMatrix.isRouted()) {
                    if (renderState.textureMatrix.isRoutedInDir(dir)) {
                        if (renderState.textureMatrix.isSubPowerInDir(dir)) {
                            texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(0, +23F / 100), LogisticsNewRenderPipe.statusBCTexture) };
                        } else {
                            texture = new I3DOperation[] { LogisticsNewRenderPipe.statusBCTexture };
                        }
                    } else {
                        texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(0, -23F / 100), LogisticsNewRenderPipe.statusBCTexture) };
                    }
                }
                for (IModel3D model : LogisticsNewRenderPipe.sideBC.get(dir)) {
                    objectsToRender.add(new RenderEntry(model, texture));
                }
            } else if (!pipeTile.pipe.hasSpecialPipeEndAt(dir)) {
                I3DOperation[] texture = new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture };
                if (renderState.textureMatrix.isRouted()) {
                    if (renderState.textureMatrix.isRoutedInDir(dir)) {
                        if (renderState.textureMatrix.isSubPowerInDir(dir)) {
                            texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(-2.5F / 10, 0), LogisticsNewRenderPipe.statusTexture) };
                        } else {
                            texture = new I3DOperation[] { LogisticsNewRenderPipe.statusTexture };
                        }
                    } else {
                        if (renderState.textureMatrix.isHasPowerUpgrade()) {
                            if (renderState.textureMatrix.getPointedOrientation() == dir) {
                                texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(+2.5F / 10, 0), LogisticsNewRenderPipe.statusTexture) };
                            } else {
                                texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(-2.5F / 10, 37F / 100), LogisticsNewRenderPipe.statusTexture) };
                            }
                        } else {
                            if (renderState.textureMatrix.getPointedOrientation() == dir) {
                                texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(+2.5F / 10, 37F / 100), LogisticsNewRenderPipe.statusTexture) };
                            } else {
                                texture = new I3DOperation[] { new LPUVTransformationList(new LPUVTranslation(0, 37F / 100), LogisticsNewRenderPipe.statusTexture) };
                            }
                        }
                    }
                }
                for (IModel3D model : LogisticsNewRenderPipe.sideNormal.get(dir)) {
                    double[] bounds = { Block.FULL_BLOCK_AABB.minY, Block.FULL_BLOCK_AABB.minZ, Block.FULL_BLOCK_AABB.minX, Block.FULL_BLOCK_AABB.maxY, Block.FULL_BLOCK_AABB.maxZ, Block.FULL_BLOCK_AABB.maxX };
                    if (pipeTile.getWorld() != null) {
                        // This can be null in some cases now !!!
                        DoubleCoordinates coords = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipeTile), dir);
                        Block block = coords.getBlock(pipeTile.getWorld());
                        AxisAlignedBB bb = block.getCollisionBoundingBox(coords.getBlockState(pipeTile.getWorld()), pipeTile.getWorld(), coords.getBlockPos());
                        if (bb == null)
                            bb = Block.FULL_BLOCK_AABB;
                        bounds = new double[] { bb.minY, bb.minZ, bb.minX, bb.maxY, bb.maxZ, bb.maxX };
                        if (SimpleServiceLocator.enderIOProxy.isItemConduit(coords.getTileEntity(pipeTile.getWorld()), dir.getOpposite()) || SimpleServiceLocator.enderIOProxy.isFluidConduit(coords.getTileEntity(pipeTile.getWorld()), dir.getOpposite())) {
                            bounds = new double[] { 0.0249D, 0.0249D, 0.0249D, 0.9751D, 0.9751D, 0.9751D };
                        }
                    }
                    double bound = bounds[dir.ordinal() / 2 + (dir.ordinal() % 2 == 0 ? 3 : 0)];
                    ScaleObject key = new ScaleObject(model, bound);
                    IModel3D model2 = LogisticsNewRenderPipe.scaleMap.get(key);
                    if (model2 == null) {
                        model2 = model.copy();
                        IVec3 min = model2.bounds().min();
                        model2.apply(new LPTranslation(min).inverse());
                        double toAdd;
                        if (dir.ordinal() % 2 == 1) {
                            toAdd = 1 + (bound / LPConstants.PIPE_MIN_POS);
                            model2.apply(new LPScale(dir.getDirectionVec().getX() != 0 ? toAdd : 1, dir.getDirectionVec().getY() != 0 ? toAdd : 1, dir.getDirectionVec().getZ() != 0 ? toAdd : 1));
                        } else {
                            bound = 1 - bound;
                            toAdd = 1 + (bound / LPConstants.PIPE_MIN_POS);
                            model2.apply(new LPScale(dir.getDirectionVec().getX() != 0 ? toAdd : 1, dir.getDirectionVec().getY() != 0 ? toAdd : 1, dir.getDirectionVec().getZ() != 0 ? toAdd : 1));
                            model2.apply(new LPTranslation(dir.getDirectionVec().getX() * bound, dir.getDirectionVec().getY() * bound, dir.getDirectionVec().getZ() * bound));
                        }
                        model2.apply(new LPTranslation(min));
                        LogisticsNewRenderPipe.scaleMap.put(key, model2);
                    }
                    objectsToRender.add(new RenderEntry(model2, texture));
                }
            }
            for (Edge edge : Edge.values()) {
                if (edge.part1 == dir || edge.part2 == dir) {
                    edgesToRender.remove(edge);
                    for (PipeMount mount : PipeMount.values()) {
                        if ((mount.dir == edge.part1 && mount.side == edge.part2) || (mount.dir == edge.part2 && mount.side == edge.part1)) {
                            mountCanidates.remove(mount);
                        }
                    }
                }
            }
            for (Corner corner : Corner.values()) {
                if (corner.ew.dir == dir || corner.ns.dir == dir || corner.ud.dir == dir) {
                    if (!connectionAtCorner.containsKey(corner)) {
                        connectionAtCorner.put(corner, 1);
                    } else {
                        connectionAtCorner.put(corner, connectionAtCorner.get(corner) + 1);
                    }
                }
            }
        }
    }
    for (Corner corner : Corner.values()) {
        TextureTransformation cornerTexture = LogisticsNewRenderPipe.basicPipeTexture;
        if (!renderState.textureMatrix.isHasPower() && renderState.textureMatrix.isRouted()) {
            cornerTexture = LogisticsNewRenderPipe.inactiveTexture;
        } else if (!renderState.textureMatrix.isRouted() && connectionCount > 2) {
            cornerTexture = LogisticsNewRenderPipe.inactiveTexture;
        }
        int count = connectionAtCorner.containsKey(corner) ? connectionAtCorner.get(corner) : 0;
        if (count == 0) {
            for (IModel3D model : LogisticsNewRenderPipe.corners_M.get(corner)) {
                objectsToRender.add(new RenderEntry(model, cornerTexture));
            }
        } else if (count == 1) {
            for (PipeTurnCorner turn : PipeTurnCorner.values()) {
                if (turn.corner != corner) {
                    continue;
                }
                if (renderState.pipeConnectionMatrix.isConnected(turn.getPointer()) || pipeTile.pipe.hasSpecialPipeEndAt(turn.getPointer())) {
                    objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.spacers.get(turn), cornerTexture));
                    break;
                }
            }
        } else if (count == 2) {
            for (PipeTurnCorner turn : PipeTurnCorner.values()) {
                if (turn.corner != corner) {
                    continue;
                }
                if (!renderState.pipeConnectionMatrix.isConnected(turn.getPointer()) || pipeTile.pipe.hasSpecialPipeEndAt(turn.getPointer())) {
                    objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.corners_I.get(turn), cornerTexture));
                    break;
                }
            }
        } else if (count == 3) {
            for (IModel3D model : LogisticsNewRenderPipe.corners_I3.get(corner)) {
                objectsToRender.add(new RenderEntry(model, cornerTexture));
            }
        }
    }
    edgesToRender.stream().map(edge -> new RenderEntry(LogisticsNewRenderPipe.edges.get(edge), LogisticsNewRenderPipe.basicPipeTexture)).forEach(objectsToRender::add);
    for (int i = 0; i < 6; i += 2) {
        EnumFacing dir = EnumFacing.getFront(i);
        List<EnumFacing> list = new ArrayList<>(Arrays.asList(EnumFacing.VALUES));
        list.remove(dir);
        list.remove(dir.getOpposite());
        if (renderState.pipeConnectionMatrix.isConnected(dir) && renderState.pipeConnectionMatrix.isConnected(dir.getOpposite())) {
            boolean found = false;
            for (EnumFacing dir2 : list) {
                if (renderState.pipeConnectionMatrix.isConnected(dir2)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                switch(dir) {
                    case DOWN:
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.EAST_SIDE), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.WEST_SIDE), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.NORTH_SIDE), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.SOUTH_SIDE), LogisticsNewRenderPipe.basicPipeTexture));
                        break;
                    case NORTH:
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.EAST_UP), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.WEST_UP), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.UP_SIDE), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.DOWN_SIDE), LogisticsNewRenderPipe.basicPipeTexture));
                        break;
                    case WEST:
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.UP_UP), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.DOWN_UP), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.NORTH_UP), LogisticsNewRenderPipe.basicPipeTexture));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.SOUTH_UP), LogisticsNewRenderPipe.basicPipeTexture));
                        break;
                    default:
                        break;
                }
            }
        }
    }
    boolean[] solidSides = new boolean[6];
    if (pipeTile.getWorld() != null) {
        // This can be null in some cases now !!!
        for (EnumFacing dir : EnumFacing.VALUES) {
            DoubleCoordinates pos = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipeTile), dir);
            Block blockSide = pos.getBlock(pipeTile.getWorld());
            if (blockSide == null || !blockSide.isSideSolid(pos.getBlockState(pipeTile.getWorld()), pipeTile.getWorld(), pos.getBlockPos(), dir.getOpposite()) || renderState.pipeConnectionMatrix.isConnected(dir)) {
                mountCanidates.removeIf(mount -> mount.dir == dir);
            } else {
                solidSides[dir.ordinal()] = true;
            }
        }
        mountCanidates.removeIf(mount -> SimpleServiceLocator.mcmpProxy.hasParts(pipeTile));
    } else {
        mountCanidates.clear();
    }
    if (!mountCanidates.isEmpty()) {
        if (solidSides[EnumFacing.DOWN.ordinal()]) {
            findOponentOnSameSide(mountCanidates, EnumFacing.DOWN);
        } else if (solidSides[EnumFacing.UP.ordinal()]) {
            findOponentOnSameSide(mountCanidates, EnumFacing.UP);
        } else {
            removeFromSide(mountCanidates, EnumFacing.DOWN);
            removeFromSide(mountCanidates, EnumFacing.UP);
            if (mountCanidates.size() > 2) {
                removeIfHasOponentSide(mountCanidates);
            }
            if (mountCanidates.size() > 2) {
                removeIfHasConnectedSide(mountCanidates);
            }
            if (mountCanidates.size() > 2) {
                findOponentOnSameSide(mountCanidates, mountCanidates.get(0).dir);
            }
        }
        if (LogisticsPipes.isDEBUG() && mountCanidates.size() > 2) {
            new RuntimeException("Trying to render " + mountCanidates.size() + " Mounts").printStackTrace();
        }
        mountCanidates.stream().map(mount -> new RenderEntry(LogisticsNewRenderPipe.mounts.get(mount), LogisticsNewRenderPipe.basicPipeTexture)).forEach(objectsToRender::add);
    }
    for (EnumFacing dir : EnumFacing.VALUES) {
        if (!renderState.pipeConnectionMatrix.isConnected(dir)) {
            for (IModel3D model : LogisticsNewRenderPipe.texturePlate_Outer.get(dir)) {
                TextureTransformation icon = Textures.LPnewPipeIconProvider.getIcon(renderState.textureMatrix.getTextureIndex());
                if (icon != null) {
                    objectsToRender.add(new RenderEntry(model, new LPUVTransformationList(new LPUVScale(12f / 16, 12f / 16), icon)));
                }
            }
        }
    }
    if (renderState.textureMatrix.isFluid()) {
        for (EnumFacing dir : EnumFacing.VALUES) {
            if (!renderState.pipeConnectionMatrix.isConnected(dir)) {
                LogisticsNewRenderPipe.texturePlate_Inner.get(dir).stream().map(model -> new RenderEntry(model, new I3DOperation[] { LogisticsNewRenderPipe.glassCenterTexture })).forEach(objectsToRender::add);
            } else {
                if (!renderState.textureMatrix.isRoutedInDir(dir)) {
                    LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().stream().map(model -> new RenderEntry(model, new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture })).forEach(objectsToRender::add);
                }
            }
        }
    }
    SimpleServiceLocator.thermalDynamicsProxy.renderPipeConnections(pipeTile, objectsToRender);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Arrays(java.util.Arrays) IVec3(logisticspipes.proxy.object3d.interfaces.IVec3) Textures(logisticspipes.textures.Textures) LogisticsPipes(logisticspipes.LogisticsPipes) Quartet(logisticspipes.utils.tuples.Quartet) MainProxy(logisticspipes.proxy.MainProxy) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) ClientConfiguration(network.rs485.logisticspipes.config.ClientConfiguration) Map(java.util.Map) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) PipeBlockRequestTable(logisticspipes.pipes.PipeBlockRequestTable) GL11(org.lwjgl.opengl.GL11) I3DOperation(logisticspipes.proxy.object3d.interfaces.I3DOperation) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) CoordinateUtils(network.rs485.logisticspipes.world.CoordinateUtils) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Entry(java.util.Map.Entry) PipeRenderState(logisticspipes.renderer.state.PipeRenderState) EntityModelFX(logisticspipes.pipefxhandlers.EntityModelFX) IModel3D(logisticspipes.proxy.object3d.interfaces.IModel3D) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) LPTranslation(logisticspipes.proxy.object3d.operation.LPTranslation) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) HashMap(java.util.HashMap) PipeItemsBasicLogistics(logisticspipes.pipes.PipeItemsBasicLogistics) LPUVTranslation(logisticspipes.proxy.object3d.operation.LPUVTranslation) LPUVTransformationList(logisticspipes.proxy.object3d.operation.LPUVTransformationList) ArrayList(java.util.ArrayList) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) Lists(com.google.common.collect.Lists) Minecraft(net.minecraft.client.Minecraft) IBounds(logisticspipes.proxy.object3d.interfaces.IBounds) LinkedList(java.util.LinkedList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) LPConstants(logisticspipes.LPConstants) Nonnull(javax.annotation.Nonnull) LPColourMultiplier(logisticspipes.proxy.object3d.operation.LPColourMultiplier) Iterator(java.util.Iterator) World(net.minecraft.world.World) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) TextureMap(net.minecraft.client.renderer.texture.TextureMap) EnumFacing(net.minecraft.util.EnumFacing) LPUVScale(logisticspipes.proxy.object3d.operation.LPUVScale) ParticleManager(net.minecraft.client.particle.ParticleManager) ResourceLocation(net.minecraft.util.ResourceLocation) Data(lombok.Data) TextureTransformation(logisticspipes.proxy.object3d.interfaces.TextureTransformation) TileEntity(net.minecraft.tileentity.TileEntity) LPScale(logisticspipes.proxy.object3d.operation.LPScale) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) IModel3D(logisticspipes.proxy.object3d.interfaces.IModel3D) LPUVScale(logisticspipes.proxy.object3d.operation.LPUVScale) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) I3DOperation(logisticspipes.proxy.object3d.interfaces.I3DOperation) LPUVTransformationList(logisticspipes.proxy.object3d.operation.LPUVTransformationList) LPTranslation(logisticspipes.proxy.object3d.operation.LPTranslation) TileEntity(net.minecraft.tileentity.TileEntity) LPUVTranslation(logisticspipes.proxy.object3d.operation.LPUVTranslation) IVec3(logisticspipes.proxy.object3d.interfaces.IVec3) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) TextureTransformation(logisticspipes.proxy.object3d.interfaces.TextureTransformation) Block(net.minecraft.block.Block) LPScale(logisticspipes.proxy.object3d.operation.LPScale)

Example 94 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates 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<DuctUnitItem, GridItem> routes = getDuct().getCache(true);
        Iterable<Route<DuctUnitItem, GridItem>> paramIterable = routes.outputRoutes;
        Route<DuctUnitItem, GridItem> 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) {
            // noinspection unchecked
            route = (Route<DuctUnitItem, GridItem>) cache;
            if (!routes.outputRoutes.contains(route)) {
                route = null;
            }
        }
        if (route == null) {
            Pair<Double, Route<DuctUnitItem, GridItem>> closesedConnection = null;
            List<DoubleCoordinates> visited = new ArrayList<>();
            visited.add(new DoubleCoordinates(from));
            for (Route<DuctUnitItem, GridItem> localRoute1 : paramIterable) {
                if (localRoute1.endPoint instanceof LPDuctUnitItem) {
                    LPDuctUnitItem lpDuct = (LPDuctUnitItem) 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, EnumFacing.getFront(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(), getDuct(), route.copy(), (byte) serverItem.output.ordinal(), (byte) 1);
            // noinspection ConstantConditions
            ((ILPTravelingItemInfo) travelItem).setLPRoutingInfoAddition(serverItem.getInfo());
            getDuct().insertNewItem(travelItem);
            return true;
        }
    } else {
        return true;
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ILPTravelingItemInfo(logisticspipes.asm.td.ILPTravelingItemInfo) GridItem(cofh.thermaldynamics.duct.item.GridItem) IRouter(logisticspipes.routing.IRouter) TravelingItem(cofh.thermaldynamics.duct.item.TravelingItem) LPTravelingItem(logisticspipes.transport.LPTravelingItem) Route(cofh.thermaldynamics.multiblock.Route) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) Triplet(logisticspipes.utils.tuples.Triplet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) DuctUnitItem(cofh.thermaldynamics.duct.item.DuctUnitItem)

Example 95 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class TDDuctInformationProvider method getDistanceTo.

@Override
public double getDistanceTo(int destinationint, EnumFacing ignore, ItemIdentifier ident, boolean isActive, double traveled, double max, List<DoubleCoordinates> visited) {
    if (traveled >= max) {
        return Integer.MAX_VALUE;
    }
    IRouter destination = SimpleServiceLocator.routerManager.getRouter(destinationint);
    if (destination == null) {
        return Integer.MAX_VALUE;
    }
    LinkedList<Route<DuctUnitItem, GridItem>> paramIterable = getDuct().getCache(true).outputRoutes;
    double closesedConnection = Integer.MAX_VALUE;
    for (Route<DuctUnitItem, GridItem> localRoute1 : paramIterable) {
        if (localRoute1.endPoint instanceof LPDuctUnitItem) {
            LPDuctUnitItem lpDuct = (LPDuctUnitItem) localRoute1.endPoint;
            if (traveled + localRoute1.pathWeight > max) {
                continue;
            }
            DoubleCoordinates pos = new DoubleCoordinates((TileEntity) lpDuct.pipe);
            if (visited.contains(pos)) {
                continue;
            }
            visited.add(pos);
            double distance = lpDuct.pipe.getDistanceTo(destinationint, EnumFacing.getFront(localRoute1.pathDirections.get(localRoute1.pathDirections.size() - 1)).getOpposite(), ident, isActive, traveled + localRoute1.pathWeight, Math.min(max, closesedConnection), visited);
            visited.remove(pos);
            if (distance != Integer.MAX_VALUE && distance + localRoute1.pathWeight < closesedConnection) {
                closesedConnection = distance + localRoute1.pathWeight;
            }
        }
    }
    return closesedConnection;
}
Also used : GridItem(cofh.thermaldynamics.duct.item.GridItem) IRouter(logisticspipes.routing.IRouter) DuctUnitItem(cofh.thermaldynamics.duct.item.DuctUnitItem) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Route(cofh.thermaldynamics.multiblock.Route)

Aggregations

DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)94 TileEntity (net.minecraft.tileentity.TileEntity)57 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)22 LPPositionSet (logisticspipes.utils.LPPositionSet)19 ArrayList (java.util.ArrayList)17 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)15 EnumFacing (net.minecraft.util.EnumFacing)14 ItemStack (net.minecraft.item.ItemStack)12 World (net.minecraft.world.World)12 LogisticsTileGenericSubMultiBlock (logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)11 Block (net.minecraft.block.Block)11 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)10 SideOnly (cpw.mods.fml.relauncher.SideOnly)7 List (java.util.List)7 DoubleCoordinatesType (network.rs485.logisticspipes.world.DoubleCoordinatesType)7 ILPTEInformation (logisticspipes.asm.te.ILPTEInformation)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 DockingStation (buildcraft.api.robots.DockingStation)5