BlockFeatureRenderer.java

net.minecraft.client.renderer.feature.BlockFeatureRenderer

信息

  • 全限定名:net.minecraft.client.renderer.feature.BlockFeatureRenderer
  • 类型:public class
  • 包:net.minecraft.client.renderer.feature
  • 源码路径:src/main/java/net/minecraft/client/renderer/feature/BlockFeatureRenderer.java
  • 起始行号:L34
  • 职责:

    TODO

字段/常量

  • DIRECTIONS

    • 类型: Direction[]
    • 修饰符: private static final
    • 源码定位: L35
    • 说明:

      TODO

  • NO_TINT

    • 类型: int[]
    • 修饰符: private static final
    • 源码定位: L36
    • 说明:

      TODO

  • quadInstance

    • 类型: QuadInstance
    • 修饰符: private final
    • 源码定位: L37
    • 说明:

      TODO

  • random

    • 类型: RandomSource
    • 修饰符: private final
    • 源码定位: L38
    • 说明:

      TODO

  • parts

    • 类型: List<BlockStateModelPart>
    • 修饰符: private final
    • 源码定位: L39
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

public void renderSolid(SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource, BlockStateModelSet blockStateModelSet, OutlineBufferSource outlineBufferSource, OptionsRenderState optionsState) @ L41

  • 方法名:renderSolid
  • 源码定位:L41
  • 返回类型:void
  • 修饰符:public

参数:

  • nodeCollection: SubmitNodeCollection
  • bufferSource: MultiBufferSource.BufferSource
  • blockStateModelSet: BlockStateModelSet
  • outlineBufferSource: OutlineBufferSource
  • optionsState: OptionsRenderState

说明:

TODO

public void renderTranslucent(SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource, BlockStateModelSet blockStateModelSet, OutlineBufferSource outlineBufferSource, MultiBufferSource.BufferSource crumblingBufferSource, OptionsRenderState optionsState) @ L52

  • 方法名:renderTranslucent
  • 源码定位:L52
  • 返回类型:void
  • 修饰符:public

参数:

  • nodeCollection: SubmitNodeCollection
  • bufferSource: MultiBufferSource.BufferSource
  • blockStateModelSet: BlockStateModelSet
  • outlineBufferSource: OutlineBufferSource
  • crumblingBufferSource: MultiBufferSource.BufferSource
  • optionsState: OptionsRenderState

说明:

TODO

private void renderMovingBlockSubmits(SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource, BlockStateModelSet blockStateModelSet, OptionsRenderState optionsState, boolean translucent) @ L65

  • 方法名:renderMovingBlockSubmits
  • 源码定位:L65
  • 返回类型:void
  • 修饰符:private

参数:

  • nodeCollection: SubmitNodeCollection
  • bufferSource: MultiBufferSource.BufferSource
  • blockStateModelSet: BlockStateModelSet
  • optionsState: OptionsRenderState
  • translucent: boolean

说明:

TODO

private static void putBakedQuad(PoseStack poseStack, MultiBufferSource.BufferSource bufferSource, float x, float y, float z, BakedQuad quad, QuadInstance instance, ChunkSectionLayer layer) @ L96

  • 方法名:putBakedQuad
  • 源码定位:L96
  • 返回类型:void
  • 修饰符:private static

参数:

  • poseStack: PoseStack
  • bufferSource: MultiBufferSource.BufferSource
  • x: float
  • y: float
  • z: float
  • quad: BakedQuad
  • instance: QuadInstance
  • layer: ChunkSectionLayer

说明:

TODO

private void renderBlockModelSubmits(SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource, OutlineBufferSource outlineBufferSource, boolean translucent) @ L118

  • 方法名:renderBlockModelSubmits
  • 源码定位:L118
  • 返回类型:void
  • 修饰符:private

参数:

  • nodeCollection: SubmitNodeCollection
  • bufferSource: MultiBufferSource.BufferSource
  • outlineBufferSource: OutlineBufferSource
  • translucent: boolean

说明:

TODO

private void renderBreakingBlockModelSubmits(SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource) @ L142

  • 方法名:renderBreakingBlockModelSubmits
  • 源码定位:L142
  • 返回类型:void
  • 修饰符:private

参数:

  • nodeCollection: SubmitNodeCollection
  • bufferSource: MultiBufferSource.BufferSource

说明:

TODO

