mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
fix light packet reading (in older versions), fix some chunk bugs
This commit is contained in:
parent
ee02484494
commit
465e9c4bf0
Binary file not shown.
Before Width: | Height: | Size: 259 KiB |
@ -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)
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ class DebugHUDElement(hudRenderer: HUDRenderer) : LayoutedHUDElement<GridLayout>
|
||||
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
|
||||
}
|
||||
|
@ -235,6 +235,16 @@ object ChunkUtil {
|
||||
return true
|
||||
}
|
||||
|
||||
val Array<Chunk?>.loaded: Boolean
|
||||
get() {
|
||||
for (neighbour in this) {
|
||||
if (neighbour?.isLoaded != true) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
fun getChunkNeighbourPositions(chunkPosition: Vec2i): Array<Vec2i> {
|
||||
return arrayOf(
|
||||
|
@ -52,7 +52,7 @@ object LightUtil {
|
||||
}
|
||||
|
||||
private fun readLightArray(buffer: PlayInByteBuffer, lightMask: BitSet, dimension: DimensionProperties): Triple<Array<ByteArray?>, 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user