From d331d314d880dadc55cf02a45fa947c25e0f8476 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Thu, 30 May 2024 01:21:55 -0700 Subject: [PATCH] Fix model offset being ignored in non-terrain rendering (#3799) - Add exception handling to BlockRenderContext#render to match vanilla (cherry picked from commit 8d125e3b6f2a97faa073af8ea95c197fd7a2ceb1) --- .../renderer/render/BlockRenderContext.java | 42 ++++++++++++------- .../renderer/render/TerrainRenderContext.java | 4 +- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/BlockRenderContext.java b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/BlockRenderContext.java index 88e6dd9f86..7e304d8d60 100644 --- a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/BlockRenderContext.java +++ b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/BlockRenderContext.java @@ -21,7 +21,11 @@ import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.crash.CrashException; +import net.minecraft.util.crash.CrashReport; +import net.minecraft.util.crash.CrashReportSection; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.random.Random; import net.minecraft.world.BlockRenderView; @@ -55,23 +59,33 @@ protected VertexConsumer getVertexConsumer(RenderLayer layer) { } public void render(BlockRenderView blockView, BakedModel model, BlockState state, BlockPos pos, MatrixStack matrixStack, VertexConsumer buffer, boolean cull, Random random, long seed, int overlay) { - this.vertexConsumer = buffer; - this.matrix = matrixStack.peek().getPositionMatrix(); - this.normalMatrix = matrixStack.peek().getNormalMatrix(); - this.overlay = overlay; + try { + Vec3d offset = state.getModelOffset(blockView, pos); + matrixStack.translate(offset.x, offset.y, offset.z); - blockInfo.random = random; - blockInfo.seed = seed; - blockInfo.recomputeSeed = false; + this.vertexConsumer = buffer; + this.matrix = matrixStack.peek().getPositionMatrix(); + this.normalMatrix = matrixStack.peek().getNormalMatrix(); + this.overlay = overlay; - aoCalc.clear(); - blockInfo.prepareForWorld(blockView, cull); - blockInfo.prepareForBlock(state, pos, model.useAmbientOcclusion()); + blockInfo.random = random; + blockInfo.seed = seed; + blockInfo.recomputeSeed = false; - model.emitBlockQuads(blockView, state, pos, blockInfo.randomSupplier, this); + aoCalc.clear(); + blockInfo.prepareForWorld(blockView, cull); + blockInfo.prepareForBlock(state, pos, model.useAmbientOcclusion()); - blockInfo.release(); - blockInfo.random = null; - this.vertexConsumer = null; + model.emitBlockQuads(blockView, state, pos, blockInfo.randomSupplier, this); + } catch (Throwable throwable) { + CrashReport crashReport = CrashReport.create(throwable, "Tessellating block model - Indigo Renderer"); + CrashReportSection crashReportSection = crashReport.addElement("Block model being tessellated"); + CrashReportSection.addBlockInfo(crashReportSection, blockView, pos, state); + throw new CrashException(crashReport); + } finally { + blockInfo.release(); + blockInfo.random = null; + this.vertexConsumer = null; + } } } diff --git a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/TerrainRenderContext.java b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/TerrainRenderContext.java index 2aa5e8f2cc..bb29700a76 100644 --- a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/TerrainRenderContext.java +++ b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/render/TerrainRenderContext.java @@ -85,8 +85,8 @@ public void release() { /** Called from chunk renderer hook. */ public void tessellateBlock(BlockState blockState, BlockPos blockPos, final BakedModel model, MatrixStack matrixStack) { try { - Vec3d vec3d = blockState.getModelOffset(chunkInfo.blockView, blockPos); - matrixStack.translate(vec3d.x, vec3d.y, vec3d.z); + Vec3d offset = blockState.getModelOffset(chunkInfo.blockView, blockPos); + matrixStack.translate(offset.x, offset.y, offset.z); this.matrix = matrixStack.peek().getPositionMatrix(); this.normalMatrix = matrixStack.peek().getNormalMatrix();