Search in sources :

Example 1 with CCQuad

use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.

the class FacadeRenderer method applyItemTint.

public static List<CCQuad> applyItemTint(List<CCQuad> quads, ItemStack stack) {
    List<CCQuad> retQuads = new LinkedList<>();
    for (CCQuad quad : quads) {
        int colour = -1;
        if (quad.hasTint()) {
            colour = Minecraft.getMinecraft().getItemColors().colorMultiplier(stack, quad.tintIndex);
            if (EntityRenderer.anaglyphEnable) {
                colour = TextureUtil.anaglyphColor(colour);
            }
            colour = colour | 0xFF000000;
        }
        CCQuad copyQuad = quad.copy();
        Colour c = new ColourARGB(colour);
        for (Colour qC : copyQuad.colours) {
            qC.multiply(c);
        }
        retQuads.add(copyQuad);
    }
    return retQuads;
}
Also used : ColourARGB(codechicken.lib.colour.ColourARGB) CCQuad(codechicken.lib.render.CCQuad) LinkedList(java.util.LinkedList) Colour(codechicken.lib.colour.Colour)

Example 2 with CCQuad

use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.

the class FacadeRenderer method sliceQuads.

public static List<CCQuad> sliceQuads(List<CCQuad> quads, int side, Cuboid6 bounds) {
    boolean flag, flag2;
    double[][] quadPos = new double[4][3];
    boolean[] flat = new boolean[3];
    int verticesPerFace = 4;
    List<CCQuad> finalQuads = new LinkedList<>();
    for (CCQuad quad : quads) {
        flag = flag2 = false;
        for (int i = 0; i < 3; i++) {
            flat[i] = true;
        }
        Vector3 first = quad.vertices[0].vec;
        for (int v = 0; v < 4; v++) {
            quadPos[v] = quad.vertices[v].vec.toArrayD();
            flag = flag || quadPos[v][sideOffsets[side]] != sideSoftBounds[side];
            flag2 = flag2 || quadPos[v][sideOffsets[side]] != (1 - sideSoftBounds[side]);
            if (v != 0) {
                flat[0] = flat[0] && quad.vertices[v].vec.x == first.x;
                flat[1] = flat[1] && quad.vertices[v].vec.y == first.y;
                flat[2] = flat[2] && quad.vertices[v].vec.z == first.z;
            }
        }
        int s = -1;
        if (flag && flag2) {
            for (int vi = 0; vi < 3; vi++) {
                if (flat[vi]) {
                    if (vi != sideOffsets[side]) {
                        s = vi;
                        break;
                    } else {
                        flag = false;
                    }
                }
            }
        }
        for (int k2 = 0; k2 < verticesPerFace; k2++) {
            boolean flag3 = quadPos[k2][sideOffsets[side]] != sideSoftBounds[side];
            for (int j = 0; j < 3; j++) {
                if (j == sideOffsets[side]) {
                    quadPos[k2][j] = clampF(quadPos[k2][j], bounds, j);
                } else {
                    if (flag && flag2 && flag3) {
                        quadPos[k2][j] = MathHelper.clamp(quadPos[k2][j], FACADE_RENDER_OFFSET, FACADE_RENDER_OFFSET2);
                    }
                }
            }
            if (s != -1) {
                double u, v;
                if (s == 0) {
                    u = quadPos[k2][1];
                    v = quadPos[k2][2];
                } else if (s == 1) {
                    u = quadPos[k2][0];
                    v = quadPos[k2][2];
                } else {
                    u = quadPos[k2][0];
                    v = quadPos[k2][1];
                }
                u = MathHelper.clamp(u, 0, 1) * 16;
                v = MathHelper.clamp(v, 0, 1) * 16;
                TextureAtlasSprite sideTexture = quad.sprite;
                u = sideTexture.getInterpolatedU(u);
                v = sideTexture.getInterpolatedV(v);
                quad.vertices[k2].uv.set(u, v);
                quad.tintIndex = -1;
            }
            quad.vertices[k2].vec.set(quadPos[k2]);
        }
        finalQuads.add(quad);
    }
    return finalQuads;
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3(codechicken.lib.vec.Vector3) CCQuad(codechicken.lib.render.CCQuad) LinkedList(java.util.LinkedList)

Example 3 with CCQuad

use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.

the class FacadeRenderer method renderBlockQuads.

public static boolean renderBlockQuads(VertexLighterFlat lighter, IBlockAccess access, IBlockState state, List<CCQuad> quads, BlockPos pos) {
    if (!quads.isEmpty()) {
        lighter.setWorld(access);
        lighter.setState(state);
        lighter.setBlockPos(pos);
        lighter.updateBlockInfo();
        for (CCQuad quad : quads) {
            quad.pipe(lighter);
        }
        return true;
    }
    return false;
}
Also used : CCQuad(codechicken.lib.render.CCQuad)

Example 4 with CCQuad

use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.

the class FacadeRenderer method renderBlockCover.

public static boolean renderBlockCover(CCRenderState ccrs, Matrix4 translation, IBlockAccess world, BlockPos pos, int side, IBlockState state, Cuboid6 bounds) {
    EnumFacing face = EnumFacing.VALUES[side];
    IBlockAccess coverAccess = new FacadeBlockAccess(world, pos, face, state);
    BlockRendererDispatcher dispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
    try {
        state = state.getActualState(coverAccess, pos);
    } catch (Exception ignored) {
    }
    IBakedModel model = dispatcher.getModelForState(state);
    try {
        state = state.getBlock().getExtendedState(state, coverAccess, pos);
    } catch (Exception ignored) {
    }
    long posRand = net.minecraft.util.math.MathHelper.getPositionRandom(pos);
    List<BakedQuad> bakedQuads = new LinkedList<>(model.getQuads(state, null, posRand));
    for (EnumFacing face2 : EnumFacing.VALUES) {
        bakedQuads.addAll(model.getQuads(state, face2, posRand));
    }
    List<CCQuad> quads = CCQuad.fromArray(bakedQuads);
    quads = sliceQuads(quads, side, bounds);
    if (!quads.isEmpty()) {
        VertexLighterFlat lighter = setupLighter(ccrs, translation, state, coverAccess, pos, model);
        return renderBlockQuads(lighter, coverAccess, state, quads, pos);
    }
    return false;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) EnumFacing(net.minecraft.util.EnumFacing) IBlockAccess(net.minecraft.world.IBlockAccess) CCQuad(codechicken.lib.render.CCQuad) LinkedList(java.util.LinkedList) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) VertexLighterFlat(net.minecraftforge.client.model.pipeline.VertexLighterFlat) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 5 with CCQuad

use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.

the class FacadeRenderer method renderItemCover.

public static void renderItemCover(CCRenderState ccrs, int side, ItemStack renderStack, Cuboid6 bounds) {
    Minecraft minecraft = Minecraft.getMinecraft();
    RenderItem renderItem = minecraft.getRenderItem();
    IBakedModel model = renderItem.getItemModelWithOverrides(renderStack, null, null);
    IBlockState state = FacadeHelper.lookupBlockForItem(renderStack);
    String cacheKey = state.getBlock().getRegistryName() + "|" + state.getBlock().getMetaFromState(state);
    List<CCQuad> renderQuads = itemQuadCache.getIfPresent(cacheKey);
    if (renderQuads == null) {
        List<BakedQuad> quads = new ArrayList<>(model.getQuads(null, null, 0));
        for (EnumFacing face : EnumFacing.VALUES) {
            quads.addAll(model.getQuads(null, face, 0));
        }
        renderQuads = applyItemTint(sliceQuads(CCQuad.fromArray(quads), side, bounds), renderStack);
        itemQuadCache.put(cacheKey, renderQuads);
    }
    AdvCCRSConsumer consumer = new AdvCCRSConsumer(ccrs);
    consumer.setTranslation(new Matrix4().translate(Vector3.center.copy().subtract(bounds.center())).scale(1.05, 1.05, 1.05));
    for (CCQuad quad : renderQuads) {
        quad.pipe(consumer);
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) CCQuad(codechicken.lib.render.CCQuad) Minecraft(net.minecraft.client.Minecraft) Matrix4(codechicken.lib.vec.Matrix4) RenderItem(net.minecraft.client.renderer.RenderItem) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Aggregations

CCQuad (codechicken.lib.render.CCQuad)5 LinkedList (java.util.LinkedList)3 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)2 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)2 EnumFacing (net.minecraft.util.EnumFacing)2 Colour (codechicken.lib.colour.Colour)1 ColourARGB (codechicken.lib.colour.ColourARGB)1 Matrix4 (codechicken.lib.vec.Matrix4)1 Vector3 (codechicken.lib.vec.Vector3)1 ArrayList (java.util.ArrayList)1 IBlockState (net.minecraft.block.state.IBlockState)1 Minecraft (net.minecraft.client.Minecraft)1 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)1 RenderItem (net.minecraft.client.renderer.RenderItem)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 IBlockAccess (net.minecraft.world.IBlockAccess)1 VertexLighterFlat (net.minecraftforge.client.model.pipeline.VertexLighterFlat)1