From 7ff14d8fde70e1337f14e9a460df7d94918733e0 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Tue, 4 Oct 2022 23:19:21 +0200 Subject: [PATCH] heightmap: properly respect world height, fix crash when starting from above world height --- .../minosoft/data/world/chunk/light/ChunkLight.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/data/world/chunk/light/ChunkLight.kt b/src/main/java/de/bixilon/minosoft/data/world/chunk/light/ChunkLight.kt index e6def5573..8fc6bb257 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/chunk/light/ChunkLight.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/chunk/light/ChunkLight.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger and contributors + * Copyright (C) 2020-2022 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -192,7 +192,11 @@ class ChunkLight(private val chunk: Chunk) { var y = minY - sectionLoop@ for (sectionIndex in startY.sectionHeight downTo 0) { + sectionLoop@ for (sectionIndex in (startY.sectionHeight - chunk.lowestSection) downTo chunk.lowestSection * ProtocolDefinition.SECTION_HEIGHT_Y) { + if (sectionIndex >= sections.size) { + // starting from above world + continue + } val section = sections[sectionIndex] ?: continue section.acquire() @@ -368,6 +372,7 @@ class ChunkLight(private val chunk: Chunk) { } fun recalculateSkylight(sectionHeight: Int) { -// TODO + val minY = sectionHeight * ProtocolDefinition.SECTION_HEIGHT_Y + // TODO } }