From d3a5786642aea78c415bf511013e75f34dc2c500 Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Thu, 25 Jun 2020 18:55:48 +0200 Subject: [PATCH] world: work around Minecraft lighting nonsense Minecraft occasionally generates chunks which are not yet lit. In the past, I'd have said to just make them not render, but these can sometimes be large areas of the world. Instead, render them with full bright SkyLight. This looks less bad than whatever is stored in the SkyLight property in these cases. Closes #1787, probably. Only one person bothered providing a sample file. --- overviewer_core/world.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/overviewer_core/world.py b/overviewer_core/world.py index e121002..5dcecad 100644 --- a/overviewer_core/world.py +++ b/overviewer_core/world.py @@ -1428,16 +1428,22 @@ class RegionSet(object): # Turn the skylight array into a 16x16x16 matrix. The array comes # packed 2 elements per byte, so we need to expand it. try: - if 'SkyLight' in section: - skylight = numpy.frombuffer(section['SkyLight'], dtype=numpy.uint8) - skylight = skylight.reshape((16,16,8)) - else: # Special case introduced with 1.14 - skylight = numpy.zeros((16,16,8), dtype=numpy.uint8) - skylight_expanded = numpy.empty((16,16,16), dtype=numpy.uint8) - skylight_expanded[:,:,::2] = skylight & 0x0F - skylight_expanded[:,:,1::2] = (skylight & 0xF0) >> 4 - del skylight - section['SkyLight'] = skylight_expanded + # Sometimes, Minecraft loves generating chunks with no light info. + # These mostly appear to have those two properties, and in this case + # we default to full-bright as it's less jarring to look at than all-black. + if chunk_data.get("Status", "") == "spawn" and 'Lights' in chunk_data: + section['SkyLight'] = numpy.full((16,16,16), 255, dtype=numpy.uint8) + else: + if 'SkyLight' in section: + skylight = numpy.frombuffer(section['SkyLight'], dtype=numpy.uint8) + skylight = skylight.reshape((16,16,8)) + else: # Special case introduced with 1.14 + skylight = numpy.zeros((16,16,8), dtype=numpy.uint8) + skylight_expanded = numpy.empty((16,16,16), dtype=numpy.uint8) + skylight_expanded[:,:,::2] = skylight & 0x0F + skylight_expanded[:,:,1::2] = (skylight & 0xF0) >> 4 + del skylight + section['SkyLight'] = skylight_expanded # Turn the BlockLight array into a 16x16x16 matrix, same as SkyLight if 'BlockLight' in section: