From f5c6fe8304a06e6eb4b985d63600c4f4a7ef94a8 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sun, 28 Aug 2022 22:52:18 +0200 Subject: [PATCH] light: properly recalculate solid block changes --- .../data/world/chunk/light/SectionLight.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/data/world/chunk/light/SectionLight.kt b/src/main/java/de/bixilon/minosoft/data/world/chunk/light/SectionLight.kt index e415d5696..fdcd8eadd 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/chunk/light/SectionLight.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/chunk/light/SectionLight.kt @@ -44,42 +44,45 @@ class SectionLight( // that is kind of hacky, but far easier and kind of faster val light = this.light[getIndex(x, y, z)].toInt() and 0x0F - decreaseLight(x, y, z, light) + decreaseLight(x, y, z, light, true) // just clear the light + decreaseLight(x, y, z, light, false) // } - private fun decreaseLight(x: Int, y: Int, z: Int, light: Int) { - decreaseCheckLevel(x, z, light) + private fun decreaseLight(x: Int, y: Int, z: Int, light: Int, reset: Boolean) { + decreaseCheckLevel(x, z, light, reset) val neighbours = section.neighbours ?: return if (y - light < 0) { - neighbours[Directions.O_DOWN]?.light?.decreaseCheckLevel(x, z, light - y) + 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)) + neighbours[Directions.O_UP]?.light?.decreaseCheckLevel(x, z, light - (ProtocolDefinition.SECTION_MAX_Y - y), reset) } } - private fun decreaseCheckLevel(x: Int, z: Int, light: Int) { - decreaseCheckX(z, light) + private fun decreaseCheckLevel(x: Int, z: Int, light: Int, reset: Boolean) { + decreaseCheckX(z, light, reset) val neighbours = section.neighbours ?: return if (x - light < 0) { - neighbours[Directions.O_WEST]?.light?.decreaseCheckX(z, light - x) + neighbours[Directions.O_WEST]?.light?.decreaseCheckX(z, light - x, reset) } if (x + light > ProtocolDefinition.SECTION_MAX_X) { - neighbours[Directions.O_EAST]?.light?.decreaseCheckX(z, light - (ProtocolDefinition.SECTION_MAX_X - x)) + neighbours[Directions.O_EAST]?.light?.decreaseCheckX(z, light - (ProtocolDefinition.SECTION_MAX_X - x), reset) } } - private fun decreaseCheckX(z: Int, light: Int) { + private fun decreaseCheckX(z: Int, light: Int, reset: Boolean) { val neighbours = section.neighbours ?: return - recalculate() + if (reset) resetLight() else calculate() if (z - light < 0) { - neighbours[Directions.O_NORTH]?.light?.recalculate() + val neighbour = neighbours[Directions.O_NORTH]?.light + if (reset) neighbour?.resetLight() else neighbour?.calculate() } if (z + light > ProtocolDefinition.SECTION_MAX_Z) { - neighbours[Directions.O_SOUTH]?.light?.recalculate() + val neighbour = neighbours[Directions.O_SOUTH]?.light + if (reset) neighbour?.resetLight() else neighbour?.calculate() } }