mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
clear top and bottom chunk light
This commit is contained in:
parent
575b60baab
commit
3404348bff
@ -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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user