Search in sources :

Example 1 with Matrix4f

use of net.minecraft.util.math.Matrix4f in project Skyblocker by LifeIsAParadox.

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().getPositionMatrix();
    Matrix3f normal = matrices.peek().getNormalMatrix();
    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)

Example 2 with Matrix4f

use of net.minecraft.util.math.Matrix4f in project MasaGadget by plusls.

the class InventoryOverlayRenderHandler method renderOrderedTooltip.

public void renderOrderedTooltip(MatrixStack matrices, ItemStack stack, int x, int y) {
    y = y + 8;
    MinecraftClient mc = MinecraftClient.getInstance();
    List<OrderedText> lines = Lists.transform(stack.getTooltip(mc.player, mc.options.advancedItemTooltips ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL), Text::asOrderedText);
    List<TooltipComponent> components = lines.stream().map(TooltipComponent::of).collect(Collectors.toList());
    if (components.isEmpty())
        return;
    int k = 0;
    int l = (components.size() == 1) ? -2 : 0;
    for (TooltipComponent lv : components) {
        int m = lv.getWidth(mc.textRenderer);
        if (m > k)
            k = m;
        l += lv.getHeight();
    }
    int n = x + 12;
    int o = y - 12;
    int p = k;
    int q = l;
    if (n + k > GuiUtils.getScaledWindowWidth())
        n -= 28 + k;
    if (o + q + 6 > GuiUtils.getScaledWindowHeight())
        o = GuiUtils.getScaledWindowHeight() - q - 6;
    matrices.push();
    int r = -267386864;
    int s = 1347420415;
    int t = 1344798847;
    int u = 400;
    float f = mc.getItemRenderer().zOffset;
    mc.getItemRenderer().zOffset = 400.0F;
    Tessellator lv2 = Tessellator.getInstance();
    BufferBuilder lv3 = lv2.getBuffer();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    lv3.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    Matrix4f lv4 = matrices.peek().getPositionMatrix();
    fillGradient(lv4, lv3, n - 3, o - 4, n + p + 3, o - 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o + q + 3, n + p + 3, o + q + 4, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o - 3, n + p + 3, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 4, o - 3, n - 3, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n + p + 3, o - 3, n + p + 4, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o - 3 + 1, n - 3 + 1, o + q + 3 - 1, 400, 1347420415, 1344798847);
    fillGradient(lv4, lv3, n + p + 2, o - 3 + 1, n + p + 3, o + q + 3 - 1, 400, 1347420415, 1344798847);
    fillGradient(lv4, lv3, n - 3, o - 3, n + p + 3, o - 3 + 1, 400, 1347420415, 1347420415);
    fillGradient(lv4, lv3, n - 3, o + q + 2, n + p + 3, o + q + 3, 400, 1344798847, 1344798847);
    RenderSystem.enableDepthTest();
    RenderSystem.disableTexture();
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    lv3.end();
    BufferRenderer.draw(lv3);
    RenderSystem.disableBlend();
    RenderSystem.enableTexture();
    VertexConsumerProvider.Immediate lv5 = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
    matrices.translate(0.0D, 0.0D, 400.0D);
    int v = o;
    for (int w = 0; w < components.size(); w++) {
        TooltipComponent lv6 = components.get(w);
        lv6.drawText(mc.textRenderer, n, v, lv4, lv5);
        v += lv6.getHeight() + ((w == 0) ? 2 : 0);
    }
    lv5.draw();
    matrices.pop();
    v = o;
    for (int i = 0; i < components.size(); i++) {
        TooltipComponent lv7 = components.get(i);
        lv7.drawItems(mc.textRenderer, n, v, matrices, mc.getItemRenderer(), 400);
        v += lv7.getHeight() + ((i == 0) ? 2 : 0);
    }
    mc.getItemRenderer().zOffset = f;
}
Also used : OrderedText(net.minecraft.text.OrderedText) Text(net.minecraft.text.Text) Matrix4f(net.minecraft.util.math.Matrix4f) MinecraftClient(net.minecraft.client.MinecraftClient) OrderedText(net.minecraft.text.OrderedText) TooltipComponent(net.minecraft.client.gui.tooltip.TooltipComponent)

Example 3 with Matrix4f

use of net.minecraft.util.math.Matrix4f in project MasaGadget by plusls.

the class RenderUtil method renderTextOnEntity.

// 只能在 EntityRenderer.render 中调用
public static void renderTextOnEntity(MatrixStack matrixStack, Entity entity, EntityRenderDispatcher entityRenderDispatcher, VertexConsumerProvider vertexConsumerProvider, Text text, float height) {
    MinecraftClient client = MinecraftClient.getInstance();
    if (entityRenderDispatcher.getSquaredDistanceToCamera(entity) <= 4096.0D) {
        matrixStack.push();
        matrixStack.translate(0, height, 0);
        matrixStack.multiply(entityRenderDispatcher.getRotation());
        matrixStack.scale(-0.018F, -0.018F, 0.018F);
        matrixStack.translate(0, 0, -33);
        Matrix4f lv = matrixStack.peek().getPositionMatrix();
        float g = MinecraftClient.getInstance().options.getTextBackgroundOpacity(0.25F);
        int k = (int) (g * 255.0F) << 24;
        float h = (float) (-client.textRenderer.getWidth(text) / 2);
        client.textRenderer.draw(text, h, 0, 553648127, false, lv, vertexConsumerProvider, false, k, 0xf00000);
        client.textRenderer.draw(text, h, 0, -1, false, lv, vertexConsumerProvider, false, 0, 0xf00000);
        matrixStack.pop();
    }
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) MinecraftClient(net.minecraft.client.MinecraftClient)

