Jump to content

Recommended Posts

Posted

It's pretty straight forward here.

When I play in a singleplayer world the command works, you can find it using TAB as-well. But when I play on multiplayer the command does not work at all, like it doesn't exist.

Do I need to configure it to work on a server too somehow? I am extending CommandBase in my class file.

Posted

It sounds like you're only registering it on the client. You need to register your commands on both physical sides in FMLServerStartingEvent, which needs to be handled by a @Mod.EventHandler method in your @Mod class.

 

If you're doing this and it's still not working, post your code.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 2/12/2017 at 11:25 AM, Choonster said:

It sounds like you're only registering it on the client. You need to register your commands on both physical sides in FMLServerStartingEvent, which needs to be handled by a @Mod.EventHandler method in your @Mod class.

 

If you're doing this and it's still not working, post your code.

Expand  
 

 

Yeah this is what I was doing:

    @EventHandler
    public void serverLoad(FMLServerStartingEvent event) {
        event.registerServerCommand(new testCommand());
    }

 

Posted

Is this in your @Mod class? Are there any errors in the log?

 

Post the testCommand class.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 2/12/2017 at 1:23 PM, Choonster said:

Is this in your @Mod class? Are there any errors in the log?

 

Post the testCommand class.

Expand  
 
 

If by @Mod class you mean the main class that has the mod name in it, then yes, it is.

 

This is the test command class:

public class testCommand extends CommandBase {
    @Override
    public String getCommandName() {
        return "test";
    }
    @Override
    public String getCommandUsage(ICommandSender sender) {
        return "/<command>";
    }
    
    @Override
    public int getRequiredPermissionLevel() {
        return 0;
    }
    
    @Override
    public boolean canCommandSenderUseCommand(ICommandSender sender) {
        return true;
    }
    @Override
    public void processCommand(ICommandSender sender, String[] args) throws CommandException {
        if (sender instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) sender;
            player.addChatComponentMessage(new ChatComponentText("Works!"));
        }
    }
}

 

Posted
  On 2/12/2017 at 5:27 PM, diesieben07 said:

And the names FMLServerStartingEvent and registerServerCommand did not make you suspicious then? O.o

For client-side commands you need to use ClientCommandHandler.

Expand  
 

Changed it to this one:

    @EventHandler
    public void serverLoad(ClientCommandHandler event) {
        event.registerCommand(new testCommand());
    }

 

Now it doesn't work not in single and not on multiplayer.

I think I tried using this before and it just didn't work so I used the server one.

Posted (edited)
  On 2/12/2017 at 5:31 PM, Bets said:

Changed it to this one:

    @EventHandler
    public void serverLoad(ClientCommandHandler event) {
        event.registerCommand(new testCommand());
    }

 

Now it doesn't work not in single and not on multiplayer.

I think I tried using this before and it just didn't work so I used the server one.

Expand  

 

ClientCommandHandler isn't an event, you can't subscribe to it. You need to call ClientCommandHandler#registerCommand from your client proxy in preInit.

 

There should be an error in the log telling you that the method is invalid.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 2/12/2017 at 5:42 PM, Choonster said:

 

ClientCommandHandler isn't an event, you can't subscribe to it. You need to call ClientCommandHandler#registerCommand from your client proxy in preInit.

 

There should be an error in the log telling you that the method is invalid.

Expand  
 

I have this in my preinit

    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent e) {
        MinecraftForge.EVENT_BUS.register(new THING());
        
    }

How do I call  ntCommandHandler#registerCommand?

Posted

How do you call any other method?

 

You get an instance of an object and press the . key and type the method name...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 2/13/2017 at 3:48 PM, Draco18s said:

How do you call any other method?

 

You get an instance of an object and press the . key and type the method name...

Expand  
 

Yes I know, but where should I call it, inside my @Mod class? how do I do this? should it be inside my preinit? what should be before it?

Posted

...yes...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 2/16/2017 at 11:07 PM, Draco18s said:

...yes...

Expand  
 

I'm a little lost right now...

I have a class that extends CommandBase, there I give it the command name, usage etc.

Do I need to call that class from my preinitevent (I need to perhaps register it?), right? How do I do that? just like I did for my "THING" class? or there is some other way to do so?

The command class is called testCommand, and as I said before extends CommandBase. So I should just add this line to my preinit?

MinecraftForge.EVENT_BUS.register(new testCommand());

 

Posted

No. It's a command, not an event handler, and furthermore, it's a client-side command. You need to register it with the ClientCommandHandler instance in your pre-init event. 

 

You should really learn Java before trying to mod, it will make your life a lot easier. Right now you're making a lot of mistakes that you wouldn't be if you had a basic knowledge of Java.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

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.