Search in sources :

Example 1 with ExtendedChunkData

use of me.jellysquid.mods.sodium.client.render.pipeline.ExtendedChunkData 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)

Aggregations

ChunkMeshBuilder (me.jellysquid.mods.sodium.client.render.mesh.ChunkMeshBuilder)1 ExtendedChunkData (me.jellysquid.mods.sodium.client.render.pipeline.ExtendedChunkData)1 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 BufferBuilder (net.minecraft.client.render.BufferBuilder)1 RenderLayer (net.minecraft.client.render.RenderLayer)1 BlockRenderManager (net.minecraft.client.render.block.BlockRenderManager)1 ChunkOcclusionDataBuilder (net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder)1 ChunkRendererRegion (net.minecraft.client.render.chunk.ChunkRendererRegion)1 Vector3f (net.minecraft.client.util.math.Vector3f)1 FluidState (net.minecraft.fluid.FluidState)1 BlockPos (net.minecraft.util.math.BlockPos)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1