Search in sources :

Example 56 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project Hypnotic-Client by Hypnotic-Development.

the class ColorPicker method render.

public void render(MatrixStack matrices, int mouseX, int mouseY) {
    colorSet.displayName = colorSet.name;
    int sx = x + 5, sy = y + 4 + height + 12, ex = x + width - 17, ey = y + 4 + height + getHeight(width) + 8;
    RenderUtils.fill(matrices, x, y + height, x + width, y + height * 8.5, -1);
    RenderUtils.fill(matrices, x + 1, y + height, x + width - 1, y + height * 8.5, new Color(40, 40, 40, 255).getRGB());
    RenderUtils.fill(matrices, sx + 3 + (int) FontManager.robotoSmall.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()) + 17, sy - 4, sx + 27 + (int) FontManager.robotoSmall.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()), sy - 12, new Color(0, 0, 0, 200).getRGB());
    DrawableHelper.fill(matrices, sx, sy, ex, ey, -1);
    int satColor = MathHelper.hsvToRgb(colorSet.hue, 1f, 1f);
    int red = satColor >> 16 & 255;
    int green = satColor >> 8 & 255;
    int blue = satColor & 255;
    RenderSystem.disableBlend();
    RenderSystem.disableTexture();
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
    // Draw the color
    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    bufferBuilder.vertex(ex, sy, 0).color(red, green, blue, 255).next();
    bufferBuilder.vertex(sx, sy, 0).color(red, green, blue, 0).next();
    bufferBuilder.vertex(sx, ey, 0).color(red, green, blue, 0).next();
    bufferBuilder.vertex(ex, ey, 0).color(red, green, blue, 255).next();
    tessellator.draw();
    // Draw the black stuff
    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    bufferBuilder.vertex(ex, sy, 0).color(0, 0, 0, 0).next();
    bufferBuilder.vertex(sx, sy, 0).color(0, 0, 0, 0).next();
    bufferBuilder.vertex(sx, ey, 0).color(0, 0, 0, 255).next();
    bufferBuilder.vertex(ex, ey, 0).color(0, 0, 0, 255).next();
    tessellator.draw();
    RenderSystem.disableBlend();
    RenderSystem.enableTexture();
    // Set the color
    if (hovered(mouseX, mouseY, sx, sy, ex, ey) && lmDown) {
        colorSet.bri = 1f - 1f / ((float) (ey - sy) / (mouseY - sy));
        colorSet.sat = 1f / ((float) (ex - sx) / (mouseX - sx));
    }
    int briY = (int) (ey - (ey - sy) * colorSet.bri);
    int satX = (int) (sx + (ex - sx) * colorSet.sat);
    RenderUtils.fill(matrices, satX - 2, briY - 2, satX + 2, briY + 2, Color.GRAY.brighter().getRGB(), Color.WHITE.darker().getRGB(), Color.WHITE.getRGB());
    FontManager.robotoSmall.drawWithShadow(matrices, colorSet.name, (int) sx, (int) sy - 12, -1);
    FontManager.robotoSmall.drawWithShadow(matrices, "#" + colorSet.getHex().toUpperCase(), (int) sx + FontManager.robotoSmall.getStringWidth(colorSet.name) + 12, (int) sy - 12, colorSet.getRGB());
    RenderUtils.fill(matrices, sx + 3 + FontManager.robotoSmall.getStringWidth(colorSet.name), sy - 4, sx + 10 + FontManager.robotoSmall.getStringWidth(colorSet.name), sy - 12, colorSet.getColor().getRGB());
    // Set hex codes
    if (hovered(mouseX, mouseY, sx + 3 + (int) FontManager.robotoSmall.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()) + 17, sy - 12, sx + 27 + (int) FontManager.robotoSmall.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()), sy - 4)) {
        RenderSystem.disableDepthTest();
        RenderSystem.depthFunc(GL11.GL_ALWAYS);
        RenderUtils.fill(matrices, mouseX, mouseY, mouseX + FontManager.robotoSmall.getStringWidth("Sets the hex color to your current clipboard") + 6, mouseY - 12, new Color(0, 0, 0, 200).getRGB());
        FontManager.robotoSmall.drawWithShadow(matrices, "Sets the hex color to your current clipboard", mouseX + 2, mouseY - 10, -1);
        RenderSystem.depthFunc(GL11.GL_LEQUAL);
        RenderSystem.enableDepthTest();
        if (lmDown && colorSet.getColor() != colorSet.hexToRgb(mc.keyboard.getClipboard())) {
            Color hexColor = colorSet.hexToRgb(mc.keyboard.getClipboard());
            float[] vals = colorSet.rgbToHsv(hexColor.getRed(), hexColor.getGreen(), hexColor.getBlue(), hexColor.getAlpha());
            colorSet.setHSV(vals[0], vals[1], vals[2]);
            h = vals[0];
            s = vals[1];
            v = vals[2];
        }
    }
    sx = ex + 5;
    ex = ex + 12;
    for (int i = sy; i < ey; i++) {
        float curHue = 1f / ((float) (ey - sy) / (i - sy));
        DrawableHelper.fill(matrices, sx, i, ex, i + 1, 0xff000000 | MathHelper.hsvToRgb(curHue, 1f, 1f));
    }
    if (hovered(mouseX, mouseY, sx, sy, ex, ey) && lmDown) {
        colorSet.hue = 1f / ((float) (ey - sy) / (mouseY - sy));
    }
    int hueY = (int) (sy + (ey - sy) * colorSet.hue);
    RenderUtils.fill(matrices, sx, hueY - 2, ex, hueY + 2, Color.GRAY.brighter().getRGB(), Color.WHITE.darker().getRGB(), Color.WHITE.getRGB());
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) Color(java.awt.Color) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 57 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project Hypnotic-Client by Hypnotic-Development.

the class ColorBox method render.

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY) {
    colorSet.displayName = colorSet.name;
    int sx = this.x - 10, sy = this.y + 12, ex = this.x + 100, ey = this.y + getHeight(120);
    HypnoticScreen.fontMed.drawWithShadow(matrices, colorSet.name, (int) sx, (int) sy - 12, -1);
    HypnoticScreen.fontMed.drawWithShadow(matrices, "#" + colorSet.getHex().toUpperCase(), (int) sx + HypnoticScreen.fontMed.getStringWidth(colorSet.name) + 12, (int) sy - 12, colorSet.getRGB());
    if (hovered((int) mouseX, (int) mouseY, sx + 160, sy - 12, sx + 190, sy - 4) && rmDown) {
        RenderUtils.setup2DRender(true);
        RenderUtils.end2DRender();
        open = !open;
        rmDown = false;
    }
    RenderUtils.fill(matrices, sx + 190, sy - 12, sx + 160, sy - 4, colorSet.getColor().getRGB());
    RenderUtils.fill(matrices, sx + 3 + HypnoticScreen.fontMed.getStringWidth(colorSet.name), sy - 3, sx + 10 + HypnoticScreen.fontMed.getStringWidth(colorSet.name), sy - 11, colorSet.getColor().getRGB());
    if (hovered(mouseX, mouseY, sx + 3 + (int) HypnoticScreen.fontMed.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()) + 17, sy - 12, sx + 27 + (int) HypnoticScreen.fontMed.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()), sy - 4)) {
        RenderUtils.setup2DRender(true);
        RenderUtils.end2DRender();
        if (lmDown && colorSet.getColor() != colorSet.hexToRgb(mc.keyboard.getClipboard())) {
            Color hexColor = colorSet.hexToRgb(mc.keyboard.getClipboard());
            float[] vals = colorSet.rgbToHsv(hexColor.getRed(), hexColor.getGreen(), hexColor.getBlue(), hexColor.getAlpha());
            colorSet.setHSV(vals[0], vals[1], vals[2]);
            h = vals[0];
            s = vals[1];
            v = vals[2];
        }
    }
    if (!open) {
        return;
    }
    RenderUtils.fill(matrices, sx + 3 + (int) HypnoticScreen.fontMed.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()) + 17, sy - 4, sx + 27 + (int) HypnoticScreen.fontMed.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()), sy - 12, new Color(0, 0, 0, 200).getRGB());
    RenderUtils.fill(matrices, sx, sy, ex, ey, -1);
    int satColor = MathHelper.hsvToRgb(colorSet.hue, 1f, 1f);
    int red = satColor >> 16 & 255;
    int green = satColor >> 8 & 255;
    int blue = satColor & 255;
    RenderSystem.disableBlend();
    RenderSystem.disableTexture();
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
    // Draw the color
    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    bufferBuilder.vertex(ex, sy, 0).color(red, green, blue, 255).next();
    bufferBuilder.vertex(sx, sy, 0).color(red, green, blue, 0).next();
    bufferBuilder.vertex(sx, ey, 0).color(red, green, blue, 0).next();
    bufferBuilder.vertex(ex, ey, 0).color(red, green, blue, 255).next();
    tessellator.draw();
    // Draw the black stuff
    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    bufferBuilder.vertex(ex, sy, 0).color(0, 0, 0, 0).next();
    bufferBuilder.vertex(sx, sy, 0).color(0, 0, 0, 0).next();
    bufferBuilder.vertex(sx, ey, 0).color(0, 0, 0, 255).next();
    bufferBuilder.vertex(ex, ey, 0).color(0, 0, 0, 255).next();
    tessellator.draw();
    RenderSystem.disableBlend();
    RenderSystem.enableTexture();
    // Set the color
    if (hovered(mouseX, mouseY, sx, sy, ex, ey) && lmDown) {
        colorSet.bri = 1f - 1f / ((float) (ey - sy) / (mouseY - sy));
        colorSet.sat = 1f / ((float) (ex - sx) / (mouseX - sx));
    }
    int briY = (int) (ey - (ey - sy) * colorSet.bri);
    int satX = (int) (sx + (ex - sx) * colorSet.sat);
    // Set hex codes
    if (hovered(mouseX, mouseY, sx + 3 + (int) HypnoticScreen.fontMed.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()) + 17, sy - 12, sx + 27 + (int) HypnoticScreen.fontMed.getStringWidth(colorSet.name + colorSet.getHex().toUpperCase()), sy - 4)) {
        RenderUtils.setup2DRender(true);
        RenderUtils.fill(matrices, mouseX, mouseY, mouseX + HypnoticScreen.fontMed.getStringWidth("Sets the hex color to your current clipboard") + 6, mouseY - 12, new Color(0, 0, 0, 200).getRGB());
        HypnoticScreen.fontMed.drawWithShadow(matrices, "Sets the hex color to your current clipboard", mouseX + 2, mouseY - 10, -1);
        RenderUtils.end2DRender();
        if (lmDown && colorSet.getColor() != colorSet.hexToRgb(mc.keyboard.getClipboard())) {
            Color hexColor = colorSet.hexToRgb(mc.keyboard.getClipboard());
            float[] vals = colorSet.rgbToHsv(hexColor.getRed(), hexColor.getGreen(), hexColor.getBlue(), hexColor.getAlpha());
            colorSet.setHSV(vals[0], vals[1], vals[2]);
            h = vals[0];
            s = vals[1];
            v = vals[2];
        }
    }
    sx = ex + 5;
    ex = ex + 12;
    for (int i = sy; i < ey; i++) {
        float curHue = 1f / ((float) (ey - sy) / (i - sy));
        DrawableHelper.fill(matrices, sx, i, ex, i + 1, 0xff000000 | MathHelper.hsvToRgb(curHue, 1f, 1f));
    }
    if (hovered(mouseX, mouseY, sx, sy, ex, ey) && lmDown) {
        colorSet.hue = 1f / ((float) (ey - sy) / (mouseY - sy));
    }
    int hueY = (int) (sy + (ey - sy) * colorSet.hue);
    RenderUtils.fill(matrices, sx, hueY - 1, ex, hueY + 1, -1);
    RenderUtils.drawOutlineCircle(matrices, satX - 3, briY - 3, 6, Color.WHITE);
    super.render(matrices, mouseX, mouseY);
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) Color(java.awt.Color) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 58 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project Hypnotic-Client by Hypnotic-Development.

