pixlyzer: don't crash when block entity is not implemented

This commit is contained in:
Moritz Zwerger 2023-11-04 19:13:53 +01:00
parent 93a5c3a48d
commit ec8dbbdcb4
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -25,14 +25,14 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import kotlin.reflect.jvm.javaField import kotlin.reflect.jvm.javaField
abstract class PixLyzerBlockWithEntity<T : BlockEntity>(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>) : PixLyzerBlock(resourceLocation, registries, data), BlockWithEntity<BlockEntity> { abstract class PixLyzerBlockWithEntity<T : BlockEntity>(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>) : PixLyzerBlock(resourceLocation, registries, data), BlockWithEntity<BlockEntity> {
private val blockEntity: BlockEntityType<BlockEntity> = unsafeNull() private val blockEntity: BlockEntityType<BlockEntity>? = unsafeNull()
init { init {
FACTORY_FIELD.inject<RegistryItem>(this) FACTORY_FIELD.inject<RegistryItem>(this)
} }
override fun createBlockEntity(connection: PlayConnection) = blockEntity.factory.build(connection) override fun createBlockEntity(connection: PlayConnection) = blockEntity?.factory?.build(connection)
private companion object { private companion object {
val FACTORY_FIELD = PixLyzerBlockWithEntity<*>::blockEntity.javaField!! val FACTORY_FIELD = PixLyzerBlockWithEntity<*>::blockEntity.javaField!!