mojira.dev
MC-117412

Heightmap min value not set when loading chunk from NBT

The bug

Note: The following is based on decompiled code, using MCP naming.

The minimum heightmap value for a chunk is currently set when the heightmap is populated either by chunk generation on the server, or by a chunk data packet being received by the client. However, it is not set when a chunk is read from NBT (see AnvilChunkLoader#readChunkFromNBT()).

This means that server-side, any chunk not freshly generated will have a heightmap minimum of 0.
The main effect of this is that lighting checks performed by Chunk#recheckGaps() will call World#checkLightFor() for all y-values between 0 and the heightmap value for that column (+1), instead of a reduced range.

Possible fix

The heightMapMinimum field should be updated when the heightmap is set in Chunk#setHeightMap(). For example:

public void setHeightMap(int[] newHeightMap)
{
    if (this.heightMap.length != newHeightMap.length)
    {
        LOGGER.warn("Could not set level chunk heightmap, array length is {} instead of {}", newHeightMap.length, this.heightMap.length);
    }
    else
    {
        System.arraycopy(newHeightMap, 0, this.heightMap, 0, this.heightMap.length);
        // *update heightmap min value here*
    }
}

Comments 1

Can this still be reproduced in the latest 1.16 development snapshot?

Ben Staddon

(Unassigned)

Confirmed

Lighting

chunk, chunk-loading, height, lighting, nbt

Minecraft 1.11.2, Minecraft 1.12.2, Minecraft 1.13.2

Retrieved