the class RenderUtils method fill.

public static void fill(MatrixStack matrixStack, double x1, double y1, double x2, double y2, Color color) {
    Matrix4f matrix = matrixStack.peek().getPositionMatrix();
    double j;
    if (x1 < x2) {
        j = x1;
        x1 = x2;
        x2 = j;
    }
    if (y1 < y2) {
        j = y1;
        y1 = y2;
        y2 = j;
    }
    float f = (float) color.getRed() / 255.0F;
    float g = (float) color.getGreen() / 255.0F;
    float h = (float) color.getBlue() / 255.0F;
    float k = (float) color.getAlpha() / 255.0F;
    BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
    RenderSystem.enableBlend();
    RenderSystem.disableTexture();
    RenderSystem.defaultBlendFunc();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    bufferBuilder.vertex(matrix, (float) x1, (float) y2, 0.0F).color(g, h, k, f).next();
    bufferBuilder.vertex(matrix, (float) x2, (float) y2, 0.0F).color(g, h, k, f).next();
    bufferBuilder.vertex(matrix, (float) x2, (float) y1, 0.0F).color(g, h, k, f).next();
    bufferBuilder.vertex(matrix, (float) x1, (float) y1, 0.0F).color(g, h, k, f).next();
    bufferBuilder.end();
    BufferRenderer.draw(bufferBuilder);
    RenderSystem.enableTexture();
    RenderSystem.disableBlend();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) IMatrix4f(dev.hypnotic.utils.mixin.IMatrix4f) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 59 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project Hypnotic-Client by Hypnotic-Development.

