Search in sources :

Example 6 with Matrix4f

use of net.minecraft.util.math.Matrix4f in project MCDoom by AzureDoom.

the class BFGCellRender method renderCrystalBeam.

public static void renderCrystalBeam(float dx, float dy, float dz, float tickDelta, int age, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
    float f = MathHelper.sqrt(dx * dx + dz * dz);
    float g = MathHelper.sqrt(dx * dx + dy * dy + dz * dz);
    matrices.push();
    matrices.translate(0.0D, 1.0D, 0.0D);
    matrices.multiply(Vec3f.POSITIVE_Y.getRadialQuaternion((float) (-Math.atan2((double) dz, (double) dx)) - 1.5707964F));
    matrices.multiply(Vec3f.POSITIVE_X.getRadialQuaternion((float) (-Math.atan2((double) f, (double) dy)) - 1.5707964F));
    VertexConsumer vertexConsumer = vertexConsumers.getBuffer(CRYSTAL_BEAM_LAYER);
    float h = 0.0F - ((float) age + tickDelta) * 0.01F;
    float i = MathHelper.sqrt(dx * dx + dy * dy + dz * dz) / 32.0F - ((float) age + tickDelta) * 0.01F;
    float k = 0.0F;
    float l = 0.75F;
    float m = 0.0F;
    MatrixStack.Entry entry = matrices.peek();
    Matrix4f matrix4f = entry.getPositionMatrix();
    Matrix3f matrix3f = entry.getNormalMatrix();
    for (int n = 1; n <= 8; ++n) {
        float o = MathHelper.sin((float) n * 6.2831855F / 8.0F) * 0.75F;
        float p = MathHelper.cos((float) n * 6.2831855F / 8.0F) * 0.75F;
        float q = (float) n / 8.0F;
        vertexConsumer.vertex(matrix4f, k * 0.2F, l * 0.2F, 0.0F).color(0, 0, 0, 255).texture(m, h).overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next();
        vertexConsumer.vertex(matrix4f, k, l, g).color(255, 255, 255, 255).texture(m, i).overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next();
        vertexConsumer.vertex(matrix4f, o, p, g).color(255, 255, 255, 255).texture(q, i).overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next();
        vertexConsumer.vertex(matrix4f, o * 0.2F, p * 0.2F, 0.0F).color(0, 0, 0, 255).texture(q, h).overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next();
        k = o;
        l = p;
        m = q;
    }
    matrices.pop();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) Matrix3f(net.minecraft.util.math.Matrix3f) MatrixStack(net.minecraft.client.util.math.MatrixStack) VertexConsumer(net.minecraft.client.render.VertexConsumer)

Example 7 with Matrix4f

use of net.minecraft.util.math.Matrix4f 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 Matrix4f

use of net.minecraft.util.math.Matrix4f 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 Matrix4f

use of net.minecraft.util.math.Matrix4f in project BleachHack by BleachDrinker420.

the class Peek method drawMapToolTip.

public void drawMapToolTip(MatrixStack matrices, Slot slot, int mouseX, int mouseY) {
    if (slot.getStack().getItem() != Items.FILLED_MAP) {
        return;
    }
    Integer id = FilledMapItem.getMapId(slot.getStack());
    MapState mapState = FilledMapItem.getMapState(id, mc.world);
    if (mapState == null) {
        return;
    }
    float scale = getSetting(2).asToggle().getChild(0).asSlider().getValueFloat() / 1.25f;
    matrices.push();
    matrices.translate(mouseX + 14, mouseY - 18 - 135 * scale, 0);
    matrices.scale(scale, scale, 0.0078125f);
    VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
    VertexConsumer backgroundVertexer = immediate.getBuffer(MAP_BACKGROUND_CHECKERBOARD);
    Matrix4f matrix4f = matrices.peek().getModel();
    backgroundVertexer.vertex(matrix4f, -7f, 135f, -10f).color(255, 255, 255, 255).texture(0f, 1f).light(0xf000f0).next();
    backgroundVertexer.vertex(matrix4f, 135f, 135f, -10f).color(255, 255, 255, 255).texture(1f, 1f).light(0xf000f0).next();
    backgroundVertexer.vertex(matrix4f, 135f, -7f, -10f).color(255, 255, 255, 255).texture(1f, 0f).light(0xf000f0).next();
    backgroundVertexer.vertex(matrix4f, -7f, -7f, -10f).color(255, 255, 255, 255).texture(0f, 0f).light(0xf000f0).next();
    mc.gameRenderer.getMapRenderer().draw(matrices, immediate, id, mapState, false, 0xf000f0);
    immediate.draw();
    matrices.pop();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) MapState(net.minecraft.item.map.MapState) VertexConsumer(net.minecraft.client.render.VertexConsumer) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 10 with Matrix4f

use of net.minecraft.util.math.Matrix4f in project BleachHack by BleachDrinker420.

the class Vertexer method vertexLine.

public static void vertexLine(MatrixStack matrices, VertexConsumer vertexConsumer, float x1, float y1, float z1, float x2, float y2, float z2, LineColor lineColor) {
    Matrix4f model = matrices.peek().getModel();
    Matrix3f normal = matrices.peek().getNormal();
    Vec3f normalVec = getNormal(normal, x1, y1, z1, x2, y2, z2);
    int[] color1 = lineColor.getColor(x1, y1, z1, 0);
    int[] color2 = lineColor.getColor(x2, y2, z2, 1);
    vertexConsumer.vertex(model, x1, y1, z1).color(color1[0], color1[1], color1[2], color1[3]).normal(normal, normalVec.getX(), normalVec.getY(), normalVec.getZ()).next();
    vertexConsumer.vertex(model, x2, y2, z2).color(color2[0], color2[1], color2[2], color2[3]).normal(normal, normalVec.getX(), normalVec.getY(), normalVec.getZ()).next();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) Matrix3f(net.minecraft.util.math.Matrix3f) Vec3f(net.minecraft.util.math.Vec3f)

Aggregations

Matrix4f (net.minecraft.util.math.Matrix4f)112 BufferBuilder (net.minecraft.client.render.BufferBuilder)69 GameRenderer (net.minecraft.client.render.GameRenderer)38 Vec3d (net.minecraft.util.math.Vec3d)14 IMatrix4f (dev.hypnotic.utils.mixin.IMatrix4f)13 Matrix3f (net.minecraft.util.math.Matrix3f)13 TextRenderer (net.minecraft.client.font.TextRenderer)11 ClickGui (net.wurstclient.clickgui.ClickGui)8 MatrixStack (net.minecraft.client.util.math.MatrixStack)7 VertexConsumer (net.minecraft.client.render.VertexConsumer)6 Color (java.awt.Color)5 Shader (net.minecraft.client.render.Shader)5 Vec3f (net.minecraft.util.math.Vec3f)5 MinecraftClient (net.minecraft.client.MinecraftClient)3 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)3 Camera (net.minecraft.client.render.Camera)3 Tessellator (net.minecraft.client.render.Tessellator)3 VertexConsumerProvider (net.minecraft.client.render.VertexConsumerProvider)3 Vector3f (net.minecraft.client.util.math.Vector3f)3 Vector4f (net.minecraft.client.util.math.Vector4f)3