From d2d45008b048f1c1c46ecb37753b7aac6f2f7925 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 25 Mar 2025 20:19:22 +0100 Subject: [PATCH] heightmap: use section height index is prune to errors and not very natural --- .../data/world/chunk/heightmap/ChunkHeightmap.kt | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/data/world/chunk/heightmap/ChunkHeightmap.kt b/src/main/java/de/bixilon/minosoft/data/world/chunk/heightmap/ChunkHeightmap.kt index e9818a9ef..2c47b416e 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/chunk/heightmap/ChunkHeightmap.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/chunk/heightmap/ChunkHeightmap.kt @@ -43,17 +43,11 @@ abstract class ChunkHeightmap(protected val chunk: Chunk) : Heightmap { } private fun trace(position: InChunkPosition, notify: Boolean) { - val sections = chunk.sections - var y = Int.MIN_VALUE val index = position.xz - sectionLoop@ for (sectionIndex in (position.y.sectionHeight - chunk.minSection) downTo 0) { - if (sectionIndex >= sections.size) { - // starting from above world - continue - } - val section = sections[sectionIndex] ?: continue + sectionLoop@ for (sectionHeight in position.y.sectionHeight downTo chunk.minSection) { + val section = chunk[sectionHeight] ?: continue if (section.blocks.isEmpty) continue val min = section.blocks.minPosition @@ -63,11 +57,11 @@ abstract class ChunkHeightmap(protected val chunk: Chunk) : Heightmap { for (sectionY in max.y downTo min.y) { - val state = section.blocks[InSectionPosition((sectionY shl 8) or index)] ?: continue + val state = section.blocks[InSectionPosition(index).with(y = sectionY)] ?: continue val pass = passes(state) if (pass == HeightmapPass.PASSES) continue - y = (sectionIndex + chunk.minSection) * ProtocolDefinition.SECTION_HEIGHT_Y + sectionY + y = sectionHeight * ProtocolDefinition.SECTION_HEIGHT_Y + sectionY if (pass == HeightmapPass.ABOVE) y++ break@sectionLoop