/* * Decompiled with CFR 0.152. */ package net.minecraft.client.renderer.block; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; import net.minecraft.ReportedException; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.SpecialBlockModelRenderer; import net.minecraft.client.renderer.block.BlockModelShaper; import net.minecraft.client.renderer.block.LiquidBlockRenderer; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.renderer.block.model.BlockModelPart; import net.minecraft.client.renderer.block.model.BlockStateModel; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.model.MaterialSet; import net.minecraft.core.BlockPos; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManagerReloadListener; import net.minecraft.util.RandomSource; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FluidState; public class BlockRenderDispatcher implements ResourceManagerReloadListener { private final BlockModelShaper blockModelShaper; private final MaterialSet materials; private final ModelBlockRenderer modelRenderer; private final Supplier specialBlockModelRenderer; private final LiquidBlockRenderer liquidBlockRenderer; private final RandomSource singleThreadRandom = RandomSource.create(); private final List singleThreadPartList = new ArrayList(); private final BlockColors blockColors; public BlockRenderDispatcher(BlockModelShaper blockModelShaper, MaterialSet materials, Supplier specialBlockModelRenderer, BlockColors blockColors) { this.blockModelShaper = blockModelShaper; this.materials = materials; this.specialBlockModelRenderer = specialBlockModelRenderer; this.blockColors = blockColors; this.modelRenderer = new ModelBlockRenderer(this.blockColors); this.liquidBlockRenderer = new LiquidBlockRenderer(); } public BlockModelShaper getBlockModelShaper() { return this.blockModelShaper; } public void renderBreakingTexture(BlockState state, BlockPos pos, BlockAndTintGetter level, PoseStack poseStack, VertexConsumer builder) { if (state.getRenderShape() != RenderShape.MODEL) { return; } BlockStateModel model = this.blockModelShaper.getBlockModel(state); this.singleThreadRandom.setSeed(state.getSeed(pos)); this.singleThreadPartList.clear(); model.collectParts(this.singleThreadRandom, this.singleThreadPartList); this.modelRenderer.tesselateBlock(level, this.singleThreadPartList, state, pos, poseStack, builder, true, OverlayTexture.NO_OVERLAY); } public void renderBatched(BlockState blockState, BlockPos pos, BlockAndTintGetter level, PoseStack poseStack, VertexConsumer builder, boolean cull, List parts) { try { this.modelRenderer.tesselateBlock(level, parts, blockState, pos, poseStack, builder, cull, OverlayTexture.NO_OVERLAY); } catch (Throwable t) { CrashReport report = CrashReport.forThrowable(t, "Tesselating block in world"); CrashReportCategory category = report.addCategory("Block being tesselated"); CrashReportCategory.populateBlockDetails(category, level, pos, blockState); throw new ReportedException(report); } } public void renderLiquid(BlockPos pos, BlockAndTintGetter level, VertexConsumer builder, BlockState blockState, FluidState fluidState) { try { this.liquidBlockRenderer.tesselate(level, pos, builder, blockState, fluidState); } catch (Throwable t) { CrashReport report = CrashReport.forThrowable(t, "Tesselating liquid in world"); CrashReportCategory category = report.addCategory("Block being tesselated"); CrashReportCategory.populateBlockDetails(category, level, pos, blockState); throw new ReportedException(report); } } public ModelBlockRenderer getModelRenderer() { return this.modelRenderer; } public BlockStateModel getBlockModel(BlockState state) { return this.blockModelShaper.getBlockModel(state); } public void renderSingleBlock(BlockState state, PoseStack poseStack, MultiBufferSource bufferSource, int lightCoords, int overlayCoords) { RenderShape shape = state.getRenderShape(); if (shape == RenderShape.INVISIBLE) { return; } BlockStateModel model = this.getBlockModel(state); int col = this.blockColors.getColor(state, null, null, 0); float r = (float)(col >> 16 & 0xFF) / 255.0f; float g = (float)(col >> 8 & 0xFF) / 255.0f; float b = (float)(col & 0xFF) / 255.0f; ModelBlockRenderer.renderModel(poseStack.last(), bufferSource.getBuffer(ItemBlockRenderTypes.getRenderType(state)), model, r, g, b, lightCoords, overlayCoords); } @Override public void onResourceManagerReload(ResourceManager resourceManager) { this.liquidBlockRenderer.setupSprites(this.blockModelShaper, this.materials); } }