Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted
comment_37745

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?

  • Author
comment_37748

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.