Kotlin for Forge

Kotlin for Forge

70M Downloads

KDeferredRegister & Datagenerators - lateinit property was not initialized

theoparis opened this issue ยท 3 comments

commented

So I tried to make a block state data generator, and i called .get() in the data generator provider and it crashed while running the runData task with this:

Caused by: kotlin.UninitializedPropertyAccessException: lateinit property value has not been initialized
[14:20:47] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: 	at thedarkcolour.kotlinforforge.forge.ObjectHolderDelegate.get(Forge.kt:271)
[14:20:47] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: 	at com.theoparis.lightson.data.client.ModBlockStateProvider.registerBulb(ModBlockStateProvider.kt:25)
[14:20:47] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: 	at com.theoparis.lightson.data.client.ModBlockStateProvider.registerStatesAndModels(ModBlockStateProvider.kt:18)
commented

I wonder if it's due to the way i used my custom methods?

object ModBlocks {
    val REGISTRY = KDeferredRegister(ForgeRegistries.BLOCKS, LightsOnMod.ID)

    val BULB = register("bulb") {
        BulbBlock(AbstractBlock.Properties.create(Material.ROCK).setLightLevel { 15 }.hardnessAndResistance(3.0f))
    }

    private fun <T : Block> register(name: String, block: () -> T): BlockReg<T> {
        val ret: ObjectHolderDelegate<T> = REGISTRY.register(name, block) as ObjectHolderDelegate<T>
        ModItems.REGISTRY.register(name) {
            BlockItem(ret.get(), Item.Properties().group(ItemGroup.BUILDING_BLOCKS))
        }
        return BlockReg(name, ret)
    }
}

data class BlockReg<T : Block>(val name: String, val obj: ObjectHolderDelegate<T>)
commented

B R U H
I forgot

        ModBlocks.REGISTRY.register(MOD_BUS)
commented

Let me know if it's still broken