Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading