mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
fix some crashes in chunk section data
This commit is contained in:
parent
32f29325b8
commit
7679e4e012
@ -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++
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user