Search in sources :

Example 6 with I3DOperation

use of logisticspipes.proxy.object3d.interfaces.I3DOperation in project LogisticsPipes by RS485.

the class LogisticsNewRenderPipe method fillObjectsToRenderList.

private 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 (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (renderState.pipeConnectionMatrix.isConnected(dir) || pipeTile.pipe.hasSpecialPipeEndAt(dir)) {
            connectionCount++;
            if (renderState.pipeConnectionMatrix.isBCConnected(dir) || renderState.pipeConnectionMatrix.isTDConnected(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)) {
                    DoubleCoordinates coords = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipeTile), dir);
                    Block block = coords.getBlock(pipeTile.getWorld());
                    double[] bounds = { block.getBlockBoundsMinY(), block.getBlockBoundsMinZ(), block.getBlockBoundsMinX(), block.getBlockBoundsMaxY(), block.getBlockBoundsMaxZ(), block.getBlockBoundsMaxX() };
                    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 = 1;
                        if (dir.ordinal() % 2 == 1) {
                            toAdd = 1 + (bound / LPConstants.PIPE_MIN_POS);
                            model2.apply(new LPScale(dir.offsetX != 0 ? toAdd : 1, dir.offsetY != 0 ? toAdd : 1, dir.offsetZ != 0 ? toAdd : 1));
                        } else {
                            bound = 1 - bound;
                            toAdd = 1 + (bound / LPConstants.PIPE_MIN_POS);
                            model2.apply(new LPScale(dir.offsetX != 0 ? toAdd : 1, dir.offsetY != 0 ? toAdd : 1, dir.offsetZ != 0 ? toAdd : 1));
                            model2.apply(new LPTranslation(dir.offsetX * bound, dir.offsetY * bound, dir.offsetZ * 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()) {
        IIconTransformation 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, new I3DOperation[] { 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), new I3DOperation[] { 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), new I3DOperation[] { cornerTexture }));
                    break;
                }
            }
        } else if (count == 3) {
            for (IModel3D model : LogisticsNewRenderPipe.corners_I3.get(corner)) {
                objectsToRender.add(new RenderEntry(model, new I3DOperation[] { cornerTexture }));
            }
        }
    }
    objectsToRender.addAll(edgesToRender.stream().map(edge -> new RenderEntry(LogisticsNewRenderPipe.edges.get(edge), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture })).collect(Collectors.toList()));
    for (int i = 0; i < 6; i += 2) {
        ForgeDirection dir = ForgeDirection.getOrientation(i);
        List<ForgeDirection> list = new ArrayList<>(Arrays.asList(ForgeDirection.VALID_DIRECTIONS));
        list.remove(dir);
        list.remove(dir.getOpposite());
        if (renderState.pipeConnectionMatrix.isConnected(dir) && renderState.pipeConnectionMatrix.isConnected(dir.getOpposite())) {
            boolean found = false;
            for (ForgeDirection 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), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.WEST_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.NORTH_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.SOUTH_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        break;
                    case NORTH:
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.EAST_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.WEST_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.UP_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.DOWN_SIDE), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        break;
                    case WEST:
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.UP_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.DOWN_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.NORTH_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.supports.get(PipeSupport.SOUTH_UP), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture }));
                        break;
                    default:
                        break;
                }
            }
        }
    }
    boolean[] solidSides = new boolean[6];
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        DoubleCoordinates pos = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipeTile), dir);
        Block blockSide = pos.getBlock(pipeTile.getWorldObj());
        if (blockSide == null || !blockSide.isSideSolid(pipeTile.getWorldObj(), pos.getXInt(), pos.getYInt(), pos.getZInt(), dir.getOpposite()) || renderState.pipeConnectionMatrix.isConnected(dir)) {
            Iterator<PipeMount> iter = mountCanidates.iterator();
            while (iter.hasNext()) {
                PipeMount mount = iter.next();
                if (mount.dir == dir) {
                    iter.remove();
                }
            }
        } else {
            solidSides[dir.ordinal()] = true;
        }
    }
    if (!mountCanidates.isEmpty()) {
        if (solidSides[ForgeDirection.DOWN.ordinal()]) {
            findOponentOnSameSide(mountCanidates, ForgeDirection.DOWN);
        } else if (solidSides[ForgeDirection.UP.ordinal()]) {
            findOponentOnSameSide(mountCanidates, ForgeDirection.UP);
        } else {
            removeFromSide(mountCanidates, ForgeDirection.DOWN);
            removeFromSide(mountCanidates, ForgeDirection.UP);
            if (mountCanidates.size() > 2) {
                removeIfHasOponentSide(mountCanidates);
            }
            if (mountCanidates.size() > 2) {
                removeIfHasConnectedSide(mountCanidates);
            }
            if (mountCanidates.size() > 2) {
                findOponentOnSameSide(mountCanidates, mountCanidates.get(0).dir);
            }
        }
        if (LPConstants.DEBUG && mountCanidates.size() > 2) {
            new RuntimeException("Trying to render " + mountCanidates.size() + " Mounts").printStackTrace();
        }
        objectsToRender.addAll(mountCanidates.stream().map(mount -> new RenderEntry(LogisticsNewRenderPipe.mounts.get(mount), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture })).collect(Collectors.toList()));
    }
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (!renderState.pipeConnectionMatrix.isConnected(dir)) {
            for (IModel3D model : LogisticsNewRenderPipe.texturePlate_Outer.get(dir)) {
                IIconTransformation icon = Textures.LPnewPipeIconProvider.getIcon(renderState.textureMatrix.getTextureIndex());
                if (icon != null) {
                    objectsToRender.add(new RenderEntry(model, new I3DOperation[] { icon }));
                }
            }
        }
    }
    if (renderState.textureMatrix.isFluid()) {
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            if (!renderState.pipeConnectionMatrix.isConnected(dir)) {
                objectsToRender.addAll(LogisticsNewRenderPipe.texturePlate_Inner.get(dir).stream().map(model -> new RenderEntry(model, new I3DOperation[] { LogisticsNewRenderPipe.glassCenterTexture })).collect(Collectors.toList()));
            } else {
                if (!renderState.textureMatrix.isRoutedInDir(dir)) {
                    objectsToRender.addAll(LogisticsNewRenderPipe.sideTexturePlate.get(dir).getValue1().stream().map(model -> new RenderEntry(model, new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture })).collect(Collectors.toList()));
                }
            }
        }
    }
}
Also used : IModel3D(logisticspipes.proxy.object3d.interfaces.IModel3D) I3DOperation(logisticspipes.proxy.object3d.interfaces.I3DOperation) TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IIconTransformation(logisticspipes.proxy.object3d.interfaces.IIconTransformation) IVec3(logisticspipes.proxy.object3d.interfaces.IVec3) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Block(net.minecraft.block.Block)