private static void putPartQuads(BlockStateModelPart part, PoseStack.Pose pose, QuadInstance quadInstance, int[] tintLayers, VertexConsumer buffer, VertexConsumer outlineBuffer) @ L164

  • 方法名:putPartQuads
  • 源码定位:L164
  • 返回类型:void
  • 修饰符:private static

参数:

  • part: BlockStateModelPart
  • pose: PoseStack.Pose
  • quadInstance: QuadInstance
  • tintLayers: int[]
  • buffer: VertexConsumer
  • outlineBuffer: VertexConsumer

说明:

TODO

private static void putQuad(PoseStack.Pose pose, BakedQuad quad, QuadInstance instance, int[] tintLayers, VertexConsumer buffer, VertexConsumer outlineBuffer) @ L183

  • 方法名:putQuad
  • 源码定位:L183
  • 返回类型:void
  • 修饰符:private static

参数:

  • pose: PoseStack.Pose
  • quad: BakedQuad
  • instance: QuadInstance
  • tintLayers: int[]
  • buffer: VertexConsumer
  • outlineBuffer: VertexConsumer

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class BlockFeatureRenderer {
    private static final Direction[] DIRECTIONS = Direction.values();
    private static final int[] NO_TINT = new int[0];
    private final QuadInstance quadInstance = new QuadInstance();
    private final RandomSource random = RandomSource.createThreadLocalInstance(0L);
    private final List<BlockStateModelPart> parts = new ArrayList<>();
 
    public void renderSolid(
        SubmitNodeCollection nodeCollection,
        MultiBufferSource.BufferSource bufferSource,
        BlockStateModelSet blockStateModelSet,
        OutlineBufferSource outlineBufferSource,
        OptionsRenderState optionsState
    ) {
        this.renderMovingBlockSubmits(nodeCollection, bufferSource, blockStateModelSet, optionsState, false);
        this.renderBlockModelSubmits(nodeCollection, bufferSource, outlineBufferSource, false);
    }
 
    public void renderTranslucent(
        SubmitNodeCollection nodeCollection,
        MultiBufferSource.BufferSource bufferSource,
        BlockStateModelSet blockStateModelSet,
        OutlineBufferSource outlineBufferSource,
        MultiBufferSource.BufferSource crumblingBufferSource,
        OptionsRenderState optionsState
    ) {
        this.renderMovingBlockSubmits(nodeCollection, bufferSource, blockStateModelSet, optionsState, true);
        this.renderBlockModelSubmits(nodeCollection, bufferSource, outlineBufferSource, true);
        this.renderBreakingBlockModelSubmits(nodeCollection, crumblingBufferSource);
    }
 
    private void renderMovingBlockSubmits(
        SubmitNodeCollection nodeCollection,
        MultiBufferSource.BufferSource bufferSource,
        BlockStateModelSet blockStateModelSet,
        OptionsRenderState optionsState,
        boolean translucent
    ) {
        PoseStack poseStack = new PoseStack();
        BlockQuadOutput output = (x, y, z, quad, instance) -> putBakedQuad(poseStack, bufferSource, x, y, z, quad, instance, quad.materialInfo().layer());
        BlockQuadOutput solidOutput = (x, y, z, quad, instance) -> putBakedQuad(poseStack, bufferSource, x, y, z, quad, instance, ChunkSectionLayer.SOLID);
        Minecraft minecraft = Minecraft.getInstance();
        boolean ambientOcclusion = optionsState.ambientOcclusion;
        boolean cutoutLeaves = optionsState.cutoutLeaves;
        ModelBlockRenderer blockRenderer = new ModelBlockRenderer(ambientOcclusion, false, minecraft.getBlockColors());
 
        for (SubmitNodeStorage.MovingBlockSubmit submit : nodeCollection.getMovingBlockSubmits()) {
            MovingBlockRenderState movingBlockRenderState = submit.movingBlockRenderState();
            BlockState blockState = movingBlockRenderState.blockState;
            BlockStateModel model = blockStateModelSet.get(blockState);
            if (model.hasMaterialFlag(1) == translucent) {
                poseStack.setIdentity();
                poseStack.mulPose(submit.pose());
                BlockQuadOutput blockOutput = ModelBlockRenderer.forceOpaque(cutoutLeaves, blockState) ? solidOutput : output;
                long blockSeed = blockState.getSeed(movingBlockRenderState.randomSeedPos);
                blockRenderer.tesselateBlock(
                    blockOutput, 0.0F, 0.0F, 0.0F, movingBlockRenderState, movingBlockRenderState.blockPos, blockState, model, blockSeed
                );
            }
        }
    }
 
    private static void putBakedQuad(
        PoseStack poseStack,
        MultiBufferSource.BufferSource bufferSource,
        float x,
        float y,
        float z,
        BakedQuad quad,
        QuadInstance instance,
        ChunkSectionLayer layer
    ) {
        poseStack.pushPose();
        poseStack.translate(x, y, z);
 
        VertexConsumer buffer = bufferSource.getBuffer(switch (layer) {
            case SOLID -> RenderTypes.solidMovingBlock();
            case CUTOUT -> RenderTypes.cutoutMovingBlock();
            case TRANSLUCENT -> RenderTypes.translucentMovingBlock();
        });
        buffer.putBakedQuad(poseStack.last(), quad, instance);
        poseStack.popPose();
    }
 
    private void renderBlockModelSubmits(
        SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource, OutlineBufferSource outlineBufferSource, boolean translucent
    ) {
        for (SubmitNodeStorage.BlockModelSubmit submit : nodeCollection.getBlockModelSubmits()) {
            if (submit.renderType().hasBlending() == translucent) {
                VertexConsumer buffer = bufferSource.getBuffer(submit.renderType());
                VertexConsumer outlineBuffer;
                if (submit.outlineColor() != 0) {
                    outlineBufferSource.setColor(submit.outlineColor());
                    outlineBuffer = outlineBufferSource.getBuffer(submit.renderType());
                } else {
                    outlineBuffer = null;
                }
 
                this.quadInstance.setLightCoords(submit.lightCoords());
                this.quadInstance.setOverlayCoords(submit.overlayCoords());
 
                for (BlockStateModelPart part : submit.modelParts()) {
                    putPartQuads(part, submit.pose(), this.quadInstance, submit.tintLayers(), buffer, outlineBuffer);
                }
            }
        }
    }
 
    private void renderBreakingBlockModelSubmits(SubmitNodeCollection nodeCollection, MultiBufferSource.BufferSource bufferSource) {
        this.quadInstance.setLightCoords(15728880);
        this.quadInstance.setOverlayCoords(OverlayTexture.NO_OVERLAY);
 
        for (SubmitNodeStorage.BreakingBlockModelSubmit submit : nodeCollection.getBreakingBlockModelSubmits()) {
            VertexConsumer buffer = new SheetedDecalTextureGenerator(
                bufferSource.getBuffer(ModelBakery.DESTROY_TYPES.get(submit.progress())), submit.pose(), 1.0F
            );
            this.random.setSeed(submit.seed());
 
            try {
                submit.model().collectParts(this.random, this.parts);
 
                for (BlockStateModelPart part : this.parts) {
                    putPartQuads(part, submit.pose(), this.quadInstance, NO_TINT, buffer, null);
                }
            } finally {
                this.parts.clear();
            }
        }
    }
 
    private static void putPartQuads(
        BlockStateModelPart part,
        PoseStack.Pose pose,
        QuadInstance quadInstance,
        int[] tintLayers,
        VertexConsumer buffer,
        @Nullable VertexConsumer outlineBuffer
    ) {
        for (Direction direction : DIRECTIONS) {
            for (BakedQuad quad : part.getQuads(direction)) {
                putQuad(pose, quad, quadInstance, tintLayers, buffer, outlineBuffer);
            }
        }
 
        for (BakedQuad quad : part.getQuads(null)) {
            putQuad(pose, quad, quadInstance, tintLayers, buffer, outlineBuffer);
        }
    }
 
    private static void putQuad(
        PoseStack.Pose pose, BakedQuad quad, QuadInstance instance, int[] tintLayers, VertexConsumer buffer, @Nullable VertexConsumer outlineBuffer
    ) {
        int tintIndex = quad.materialInfo().tintIndex();
        boolean tintColor = tintIndex != -1 && tintIndex < tintLayers.length;
        instance.setColor(tintColor ? tintLayers[tintIndex] : -1);
        buffer.putBakedQuad(pose, quad, instance);
        if (outlineBuffer != null) {
            outlineBuffer.putBakedQuad(pose, quad, instance);
        }
    }
}

引用的其他类