Search in sources :

Example 1 with IVertexBuilder

use of com.mojang.blaze3d.vertex.IVertexBuilder in project Bookshelf by Darkhax-Minecraft.

the class RenderUtils method renderBlock.

/**
 * Renders a block state into the world. This only exists for optifine compatibility mode.
 *
 * @param state The state to render.
 * @param world The world context to render into.
 * @param pos The position of the block.
 * @param matrix The render matrix.
 * @param buffer The render buffer.
 */
private static void renderBlock(BlockState state, World world, BlockPos pos, MatrixStack matrix, IRenderTypeBuffer buffer) {
    final BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer();
    final IBakedModel model = dispatcher.getBlockModel(state);
    final boolean useAO = Minecraft.useAmbientOcclusion() && state.getLightValue(world, pos) == 0 && model.useAmbientOcclusion();
    final RenderType type = RenderUtils.findRenderType(state);
    if (type != null) {
        ForgeHooksClient.setRenderLayer(type);
        final IVertexBuilder builder = buffer.getBuffer(type);
        renderModel(dispatcher.getModelRenderer(), useAO, world, model, state, pos, matrix, builder, false, OverlayTexture.NO_OVERLAY);
        ForgeHooksClient.setRenderLayer(null);
    }
}
Also used : IBakedModel(net.minecraft.client.renderer.model.IBakedModel) RenderType(net.minecraft.client.renderer.RenderType) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Example 2 with IVertexBuilder

use of com.mojang.blaze3d.vertex.IVertexBuilder in project AgriCraft by AgriCraft.

the class AgriGenomeRenderer method addVertex.

protected void addVertex(IRenderTypeBuffer buffer, Matrix4f matrix, float x, float y, float z, float r, float g, float b, float a, float w) {
    IVertexBuilder builder = this.getVertexBuilder(buffer, this.getRenderType(w));
    builder.pos(matrix, x, y, z).color(r, g, b, a).endVertex();
}
Also used : IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Example 3 with IVertexBuilder

use of com.mojang.blaze3d.vertex.IVertexBuilder 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 4 with IVertexBuilder

use of com.mojang.blaze3d.vertex.IVertexBuilder 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 5 with IVertexBuilder

use of com.mojang.blaze3d.vertex.IVertexBuilder in project Overloaded by CJ-MC-Mods.

the class RenderMultiToolAssist method renderBlockModel.

private static void renderBlockModel(RenderWorldLastEvent event, BlockPos toRenderAt, @Nonnull IBakedModel model, @Nonnull BlockState state) {
    ActiveRenderInfo camera = Minecraft.getInstance().gameRenderer.getMainCamera();
    final double x = camera.getPosition().x();
    final double y = camera.getPosition().y();
    final double z = camera.getPosition().z();
    event.getMatrixStack().pushPose();
    event.getMatrixStack().translate(toRenderAt.getX() - x, toRenderAt.getY() - y, toRenderAt.getZ() - z);
    IVertexBuilder buffer = Minecraft.getInstance().renderBuffers().bufferSource().getBuffer(GhostRenderType.getInstance());
    Minecraft.getInstance().getBlockRenderer().getModelRenderer().tesselateBlock(Minecraft.getInstance().level, model, state, toRenderAt, event.getMatrixStack(), buffer, false, Minecraft.getInstance().level.random, 0, 0);
    event.getMatrixStack().popPose();
    Minecraft.getInstance().renderBuffers().bufferSource().endBatch(GhostRenderType.getInstance());
}
Also used : ActiveRenderInfo(net.minecraft.client.renderer.ActiveRenderInfo) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Aggregations

IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)8 IBakedModel (net.minecraft.client.renderer.model.IBakedModel)3 BlockPos (net.minecraft.util.math.BlockPos)3 BlockState (net.minecraft.block.BlockState)2 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)2 RenderType (net.minecraft.client.renderer.RenderType)2 Matrix4f (net.minecraft.util.math.vector.Matrix4f)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2 World (net.minecraft.world.World)2 BlockBPMultipart (com.bluepowermod.block.BlockBPMultipart)1 BlockGreenHouseAir (com.infinityraider.agricraft.content.world.BlockGreenHouseAir)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 Random (java.util.Random)1 ActiveRenderInfo (net.minecraft.client.renderer.ActiveRenderInfo)1 IRenderTypeBuffer (net.minecraft.client.renderer.IRenderTypeBuffer)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 Direction (net.minecraft.util.Direction)1 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1