Skip to content

Commit

Permalink
Merge pull request #295 from PepperCode1/pr/1.20.x/main/fix-model-offset
Browse files Browse the repository at this point in the history
Fix non-terrain model offset
  • Loading branch information
comp500 authored Jun 10, 2024
2 parents c8648d2 + 4960ac9 commit 8e5a2e6
Showing 1 changed file with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
}

0 comments on commit 8e5a2e6

Please sign in to comment.