fix some crashes in chunk section data

This commit is contained in:
Bixilon 2022-03-03 19:57:08 +01:00
parent 32f29325b8
commit 7679e4e012
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 6 additions and 6 deletions

View File

@ -13,7 +13,6 @@
package de.bixilon.minosoft.data.world.container
import de.bixilon.kutil.cast.CastUtil.nullCast
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.types.FluidBlock
@ -27,10 +26,11 @@ class BlockSectionDataProvider(
override fun recalculate() {
super.recalculate()
val data: Array<BlockState?> = data?.nullCast() ?: return // ToDo: ClassCastException
val data: Array<Any?> = data ?: return // ToDo: ClassCastException
fluidCount = 0
for (blockState in data) {
blockState as BlockState?
if (blockState.isFluid()) {
fluidCount++
}

View File

@ -23,7 +23,7 @@ open class SectionDataProvider<T>(
data: Array<T>? = null,
val checkSize: Boolean = false,
) : Iterable<T> {
protected var data: Array<T?>? = data?.unsafeCast()
protected var data: Array<Any?>? = data?.unsafeCast()
private set
protected val lock = SimpleLock() // lock while reading (blocks writing)
var count: Int = 0
@ -142,7 +142,7 @@ open class SectionDataProvider<T>(
if (count == 0) {
this.data = null
unlock()
return previous
return previous.unsafeCast()
}
} else if (previous == null) {
count++
@ -163,7 +163,7 @@ open class SectionDataProvider<T>(
}
}
unlock()
return previous
return previous.unsafeCast()
}
fun acquire() {
@ -188,7 +188,7 @@ open class SectionDataProvider<T>(
fun setData(data: Array<T>) {
lock()
check(data.size == ProtocolDefinition.BLOCKS_PER_SECTION) { "Size does not match!" }
this.data = data as Array<T?>
this.data = data as Array<Any?>
recalculate()
unlock()
}