Search in sources :

Example 1 with Matrix4f

use of net.minecraft.util.math.vector.Matrix4f in project AgriCraft by AgriCraft.

the class BlockGreenHouseAirRenderer method highlightGreenHouseAirBlocks.

protected void highlightGreenHouseAirBlocks(World world, BlockPos origin, MatrixStack transforms) {
    IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
    IVertexBuilder builder = buffer.getBuffer(this.getRenderType());
    transforms.push();
    Vector3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
    transforms.translate(-projectedView.x, -projectedView.y, -projectedView.z);
    Matrix4f matrix4f = transforms.getLast().getMatrix();
    BlockPos.Mutable pos = origin.toMutable();
    for (int x = -RANGE; x <= RANGE; x++) {
        for (int y = -RANGE; y <= RANGE; y++) {
            for (int z = -RANGE; z <= RANGE; z++) {
                pos.setPos(origin.getX() + x, origin.getY() + y, origin.getZ() + z);
                if (world.getBlockState(pos).getBlock() instanceof BlockGreenHouseAir) {
                    this.renderWireFrameCube(builder, matrix4f, pos);
                }
            }
        }
    }
    transforms.pop();
    buffer.finish(this.getRenderType());
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) BlockGreenHouseAir(com.infinityraider.agricraft.content.world.BlockGreenHouseAir) Vector3d(net.minecraft.util.math.vector.Vector3d) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) BlockPos(net.minecraft.util.math.BlockPos) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Example 2 with Matrix4f

use of net.minecraft.util.math.vector.Matrix4f in project AgriCraft by AgriCraft.

the class JournalScreenContext method drawColored.

