Java Code Examples for net.minecraftforge.client.MinecraftForgeClient#getRenderLayer()

The following examples show how to use net.minecraftforge.client.MinecraftForgeClient#getRenderLayer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InvPipeRenderer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setBrightness(world, pos);
    IVertexOperation[] pipeline = {new Translation(pos)};

    BlockInventoryPipe block = (BlockInventoryPipe) state.getBlock();
    TileEntityInventoryPipe tileEntity = (TileEntityInventoryPipe) block.getPipeTileEntity(world, pos);
    if (tileEntity == null) {
        return false;
    }
    int paintingColor = tileEntity.getInsulationColor();
    int connectedSidesMask = block.getActualConnections(tileEntity, world);

    BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
    if (renderLayer == BlockRenderLayer.SOLID) {
        renderPipe(renderState, pipeline, paintingColor, connectedSidesMask);
    }
    ICoverable coverable = tileEntity.getCoverableImplementation();
    coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
    return true;
}
 
Example 2
Source File: CableRenderer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setBrightness(world, pos);
    IVertexOperation[] pipeline = {new Translation(pos)};

    BlockCable blockCable = (BlockCable) state.getBlock();
    TileEntityCable tileEntityCable = (TileEntityCable) blockCable.getPipeTileEntity(world, pos);
    if (tileEntityCable == null) return false;
    int paintingColor = tileEntityCable.getInsulationColor();
    int connectedSidesMask = blockCable.getActualConnections(tileEntityCable, world);
    Insulation insulation = tileEntityCable.getPipeType();
    Material material = tileEntityCable.getPipeMaterial();
    if (insulation != null && material != null) {
        BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
        if (renderLayer == BlockRenderLayer.CUTOUT) {
            renderCableBlock(material, insulation, paintingColor, renderState, pipeline, connectedSidesMask);
        }
        ICoverable coverable = tileEntityCable.getCoverableImplementation();
        coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
    }
    return true;
}
 
Example 3
Source File: MetaTileEntityRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    MetaTileEntity metaTileEntity = BlockMachine.getMetaTileEntity(world, pos);
    if (metaTileEntity == null) {
        return false;
    }
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    Matrix4 translation = new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ());
    BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
    if (metaTileEntity.canRenderInLayer(renderLayer)) {
        renderState.lightMatrix.locate(world, pos);
        IVertexOperation[] pipeline = new IVertexOperation[]{renderState.lightMatrix};
        metaTileEntity.renderMetaTileEntity(renderState, translation.copy(), pipeline);
    }
    Matrix4 coverTranslation = new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ());
    metaTileEntity.renderCovers(renderState, coverTranslation, renderLayer);

    if (metaTileEntity.isFragile() && renderLayer == BlockRenderLayer.CUTOUT) {
        TextureMap textureMap = Minecraft.getMinecraft().getTextureMapBlocks();
        Random posRand = new Random(MathHelper.getPositionRandom(pos));
        int destroyStage = posRand.nextInt(10);
        TextureAtlasSprite atlasSprite = textureMap.getAtlasSprite("minecraft:blocks/destroy_stage_" + destroyStage);
        for (EnumFacing face : EnumFacing.VALUES) {
            Textures.renderFace(renderState, translation, new IVertexOperation[0], face, Cuboid6.full, atlasSprite);
        }
    }
    return true;
}
 
Example 4
Source File: CoverFacade.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, Cuboid6 plateBox, BlockRenderLayer layer) {
    BlockRenderLayer oldLayer = MinecraftForgeClient.getRenderLayer();
    ForgeHooksClient.setRenderLayer(layer);
    FacadeRenderer.renderBlockCover(renderState, translation, coverHolder.getWorld(), coverHolder.getPos(), attachedSide.getIndex(), facadeState, plateBox);
    ForgeHooksClient.setRenderLayer(oldLayer);
}
 
Example 5
Source File: FluidPipeRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setBrightness(world, pos);

    BlockFluidPipe blockPipe = ((BlockFluidPipe) state.getBlock());
    TileEntityFluidPipe tileEntityPipe = (TileEntityFluidPipe) blockPipe.getPipeTileEntity(world, pos);

    if (tileEntityPipe == null) {
        return false;
    }

    FluidPipeType fluidPipeType = tileEntityPipe.getPipeType();
    Material pipeMaterial = tileEntityPipe.getPipeMaterial();
    int paintingColor = tileEntityPipe.getInsulationColor();

    if (fluidPipeType != null && pipeMaterial != null) {
        BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();

        if (renderLayer == BlockRenderLayer.CUTOUT) {
            int connectedSidesMask = blockPipe.getActualConnections(tileEntityPipe, world);
            IVertexOperation[] pipeline = new IVertexOperation[] {new Translation(pos)};
            renderPipeBlock(pipeMaterial, fluidPipeType, paintingColor, renderState, pipeline, connectedSidesMask);
        }

        ICoverable coverable = tileEntityPipe.getCoverableImplementation();
        coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
    }
    return true;
}
 
