Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-170012

Lightmaps are missing for initial skylight

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 23w16a
    • 1.15.1, 1.15.2 Pre-release 2, 1.15.2, 20w06a, 20w20b, 20w21a, 1.16.2, 1.16.4, 20w48a, 1.17, 1.17.1 Pre-release 1, 1.17.1, 21w37a, 21w40a, 1.18, 1.19 Pre-release 3
    • Confirmed
    • Lighting
    • Important

      Upon initial lighting of a chunk, skylight (and blocklight which doesn't matter here) is directly propagated to all neighbors. However, those neighbors might not have their lightmaps set up correctly, yet.
      Non-empty subchunks are only registered during initial lighting

      net.minecraft.world.ServerLightingProvider.java
      public CompletableFuture<Chunk> light(Chunk chunk, boolean bl) {
          ChunkPos chunkPos = chunk.getPos();
          chunk.setLightOn(false);
          this.enqueue(chunkPos.x, chunkPos.z, ServerLightingProvider.Stage.PRE_UPDATE, Util.debugRunnable(() -> {
              ChunkSection[] chunkSections = chunk.getSectionArray();
      
              for(int i = 0; i < 16; ++i) {
                  ChunkSection chunkSection = chunkSections[i];
                  if (!ChunkSection.isEmpty(chunkSection)) {
                      super.updateSectionStatus(ChunkSectionPos.from(chunkPos, i), false);
                  }
              }
              ...
      

      This means that during initial lighting, neighbor chunks might have not yet registered their non-empty subchunks and hence lightmaps might not have been setup yet correctly.
      This can cause skylight updates to get stuck at missing lightmaps. When later on the missing lightmaps get created during initial lighting of the neighbor chunks, those lightmaps will be initialized by copying down the skylight values from the lightmap above it. Hence, if such a subchunk contains any blocks but did not have a lightmap associated to it, the lightmap will now be initialized to wrong values, making the subchunk erroneously bright.

      As a concrete example, I will use "erase cached data" in order to force a relighting and hence simulate initial skylight on a well controlled geometry.

      • Create a new redstone-ready world
      • /tp 500 56 0
      • /fill 496 80 0 511 95 15 minecraft:stone hollow
      • /setblock 487 119 7 minecraft:stone
      • /tp @s 0 56 0 270 0
      • Optimize world -> erase cached data
      • Fly 500 blocks in +x direction and fly inside the stone cube using spectator mode

       

      Fortunately, this issue is quite easy to solve. Simply move the registration of non-empty subchunks outside of the initial lighting to some earlier stage. Concretely, add some pre_light stage to worldgen that registers all non-empty subchunks and require all neighbors to have passed this stage before running initial lighting for a chunk.

       

      Best,
      PhiPro

        1. 2020-01-18_00.26.19.png
          328 kB
          Philipp Provenzano
        2. 2021-06-26_19.53.43.png
          432 kB
          [Mod] ampolive

            Unassigned Unassigned
            PhiPro Philipp Provenzano
            Votes:
            25 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: