Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ejektaflex opened this issue Jul 27, 2019 · 2 comments
Closed

Comments

@ejektaflex
Copy link
Contributor

ejektaflex commented Jul 27, 2019

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
Copy link
Owner

autaut03 commented Jul 29, 2019

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
Copy link
Owner

autaut03 commented Nov 9, 2019

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.

@autaut03 autaut03 closed this as completed Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants