skylight: properly check heightmap

Everything ABOVE the heightmap should be 0xF0 and not EQUALS.
This commit is contained in:
Bixilon 2022-10-11 18:23:17 +02:00
parent b44dd7eaef
commit c067c0e1f9
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 9 additions and 4 deletions

View File

@ -114,7 +114,7 @@ class ChunkLight(private val chunk: Chunk) {
return top[index].toInt() or 0xF0 // top has always sky=15
}
var light = chunk[sectionHeight]?.light?.get(index)?.toInt() ?: 0x00
if (y >= heightmap[heightmapIndex]) {
if (y > heightmap[heightmapIndex]) {
// set sky=15
light = light or 0xF0
}
@ -203,9 +203,14 @@ class ChunkLight(private val chunk: Chunk) {
for (sectionY in ProtocolDefinition.SECTION_MAX_Y downTo 0) {
val light = section.blocks.unsafeGet(x, sectionY, z)?.lightProperties ?: continue
if (light.propagatesSkylight) {
// can go through block
continue
}
y = (sectionIndex + chunk.lowestSection) * ProtocolDefinition.SECTION_HEIGHT_Y + sectionY
if (light.propagatesLight(Directions.UP)) {
// can enter the block, but not leave
y--
}
section.release()
break@sectionLoop
}
@ -360,7 +365,7 @@ class ChunkLight(private val chunk: Chunk) {
val maxSection = chunk.sections?.get(maxHeight.sectionHeight - chunk.lowestSection)
val baseY = sectionHeight * ProtocolDefinition.SECTION_HEIGHT_Y
if (maxSection != null) {
for (y in (if (skylightStart.sectionHeight != sectionHeight) ProtocolDefinition.SECTION_MAX_Y else skylightStart.inSectionHeight) downTo maxHeight.inSectionHeight + 1) {
for (y in (if (skylightStart.sectionHeight != sectionHeight) ProtocolDefinition.SECTION_MAX_Y else skylightStart.inSectionHeight) downTo maxHeight.inSectionHeight) {
maxSection.light.traceSkylightIncrease(x, y, z, ProtocolDefinition.MAX_LIGHT_LEVEL.toInt(), null, baseY + y, false)
}
maxSection.light.update = true

View File

@ -307,7 +307,7 @@ class SectionLight(
fun traceSkylightIncrease(x: Int, y: Int, z: Int, nextLevel: Int, target: Directions?, totalY: Int, noForce: Boolean) {
val chunk = section.chunk ?: Broken("chunk == null")
val heightmapIndex = (z shl 4) or x
if (noForce && totalY >= chunk.light.heightmap[heightmapIndex]) {
if (noForce && totalY > chunk.light.heightmap[heightmapIndex]) {
// this light level will be 15, don't care
return
}
@ -450,7 +450,7 @@ class SectionLight(
// check if neighbours are above heightmap, if so set light level to max
val chunkNeighbours = it.neighbours ?: return@let
val minHeight = it.light.getNeighbourMinHeight(chunkNeighbours, x, z)
if (minHeight <= totalY) {
if (totalY > minHeight) {
skylight = ProtocolDefinition.MAX_LIGHT_LEVEL.toInt()
}
}