Skip to content

Commit

Permalink
Fix model offset being ignored in non-terrain rendering (#3799)
Browse files Browse the repository at this point in the history
- Add exception handling to BlockRenderContext#render to match vanilla

(cherry picked from commit 8d125e3)
  • Loading branch information
PepperCode1 authored and modmuss50 committed May 30, 2024
1 parent 6605d1a commit d331d31
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d331d31

Please sign in to comment.