From 4960ac9b81d95743a00563a9d29bd543c0704798 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:40:17 -0700 Subject: [PATCH] Fix non-terrain model offset --- .../render/NonTerrainBlockRenderContext.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java b/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java index 897a011..180d6a4 100644 --- a/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java +++ b/src/main/java/link/infra/indium/renderer/render/NonTerrainBlockRenderContext.java @@ -24,7 +24,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; @@ -51,24 +55,34 @@ protected void bufferQuad(MutableQuadViewImpl quad, Material material) { } 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; + this.vertexConsumer = buffer; + this.matrix = matrixStack.peek().getPositionMatrix(); + this.normalMatrix = matrixStack.peek().getNormalMatrix(); + this.overlay = overlay; - aoCalc.clear(); - lightCache.reset(pos, blockView); - blockInfo.prepareForWorld(blockView, cull); - blockInfo.prepareForBlock(state, pos, seed, model.useAmbientOcclusion()); + blockInfo.random = random; - model.emitBlockQuads(blockView, state, pos, blockInfo.randomSupplier, this); + aoCalc.clear(); + lightCache.reset(pos, blockView); + blockInfo.prepareForWorld(blockView, cull); + blockInfo.prepareForBlock(state, pos, seed, model.useAmbientOcclusion()); - // blockInfo is thread-local, not cleaned up when leaving world (and could be called for arbitrary BlockRenderViews) - blockInfo.release(); - lightCache.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 - Indium Renderer"); + CrashReportSection crashReportSection = crashReport.addElement("Block model being tessellated"); + CrashReportSection.addBlockInfo(crashReportSection, blockView, pos, state); + throw new CrashException(crashReport); + } finally { + // blockInfo is thread-local, not cleaned up when leaving world (and could be called for arbitrary BlockRenderViews) + blockInfo.release(); + lightCache.release(); + blockInfo.random = null; + this.vertexConsumer = null; + } } }