Jump to content

Error with adding listener to Capability


Babelincoln1809

Recommended Posts

I'm doing my first capability, and I followed what I was referencing pretty closely albeit had to change things for my own capability. The issue comes in when running my mod, it says it needs an "addGenericListener" rather than "addListener" when the thing I'm referencing doesn't use that anywhere. I really don't how to fix the issue I'm still new to making capabilities, and I hope I explained my issue well, so any help is much appreciated.

 

Code:

Registering the Capability in the FmlCommonSetup: https://pastebin.com/5wMSrM5N

ICoolDown Interface: https://pastebin.com/jHZPwuNY

DefaultCoolDownCapability class: https://pastebin.com/pDiH3eev

CoolDownStorage class: https://pastebin.com/7e59wfuR

CoolDownProvider class: https://pastebin.com/dgCv94iG

CoolDownHandler class: https://pastebin.com/CuhG1wFR

CoolDownCapability class: https://pastebin.com/7E7Yg9Bh

Link to comment
Share on other sites

Instead of subscribing event listeners like this:

MinecraftForge.EVENT_BUS.addListener(CoolDownHandler::onAttachCapabilities);
MinecraftForge.EVENT_BUS.addListener(CoolDownHandler::doCoolDown);

you can annotate the event listener class with @Mod.EventBusSubscriber()

and then anotate the event listener methods with @SubscribeEvent

 

that is not the only way to do it, but it is the one I find easier, and it should solve your listener issue

for documentation on events you can check out: https://mcforge.readthedocs.io/en/latest/events/intro/

or: https://forge.gemwire.uk/wiki/Events#Event_Listeners

Link to comment
Share on other sites

1 hour ago, kiou.23 said:

you can annotate the event listener class with @Mod.EventBusSubscriber()

and then anotate the event listener methods with @SubscribeEvent

 

that is not the only way to do it, but it is the one I find easier, and it should solve your listener issue

for documentation on events you can check out: https://mcforge.readthedocs.io/en/latest/events/intro/

or: https://forge.gemwire.uk/wiki/Events#Event_Listeners

I don't even know why I didn't think of that in the first place, thank you! It worked! I was WAY overthinking it lolol

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.