Example 4 with Matrix4f

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

the class ChaingunMobRender method render.

@Override
public void render(ChaingunMobEntity persistentProjectileEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
    matrixStack.push();
    matrixStack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(MathHelper.lerp(g, persistentProjectileEntity.prevYaw, persistentProjectileEntity.getYaw()) - 90.0F));
    matrixStack.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(MathHelper.lerp(g, persistentProjectileEntity.prevPitch, persistentProjectileEntity.getPitch())));
    matrixStack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(45.0F));
    matrixStack.scale(0.05625F, 0.05625F, 0.05625F);
    matrixStack.translate(-4.0D, 0.0D, 0.0D);
    VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(RenderLayer.getEntityCutout(this.getTexture(persistentProjectileEntity)));
    MatrixStack.Entry entry = matrixStack.peek();
    Matrix4f matrix4f = entry.getPositionMatrix();
    Matrix3f matrix3f = entry.getNormalMatrix();
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, -2, -2, 0.0F, 0.15625F, -1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, -2, 2, 0.15625F, 0.15625F, -1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, 2, 2, 0.15625F, 0.3125F, -1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, 2, -2, 0.0F, 0.3125F, -1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, 2, -2, 0.0F, 0.15625F, 1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, 2, 2, 0.15625F, 0.15625F, 1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, -2, 2, 0.15625F, 0.3125F, 1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, -2, -2, 0.0F, 0.3125F, 1, 0, 0, i);
    for (int u = 0; u < 4; ++u) {
        matrixStack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90.0F));
        this.method_23153(matrix4f, matrix3f, vertexConsumer, -8, -2, 0, 0.0F, 0.0F, 0, 1, 0, i);
        this.method_23153(matrix4f, matrix3f, vertexConsumer, 8, -2, 0, 0.5F, 0.0F, 0, 1, 0, i);
        this.method_23153(matrix4f, matrix3f, vertexConsumer, 8, 2, 0, 0.5F, 0.15625F, 0, 1, 0, i);
        this.method_23153(matrix4f, matrix3f, vertexConsumer, -8, 2, 0, 0.0F, 0.15625F, 0, 1, 0, i);
    }
    matrixStack.pop();
    super.render(persistentProjectileEntity, f, g, matrixStack, vertexConsumerProvider, i);
}
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 5 with Matrix4f

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

the class DroneBoltRender method render.

@Override
public void render(DroneBoltEntity persistentProjectileEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
    matrixStack.push();
    matrixStack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(MathHelper.lerp(g, persistentProjectileEntity.prevYaw, persistentProjectileEntity.getYaw()) - 90.0F));
    matrixStack.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(MathHelper.lerp(g, persistentProjectileEntity.prevPitch, persistentProjectileEntity.getPitch())));
    matrixStack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(45.0F));
    matrixStack.scale(0.05625F, 0.05625F, 0.05625F);
    matrixStack.translate(-4.0D, 0.0D, 0.0D);
    VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(RenderLayer.getEntityCutout(this.getTexture(persistentProjectileEntity)));
    MatrixStack.Entry entry = matrixStack.peek();
    Matrix4f matrix4f = entry.getPositionMatrix();
    Matrix3f matrix3f = entry.getNormalMatrix();
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, -2, -2, 0.0F, 0.15625F, -1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, -2, 2, 0.15625F, 0.15625F, -1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, 2, 2, 0.15625F, 0.3125F, -1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, 2, -2, 0.0F, 0.3125F, -1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, 2, -2, 0.0F, 0.15625F, 1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, 2, 2, 0.15625F, 0.15625F, 1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, -2, 2, 0.15625F, 0.3125F, 1, 0, 0, i);
    this.method_23153(matrix4f, matrix3f, vertexConsumer, -7, -2, -2, 0.0F, 0.3125F, 1, 0, 0, i);
    for (int u = 0; u < 4; ++u) {
        matrixStack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90.0F));
        this.method_23153(matrix4f, matrix3f, vertexConsumer, -8, -2, 0, 0.0F, 0.0F, 0, 1, 0, i);
        this.method_23153(matrix4f, matrix3f, vertexConsumer, 8, -2, 0, 0.5F, 0.0F, 0, 1, 0, i);
        this.method_23153(matrix4f, matrix3f, vertexConsumer, 8, 2, 0, 0.5F, 0.15625F, 0, 1, 0, i);
        this.method_23153(matrix4f, matrix3f, vertexConsumer, -8, 2, 0, 0.0F, 0.15625F, 0, 1, 0, i);
    }
    matrixStack.pop();
    super.render(persistentProjectileEntity, f, g, matrixStack, vertexConsumerProvider, i);
}
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)

Aggregations

Matrix4f (net.minecraft.util.math.Matrix4f)48 BufferBuilder (net.minecraft.client.render.BufferBuilder)18 IMatrix4f (dev.hypnotic.utils.mixin.IMatrix4f)13 Matrix3f (net.minecraft.util.math.Matrix3f)12 GameRenderer (net.minecraft.client.render.GameRenderer)11 Vec3d (net.minecraft.util.math.Vec3d)8 MatrixStack (net.minecraft.client.util.math.MatrixStack)6 Color (java.awt.Color)5 VertexConsumer (net.minecraft.client.render.VertexConsumer)5 Vec3f (net.minecraft.util.math.Vec3f)5 MinecraftClient (net.minecraft.client.MinecraftClient)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 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)2 Entity (net.minecraft.entity.Entity)2 LiteralText (net.minecraft.text.LiteralText)2 Identifier (net.minecraft.util.Identifier)2