clear top and bottom chunk light

This commit is contained in:
Bixilon 2022-10-12 18:51:52 +02:00
parent 575b60baab
commit 3404348bff
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 47 additions and 2 deletions

View File

@ -155,6 +155,38 @@ class BorderSectionLight(
}
}
internal fun decreaseCheckLevel(x: Int, z: Int, light: Int, reset: Boolean) {
decreaseCheckX(z, light, reset)
val neighbours = chunk.neighbours ?: return
if (x - light < 0) {
neighbours[ChunkNeighbours.WEST].getBorderLight().decreaseCheckX(z, light - x, reset)
}
if (x + light > ProtocolDefinition.SECTION_MAX_X) {
neighbours[ChunkNeighbours.EAST].getBorderLight().decreaseCheckX(z, light - (ProtocolDefinition.SECTION_MAX_X - x), reset)
}
}
private fun decreaseCheckX(z: Int, light: Int, reset: Boolean) {
val neighbours = chunk.neighbours ?: return
if (reset) reset()
if (z - light < 0) {
val neighbour = neighbours[ChunkNeighbours.NORTH].getBorderLight()
if (reset) neighbour.reset()
}
if (z + light > ProtocolDefinition.SECTION_MAX_Z) {
val neighbour = neighbours[ChunkNeighbours.SOUTH].getBorderLight()
if (reset) neighbour.reset()
}
}
fun reset() {
for (i in light.indices) {
light[i] = 0x00
}
}
fun update(array: ByteArray) {
// ToDo: Save light from server
}

View File

@ -122,6 +122,8 @@ class ChunkLight(private val chunk: Chunk) {
}
fun recalculate(fireEvent: Boolean = true, fireSameChunkEvent: Boolean = true) {
bottom.reset()
top.reset()
val sections = chunk.sections ?: Broken("Sections is null")
for (section in sections) {
if (section == null) {
@ -157,6 +159,8 @@ class ChunkLight(private val chunk: Chunk) {
}
section.light.reset()
}
bottom.reset()
top.reset()
}
fun propagateFromNeighbours(fireEvent: Boolean = true, fireSameChunkEvent: Boolean = true) {

View File

@ -64,11 +64,20 @@ class SectionLight(
decreaseCheckLevel(x, z, light, reset)
val neighbours = section.neighbours ?: return
val chunk = section.chunk
if (y - light < 0) {
neighbours[Directions.O_DOWN]?.light?.decreaseCheckLevel(x, z, light - y, reset)
if (section.sectionHeight == chunk?.lowestSection) {
chunk.light.bottom.decreaseCheckLevel(x, z, light - y, reset)
} else {
neighbours[Directions.O_DOWN]?.light?.decreaseCheckLevel(x, z, light - y, reset)
}
}
if (y + light > ProtocolDefinition.SECTION_MAX_Y) {
neighbours[Directions.O_UP]?.light?.decreaseCheckLevel(x, z, light - (ProtocolDefinition.SECTION_MAX_Y - y), reset)
if (section.sectionHeight == chunk?.highestSection) {
chunk.light.top.decreaseCheckLevel(x, z, light - (ProtocolDefinition.SECTION_MAX_Y - y), reset)
} else {
neighbours[Directions.O_UP]?.light?.decreaseCheckLevel(x, z, light - (ProtocolDefinition.SECTION_MAX_Y - y), reset)
}
}
}