autaut03 / kottle

Kotlin language provider for Forge 1.13.2+
GNU Lesser General Public License v3.0
31 stars 13 forks source link

Adding a listener for RegistryEvent.Register<Item> throws error #8

Closed ejektaflex closed 5 years ago

ejektaflex commented 5 years ago

It seems that trying to listen for this event does not work. Forge 28.0.14 Kottle 1.1.0

My code is:

addListener<RegistryEvent.Register<Item>>(SetupLifecycle::registerItems)

fun registerItems(event: RegistryEvent.Register<Item>) {
  ...
}

The specific error is: Failed to resolve handler for "ejektaflex.bountiful.BountifulMod$sam$i$java_util_function_Consumer$0@53a3ffcc" caused by Failed to resolve consumer event type: ejektaflex.bountiful.BountifulMod$sam$i$java_util_function_Consumer$0@53a3ffcc

It seems to be this specific line, it might be what is returning null

Error log: https://gist.github.com/ejektaflex/96d80d6ece525a91fac82f6a91c95040

autaut03 commented 5 years ago

For anyone else viewing this:

as a workaround for now, please use either of other available methods to register event listeners:

.register(ListenerObject)
.addListener { event: RegistryEvent.Register<Item> -> ListenerObject.registerItems(event) }
@KotlinEventBusSubscriber
autaut03 commented 5 years ago

Finally had time to have my hands on that.

In short the answer is that it's not Kottle's fault. Forge internally uses https://github.com/jhalterman/typetools to auto-resolve type of event to register. Consumer is passed into that (most likely kotlin's compiler's wrapper for that method call), which breaks everything.

There's nothing that can be done about it, unfortunately. This Forge's internal magic only properly works with Java (as it should).

I'll add it to the docs.