From 83ab7656c937b8dcd568a8d77cd2062be5329909 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Wed, 21 Jun 2023 13:30:36 -0500 Subject: [PATCH] Fix experimental lighting pipeline breaking vanilla's emissive rendering. Closes #9552 (#9582) --- .../client/model/lighting/FlatQuadLighter.java | 5 +++-- .../client/model/lighting/QuadLighter.java | 18 ++++++++++++++++++ .../model/lighting/SmoothQuadLighter.java | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/lighting/FlatQuadLighter.java b/src/main/java/net/minecraftforge/client/model/lighting/FlatQuadLighter.java index 7aa273bc90..2e6ddc66b6 100644 --- a/src/main/java/net/minecraftforge/client/model/lighting/FlatQuadLighter.java +++ b/src/main/java/net/minecraftforge/client/model/lighting/FlatQuadLighter.java @@ -38,9 +38,10 @@ public class FlatQuadLighter extends QuadLighter isFullCube = Block.isShapeFullBlock(state.getCollisionShape(level, pos)); for (Direction side : SIDES) { - packedLight[side.ordinal()] = LevelRenderer.getLightColor(level, pos.relative(side)); + packedLight[side.ordinal()] = getLightColor(level, pos.relative(side), state); } - packedLight[6] = LevelRenderer.getLightColor(level, pos); + //Note: We can just use the LevelRenderer method as we know the state is the state at the given position + packedLight[6] = LevelRenderer.getLightColor(level, state, pos); } @Override diff --git a/src/main/java/net/minecraftforge/client/model/lighting/QuadLighter.java b/src/main/java/net/minecraftforge/client/model/lighting/QuadLighter.java index 3dc9d25b34..baf3abe579 100644 --- a/src/main/java/net/minecraftforge/client/model/lighting/QuadLighter.java +++ b/src/main/java/net/minecraftforge/client/model/lighting/QuadLighter.java @@ -8,9 +8,11 @@ package net.minecraftforge.client.model.lighting; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.block.state.BlockState; import org.joml.Vector3f; @@ -150,4 +152,20 @@ public abstract class QuadLighter float yFactor = constantAmbientLight ? 0.9F : ((3.0F + normalY) / 4.0F); return Math.min(normalX * normalX * 0.6F + normalY * normalY * yFactor + normalZ * normalZ * 0.8F, 1.0F); } + + /** + * Note: This method is subtly different than {@link net.minecraft.client.renderer.LevelRenderer#getLightColor(BlockAndTintGetter, BlockState, BlockPos)} + * as it only uses the state for querying if the state has emissive rendering but instead looks up the state at the given position for checking the + * light emission. + */ + protected static int getLightColor(BlockAndTintGetter level, BlockPos pos, BlockState state) + { + if (state.emissiveRendering(level, pos)) + { + return LightTexture.FULL_BRIGHT; + } + int skyLight = level.getBrightness(LightLayer.SKY, pos); + int blockLight = Math.max(level.getBrightness(LightLayer.BLOCK, pos), level.getBlockState(pos).getLightEmission(level, pos)); + return skyLight << 20 | blockLight << 4; + } } diff --git a/src/main/java/net/minecraftforge/client/model/lighting/SmoothQuadLighter.java b/src/main/java/net/minecraftforge/client/model/lighting/SmoothQuadLighter.java index 248ce63bc6..6c39f2be1f 100644 --- a/src/main/java/net/minecraftforge/client/model/lighting/SmoothQuadLighter.java +++ b/src/main/java/net/minecraftforge/client/model/lighting/SmoothQuadLighter.java @@ -50,7 +50,7 @@ public class SmoothQuadLighter extends QuadLighter pos.setWithOffset(origin, x - 1, y - 1, z - 1); BlockState neighborState = level.getBlockState(pos); t[x][y][z] = neighborState.getLightBlock(level, pos) < 15; - int brightness = LevelRenderer.getLightColor(level, pos); + int brightness = getLightColor(level, pos, state); s[x][y][z] = LightTexture.sky(brightness); b[x][y][z] = LightTexture.block(brightness); ao[x][y][z] = neighborState.getShadeBrightness(level, pos);