Search in sources :

Example 6 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project BlockMeter by ModProg.

the class ColorButton method render.

@Override
public void render(MatrixStack stack, final int int_1, final int int_2, final float float_1) {
    super.render(stack, int_1, int_2, float_1);
    RenderSystem.disableTexture();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = tessellator.getBuffer();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    int r = this.color.getRed();
    int g = this.color.getGreen();
    int b = this.color.getBlue();
    int a = texture ? 102 : 255;
    bufferBuilder.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    bufferBuilder.vertex((double) this.x - (texture ? 1 : 0), (double) this.y - (texture ? 1 : 0), 0.0).color(r, g, b, a).next();
    bufferBuilder.vertex((double) this.x - (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0.0).color(r, g, b, a).next();
    bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0.0).color(r, g, b, a).next();
    bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), (double) this.y - (texture ? 1 : 0), 0.0).color(r, g, b, a).next();
    tessellator.draw();
    RenderSystem.enableTexture();
    if (text != null) {
        boolean dark = (0.299f * color.getRed() + 0.587f * color.getBlue() + 0.114f * color.getRed()) / 255f < 0.8f;
        @SuppressWarnings("resource") final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
        int text_width = textRenderer.getWidth(text);
        if (dark || texture)
            textRenderer.drawWithShadow(stack, text, x + width / 2 - text_width / 2, y + height / 2 - 4, 0xFFFFFF);
        else {
            // shadow
            textRenderer.draw(stack, text, x + width / 2 - text_width / 2 + 1, y + height / 2 - 3, 0xAAAAAA);
            textRenderer.draw(stack, text, x + width / 2 - text_width / 2, y + height / 2 - 4, 0);
        }
    }
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 7 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project BlockMeter by ModProg.

the class ClientMeasureBox method render.

/**
 * Renders the Box
 *
 * @param camera           rendering Camera
 * @param stack
 * @param currentDimension Dimension the Player currently is in
 * @param boxCreatorName   Name of the Player that created the Box
 */
public void render(final Camera camera, final MatrixStack stack, final Identifier currentDimension, final Text boxCreatorName) {
    if (!(currentDimension.equals(this.dimension))) {
        return;
    }
    final Vec3d pos = camera.getPos();
    // FIXME This actually does nothing
    RenderSystem.lineWidth(2.0f);
    RenderSystem.disableDepthTest();
    RenderSystem.disableTexture();
    RenderSystem.disableBlend();
    stack.push();
    stack.translate(-pos.x, -pos.y, -pos.z);
    final Matrix4f model = stack.peek().getPositionMatrix();
    final Tessellator tess = Tessellator.getInstance();
    final BufferBuilder buffer = tess.getBuffer();
    final float[] color = this.color.getColorComponents();
    final float r = color[0];
    final float g = color[1];
    final float b = color[2];
    // FIXME This actually does nothing
    final float a = 0.8f;
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    buffer.begin(DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
    buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.minZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.maxZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.maxZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.minZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.maxZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.minZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.minX, (float) this.box.maxY, (float) this.box.maxZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.maxZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.maxZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.minZ).color(r, g, b, a).next();
    buffer.vertex(model, (float) this.box.maxX, (float) this.box.minY, (float) this.box.minZ).color(r, g, b, a).next();
    tess.draw();
    if (BlockMeterClient.getConfigManager().getConfig().innerDiagonal) {
        buffer.begin(DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
        buffer.vertex(model, (float) this.box.minX, (float) this.box.minY, (float) this.box.minZ).color(r, g, b, a).next();
        buffer.vertex(model, (float) this.box.maxX, (float) this.box.maxY, (float) this.box.maxZ).color(r, g, b, a).next();
        tess.draw();
    }
    RenderSystem.enableTexture();
    RenderSystem.lineWidth(1.0f);
    this.drawLengths(camera, stack, boxCreatorName);
    RenderSystem.enableBlend();
    RenderSystem.enableDepthTest();
    stack.pop();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer) Vec3d(net.minecraft.util.math.Vec3d)

Example 8 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project BlockMeter by ModProg.

the class ClientMeasureBox method drawText.

/**
 * Draws a text with orientation and position
 *
 * @param stack
 * @param x
 * @param y
 * @param z
 * @param yaw
 * @param pitch
 * @param text
 * @param playerPos
 */
private void drawText(final MatrixStack stack, final double x, final double y, final double z, final float yaw, final float pitch, final String text, final Vec3d playerPos) {
    @SuppressWarnings("resource") final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
    final LiteralText literalText = new LiteralText(text);
    float size = 0.03f;
    final int constDist = 10;
    if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) {
        final float dist = (float) Math.sqrt((x - playerPos.x) * (x - playerPos.x) + (y - playerPos.y) * (y - playerPos.y) + (z - playerPos.z) * (z - playerPos.z));
        if (dist > constDist)
            size = dist * size / constDist;
    }
    stack.push();
    stack.translate(x, y + 0.15, z);
    stack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180.0F - yaw));
    stack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-pitch));
    stack.scale(size, -size, 0.001f);
    final int width = textRenderer.getWidth(literalText);
    stack.translate((-width / 2), 0.0, 0.0);
    final Matrix4f model = stack.peek().getPositionMatrix();
    final BufferBuilder buffer = Tessellator.getInstance().getBuffer();
    int textColor = color.getSignColor();
    final ModConfig conf = BlockMeterClient.getConfigManager().getConfig();
    if (conf.backgroundForLabels) {
        final float[] colors = this.color.getColorComponents();
        buffer.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
        buffer.vertex(model, -1, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, -1, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, width, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, width, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        Tessellator.getInstance().draw();
        float[] components = color.getColorComponents();
        float luminance = (0.299f * components[0] + 0.587f * components[1] + 0.114f * components[2]);
        textColor = luminance < 0.4f ? DyeColor.WHITE.getSignColor() : DyeColor.BLACK.getSignColor();
    }
    final VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(buffer);
    textRenderer.draw(literalText, 0.0f, 0.0f, textColor, // shadow
    !conf.backgroundForLabels, // matrix
    model, // draw buffer
    immediate, // seeThrough
    true, // backgroundColor => underlineColor,
    0, // light
    15728880);
    immediate.draw();
    stack.pop();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) BufferBuilder(net.minecraft.client.render.BufferBuilder) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText) ModConfig(win.baruna.blockmeter.ModConfig) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 9 with BufferBuilder

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

the class ShaderEffectWrapper method drawFramebufferToMain.

public void drawFramebufferToMain(String framebuffer) {
    Framebuffer buffer = getFramebuffer(framebuffer);
    Shader blitshader = mc.gameRenderer.blitScreenShader;
    blitshader.addSampler("DiffuseSampler", buffer.getColorAttachment());
    double w = mc.getWindow().getFramebufferWidth();
    double h = mc.getWindow().getFramebufferHeight();
    float ws = (float) buffer.viewportWidth / (float) buffer.textureWidth;
    float hs = (float) buffer.viewportHeight / (float) buffer.textureHeight;
    RenderSystem.enableBlend();
    RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
    GlStateManager._colorMask(true, true, true, false);
    GlStateManager._disableDepthTest();
    GlStateManager._depthMask(false);
    GlStateManager._viewport(0, 0, (int) w, (int) h);
    blitshader.bind();
    Tessellator tessellator = RenderSystem.renderThreadTesselator();
    BufferBuilder bufferBuilder = tessellator.getBuffer();
    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
    bufferBuilder.vertex(0, h, 0).texture(0f, 0f).color(255, 255, 255, 255).next();
    bufferBuilder.vertex(w, h, 0).texture(ws, 0f).color(255, 255, 255, 255).next();
    bufferBuilder.vertex(w, 0, 0).texture(ws, hs).color(255, 255, 255, 255).next();
    bufferBuilder.vertex(0, 0, 0).texture(0f, hs).color(255, 255, 255, 255).next();
    bufferBuilder.end();
    BufferRenderer.postDraw(bufferBuilder);
    blitshader.unbind();
    GlStateManager._depthMask(true);
    GlStateManager._colorMask(true, true, true, true);
    RenderSystem.disableBlend();
}
Also used : Framebuffer(net.minecraft.client.gl.Framebuffer) Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder) Shader(net.minecraft.client.render.Shader)

Example 10 with BufferBuilder

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

the class Renderer method drawQuadFill.

// -------------------- Quads --------------------
public static void drawQuadFill(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double x4, double y4, double z4, int cullMode, 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();
    // Fill
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    Vertexer.vertexQuad(matrices, buffer, 0f, 0f, 0f, (float) (x2 - x1), (float) (y2 - y1), (float) (z2 - z1), (float) (x3 - x1), (float) (y3 - y1), (float) (z3 - z1), (float) (x4 - x1), (float) (y4 - y1), (float) (z4 - z1), cullMode, color);
    tessellator.draw();
    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)

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