the class RenderUtils method line.

public static void line(Vec3d start, Vec3d end, Color color, MatrixStack matrices) {
    float red = color.getRed() / 255f;
    float green = color.getGreen() / 255f;
    float blue = color.getBlue() / 255f;
    float alpha = color.getAlpha() / 255f;
    Camera c = mc.gameRenderer.getCamera();
    Vec3d camPos = c.getPos();
    start = start.subtract(camPos);
    end = end.subtract(camPos);
    Matrix4f matrix = matrices.peek().getPositionMatrix();
    float x1 = (float) start.x;
    float y1 = (float) start.y;
    float z1 = (float) start.z;
    float x2 = (float) end.x;
    float y2 = (float) end.y;
    float z2 = (float) end.z;
    BufferBuilder buffer = Tessellator.getInstance().getBuffer();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    GL11.glDepthFunc(GL11.GL_ALWAYS);
    RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
    RenderSystem.defaultBlendFunc();
    RenderSystem.enableBlend();
    buffer.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION_COLOR);
    buffer.vertex(matrix, x1, y1, z1).color(red, green, blue, alpha).next();
    buffer.vertex(matrix, x2, y2, z2).color(red, green, blue, alpha).next();
    buffer.end();
    BufferRenderer.draw(buffer);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    RenderSystem.disableBlend();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) IMatrix4f(dev.hypnotic.utils.mixin.IMatrix4f) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer) Camera(net.minecraft.client.render.Camera) Vec3d(net.minecraft.util.math.Vec3d)

Example 60 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project Hypnotic-Client by Hypnotic-Development.

the class RenderUtils method drawLine.

public static void drawLine(double x1, double y1, double z1, double x2, double y2, double z2, LineColor color, float width) {
    if (!isPointVisible(x1, y1, z1) && !isPointVisible(x2, y2, z2)) {
        return;
    }
    setup3DRender(true);
    MatrixStack matrices = matrixFrom(x1, y1, z1);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder buffer = tessellator.getBuffer();
    // Line
    RenderSystem.disableDepthTest();
    RenderSystem.disableCull();
    RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader);
    RenderSystem.lineWidth(width);
    buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
    Vertexer.vertexLine(matrices, buffer, 0f, 0f, 0f, (float) (x2 - x1), (float) (y2 - y1), (float) (z2 - z1), color);
    tessellator.draw();
    RenderSystem.enableCull();
    RenderSystem.enableDepthTest();
    end3DRender();
}
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