Search in sources :

Example 1 with BlockRenderManager

use of net.minecraft.client.render.block.BlockRenderManager in project BleachHack by BleachDrinker420.

the class MixinChunkRebuildTask method newRender.

private Set<BlockEntity> newRender(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, WorldChunk.CreationType.CHECK);
                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);
                }
                EventRenderFluid event = new EventRenderFluid(fluid, blockPos3, bufferBuilder);
                BleachHack.eventBus.post(event);
                if (event.isCancelled())
                    continue;
                if (blockRenderManager.renderFluid(blockPos3, chunkRendererRegion, bufferBuilder, 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);
                }
                EventRenderBlock.Tesselate event = new EventRenderBlock.Tesselate(blockState, blockPos3, matrixStack, bufferBuilder);
                BleachHack.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.setCameraPosition(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) 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) EventRenderBlock(org.bleachhack.event.events.EventRenderBlock) EventRenderFluid(org.bleachhack.event.events.EventRenderFluid) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) HashSet(java.util.HashSet) FluidState(net.minecraft.fluid.FluidState)

Example 2 with BlockRenderManager

use of net.minecraft.client.render.block.BlockRenderManager in project Carrier by GabrielOlvH.

the class CarriableGeneric method render.

@Override
public void render(@NotNull PlayerEntity player, @NotNull CarrierComponent carrier, @NotNull MatrixStack matrices, @NotNull VertexConsumerProvider vcp, float tickDelta, int light) {
    BlockState blockState = parent.getDefaultState();
    matrices.push();
    matrices.scale(0.6f, 0.6f, 0.6f);
    float yaw = MathHelper.lerpAngleDegrees(tickDelta, player.prevBodyYaw, player.bodyYaw);
    matrices.multiply(Vec3f.NEGATIVE_Y.getDegreesQuaternion(180));
    matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-yaw));
    matrices.translate(-0.5, 0.8, -1.3);
    BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
    try {
        blockRenderManager.renderBlockAsEntity(blockState, matrices, vcp, light, OverlayTexture.DEFAULT_UV);
    } catch (Exception e) {
    // yes this is ignored
    }
    matrices.pop();
}
Also used : BlockState(net.minecraft.block.BlockState) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager)

Example 3 with BlockRenderManager

use of net.minecraft.client.render.block.BlockRenderManager in project canvas by vram-guild.

the class MixinChunkRenderer method onRebuildChunk.