private void drawColored(MatrixStack matrixStack, float x1, float x2, float y1, float y2, float minU, float maxU, float minV, float maxV, float r, float g, float b, float a) {
    x1 += baseX + renderX;
    x2 += baseX + renderX;
    y1 += baseY + renderY;
    y2 += baseY + renderY;
    BufferBuilder bufferbuilder = Tessellator.getInstance().getBuffer();
    bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
    Matrix4f matrix4f = matrixStack.getLast().getMatrix();
    bufferbuilder.pos(matrix4f, x1, y2, 5).tex(minU, maxV).color(r, g, b, a).endVertex();
    bufferbuilder.pos(matrix4f, x2, y2, 5).tex(maxU, maxV).color(r, g, b, a).endVertex();
    bufferbuilder.pos(matrix4f, x2, y1, 5).tex(maxU, minV).color(r, g, b, a).endVertex();
    bufferbuilder.pos(matrix4f, x1, y1, 5).tex(minU, minV).color(r, g, b, a).endVertex();
    bufferbuilder.finishDrawing();
    RenderSystem.enableAlphaTest();
    WorldVertexBufferUploader.draw(bufferbuilder);
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Example 3 with Matrix4f

use of net.minecraft.util.math.vector.Matrix4f in project BluePower by Qmunity.

the class BPEventHandler method blockHighlightEvent.

@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public void blockHighlightEvent(DrawHighlightEvent event) {
    PlayerEntity player = Minecraft.getInstance().player;
    if (player == null) {
        return;
    }
    World world = player.level;
    if (world == null) {
        return;
    }
    RayTraceResult mop = event.getTarget();
    if (mop instanceof BlockRayTraceResult) {
        BlockPos pos = ((BlockRayTraceResult) mop).getBlockPos();
        BlockState state = world.getBlockState(pos);
        if (state.getBlock() instanceof BlockBPMultipart) {
            BlockState partstate = MultipartUtils.getClosestState(player, pos);
            IVertexBuilder builder = event.getBuffers().getBuffer(RenderType.lines());
            if (partstate != null) {
                VoxelShape shape = partstate.getShape(world, pos, ISelectionContext.of(player));
                Vector3d projectedView = event.getInfo().getPosition();
                double d0 = pos.getX() - projectedView.x();
                double d1 = pos.getY() - projectedView.y();
                double d2 = pos.getZ() - projectedView.z();
                Matrix4f matrix4f = event.getMatrix().last().pose();
                shape.forAllEdges((startX, startY, startZ, endX, endY, endZ) -> {
                    builder.vertex(matrix4f, (float) (startX + d0), (float) (startY + d1), (float) (startZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
                    builder.vertex(matrix4f, (float) (endX + d0), (float) (endY + d1), (float) (endZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
                });
                event.setCanceled(true);
            }
        }
    }
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockBPMultipart(com.bluepowermod.block.BlockBPMultipart) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 4 with Matrix4f

use of net.minecraft.util.math.vector.Matrix4f in project BluePower by Qmunity.

the class RenderHelper method drawColoredCube.

/**
 * Draws a colored cube with the size of vector. All faces have the specified color. This uses OpenGL
 *
 * @author Koen Beckers (K4Unl) and Amadornes
 * @param vector
 */
public static void drawColoredCube(AxisAlignedBB vector, IVertexBuilder vertexBuilder, MatrixStack matrixStack, int r, int g, int b, int a, int light, boolean... renderFaces) {
    MatrixStack.Entry entry = matrixStack.last();
    Matrix4f positionMatrix = entry.pose();
    Matrix3f normalMatrix = entry.normal();
    TextureAtlasSprite sprite = Minecraft.getInstance().getModelManager().getModel(new ModelResourceLocation("minecraft:white_concrete", "")).getParticleIcon();
    float minU = sprite.getU0();
    float maxU = sprite.getU1();
    float minV = sprite.getV0();
    float maxV = sprite.getV1();
    // Top side
    if (renderFaces.length < 1 || renderFaces[0]) {
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.maxY, (float) vector.maxZ).color(r, g, b, a).uv(minU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 1.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.maxY, (float) vector.maxZ).color(r, g, b, a).uv(minU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 1.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.maxY, (float) vector.minZ).color(r, g, b, a).uv(maxU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 1.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.maxY, (float) vector.minZ).color(r, g, b, a).uv(maxU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 1.0F, 0.0F).endVertex();
    }
    // Bottom side
    if (renderFaces.length < 2 || renderFaces[1]) {
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.minY, (float) vector.maxZ).color(r, g, b, a).uv(minU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, -1.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.minY, (float) vector.maxZ).color(r, g, b, a).uv(minU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, -1.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.minY, (float) vector.minZ).color(r, g, b, a).uv(maxU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, -1.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.minY, (float) vector.minZ).color(r, g, b, a).uv(maxU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, -1.0F, 0.0F).endVertex();
    }
    // Draw west side:
    if (renderFaces.length < 3 || renderFaces[5]) {
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.minY, (float) vector.maxZ).color(r, g, b, a).uv(minU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, -1.0F, 0.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.maxY, (float) vector.maxZ).color(r, g, b, a).uv(minU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, -1.0F, 0.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.maxY, (float) vector.minZ).color(r, g, b, a).uv(maxU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, -1.0F, 0.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.minY, (float) vector.minZ).color(r, g, b, a).uv(maxU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, -1.0F, 0.0F, 0.0F).endVertex();
    }
    // Draw east side:
    if (renderFaces.length < 4 || renderFaces[4]) {
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.minY, (float) vector.minZ).color(r, g, b, a).uv(minU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 1.0F, 0.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.maxY, (float) vector.minZ).color(r, g, b, a).uv(minU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 1.0F, 0.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.maxY, (float) vector.maxZ).color(r, g, b, a).uv(maxU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 1.0F, 0.0F, 0.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.minY, (float) vector.maxZ).color(r, g, b, a).uv(maxU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 1.0F, 0.0F, 0.0F).endVertex();
    }
    // Draw north side
    if (renderFaces.length < 5 || renderFaces[3]) {
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.minY, (float) vector.minZ).color(r, g, b, a).uv(minU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 0.0F, -1.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.maxY, (float) vector.minZ).color(r, g, b, a).uv(minU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 0.0F, -1.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.maxY, (float) vector.minZ).color(r, g, b, a).uv(maxU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 0.0F, -1.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.minY, (float) vector.minZ).color(r, g, b, a).uv(maxU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 0.0F, -1.0F).endVertex();
    }
    // Draw south side
    if (renderFaces.length < 6 || renderFaces[2]) {
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.minY, (float) vector.maxZ).color(r, g, b, a).uv(minU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 0.0F, 1.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.minY, (float) vector.maxZ).color(r, g, b, a).uv(minU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 0.0F, 1.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.maxX, (float) vector.maxY, (float) vector.maxZ).color(r, g, b, a).uv(maxU, minV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 0.0F, 1.0F).endVertex();
        vertexBuilder.vertex(positionMatrix, (float) vector.minX, (float) vector.maxY, (float) vector.maxZ).color(r, g, b, a).uv(maxU, maxV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(normalMatrix, 0.0F, 0.0F, 1.0F).endVertex();
    }
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) Matrix3f(net.minecraft.util.math.vector.Matrix3f) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ModelResourceLocation(net.minecraft.client.renderer.model.ModelResourceLocation)

Example 5 with Matrix4f

use of net.minecraft.util.math.vector.Matrix4f in project AgriCraft by AgriCraft.

the class AgriGenomeRenderer method renderDoubleHelix.

/**
 * Renders an AgriCraft genome.
 *
 * Renders a right-hand, double helix with the dominant alleles on the left, and the recessive ones on the right,
 * The helix will be rotated so that the selected gene (denoted by index) is along the X-axis,
 * with a smooth transition towards the next gene.
 *
 * Notes:
 *  - The full double helix will be rendered, therefore it might appear squished or stretched based on the height
 *  - The selected gene will be colored with its color, the inactive ones will be greyed out
 *
 * @param genePairs the genome for which to draw an overlay
 * @param transforms matrix stack for the transformation
 * @param buffer the vertex buffer to draw with
 * @param index the index denoting the selected gene
 * @param transition a double denoting the transition progress to the next/previous gene (bounded by 1 and -1)
 * @param radius the radius of the double helix
 * @param height the height of the double helix
 * @param alpha the transparency of the helix
 * @param color if inactive genes should be colored or greyed
 */
public void renderDoubleHelix(List<IAgriGenePair<?>> genePairs, MatrixStack transforms, IRenderTypeBuffer buffer, int index, float transition, float radius, float height, float alpha, boolean color) {
    // Define helix properties
    int count = genePairs.size();
    if (count == 0 || radius == 0 || height == 0) {
        // Should never happen
        return;
    }
    int points = POINTS_PER_GENE * count;
    float heightStep = (height + 0.0F) / points;
    float angleStep = -(RADIANS_PER_GENE + 0.0F) / POINTS_PER_GENE;
    float angleOffset = RADIANS_PER_GENE / 2;
    float rotation = (index + transition) * RADIANS_PER_GENE;
    // Push transformation matrix
    transforms.push();
    // Rotate according to the index
    transforms.rotate(new Quaternion(Vector3f.YP, rotation, false));
    // Fetch transformation matrix
    Matrix4f matrix = transforms.getLast().getMatrix();
    // First helix
    this.drawHelix(genePairs, index, radius, angleOffset, heightStep, angleStep, points, buffer, matrix, true, alpha, color);
    // Second helix
    this.drawHelix(genePairs, index, radius, PI + angleOffset, heightStep, angleStep, points, buffer, matrix, false, alpha, color);
    // Spokes
    this.drawSpokes(genePairs, index, radius, angleOffset, PI + angleOffset, heightStep, angleStep, buffer, matrix, alpha, color);
    // Pop transformation matrix from the stack
    transforms.pop();
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) Quaternion(net.minecraft.util.math.vector.Quaternion)

Aggregations

Matrix4f (net.minecraft.util.math.vector.Matrix4f)7 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)3 IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2 BlockBPMultipart (com.bluepowermod.block.BlockBPMultipart)1 BlockGreenHouseAir (com.infinityraider.agricraft.content.world.BlockGreenHouseAir)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 BlockState (net.minecraft.block.BlockState)1 IRenderTypeBuffer (net.minecraft.client.renderer.IRenderTypeBuffer)1 ModelResourceLocation (net.minecraft.client.renderer.model.ModelResourceLocation)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 VoxelShape (net.minecraft.util.math.shapes.VoxelShape)1 Matrix3f (net.minecraft.util.math.vector.Matrix3f)1 Quaternion (net.minecraft.util.math.vector.Quaternion)1 World (net.minecraft.world.World)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1