Search in sources :

Example 46 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project KiwiClient by TangyKiwi.

the class ChunkRebuildTaskMixin method newRender2.

private Set<BlockEntity> newRender2(float cameraX, float cameraY, float cameraZ, ChunkData data, BlockBufferBuilderStorage buffers) {
    BlockPos blockPos = field_20839.getOrigin().toImmutable();
    BlockPos blockPos2 = blockPos.add(15, 15, 15);
    ChunkOcclusionDataBuilder chunkOcclusionDataBuilder = new ChunkOcclusionDataBuilder();
    Set<BlockEntity> set = new HashSet<>();
    ChunkRendererRegion chunkRendererRegion = this.region;
    this.region = null;
    MatrixStack matrixStack = new MatrixStack();
    if (chunkRendererRegion != null) {
        BlockModelRenderer.enableBrightnessCache();
        Random random = new Random();
        BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
        for (BlockPos blockPos3 : BlockPos.iterate(blockPos, blockPos2)) {
            BlockState blockState = chunkRendererRegion.getBlockState(blockPos3);
            if (blockState.isOpaqueFullCube(chunkRendererRegion, blockPos3)) {
                chunkOcclusionDataBuilder.markClosed(blockPos3);
            }
            if (blockState.hasBlockEntity()) {
                BlockEntity blockEntityx = chunkRendererRegion.getBlockEntity(blockPos3);
                if (blockEntityx != null) {
                    this.addBlockEntity(data, set, blockEntityx);
                }
            }
            FluidState fluid = chunkRendererRegion.getFluidState(blockPos3);
            if (!fluid.isEmpty()) {
                RenderLayer renderLayer = RenderLayers.getFluidLayer(fluid);
                BufferBuilder bufferBuilder = buffers.get(renderLayer);
                if (data.initializedLayers.add(renderLayer)) {
                    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                }
                RenderFluidEvent event = new RenderFluidEvent(fluid, blockPos3, bufferBuilder);
                KiwiClient.eventBus.post(event);
                if (event.isCancelled())
                    continue;
                if (blockRenderManager.renderFluid(blockPos3, chunkRendererRegion, bufferBuilder, blockState, fluid)) {
                    data.empty = false;
                    data.nonEmptyLayers.add(renderLayer);
                }
            }
            if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
                RenderLayer renderLayer = RenderLayers.getBlockLayer(blockState);
                BufferBuilder bufferBuilder = buffers.get(renderLayer);
                if (data.initializedLayers.add(renderLayer)) {
                    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                }
                RenderBlockEvent.Tesselate event = new RenderBlockEvent.Tesselate(blockState, blockPos3, matrixStack, bufferBuilder);
                KiwiClient.eventBus.post(event);
                if (event.isCancelled())
                    continue;
                matrixStack.push();
                matrixStack.translate(blockPos3.getX() & 15, blockPos3.getY() & 15, blockPos3.getZ() & 15);
                if (blockRenderManager.renderBlock(blockState, blockPos3, chunkRendererRegion, matrixStack, bufferBuilder, true, random)) {
                    data.empty = false;
                    data.nonEmptyLayers.add(renderLayer);
                }
                bufferBuilder.unfixColor();
                matrixStack.pop();
            }
        }
        if (data.nonEmptyLayers.contains(RenderLayer.getTranslucent())) {
            BufferBuilder bufferBuilder2 = buffers.get(RenderLayer.getTranslucent());
            bufferBuilder2.sortFrom(cameraX - (float) blockPos.getX(), cameraY - (float) blockPos.getY(), cameraZ - (float) blockPos.getZ());
            data.bufferState = bufferBuilder2.popState();
        }
        Stream<RenderLayer> var10000 = data.initializedLayers.stream();
        Objects.requireNonNull(buffers);
        var10000.map(buffers::get).forEach(BufferBuilder::end);
        BlockModelRenderer.disableBrightnessCache();
    }
    data.occlusionGraph = chunkOcclusionDataBuilder.build();
    return set;
}
Also used : ChunkRendererRegion(net.minecraft.client.render.chunk.ChunkRendererRegion) RenderFluidEvent(com.tangykiwi.kiwiclient.event.RenderFluidEvent) RenderBlockEvent(com.tangykiwi.kiwiclient.event.RenderBlockEvent) MatrixStack(net.minecraft.client.util.math.MatrixStack) BufferBuilder(net.minecraft.client.render.BufferBuilder) RenderLayer(net.minecraft.client.render.RenderLayer) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) HashSet(java.util.HashSet) FluidState(net.minecraft.fluid.FluidState)

Example 47 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project MiniMap by pl3xgaming.

the class Drawable method draw.

public static void draw(MatrixStack matrixStack, Identifier texture, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1) {
    RenderSystem.setShader(GameRenderer::getPositionTexShader);
    RenderSystem.setShaderTexture(0, texture);
    Matrix4f model = matrixStack.peek().getPositionMatrix();
    BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
    bufferBuilder.vertex(model, x0, y0, 0F).texture(u0, v0).next();
    bufferBuilder.vertex(model, x0, y1, 0F).texture(u0, v1).next();
    bufferBuilder.vertex(model, x1, y1, 0F).texture(u1, v1).next();
    bufferBuilder.vertex(model, x1, y0, 0F).texture(u1, v0).next();
    bufferBuilder.end();
    BufferRenderer.draw(bufferBuilder);
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 48 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project MiniMap by pl3xgaming.

the class GL method drawSolidCirc.

public static void drawSolidCirc(Matrix4f matrix, float centerX, float centerY, float radius, int res, int color) {
    RenderSystem.disableTexture();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    BufferBuilder buf = Tessellator.getInstance().getBuffer();
    buf.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
    for (int i = 0; i <= res; i++) {
        float angle = 2F * Mathf.PI * i / res;
        float x = Mathf.sin(angle) * radius;
        float y = Mathf.cos(angle) * radius;
        buf.vertex(matrix, centerX + x, centerY + y, 0F).color(color).next();
    }
    buf.end();
    BufferRenderer.draw(buf);
    RenderSystem.enableTexture();
}
Also used : BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 49 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project MiniMap by pl3xgaming.

the class GL method drawLine.

public static void drawLine(MatrixStack matrixStack, float x0, float y0, float x1, float y1, float width, int color) {
    RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader);
    RenderSystem.lineWidth(width);
    Matrix4f matrix4f = matrixStack.peek().getPositionMatrix();
    Matrix3f matrix3f = matrixStack.peek().getNormalMatrix();
    BufferBuilder buf = Tessellator.getInstance().getBuffer();
    buf.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
    buf.vertex(matrix4f, x0, y0, 0F).color(color).normal(matrix3f, 1F, 1F, 0F).next();
    buf.vertex(matrix4f, x1, y1, 0F).color(color).normal(matrix3f, 1F, 1F, 0F).next();
    buf.end();
    BufferRenderer.draw(buf);
    RenderSystem.lineWidth(1F);
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) Matrix3f(net.minecraft.util.math.Matrix3f) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer)

Example 50 with BufferBuilder

use of net.minecraft.client.render.BufferBuilder in project fabric by FabricMC.

the class ChunkRenderInfo method getInitializedBuffer.

/**
 * Lazily retrieves output buffer for given layer, initializing as needed.
 */
public AccessBufferBuilder getInitializedBuffer(int layerIndex) {
    // redundant for first layer, but probably not faster to check
    resultFlags[layerIndex] = true;
    AccessBufferBuilder result = buffers[layerIndex];
    if (result == null) {
        BufferBuilder builder = chunkTask.getBufferBuilders().get(layerIndex);
        buffers[layerIndex] = (AccessBufferBuilder) builder;
        BlockRenderLayer layer = LAYERS[layerIndex];
        if (!chunkData.isBufferInitialized(layer)) {
            // start buffer
            chunkData.markBufferInitialized(layer);
            ((AccessChunkRenderer) chunkRenderer).fabric_beginBufferBuilding(builder, chunkOrigin);
        }
        result = (AccessBufferBuilder) builder;
    }
    return result;
}
Also used : AccessChunkRenderer(net.fabricmc.indigo.renderer.accessor.AccessChunkRenderer) AccessBufferBuilder(net.fabricmc.indigo.renderer.accessor.AccessBufferBuilder) BufferBuilder(net.minecraft.client.render.BufferBuilder) BlockRenderLayer(net.minecraft.block.BlockRenderLayer) AccessBufferBuilder(net.fabricmc.indigo.renderer.accessor.AccessBufferBuilder)

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