TrueCraft
TrueCraft copied to clipboard
Lighting errors (server)
I've noticed two problems with lighting that need to be addressed:
- Deleting a semitransparent block (like leaves of a tree) will not update the blocks underneath it correctly
- Something is wrong with the way light propagates horizontally, we should have a unit test that covers propagation across all four cardinal directions
This might not be the issue but the heightmap calculation in WorldLighting doens't work properly. It seems that the chunk heightmap isn't correctly updated, which throws off the lighting because it starts at chunk.GetHeight() + 2. Grass, dirt, stone, and bedrock don't seem to count in the heightmap calculation, so for most blocks the chunk heightmap is 0 and the light heightmap is 2. This might be breaking the skylight field in LightingOperation and causing the incorrect light values.
I don't follow why starting from chunk.GetHeight() + 2 causes issues.
Because GetHeight() returns 0, so the search starts at 2, and immediately ends because level 2 is usually an opaque block.
Why would GetHeight return 0? It returns the height of that column.
I think it's because this loop doesn't break once it hits a solid block.
// Shift height downwards
while (coordinates.Y > 0)
{
coordinates.Y--;
if (GetBlockID(coordinates) != 0)
{
SetHeight((byte)coordinates.X, (byte)coordinates.Z, coordinates.Y);
if (coordinates.Y > MaxHeight)
MaxHeight = coordinates.Y;
// Should break here;
}
}
Huh. That's very odd. I feel like that should be causing unit tests failures all over the place.
Something is wrong with the way light propagates horizontally, we should have a unit test that covers propagation across all four cardinal directions
This is the only one of the two issues that remains.