Kotlin for Forge

Kotlin for Forge

70M Downloads

lateinit property value has not been initialized when registering item

joshop opened this issue ยท 2 comments

commented

I have very little experience with Kotlin for Forge or Forge in general, but I'm currently attempting to make an item with custom behavior by creating an object which inherits from Item(Properties()) or whatever properties I want and then declaring, for instance, onitemRightClick. The file containing the item:

package rous.roustestmod.item

import net.minecraft.item.Item

object TestItem : Item(Properties()) {
    // implementing methods here
}

but when I try to register it (in the same way done in the modding skeleton):

val TESTITEM by REGISTRY.registerObject("test_item") {
    TestItem
}

it gives me lateinit property value has not been initialized. What am I doing wrong - is this even the intended way to register new items?

commented

You're using an object, which cannot be initialized. You need to use a normal class.

commented

First of all you should not be using an object for an item
If you are never initializing REGISTRY from the main mod constructor then the item is never registered and you are getting the error you see here
If you need more help join my discord server