skylight: don't trace above heightmap

* yep, there was a bug :)
This commit is contained in:
Bixilon 2022-09-25 20:57:11 +02:00
parent e00a32bb41
commit e0635f2d9e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 6 additions and 6 deletions

View File

@ -586,7 +586,7 @@ class Chunk(
// ToDo: bare tracing
val baseY = sectionHeight * ProtocolDefinition.SECTION_HEIGHT_Y
for (y in ProtocolDefinition.SECTION_MAX_Y downTo 0) {
section.light.traceSkylight(x, y, z, ProtocolDefinition.MAX_LIGHT_LEVEL.toInt(), null, baseY + y, true)
section.light.traceSkylight(x, y, z, ProtocolDefinition.MAX_LIGHT_LEVEL.toInt(), null, baseY + y, false)
}
}
val sectionHeight = maxHeight.sectionHeight
@ -599,7 +599,7 @@ class Chunk(
if (block != null && !block.propagatesSkylight) {
continue
}
maxSection.light.traceSkylight(x, y, z, ProtocolDefinition.MAX_LIGHT_LEVEL.toInt(), null, baseY + y, true)
maxSection.light.traceSkylight(x, y, z, ProtocolDefinition.MAX_LIGHT_LEVEL.toInt(), null, baseY + y, false)
}
maxSection.light.update = true

View File

@ -247,20 +247,20 @@ class SectionLight(
}
private inline fun traceSkylight(x: Int, y: Int, z: Int, nextLevel: Int, direction: Directions?, totalY: Int) {
return traceSkylight(x, y, z, nextLevel, direction, totalY, false)
return traceSkylight(x, y, z, nextLevel, direction, totalY, true)
}
fun traceSkylight(x: Int, y: Int, z: Int, nextLevel: Int, direction: Directions?, totalY: Int, force: Boolean) {
fun traceSkylight(x: Int, y: Int, z: Int, nextLevel: Int, direction: Directions?, totalY: Int, noForce: Boolean) {
val chunk = section.chunk ?: Broken("chunk == null")
if (direction == Directions.UP && totalY >= chunk.getMaxHeight(x, z)) {
if (noForce && totalY >= chunk.getMaxHeight(x, z)) {
// this light level will be 15, don't care
return
}
val chunkNeighbours = chunk.neighbours ?: return
val index = getIndex(x, y, z)
val currentLight = this[index].toInt()
if (!force && ((currentLight and SKY_LIGHT_MASK) shr 4) >= nextLevel) {
if (noForce && ((currentLight and SKY_LIGHT_MASK) shr 4) >= nextLevel) {
return
}