Search in sources :

Example 11 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project BleachHack by BleachDrinker420.

the class Renderer method drawQuadOutline.

public static void drawQuadOutline(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double x4, double y4, double z4, float lineWidth, QuadColor color) {
    if (!FrustumUtils.isPointVisible(x1, y1, z1) && !FrustumUtils.isPointVisible(x2, y2, z2) && !FrustumUtils.isPointVisible(x3, y3, z3) && !FrustumUtils.isPointVisible(x4, y4, z4)) {
        return;
    }
    setup();
    MatrixStack matrices = matrixFrom(x1, y1, z1);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder buffer = tessellator.getBuffer();
    int[] colors = color.getAllColors();
    // Outline
    RenderSystem.disableCull();
    RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader);
    RenderSystem.lineWidth(lineWidth);
    buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
    Vertexer.vertexLine(matrices, buffer, 0f, 0f, 0f, (float) (x2 - x1), (float) (y2 - y1), (float) (z2 - z1), LineColor.gradient(colors[0], colors[1]));
    Vertexer.vertexLine(matrices, buffer, (float) (x2 - x1), (float) (y2 - y1), (float) (z2 - z1), (float) (x3 - x1), (float) (y3 - y1), (float) (z3 - z1), LineColor.gradient(colors[1], colors[2]));
    Vertexer.vertexLine(matrices, buffer, (float) (x3 - x1), (float) (y3 - y1), (float) (z3 - z1), (float) (x4 - x1), (float) (y4 - y1), (float) (z4 - z1), LineColor.gradient(colors[2], colors[3]));
    Vertexer.vertexLine(matrices, buffer, (float) (x4 - x1), (float) (y4 - y1), (float) (z4 - z1), 0f, 0f, 0f, LineColor.gradient(colors[3], colors[0]));
    tessellator.draw();
    RenderSystem.enableCull();
    cleanup();
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) MatrixStack(net.minecraft.client.util.math.MatrixStack) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 12 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project BleachHack by BleachDrinker420.

the class MixinChunkRebuildTask method newRender.

private Set<BlockEntity> newRender(float cameraX, float cameraY, float cameraZ, ChunkData data, BlockBufferBuilderStorage buffers) {
    BlockPos blockPos = field_20839.getOrigin().toImmutable();
    BlockPos blockPos2 = blockPos.add(15, 15, 15);
    ChunkOcclusionDataBuilder chunkOcclusionDataBuilder = new ChunkOcclusionDataBuilder();
    Set<BlockEntity> set = new HashSet<>();
    ChunkRendererRegion chunkRendererRegion = this.region;
    this.region = null;
    MatrixStack matrixStack = new MatrixStack();
    if (chunkRendererRegion != null) {
        BlockModelRenderer.enableBrightnessCache();
        Random random = new Random();
        BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
        for (BlockPos blockPos3 : BlockPos.iterate(blockPos, blockPos2)) {
            BlockState blockState = chunkRendererRegion.getBlockState(blockPos3);
            if (blockState.isOpaqueFullCube(chunkRendererRegion, blockPos3)) {
                chunkOcclusionDataBuilder.markClosed(blockPos3);
            }
            if (blockState.hasBlockEntity()) {
                BlockEntity blockEntityx = chunkRendererRegion.getBlockEntity(blockPos3, WorldChunk.CreationType.CHECK);
                if (blockEntityx != null) {
                    this.addBlockEntity(data, set, blockEntityx);
                }
            }
            FluidState fluid = chunkRendererRegion.getFluidState(blockPos3);
            if (!fluid.isEmpty()) {
                RenderLayer renderLayer = RenderLayers.getFluidLayer(fluid);
                BufferBuilder bufferBuilder = buffers.get(renderLayer);
                if (data.initializedLayers.add(renderLayer)) {
                    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                }
                EventRenderFluid event = new EventRenderFluid(fluid, blockPos3, bufferBuilder);
                BleachHack.eventBus.post(event);
                if (event.isCancelled())
                    continue;
                if (blockRenderManager.renderFluid(blockPos3, chunkRendererRegion, bufferBuilder, fluid)) {
                    data.empty = false;
                    data.nonEmptyLayers.add(renderLayer);
                }
            }
            if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
                RenderLayer renderLayer = RenderLayers.getBlockLayer(blockState);
                BufferBuilder bufferBuilder = buffers.get(renderLayer);
                if (data.initializedLayers.add(renderLayer)) {
                    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                }
                EventRenderBlock.Tesselate event = new EventRenderBlock.Tesselate(blockState, blockPos3, matrixStack, bufferBuilder);
                BleachHack.eventBus.post(event);
                if (event.isCancelled())
                    continue;
                matrixStack.push();
                matrixStack.translate(blockPos3.getX() & 15, blockPos3.getY() & 15, blockPos3.getZ() & 15);
                if (blockRenderManager.renderBlock(blockState, blockPos3, chunkRendererRegion, matrixStack, bufferBuilder, true, random)) {
                    data.empty = false;
                    data.nonEmptyLayers.add(renderLayer);
                }
                bufferBuilder.unfixColor();
                matrixStack.pop();
            }
        }
        if (data.nonEmptyLayers.contains(RenderLayer.getTranslucent())) {
            BufferBuilder bufferBuilder2 = buffers.get(RenderLayer.getTranslucent());
            bufferBuilder2.setCameraPosition(cameraX - (float) blockPos.getX(), cameraY - (float) blockPos.getY(), cameraZ - (float) blockPos.getZ());
            data.bufferState = bufferBuilder2.popState();
        }
        Stream<RenderLayer> var10000 = data.initializedLayers.stream();
        Objects.requireNonNull(buffers);
        var10000.map(buffers::get).forEach(BufferBuilder::end);
        BlockModelRenderer.disableBrightnessCache();
    }
    data.occlusionGraph = chunkOcclusionDataBuilder.build();
    return set;
}
Also used : ChunkRendererRegion(net.minecraft.client.render.chunk.ChunkRendererRegion) MatrixStack(net.minecraft.client.util.math.MatrixStack) BufferBuilder(net.minecraft.client.render.BufferBuilder) RenderLayer(net.minecraft.client.render.RenderLayer) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager) EventRenderBlock(org.bleachhack.event.events.EventRenderBlock) EventRenderFluid(org.bleachhack.event.events.EventRenderFluid) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) HashSet(java.util.HashSet) FluidState(net.minecraft.fluid.FluidState)

Example 13 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project BleachHack by BleachDrinker420.

the class WindowScreen method renderBackgroundTexture.

public void renderBackgroundTexture(int vOffset) {
    int colorOffset = (int) ((System.currentTimeMillis() / 75) % 100);
    if (colorOffset > 50)
        colorOffset = 50 - (colorOffset - 50);
    // smooth
    colorOffset = (int) (-(Math.cos(Math.PI * (colorOffset / 50d)) - 1) / 2 * 50);
    RenderSystem.disableTexture();
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    bufferBuilder.vertex(width, 0, 0).color(30, 20, 80, 255).next();
    bufferBuilder.vertex(0, 0, 0).color(30 + colorOffset / 3, 20, 80, 255).next();
    bufferBuilder.vertex(0, height + 16, 0).color(90, 54, 159, 255).next();
    bufferBuilder.vertex(width, height + 16, 0).color(105 + colorOffset, 54, 189, 255).next();
    tessellator.draw();
    RenderSystem.disableBlend();
    RenderSystem.enableTexture();
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 14 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project fabric by FabricMC.

the class MixinBufferBuilder method bufferCompatibly.

/**
 * Uses buffer vertex format to drive buffer population.
 * Relies on logic elsewhere to ensure coordinates don't include chunk offset
 * (because buffer builder will handle that.)<p>
 *
 * Calling putVertexData() would likely be a little faster but this approach
 * gives us a chance to pass vertex normals to shaders, which isn't possible
 * with the standard block format. It also doesn't require us to encode a specific
 * custom format directly, which would be prone to breakage outside our control.
 */
private void bufferCompatibly(QuadViewImpl quad) {
    final VertexFormat format = getVertexFormat();
    ;
    final int elementCount = format.getElementCount();
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < elementCount; j++) {
            VertexFormatElement e = format.getElement(j);
            switch(e.getType()) {
                case COLOR:
                    final int c = quad.spriteColor(i, 0);
                    ((BufferBuilder) (Object) this).color(c & 0xFF, (c >>> 8) & 0xFF, (c >>> 16) & 0xFF, (c >>> 24) & 0xFF);
                    break;
                case NORMAL:
                    ((BufferBuilder) (Object) this).normal(quad.normalX(i), quad.normalY(i), quad.normalZ(i));
                    break;
                case POSITION:
                    ((BufferBuilder) (Object) this).vertex(quad.x(i), quad.y(i), quad.z(i));
                    break;
                case UV:
                    if (e.getIndex() == 0) {
                        ((BufferBuilder) (Object) this).texture(quad.spriteU(i, 0), quad.spriteV(i, 0));
                    } else {
                        final int b = quad.lightmap(i);
                        ((BufferBuilder) (Object) this).texture((b >> 16) & 0xFFFF, b & 0xFFFF);
                    }
                    break;
                // these types should never occur and/or require no action
                case MATRIX:
                case BLEND_WEIGHT:
                case PADDING:
                default:
                    break;
            }
        }
        ((BufferBuilder) (Object) this).next();
    }
}
Also used : AccessBufferBuilder(net.fabricmc.indigo.renderer.accessor.AccessBufferBuilder) BufferBuilder(net.minecraft.client.render.BufferBuilder) VertexFormatElement(net.minecraft.client.render.VertexFormatElement) VertexFormat(net.minecraft.client.render.VertexFormat)

Example 15 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project KiwiClient by TangyKiwi.

the class GlyphPageFontRenderer method doDraw.

private void doDraw(float f, GlyphPage glyphPage) {
    if (this.strikethroughStyle) {
        BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
        GlStateManager._disableTexture();
        bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
        bufferBuilder.vertex((double) this.posX, (double) (this.posY + (float) (glyphPage.getMaxFontHeight() / 2)), 0.0D).next();
        bufferBuilder.vertex((double) (this.posX + f), (double) (this.posY + (float) (glyphPage.getMaxFontHeight() / 2)), 0.0D).next();
        bufferBuilder.vertex((double) (this.posX + f), (double) (this.posY + (float) (glyphPage.getMaxFontHeight() / 2) - 1.0F), 0.0D).next();
        bufferBuilder.vertex((double) this.posX, (double) (this.posY + (float) (glyphPage.getMaxFontHeight() / 2) - 1.0F), 0.0D).next();
        bufferBuilder.end();
        BufferRenderer.draw(bufferBuilder);
        GlStateManager._enableTexture();
    }
    if (this.underlineStyle) {
        BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
        GlStateManager._disableTexture();
        bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
        int l = this.underlineStyle ? -1 : 0;
        bufferBuilder.vertex((double) (this.posX + (float) l), (double) (this.posY + (float) glyphPage.getMaxFontHeight()), 0.0D).next();
        bufferBuilder.vertex((double) (this.posX + f), (double) (this.posY + (float) glyphPage.getMaxFontHeight()), 0.0D).next();
        bufferBuilder.vertex((double) (this.posX + f), (double) (this.posY + (float) glyphPage.getMaxFontHeight() - 1.0F), 0.0D).next();
        bufferBuilder.vertex((double) (this.posX + (float) l), (double) (this.posY + (float) glyphPage.getMaxFontHeight() - 1.0F), 0.0D).next();
        bufferBuilder.end();
        BufferRenderer.draw(bufferBuilder);
        GlStateManager._enableTexture();
    }
    this.posX += f;
}
Also used : BufferBuilder(net.minecraft.client.render.BufferBuilder)

Aggregations

BufferBuilder (net.minecraft.client.render.BufferBuilder)76 GameRenderer (net.minecraft.client.render.GameRenderer)46 Tessellator (net.minecraft.client.render.Tessellator)44 Matrix4f (net.minecraft.util.math.Matrix4f)18 MatrixStack (net.minecraft.client.util.math.MatrixStack)14 IMatrix4f (dev.hypnotic.utils.mixin.IMatrix4f)9 Color (java.awt.Color)9 RenderLayer (net.minecraft.client.render.RenderLayer)5 Vec3d (net.minecraft.util.math.Vec3d)5 BlockState (net.minecraft.block.BlockState)4 BlockEntity (net.minecraft.block.entity.BlockEntity)4 ChunkOcclusionDataBuilder (net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder)4 FluidState (net.minecraft.fluid.FluidState)4 BlockPos (net.minecraft.util.math.BlockPos)4 Random (java.util.Random)3 BlockRenderManager (net.minecraft.client.render.block.BlockRenderManager)3 ChunkRendererRegion (net.minecraft.client.render.chunk.ChunkRendererRegion)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 Mirror (com.qouteall.immersive_portals.portal.Mirror)2 HashSet (java.util.HashSet)2