Jump to content

ModLoader.addCommand throws exception - how to register new commands? [solved]


Recommended Posts

Posted

I am trying to register my own commands. I've searched and found a couple threads, pointing to ModLoader.addCommand(new MyCommand()). However, I get this error:

 

cpw.mods.fml.common.FMLModContainer cannot be cast to cpw.mods.fml.common.modloader.ModLoaderModContainer
at cpw.mods.fml.common.modloader.ModLoaderHelper.addCommand(ModLoaderHelper.java:213)

 

I am on forge 1.5.1. I'm sure the dependencies are being downloaded properly (I've seen them being downloaded and I haven't done anything complicated and other stuff works).

 

Is there a new way to do this? I know I could do checks every time in the Forge CommandEvent, but that seems kludgy... surely, there must be a way to directly register commands?

Posted

Wow as always, after spending tons of time (anywhere from 30 minutes to days) trying to solve a problem, I find the solution immediately after asking in the forum. Well at least this can help future users.

 

The solution is to add a @ServerStarting method in your main mod file:

 

@ServerStarting

public void serverStarting(FMLServerStartingEvent event) {

// Commands

event.registerServerCommand(new MyCommand()); // Commands extend CommandBase

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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