Fix model offset being ignored in non-terrain rendering (#3799)

- Add exception handling to BlockRenderContext#render to match vanilla

(cherry picked from commit 8d125e3b6f)
(cherry picked from commit d331d314d8)
This commit is contained in:
PepperCode1 2024-05-30 01:21:55 -07:00 committed by modmuss50
parent 1466179b97
commit 85287f9fcd
2 changed files with 30 additions and 16 deletions

View file

@ -21,7 +21,11 @@ import net.minecraft.client.render.RenderLayer;
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 @@ public class BlockRenderContext extends AbstractBlockRenderContext {
}
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;
}
}
}

View file

@ -85,8 +85,8 @@ public class TerrainRenderContext extends AbstractBlockRenderContext {
/** 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();