Example 6
Source File: AbstractPerspectiveLayeredModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData data) {
    RenderType layer = MinecraftForgeClient.getRenderLayer();
    if (layer == null) {
        layer = generalLayer;
    }
    return getLayerQuads(state, side, layer, rand, data);
}
 
Example 7
Source File: MultiLayerModel.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Nonnull
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
	final BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
	if (layer == null) { return side == null? quads : ImmutableList.<BakedQuad> of(); }

	final IBakedModel model = models.get(layer);
	return MoreObjects.firstNonNull(model, missing).getQuads(state, side, rand);
}
 
Example 8
Source File: WorldSceneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Renders scene on given coordinates with given width and height, and RGB background color
 * Note that this will ignore any transformations applied currently to projection/view matrix,
 * so specified coordinates are scaled MC gui coordinates.
 * It will return matrices of projection and view in previous state after rendering
 */
public void render(int x, int y, int width, int height, int backgroundColor) {
    Vec2f mousePosition = setupCamera(x, y, width, height, backgroundColor);
    if (renderCallback != null) {
        renderCallback.preRenderScene(this);
    }
    Minecraft minecraft = Minecraft.getMinecraft();
    minecraft.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    BlockRendererDispatcher dispatcher = minecraft.getBlockRendererDispatcher();
    BlockRenderLayer oldRenderLayer = MinecraftForgeClient.getRenderLayer();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = tessellator.getBuffer();

    bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    for (BlockPos pos : renderedBlocks) {
        if (renderFilter != null && !renderFilter.test(pos))
            continue; //do not render if position is skipped
        IBlockState blockState = world.getBlockState(pos);
        for(BlockRenderLayer renderLayer : BlockRenderLayer.values()) {
            if (!blockState.getBlock().canRenderInLayer(blockState, renderLayer)) continue;
            ForgeHooksClient.setRenderLayer(renderLayer);
            dispatcher.renderBlock(blockState, pos, world, bufferBuilder);
        }
    }
    tessellator.draw();
    ForgeHooksClient.setRenderLayer(oldRenderLayer);

    if (mousePosition != null) {
        this.lastHitBlock = handleMouseHit(mousePosition);
    } else {
        this.lastHitBlock = null;
    }

    if (lastHitBlock != null) {
        GlStateManager.disableTexture2D();
        CCRenderState renderState = CCRenderState.instance();
        renderState.startDrawing(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR, tessellator.getBuffer());
        ColourMultiplier multiplier = new ColourMultiplier(0);
        renderState.setPipeline(new Translation(lastHitBlock), multiplier);
        BlockFace blockFace = new BlockFace();
        renderState.setModel(blockFace);
        for (EnumFacing renderSide : EnumFacing.VALUES) {
            float diffuse = LightUtil.diffuseLight(renderSide);
            int color = (int) (255 * diffuse);
            multiplier.colour = RenderUtil.packColor(color, color, color, 100);
            blockFace.loadCuboidFace(Cuboid6.full, renderSide.getIndex());
            renderState.render();
        }
        renderState.draw();
        GlStateManager.enableTexture2D();
    }

    resetCamera();
}
 
