diff --git a/doc/rendering/block_outline_cube.png b/doc/rendering/block_outline_cube.png deleted file mode 100644 index bcf8c428b..000000000 Binary files a/doc/rendering/block_outline_cube.png and /dev/null differ diff --git a/src/main/java/de/bixilon/minosoft/data/world/Chunk.kt b/src/main/java/de/bixilon/minosoft/data/world/Chunk.kt index efe4e06f5..907baf22f 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/Chunk.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/Chunk.kt @@ -51,8 +51,11 @@ class Chunk( var lightInitialized = false var neighboursLoaded = false + val isLoaded: Boolean + get() = blocksInitialized && biomesInitialized && lightInitialized + val isFullyLoaded: Boolean - get() = blocksInitialized && biomesInitialized && lightInitialized && neighboursLoaded + get() = isLoaded && neighboursLoaded operator fun get(sectionHeight: Int): ChunkSection? = sections?.getOrNull(sectionHeight - lowestSection) diff --git a/src/main/java/de/bixilon/minosoft/data/world/World.kt b/src/main/java/de/bixilon/minosoft/data/world/World.kt index 782548a4f..292c519bb 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/World.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/World.kt @@ -42,7 +42,7 @@ import de.bixilon.minosoft.util.KUtil.synchronizedMapOf import de.bixilon.minosoft.util.KUtil.toSynchronizedMap import de.bixilon.minosoft.util.MMath import de.bixilon.minosoft.util.chunk.ChunkUtil -import de.bixilon.minosoft.util.chunk.ChunkUtil.fullyLoaded +import de.bixilon.minosoft.util.chunk.ChunkUtil.loaded import de.bixilon.minosoft.util.collections.SynchronizedMap import glm_.func.common.clamp import glm_.vec2.Vec2i @@ -266,19 +266,21 @@ class World( return getChunkNeighbours(ChunkUtil.getChunkNeighbourPositions(chunkPosition)) } - fun onChunkUpdate(chunkPosition: Vec2i, chunk: Chunk = get(chunkPosition)!!) { + + fun onChunkUpdate(chunkPosition: Vec2i, chunk: Chunk = this[chunkPosition]!!) { + if (chunk.neighboursLoaded) { + // return ToDo: Causes some chunks not have neighboursLoaded=true, but they should + } val neighbourPositions = ChunkUtil.getChunkNeighbourPositions(chunkPosition) val neighbours = getChunkNeighbours(neighbourPositions) - if (chunk.neighboursLoaded) { - return - } - if (neighbours.fullyLoaded) { + if (neighbours.loaded) { chunk.neighboursLoaded = true if (cacheBiomeAccessor != null) { chunk.buildBiomeCache() } } - for ((index, neighbourPosition) in neighbourPositions.withIndex()) { + for (index in 0 until 8) { + val neighbourPosition = neighbourPositions[index] if (neighbourPosition == chunkPosition) { continue } @@ -287,21 +289,22 @@ class World( if (neighbourChunk.neighboursLoaded) { continue } - var biomeSourceLoaded = true + var neighbourLoaded = true for (neighbourNeighbourChunk in getChunkNeighbours(neighbourPosition)) { - if (neighbourNeighbourChunk?.biomeSource == null) { - biomeSourceLoaded = false + if ((neighbourNeighbourChunk?.biomeSource == null && neighbourNeighbourChunk?.biomesInitialized != true) || !neighbourNeighbourChunk.blocksInitialized || !neighbourNeighbourChunk.lightInitialized) { + neighbourLoaded = false break } } - if (biomeSourceLoaded) { - neighbourChunk.neighboursLoaded = true // ToDo: only if fully loaded not just biomes - - if (cacheBiomeAccessor != null) { - neighbourChunk.buildBiomeCache() - } - connection.fireEvent(ChunkDataChangeEvent(connection, EventInitiators.UNKNOWN, neighbourPosition, neighbourChunk)) + if (!neighbourLoaded) { + continue } + neighbourChunk.neighboursLoaded = true + + if (cacheBiomeAccessor != null) { + neighbourChunk.buildBiomeCache() + } + connection.fireEvent(ChunkDataChangeEvent(connection, EventInitiators.UNKNOWN, neighbourPosition, neighbourChunk)) } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt index 5372ae097..bf3bc018b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt @@ -271,7 +271,7 @@ class DebugHUDElement(hudRenderer: HUDRenderer) : LayoutedHUDElement this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Sky properties ", connection.world.dimension?.skyProperties) } this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Biome ", connection.world.getBiome(blockPosition)) } this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { with(connection.world.getLight(blockPosition)) { BaseComponent("Light block=", (this and 0x0F), ", sky=", (this ushr 4)) } } - this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Fully loaded: ", chunk.isFullyLoaded) } + this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Fully loaded: ", world[entity.positionInfo.chunkPosition]?.isFullyLoaded) } lastChunk = chunk } diff --git a/src/main/java/de/bixilon/minosoft/util/chunk/ChunkUtil.kt b/src/main/java/de/bixilon/minosoft/util/chunk/ChunkUtil.kt index b32b59720..a2ab15ead 100644 --- a/src/main/java/de/bixilon/minosoft/util/chunk/ChunkUtil.kt +++ b/src/main/java/de/bixilon/minosoft/util/chunk/ChunkUtil.kt @@ -235,6 +235,16 @@ object ChunkUtil { return true } + val Array.loaded: Boolean + get() { + for (neighbour in this) { + if (neighbour?.isLoaded != true) { + return false + } + } + return true + } + fun getChunkNeighbourPositions(chunkPosition: Vec2i): Array { return arrayOf( diff --git a/src/main/java/de/bixilon/minosoft/util/chunk/LightUtil.kt b/src/main/java/de/bixilon/minosoft/util/chunk/LightUtil.kt index 28d285cc4..098e2d031 100644 --- a/src/main/java/de/bixilon/minosoft/util/chunk/LightUtil.kt +++ b/src/main/java/de/bixilon/minosoft/util/chunk/LightUtil.kt @@ -52,7 +52,7 @@ object LightUtil { } private fun readLightArray(buffer: PlayInByteBuffer, lightMask: BitSet, dimension: DimensionProperties): Triple, ByteArray?, ByteArray?> { - var highestSectionIndex = dimension.highestSection + var highestSectionIndex = dimension.highestSection + 1 val lowesSectionIndex = dimension.lowestSection if (buffer.versionId >= ProtocolVersions.V_20W49A) { buffer.readVarInt() // section count