Java Code Examples for net.minecraft.client.Minecraft#getBlockRendererDispatcher()

The following examples show how to use net.minecraft.client.Minecraft#getBlockRendererDispatcher() . 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: ToolRenderHandler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void drawBlockDamageTexture(Minecraft mc, Tessellator tessellator, Entity viewEntity, float partialTicks, List<BlockPos> blocksToRender, int partialBlockDamage) {
    double d3 = viewEntity.lastTickPosX + (viewEntity.posX - viewEntity.lastTickPosX) * partialTicks;
    double d4 = viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * partialTicks;
    double d5 = viewEntity.lastTickPosZ + (viewEntity.posZ - viewEntity.lastTickPosZ) * partialTicks;
    BufferBuilder bufferBuilder = tessellator.getBuffer();
    BlockRendererDispatcher rendererDispatcher = mc.getBlockRendererDispatcher();

    mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    preRenderDamagedBlocks();
    bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    bufferBuilder.setTranslation(-d3, -d4, -d5);
    bufferBuilder.noColor();

    for (BlockPos blockPos : blocksToRender) {
        IBlockState blockState = mc.world.getBlockState(blockPos);
        TileEntity tileEntity = mc.world.getTileEntity(blockPos);
        boolean hasBreak = tileEntity != null && tileEntity.canRenderBreaking();
        if (!hasBreak && blockState.getMaterial() != Material.AIR) {
            TextureAtlasSprite textureAtlasSprite = this.destroyBlockIcons[partialBlockDamage];
            rendererDispatcher.renderBlockDamage(blockState, blockPos, textureAtlasSprite, mc.world);
        }
    }

    tessellator.draw();
    bufferBuilder.setTranslation(0.0D, 0.0D, 0.0D);
    postRenderDamagedBlocks();
}
 
Example 2
Source File: RenderGlobalSchematic.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public RenderGlobalSchematic(Minecraft mc)
{
    super(mc);

    this.mc = mc;
    this.renderManager = mc.getRenderManager();

    this.vboEnabled = OpenGlHelper.useVbo();

    if (this.vboEnabled)
    {
        this.renderContainer = new VboRenderListSchematic();
        this.renderChunkFactory = new RenderChunkFactoryVbo();
    }
    else
    {
        this.renderContainer = new RenderListSchematic();
        this.renderChunkFactory = new RenderChunkFactoryList();
    }

    BlockRendererDispatcher dispatcher = mc.getBlockRendererDispatcher();
    this.blockModelShapes = dispatcher.getBlockModelShapes();
    this.blockModelRenderer = new BlockModelRendererSchematic(mc.getBlockColors());
    this.fluidRenderer = ((IMixinBlockRendererDispatcher) dispatcher).getFluidRenderer();

    DataManager.getSchematicPlacementManager().addRebuildListener(this);
}
 
Example 3
Source File: BlockRenderingRegistry.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void init() {
    if (!initialized) {
        Minecraft mc = Minecraft.getInstance();
        BlockRendererDispatcher parentDispatcher = mc.getBlockRendererDispatcher();
        mc.blockRenderDispatcher = new CCBlockRendererDispatcher(parentDispatcher, mc.getBlockColors());
        initialized = true;
    }
}
 
Example 4
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();
}