Example 9
Source File: PhysRenderChunk.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
private void updateList(BlockRenderLayer layerToUpdate) {
    if (parent.toRender.getShipRenderer() == null) {
        return;
    }
    BlockPos offsetPos = parent.toRender.getShipRenderer().offsetPos;
    if (offsetPos == null) {
        return;
    }
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    worldrenderer.begin(7, DefaultVertexFormats.BLOCK);
    worldrenderer.setTranslation(-offsetPos.getX(), -offsetPos.getY(), -offsetPos.getZ());
    GL11.glPushMatrix();
    switch (layerToUpdate) {
        case CUTOUT:
            GLAllocation.deleteDisplayLists(glCallListCutout);
            GL11.glNewList(glCallListCutout, GL11.GL_COMPILE);
            break;
        case CUTOUT_MIPPED:
            GLAllocation.deleteDisplayLists(glCallListCutoutMipped);
            GL11.glNewList(glCallListCutoutMipped, GL11.GL_COMPILE);
            break;
        case SOLID:
            GLAllocation.deleteDisplayLists(glCallListSolid);
            GL11.glNewList(glCallListSolid, GL11.GL_COMPILE);
            break;
        case TRANSLUCENT:
            GLAllocation.deleteDisplayLists(glCallListTranslucent);
            GL11.glNewList(glCallListTranslucent, GL11.GL_COMPILE);
            break;
        default:
            break;
    }

    GlStateManager.pushMatrix();
    // worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    IBlockState iblockstate;

    BlockRenderLayer oldLayer = MinecraftForgeClient.getRenderLayer();
    ForgeHooksClient.setRenderLayer(layerToUpdate);
    MutableBlockPos pos = new MutableBlockPos();
    for (int x = chunkToRender.x * 16; x < chunkToRender.x * 16 + 16; x++) {
        for (int z = chunkToRender.z * 16; z < chunkToRender.z * 16 + 16; z++) {
            for (int y = yMin; y <= yMax; y++) {
                pos.setPos(x, y, z);
                iblockstate = chunkToRender.getBlockState(pos);
                try {
                    if (iblockstate.getBlock()
                            .canRenderInLayer(iblockstate, layerToUpdate)) {
                        Minecraft.getMinecraft().getBlockRendererDispatcher()
                                .renderBlock(iblockstate, pos, chunkToRender.world,
                                        worldrenderer);
                    }
                } catch (NullPointerException e) {
                    System.out.println(
                            "Something was null! LValkyrienSkiesBase/render/PhysRenderChunk#updateList");
                }
            }
        }
    }
    tessellator.draw();
    // worldrenderer.finishDrawing();
    ForgeHooksClient.setRenderLayer(oldLayer);
    GlStateManager.popMatrix();
    GL11.glEndList();
    GL11.glPopMatrix();
    worldrenderer.setTranslation(0, 0, 0);

    switch (layerToUpdate) {
        case CUTOUT:
            needsCutoutUpdate = false;
            break;
        case CUTOUT_MIPPED:
            needsCutoutMippedUpdate = false;
            break;
        case SOLID:
            needsSolidUpdate = false;
            break;
        case TRANSLUCENT:
            needsTranslucentUpdate = false;
            break;
        default:
            break;
    }
}
 
Example 10
Source File: DryingRackBakedModel.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nonnull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
{
    List<BakedQuad> quads = Lists.newArrayList();

    RenderType renderLayer = MinecraftForgeClient.getRenderLayer();
    if (renderLayer == RenderType.getSolid())
    {
        quads.addAll(rackBakedModel.getQuads(state, side, rand));
    }
    else if (renderLayer == RenderType.getCutout() && side == null)
    {
        ItemRenderer renderItem = Minecraft.getInstance().getItemRenderer();
        World world = Minecraft.getInstance().world;

        DryingRackItemsStateData items = extraData.getData(DryingRackTileEntity.CONTAINED_ITEMS_DATA);

        for (int i = 0; i < 4; i++)
        {
            ItemStack stack = items.stacks[i];
            if (stack.isEmpty())
                continue;

            MatrixStack matrixStack = new MatrixStack();
            matrixStack.push(); // pushMatrix

            TransformationMatrix ct = itemTransforms[i];
            matrixStack.getLast().getMatrix().mul(ct.getMatrix()); // current().getPositionMatrix().multiply(getPositionMatrix)
            matrixStack.getLast().getNormal().mul(ct.getNormalMatrix()); // current().getNormalMatrix().multiply

            IBakedModel model = renderItem.getItemModelWithOverrides(stack, world, null);

            if (stack.getItem() == Items.TRIDENT)
            {
                model = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getModelManager().getModel(new ModelResourceLocation("minecraft:trident#inventory"));
            }

            model = model.handlePerspective(ItemCameraTransforms.TransformType.FIXED, matrixStack);

            if (!model.isBuiltInRenderer())
            {
                @SuppressWarnings("unchecked")
                Map<Pair<IBakedModel, TransformationMatrix>, List<BakedQuad>> cache = caches.get(i);

                Matrix4f positionTransform = matrixStack.getLast().getMatrix(); // current() // getPositionMatrix
                TransformationMatrix transformMatrix = new TransformationMatrix(positionTransform);

                Pair<IBakedModel, TransformationMatrix> pair = Pair.of(model, transformMatrix);
                List<BakedQuad> cachedQuads = cache.get(pair);
                if (cachedQuads == null)
                {

                    cachedQuads = Lists.newArrayList();
                    for (Direction face : faces)
                    {
                        List<BakedQuad> inQuads = model.getQuads(null, face, rand);
                        List<BakedQuad> outQuads = new QuadTransformer(transformMatrix).processMany(inQuads);

                        cachedQuads.addAll(outQuads);
                    }

                    cache.put(pair, cachedQuads);
                }
                quads.addAll(cachedQuads);
            }
        }
    }

    return quads;
}