From fba649a0974b9ace41e5ab2c0e9aed3ec1994fba Mon Sep 17 00:00:00 2001 From: cafe <73342801+notsocafe@users.noreply.github.com> Date: Sat, 28 Nov 2026 01:45:30 +0100 Subject: [PATCH] Keep emitting blocks at their own light level during propagation LightingEngine.spreadLightFromCursor pushes a value of (source light - opacity) to each neighbour that is brighter than it currently is. It never compares that value with the neighbour's own emission. A neighbour that emits light but is not itself scheduled for an update, such as lava at level 15, can therefore receive a propagated value lower than its emission and keep it. Observed on a client connected to a remote server, in a fresh Nether lava lake: the lighting engine wrote lava blocks with values from 1 to 14, never 15, 2311 times in 25 seconds. The air directly above the lava stayed dark, which appeared as dark patches on the lava surface. The patches did not clear with F3+A, which rebuilds render sections but does not change stored light, so the stored values themselves were wrong. The same scenario in singleplayer did not show the problem. The cause of this difference has not been identified; the fix does not depend on it. The fix takes the maximum of the propagated value and the neighbour's own block light, computed with the same LightUtil helper the initial calculation already uses: newLight = max(propagatedLight, ownLight) ownLight is only used for block light. Sky light has no per-block emission in this calculation, so its value is unchanged. Behaviour after the fix: - The diagnostic log no longer reports any lava block below 15 on the client. - The dark patches are gone in game, on the remote server. - A residual case remains: air directly above lava can settle at 13 instead of 14 when it is reached first from a lateral neighbour. It is one light level and was not visible in game. Correcting it would need propagation to pull from every neighbour, not only the one pushing, which is a larger change and is not part of this commit. --- .../dev/redstudio/alfheim/lighting/LightingEngine.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/redstudio/alfheim/lighting/LightingEngine.java b/src/main/java/dev/redstudio/alfheim/lighting/LightingEngine.java index 6d2249e..ab8745d 100644 --- a/src/main/java/dev/redstudio/alfheim/lighting/LightingEngine.java +++ b/src/main/java/dev/redstudio/alfheim/lighting/LightingEngine.java @@ -443,7 +443,12 @@ private void spreadLightFromCursor(final byte currentLight, final EnumSkyBlock l final BlockPos neighborBlockPos = neighborInfo.mutableBlockPos; - final byte newLight = (byte) (currentLight - getPosOpacity(neighborBlockPos, neighborChunk.getBlockState(neighborBlockPos), neighborChunk)); + final IBlockState neighborState = neighborChunk.getBlockState(neighborBlockPos); + final byte propagatedLight = (byte) (currentLight - getPosOpacity(neighborBlockPos, neighborState, neighborChunk)); + // A neighbour reached by propagation must not drop below its own emission: an emitting block (e.g. lava at 15) that is not scheduled itself would otherwise keep the lower value. + // Sky light is excluded because its source is the sky, not the block itself. + final byte ownLight = lightType == EnumSkyBlock.BLOCK ? (byte) ClampUtil.clampMinFirst(LightUtil.getLightValueForPos(neighborState, world, neighborBlockPos, neighborChunk), 0, MAX_LIGHT_LEVEL) : 0; + final byte newLight = (byte) Math.max(propagatedLight, ownLight); if (newLight > neighborInfo.light) enqueueBrightening(neighborBlockPos, neighborInfo.key, newLight, neighborChunk, lightType);