@Inject(method = "rebuildChunk", at = @At("HEAD"), cancellable = true, require = 1)
private void onRebuildChunk(final float x, final float y, final float z, final ChunkRenderTask chunkRenderTask, final CallbackInfo ci) {
    final TerrainRenderContext renderContext = TerrainRenderContext.POOL.get();
    final ChunkRebuildHelper help = renderContext.chunkRebuildHelper;
    help.clear();
    final ChunkRenderData chunkRenderData = ChunkRenderDataStore.claim();
    final ChunkRenderDataExt chunkDataExt = (ChunkRenderDataExt) chunkRenderData;
    final BlockPos.Mutable origin = this.origin;
    final World world = this.world;
    if (world != null) {
        chunkRenderTask.getLock().lock();
        try {
            if (chunkRenderTask.getStage() != ChunkRenderTask.Stage.COMPILING) {
                return;
            }
            chunkRenderTask.setRenderData(chunkRenderData);
        } finally {
            chunkRenderTask.getLock().unlock();
        }
        // PERF: avoid allocation
        final ChunkOcclusionGraphBuilder visibilityData = new ChunkOcclusionGraphBuilder();
        // PERF: avoid allocation
        final HashSet<BlockEntity> blockEntities = Sets.newHashSet();
        final ChunkRendererRegion vanillaRegion = chunkRenderTask.takeRegion();
        if (vanillaRegion != null) {
            final FastRenderRegion renderRegion = ((ChunkRendererRegionExt) vanillaRegion).canvas_fastRegion();
            ++chunkUpdateCount;
            help.prepareCollectors(origin.getX(), origin.getY(), origin.getZ());
            renderContext.setChunkTask(chunkRenderTask);
            /**
             * Capture the block layer result flags so our renderer can update them when more
             * than one layer is rendered for a single model. This is also where we signal the
             * renderer to prepare for a new chunk using the data we've accumulated up to this point.
             */
            renderContext.prepare((ChunkRenderer) (Object) this, origin);
            // NB: We don't use this and it probably isn't needed but leaving just in case - cost is low
            BlockModelRenderer.enableBrightnessCache();
            final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
            final BlockPos.Mutable searchPos = help.searchPos;
            final int xMin = origin.getX();
            final int yMin = origin.getY();
            final int zMin = origin.getZ();
            final int xMax = xMin + 16;
            final int yMax = yMin + 16;
            final int zMax = zMin + 16;
            for (int xPos = xMin; xPos < xMax; xPos++) {
                for (int yPos = yMin; yPos < yMax; yPos++) {
                    for (int zPos = zMin; zPos < zMax; zPos++) {
                        final BlockState blockState = renderRegion.getBlockState(xPos, yPos, zPos);
                        searchPos.set(xPos, yPos, zPos);
                        if (blockState.isFullOpaque(renderRegion, searchPos)) {
                            visibilityData.markClosed(searchPos);
                        }
                        if (blockState.getBlock().hasBlockEntity()) {
                            final BlockEntity blockEntity = renderRegion.getBlockEntity(searchPos, WorldChunk.CreationType.CHECK);
                            if (blockEntity != null) {
                                final BlockEntityRenderer<BlockEntity> blockEntityRenderer = BlockEntityRenderDispatcher.INSTANCE.get(blockEntity);
                                if (blockEntityRenderer != null) {
                                    // Fixes MC-112730 - no reason to render both globally and in chunk
                                    if (blockEntityRenderer.method_3563(blockEntity)) {
                                        // global renderer - like beacons
                                        blockEntities.add(blockEntity);
                                    } else {
                                        // chunk-local renderer
                                        chunkRenderData.addBlockEntity(blockEntity);
                                    }
                                }
                            }
                        }
                        BlockRenderLayer renderLayer;
                        // UGLY: we are relying on knowledge that fluid state is directly derived from block state, which
                        // may not be true in future versions and may break.  However, is significantly faster to re-use block
                        // state here vs. retrieving it again.
                        final FluidState fluidState = blockState.getFluidState();
                        if (!fluidState.isEmpty()) {
                            renderLayer = fluidState.getRenderLayer();
                            // TODO: apply appropriate shader props for fluids
                            final FluidBufferBuilder fluidBuilder = help.fluidBuilder.prepare(help.getCollector(renderLayer).get(Canvas.MATERIAL_STANDARD, ShaderProps.waterProps()), searchPos, renderLayer);
                            blockRenderManager.tesselateFluid(searchPos, renderRegion, fluidBuilder, fluidState);
                        }
                        if (blockState.getRenderType() == BlockRenderType.MODEL) {
                            renderContext.tesselateBlock(blockState, searchPos);
                        }
                    }
                }
            }
            if (!help.solidCollector.isEmpty()) {
                chunkRenderData.markBufferInitialized(BlockRenderLayer.SOLID);
                chunkDataExt.canvas_setNonEmpty(BlockRenderLayer.SOLID);
                final UploadableChunk.Solid abandoned = uploadSolid.getAndSet(help.solidCollector.packUploadSolid());
                if (abandoned != null) {
                    abandoned.cancel();
                }
            }
            if (!help.translucentCollector.isEmpty()) {
                final VertexCollectorList vcl = help.translucentCollector;
                chunkRenderData.markBufferInitialized(BlockRenderLayer.TRANSLUCENT);
                chunkDataExt.canvas_setNonEmpty(BlockRenderLayer.TRANSLUCENT);
                vcl.setViewCoordinates(x, y, z);
                chunkDataExt.canvas_collectorState(vcl.getCollectorState(null));
                final UploadableChunk.Translucent abandoned = uploadTranslucent.getAndSet(vcl.packUploadTranslucent());
                if (abandoned != null) {
                    abandoned.cancel();
                }
            }
            /**
             * Release all references. Probably not necessary but would be $#%! to debug if it is.
             */
            renderContext.release();
            BlockModelRenderer.disableBrightnessCache();
        }
        chunkRenderData.setOcclusionGraph(visibilityData.build());
        lock.lock();
        try {
            help.tileEntitiesToAdd.addAll(blockEntities);
            help.tileEntitiesToRemove.addAll(this.blockEntities);
            help.tileEntitiesToAdd.removeAll(this.blockEntities);
            help.tileEntitiesToRemove.removeAll(blockEntities);
            this.blockEntities.clear();
            this.blockEntities.addAll(blockEntities);
            renderer.updateBlockEntities(help.tileEntitiesToRemove, help.tileEntitiesToAdd);
        } finally {
            lock.unlock();
        }
    }
    ci.cancel();
}
Also used : ChunkRendererRegion(net.minecraft.client.render.chunk.ChunkRendererRegion) ChunkRebuildHelper(grondag.canvas.chunk.ChunkRebuildHelper) ChunkRenderData(net.minecraft.client.render.chunk.ChunkRenderData) FluidBufferBuilder(grondag.canvas.buffer.packing.FluidBufferBuilder) ChunkRenderDataExt(grondag.canvas.chunk.ChunkRenderDataExt) World(net.minecraft.world.World) TerrainRenderContext(grondag.canvas.apiimpl.rendercontext.TerrainRenderContext) ChunkOcclusionGraphBuilder(net.minecraft.client.render.chunk.ChunkOcclusionGraphBuilder) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) BlockState(net.minecraft.block.BlockState) VertexCollectorList(grondag.canvas.buffer.packing.VertexCollectorList) UploadableChunk(grondag.canvas.chunk.UploadableChunk) FastRenderRegion(grondag.canvas.chunk.FastRenderRegion) BlockRenderLayer(net.minecraft.block.BlockRenderLayer) ChunkRendererRegionExt(grondag.canvas.chunk.ChunkRendererRegionExt) FluidState(net.minecraft.fluid.FluidState) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with BlockRenderManager

use of net.minecraft.client.render.block.BlockRenderManager in project Biome-Makeover by Lemonszz.

the class GlowfishFeatureRenderer method render.

@Override
public void render(MatrixStack ms, VertexConsumerProvider vcp, int i, SalmonEntity e, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
    if (!e.isBaby() && !e.isInvisible()) {
        BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
        BlockState shroom = BMBlocks.ORANGE_GLOWSHROOM.getDefaultState();
        int m = LivingEntityRenderer.getOverlay(e, 0.0F);
        ms.push();
        ((SalmonEntityModelAccessor) this.getContextModel()).bm_getTail().rotate(ms);
        ((SalmonEntityModelAccessor) this.getContextModel()).bm_getTail().visible = false;
        ms.translate(0.0D, 0, 0.5F);
        ms.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-90));
        ms.scale(-1.0F, -1.0F, 1.0F);
        ms.translate(-0.5D, -0.5D, -0.5D);
        blockRenderManager.renderBlockAsEntity(shroom, ms, vcp, i, m);
        ms.pop();
    }
}
Also used : BlockState(net.minecraft.block.BlockState) SalmonEntityModelAccessor(party.lemons.biomemakeover.util.access.SalmonEntityModelAccessor) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager)

Example 5 with BlockRenderManager

use of net.minecraft.client.render.block.BlockRenderManager in project friends-and-foes by Faboslav.

the class MoobloomFlowerFeatureRenderer method render.

public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, T moobloomEntity, float f, float g, float h, float j, float k, float l) {
    if (!moobloomEntity.isBaby() && !moobloomEntity.isInvisible()) {
        BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
        BlockState blockState = ModBlocks.BUTTERCUP.get().getDefaultState();
        int overlay = LivingEntityRenderer.getOverlay(moobloomEntity, 0.0F);
        MinecraftClient minecraftClient = MinecraftClient.getInstance();
        boolean renderAsModel = minecraftClient.hasOutline(moobloomEntity) && moobloomEntity.isInvisible();
        BakedModel bakedModel = blockRenderManager.getModel(blockState);
        // Head
        matrixStack.push();
        this.getContextModel().getHead().rotate(matrixStack);
        matrixStack.translate(0.09D, -0.6D, -0.185D);
        matrixStack.scale(-0.8F, -0.8F, 0.8F);
        matrixStack.translate(-0.5D, -0.5D, -0.5D);
        this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
        matrixStack.pop();
        // Body
        matrixStack.push();
        matrixStack.translate(0.22D, -0.28D, -0.06D);
        matrixStack.scale(-0.8F, -0.8F, 0.8F);
        matrixStack.translate(-0.5D, -0.5D, -0.5D);
        this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
        matrixStack.pop();
        matrixStack.push();
        matrixStack.translate(-0.2D, -0.22D, 0.01D);
        matrixStack.scale(-0.8F, -0.8F, 0.8F);
        matrixStack.translate(-0.5D, -0.5D, -0.5D);
        this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
        matrixStack.pop();
        matrixStack.push();
        matrixStack.translate(0.03D, -0.28D, 0.47D);
        matrixStack.scale(-0.8F, -0.8F, 0.8F);
        matrixStack.translate(-0.5D, -0.5D, -0.5D);
        this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
        matrixStack.pop();
    }
}
Also used : BlockState(net.minecraft.block.BlockState) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager) MinecraftClient(net.minecraft.client.MinecraftClient) BakedModel(net.minecraft.client.render.model.BakedModel)

Aggregations

BlockState (net.minecraft.block.BlockState)10 BlockRenderManager (net.minecraft.client.render.block.BlockRenderManager)10 BlockPos (net.minecraft.util.math.BlockPos)5 BlockEntity (net.minecraft.block.entity.BlockEntity)4 ChunkRendererRegion (net.minecraft.client.render.chunk.ChunkRendererRegion)4 FluidState (net.minecraft.fluid.FluidState)4 Random (java.util.Random)3 BufferBuilder (net.minecraft.client.render.BufferBuilder)3 RenderLayer (net.minecraft.client.render.RenderLayer)3 ChunkOcclusionDataBuilder (net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder)3 HashSet (java.util.HashSet)2 MatrixStack (net.minecraft.client.util.math.MatrixStack)2 World (net.minecraft.world.World)2 RenderBlockEvent (com.tangykiwi.kiwiclient.event.RenderBlockEvent)1 RenderFluidEvent (com.tangykiwi.kiwiclient.event.RenderFluidEvent)1 TerrainRenderContext (grondag.canvas.apiimpl.rendercontext.TerrainRenderContext)1 FluidBufferBuilder (grondag.canvas.buffer.packing.FluidBufferBuilder)1 VertexCollectorList (grondag.canvas.buffer.packing.VertexCollectorList)1 ChunkRebuildHelper (grondag.canvas.chunk.ChunkRebuildHelper)1 ChunkRenderDataExt (grondag.canvas.chunk.ChunkRenderDataExt)1