Example 7 with I3DOperation

use of logisticspipes.proxy.object3d.interfaces.I3DOperation in project LogisticsPipes by RS485.

the class LogisticsNewRenderPipe method renderBoxWithDir.

public static void renderBoxWithDir(ForgeDirection dir) {
    List<RenderEntry> objectsToRender = new ArrayList<>();
    List<Edge> edgesToRender = new ArrayList<>(Arrays.asList(Edge.values()));
    Map<Corner, Integer> connectionAtCorner = new HashMap<>();
    for (Edge edge : Edge.values()) {
        if (edge.part1 == dir || edge.part2 == dir) {
            edgesToRender.remove(edge);
        }
    }
    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()) {
        IIconTransformation cornerTexture = LogisticsNewRenderPipe.basicPipeTexture;
        int count = connectionAtCorner.containsKey(corner) ? connectionAtCorner.get(corner) : 0;
        if (count == 0) {
            objectsToRender.addAll(LogisticsNewRenderPipe.corners_M.get(corner).stream().map(model -> new RenderEntry(model, new I3DOperation[] { cornerTexture })).collect(Collectors.toList()));
        } else if (count == 1) {
            for (PipeTurnCorner turn : PipeTurnCorner.values()) {
                if (turn.corner != corner) {
                    continue;
                }
                if (turn.getPointer() == dir) {
                    objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.spacers.get(turn), new I3DOperation[] { cornerTexture }));
                    break;
                }
            }
        } else if (count == 2) {
            for (PipeTurnCorner turn : PipeTurnCorner.values()) {
                if (turn.corner != corner) {
                    continue;
                }
                if (turn.getPointer() == dir) {
                    objectsToRender.add(new RenderEntry(LogisticsNewRenderPipe.corners_I.get(turn), new I3DOperation[] { cornerTexture }));
                    break;
                }
            }
        } else if (count == 3) {
            objectsToRender.addAll(LogisticsNewRenderPipe.corners_I3.get(corner).stream().map(model -> new RenderEntry(model, new I3DOperation[] { cornerTexture })).collect(Collectors.toList()));
        }
    }
    objectsToRender.addAll(edgesToRender.stream().map(edge -> new RenderEntry(LogisticsNewRenderPipe.edges.get(edge), new I3DOperation[] { LogisticsNewRenderPipe.basicPipeTexture })).collect(Collectors.toList()));
    for (RenderEntry model : objectsToRender) {
        model.getModel().render(model.getOperations());
    }
}
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) I3DOperation(logisticspipes.proxy.object3d.interfaces.I3DOperation) IIconTransformation(logisticspipes.proxy.object3d.interfaces.IIconTransformation)

Aggregations

I3DOperation (logisticspipes.proxy.object3d.interfaces.I3DOperation)7 ArrayList (java.util.ArrayList)3 IIconTransformation (logisticspipes.proxy.object3d.interfaces.IIconTransformation)3 IModel3D (logisticspipes.proxy.object3d.interfaces.IModel3D)3 IVec3 (logisticspipes.proxy.object3d.interfaces.IVec3)3 Block (net.minecraft.block.Block)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 LPConstants (logisticspipes.LPConstants)2 CoreUnroutedPipe (logisticspipes.pipes.basic.CoreUnroutedPipe)2 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)2 IBounds (logisticspipes.proxy.object3d.interfaces.IBounds)2 RenderEntry (logisticspipes.renderer.newpipe.RenderEntry)2 IIconRegister (net.minecraft.client.renderer.texture.IIconRegister)2 World (net.minecraft.world.World)2 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)2 IVertexOperation (codechicken.lib.render.CCRenderState.IVertexOperation)1 IVertexOperation (cofh.repack.codechicken.lib.render.CCRenderState.IVertexOperation)1 Side (cpw.mods.fml.relauncher.Side)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1