Search in sources :

Example 1 with ChunkOcclusionDataBuilder

use of net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder 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 ChunkOcclusionDataBuilder

use of net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder in project sodium-fabric by CaffeineMC.

the class ChunkGraph method getOpenChunkFaces.

private Set<Direction> getOpenChunkFaces(BlockPos pos) {
    WorldChunk chunk = this.world.getChunk(pos.getX() >> 4, pos.getZ() >> 4);
    ChunkSection section = chunk.getSectionArray()[pos.getY() >> 4];
    if (section == null || section.isEmpty()) {
        return EnumSet.allOf(Direction.class);
    }
    ChunkOcclusionDataBuilder occlusionBuilder = new ChunkOcclusionDataBuilder();
    BlockPos.Mutable mpos = new BlockPos.Mutable();
    for (int x = 0; x < 16; x++) {
        for (int y = 0; y < 16; y++) {
            for (int z = 0; z < 16; z++) {
                BlockState state = section.getBlockState(x, y, z);
                mpos.set(x, y, z);
                if (state.isFullOpaque(this.world, mpos)) {
                    occlusionBuilder.markClosed(mpos);
                }
            }
        }
    }
    return occlusionBuilder.getOpenFaces(pos);
}
Also used : BlockState(net.minecraft.block.BlockState) WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) ChunkSection(net.minecraft.world.chunk.ChunkSection)

Example 3 with ChunkOcclusionDataBuilder

use of net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder in project sodium-fabric by CaffeineMC.

the class MixinRebuildTask method render.

/**
 * @author JellySquid
 */
@Overwrite
private Set<BlockEntity> render(float cameraX, float cameraY, float cameraZ, ChunkBuilder.ChunkData data, BlockBufferBuilderStorage buffers) {
    ExtendedChunkData edata = (ExtendedChunkData) data;
    BlockPos from = this.parent.getOrigin().toImmutable();
    BlockPos to = from.add(15, 15, 15);
    ChunkOcclusionDataBuilder occlusion = new ChunkOcclusionDataBuilder();
    Set<BlockEntity> set = Sets.newHashSet();
    ChunkRendererRegion world = this.region;
    Vector3f translation = new Vector3f();
    if (world != null) {
        BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
        int minX = from.getX();
        int minY = from.getY();
        int minZ = from.getZ();
        int maxX = to.getX();
        int maxY = to.getY();
        int maxZ = to.getZ();
        BlockPos.Mutable pos = new BlockPos.Mutable();
        for (int z = minZ; z <= maxZ; z++) {
            for (int y = minY; y <= maxY; y++) {
                for (int x = minX; x <= maxX; x++) {
                    pos.set(x, y, z);
                    BlockState blockState = world.getBlockState(pos);
                    FluidState fluidState = blockState.getFluidState();
                    Block block = blockState.getBlock();
                    if (blockState.isFullOpaque(world, pos)) {
                        occlusion.markClosed(pos);
                    }
                    if (block.hasBlockEntity()) {
                        BlockEntity entity = world.getBlockEntity(pos, WorldChunk.CreationType.CHECK);
                        if (entity != null) {
                            this.addBlockEntity(data, set, entity);
                        }
                    }
                    if (!fluidState.isEmpty()) {
                        RenderLayer layer = RenderLayers.getFluidLayer(fluidState);
                        BufferBuilder builder = buffers.get(layer);
                        if (!builder.isBuilding()) {
                            builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                            edata.getInitializedLayers().add(layer);
                        }
                        blockRenderManager.renderFluid(pos, world, builder, fluidState);
                    }
                    if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
                        RenderLayer layer = RenderLayers.getBlockLayer(blockState);
                        BufferBuilder builder = buffers.get(layer);
                        if (!builder.isBuilding()) {
                            builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                            edata.getInitializedLayers().add(layer);
                        }
                        translation.set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
                        this.pipeline.renderBlock(blockState, pos, world, translation, builder, true);
                    }
                }
            }
        }
        for (RenderLayer layer : edata.getInitializedLayers()) {
            BufferBuilder builder = buffers.get(layer);
            if (layer == RenderLayer.getTranslucent()) {
                builder.sortQuads(cameraX - (float) from.getX(), cameraY - (float) from.getY(), cameraZ - (float) from.getZ());
                edata.setTranslucentBufferState(builder.popState());
            }
            builder.end();
            if (((ChunkMeshBuilder) builder).isEmpty()) {
                continue;
            }
            edata.getNonEmptyLayers().add(layer);
        }
        if (edata.getNonEmptyLayers().size() > 0) {
            edata.markNonEmpty();
        }
    }
    edata.setOcclusionData(occlusion.build());
    this.region = null;
    this.pipeline = null;
    return set;
}
Also used : ChunkRendererRegion(net.minecraft.client.render.chunk.ChunkRendererRegion) BufferBuilder(net.minecraft.client.render.BufferBuilder) RenderLayer(net.minecraft.client.render.RenderLayer) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) BlockState(net.minecraft.block.BlockState) ChunkMeshBuilder(me.jellysquid.mods.sodium.client.render.mesh.ChunkMeshBuilder) Vector3f(net.minecraft.client.util.math.Vector3f) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager) ExtendedChunkData(me.jellysquid.mods.sodium.client.render.pipeline.ExtendedChunkData) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) FluidState(net.minecraft.fluid.FluidState) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with ChunkOcclusionDataBuilder

use of net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder in project sodium-fabric by CaffeineMC.

the class ChunkRenderRebuildTask method generateMesh.

private ChunkMeshInfo generateMesh(VertexBufferCache buffers) {
    ChunkMeshInfo info = new ChunkMeshInfo();
    ChunkOcclusionDataBuilder occlusionDataBuilder = new ChunkOcclusionDataBuilder();
    Vector3f translation = new Vector3f();
    BlockPos from = this.render.getOrigin();
    BlockPos to = from.add(16, 16, 16);
    int minX = from.getX();
    int minY = from.getY();
    int minZ = from.getZ();
    int maxX = to.getX();
    int maxY = to.getY();
    int maxZ = to.getZ();
    BlockPos.Mutable pos = new BlockPos.Mutable();
    for (int z = minZ; z < maxZ; z++) {
        for (int y = minY; y < maxY; y++) {
            for (int x = minX; x < maxX; x++) {
                pos.set(x, y, z);
                BlockState blockState = this.region.getBlockState(pos);
                FluidState fluidState = blockState.getFluidState();
                Block block = blockState.getBlock();
                if (blockState.isFullOpaque(this.region, pos)) {
                    occlusionDataBuilder.markClosed(pos);
                }
                if (block.hasBlockEntity()) {
                    BlockEntity entity = this.region.getBlockEntity(pos, WorldChunk.CreationType.CHECK);
                    if (entity != null) {
                        BlockEntityRenderer<BlockEntity> renderer = BlockEntityRenderDispatcher.INSTANCE.get(entity);
                        if (renderer != null) {
                            info.blockEntities.add(entity);
                            if (renderer.rendersOutsideBoundingBox(entity)) {
                                info.globalEntities.add(entity);
                            }
                        }
                    }
                }
                if (!fluidState.isEmpty()) {
                    RenderLayer layer = RenderLayers.getFluidLayer(fluidState);
                    BufferBuilder builder = buffers.get(layer);
                    if (!builder.isBuilding()) {
                        builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                    }
                    this.fallbackPipeline.renderFluid(pos, this.region, builder, fluidState);
                }
                if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
                    RenderLayer layer = RenderLayers.getBlockLayer(blockState);
                    BufferBuilder builder = buffers.get(layer);
                    if (!builder.isBuilding()) {
                        builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                    }
                    translation.set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
                    this.pipeline.renderBlock(blockState, pos, this.region, translation, builder, true);
                }
            }
        }
    }
    BufferBuilder.State translucentBufferState = null;
    for (RenderLayer layer : RenderLayer.getBlockLayers()) {
        BufferBuilder builder = buffers.get(layer);
        if (!builder.isBuilding()) {
            continue;
        }
        if (((ChunkMeshBuilder) builder).isEmpty()) {
            continue;
        }
        if (layer == RenderLayer.getTranslucent()) {
            builder.sortQuads((float) this.camera.x - (float) from.getX(), (float) this.camera.y - (float) from.getY(), (float) this.camera.z - (float) from.getZ());
            translucentBufferState = builder.popState();
        }
        info.presentLayers.add(layer);
    }
    info.occlusionGraph = occlusionDataBuilder.build();
    info.translucentBufferState = translucentBufferState;
    return info;
}
Also used : BufferBuilder(net.minecraft.client.render.BufferBuilder) CloneableBufferBuilder(me.jellysquid.mods.sodium.client.render.chunk.CloneableBufferBuilder) RenderLayer(net.minecraft.client.render.RenderLayer) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) BlockState(net.minecraft.block.BlockState) ChunkMeshBuilder(me.jellysquid.mods.sodium.client.render.mesh.ChunkMeshBuilder) Vector3f(net.minecraft.client.util.math.Vector3f) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) FluidState(net.minecraft.fluid.FluidState) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 5 with ChunkOcclusionDataBuilder

use of net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder 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)

Aggregations

BlockState (net.minecraft.block.BlockState)5 ChunkOcclusionDataBuilder (net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder)5 BlockEntity (net.minecraft.block.entity.BlockEntity)4 BufferBuilder (net.minecraft.client.render.BufferBuilder)4 RenderLayer (net.minecraft.client.render.RenderLayer)4 FluidState (net.minecraft.fluid.FluidState)4 BlockPos (net.minecraft.util.math.BlockPos)4 BlockRenderManager (net.minecraft.client.render.block.BlockRenderManager)3 ChunkRendererRegion (net.minecraft.client.render.chunk.ChunkRendererRegion)3 HashSet (java.util.HashSet)2 Random (java.util.Random)2 ChunkMeshBuilder (me.jellysquid.mods.sodium.client.render.mesh.ChunkMeshBuilder)2 Block (net.minecraft.block.Block)2 MatrixStack (net.minecraft.client.util.math.MatrixStack)2 Vector3f (net.minecraft.client.util.math.Vector3f)2 RenderBlockEvent (com.tangykiwi.kiwiclient.event.RenderBlockEvent)1 RenderFluidEvent (com.tangykiwi.kiwiclient.event.RenderFluidEvent)1 CloneableBufferBuilder (me.jellysquid.mods.sodium.client.render.chunk.CloneableBufferBuilder)1 ExtendedChunkData (me.jellysquid.mods.sodium.client.render.pipeline.ExtendedChunkData)1 ChunkSection (net.minecraft.world.chunk.ChunkSection)1