Search in sources :

Example 1 with ShadeSeparatedBufferBuilder

use of com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder in project Create by Creators-of-Create.

the class WorldSectionElement method buildStructureBuffer.

private SuperByteBuffer buildStructureBuffer(PonderWorld world, RenderType layer) {
    BlockRenderDispatcher dispatcher = ModelUtil.VANILLA_RENDERER;
    ThreadLocalObjects objects = THREAD_LOCAL_OBJECTS.get();
    PoseStack poseStack = objects.poseStack;
    Random random = objects.random;
    ShadeSeparatingVertexConsumer shadeSeparatingWrapper = objects.shadeSeparatingWrapper;
    ShadeSeparatedBufferBuilder builder = new ShadeSeparatedBufferBuilder(512);
    BufferBuilder unshadedBuilder = objects.unshadedBuilder;
    builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
    unshadedBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
    shadeSeparatingWrapper.prepare(builder, unshadedBuilder);
    world.setMask(this.section);
    ForgeHooksClient.setRenderType(layer);
    ModelBlockRenderer.enableCaching();
    section.forEach(pos -> {
        BlockState state = world.getBlockState(pos);
        FluidState fluidState = world.getFluidState(pos);
        poseStack.pushPose();
        poseStack.translate(pos.getX(), pos.getY(), pos.getZ());
        if (state.getRenderShape() == RenderShape.MODEL && ItemBlockRenderTypes.canRenderInLayer(state, layer)) {
            BlockEntity tileEntity = world.getBlockEntity(pos);
            dispatcher.renderBatched(state, pos, world, poseStack, shadeSeparatingWrapper, true, random, tileEntity != null ? tileEntity.getModelData() : EmptyModelData.INSTANCE);
        }
        if (!fluidState.isEmpty() && ItemBlockRenderTypes.canRenderInLayer(fluidState, layer))
            dispatcher.renderLiquid(pos, world, builder, fluidState);
        poseStack.popPose();
    });
    ModelBlockRenderer.clearCache();
    ForgeHooksClient.setRenderType(null);
    world.clearMask();
    shadeSeparatingWrapper.clear();
    unshadedBuilder.end();
    builder.appendUnshadedVertices(unshadedBuilder);
    builder.end();
    return new SuperByteBuffer(builder);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Random(java.util.Random) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) BlockRenderDispatcher(net.minecraft.client.renderer.block.BlockRenderDispatcher) ShadeSeparatingVertexConsumer(com.jozufozu.flywheel.core.model.ShadeSeparatingVertexConsumer) BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) ShadeSeparatedBufferBuilder(com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder) ShadeSeparatedBufferBuilder(com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder) FluidState(net.minecraft.world.level.material.FluidState) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 2 with ShadeSeparatedBufferBuilder

use of com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder in project Create by Creators-of-Create.

the class SchematicRenderer method drawLayer.

protected SuperByteBuffer drawLayer(RenderType layer) {
    BlockRenderDispatcher dispatcher = ModelUtil.VANILLA_RENDERER;
    ThreadLocalObjects objects = THREAD_LOCAL_OBJECTS.get();
    PoseStack poseStack = objects.poseStack;
    Random random = objects.random;
    BlockPos.MutableBlockPos mutableBlockPos = objects.mutableBlockPos;
    SchematicWorld renderWorld = schematic;
    BoundingBox bounds = renderWorld.getBounds();
    ShadeSeparatingVertexConsumer shadeSeparatingWrapper = objects.shadeSeparatingWrapper;
    ShadeSeparatedBufferBuilder builder = new ShadeSeparatedBufferBuilder(512);
    BufferBuilder unshadedBuilder = objects.unshadedBuilder;
    builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
    unshadedBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
    shadeSeparatingWrapper.prepare(builder, unshadedBuilder);
    ForgeHooksClient.setRenderType(layer);
    ModelBlockRenderer.enableCaching();
    for (BlockPos localPos : BlockPos.betweenClosed(bounds.minX(), bounds.minY(), bounds.minZ(), bounds.maxX(), bounds.maxY(), bounds.maxZ())) {
        BlockPos pos = mutableBlockPos.setWithOffset(localPos, anchor);
        BlockState state = renderWorld.getBlockState(pos);
        poseStack.pushPose();
        poseStack.translate(localPos.getX(), localPos.getY(), localPos.getZ());
        if (state.getRenderShape() == RenderShape.MODEL && ItemBlockRenderTypes.canRenderInLayer(state, layer)) {
            BlockEntity tileEntity = renderWorld.getBlockEntity(localPos);
            dispatcher.renderBatched(state, pos, renderWorld, poseStack, shadeSeparatingWrapper, true, random, tileEntity != null ? tileEntity.getModelData() : EmptyModelData.INSTANCE);
        }
        poseStack.popPose();
    }
    ModelBlockRenderer.clearCache();
    ForgeHooksClient.setRenderType(null);
    shadeSeparatingWrapper.clear();
    unshadedBuilder.end();
    builder.appendUnshadedVertices(unshadedBuilder);
    builder.end();
    return new SuperByteBuffer(builder);
}
Also used : PoseStack(com.mojang.blaze3d.vertex.PoseStack) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) ShadeSeparatingVertexConsumer(com.jozufozu.flywheel.core.model.ShadeSeparatingVertexConsumer) BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) ShadeSeparatedBufferBuilder(com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) SchematicWorld(com.simibubi.create.content.schematics.SchematicWorld) BlockRenderDispatcher(net.minecraft.client.renderer.block.BlockRenderDispatcher) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) BlockPos(net.minecraft.core.BlockPos) ShadeSeparatedBufferBuilder(com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

ShadeSeparatedBufferBuilder (com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder)2 ShadeSeparatingVertexConsumer (com.jozufozu.flywheel.core.model.ShadeSeparatingVertexConsumer)2 BufferBuilder (com.mojang.blaze3d.vertex.BufferBuilder)2 PoseStack (com.mojang.blaze3d.vertex.PoseStack)2 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)2 Random (java.util.Random)2 BlockRenderDispatcher (net.minecraft.client.renderer.block.BlockRenderDispatcher)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 SchematicWorld (com.simibubi.create.content.schematics.SchematicWorld)1 BlockPos (net.minecraft.core.BlockPos)1 BoundingBox (net.minecraft.world.level.levelgen.structure.BoundingBox)1 FluidState (net.minecraft.world.level.material.FluidState)1