Jump to content

[Solved] Cannot open GUI from ICommand#execute


bugfroggy

Recommended Posts

Just for context on how experience I am with this, I started Minecraft modding about a month ago, although have experience in other languages (and a tiny bit of Java) before now.

 

I'm making a client-side mod, and for the life of me I can't figure out how to open a custom GUI via command. I have the following code that works just fine:

@SubscribeEvent
    public void onKeyInput(InputEvent.KeyInputEvent event) {

        // If open GUI key is pressed on Hypixel
        if(QuickPlay.openGui.isKeyDown() && QuickPlay.onHypixel) {
            System.out.println("Open GUI key pressed");
            Minecraft.getMinecraft().displayGuiScreen(new GuiScreen(){});
        }
    }

 

A new, blank GUI is opened when the bound key is pressed and you're on the proper server. Works fine.

 

I now have a separate GUI I was hoping to open from a command ("/qpcolor"). QpColorCommand.java#execute (Implements ICommand):

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
   Minecraft.getMinecraft().displayGuiScreen(new GuiScreen(){});
}

 

QpColorCommand is registered in QuickPlay#postInit:

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
    ClientCommandHandler.instance.registerCommand(new QpColorCommand());
}

 

But, with all of this, /qpcolor does not open the GUI. Everything else in QpColorCommand#execute runs fine! I've Google'd around with no luck. I feel like I'm missing something obvious here, but I'm not sure what. Any advice?

 

Thanks!

 

EDIT:

 

I just checked the source of another mod that opens a GUI via command. It looks like they added a 2-tick delay before opening the GUI. Is this why it is not working for me? Is there a better way around this? Any advice is appreciated.

Edited by bugfroggy
Added info that I went and checked source
Link to comment
Share on other sites

12 minutes ago, diesieben07 said:

Yes, after the command executes, the chat GUI tells minecraft to close any open GUI, assuming the chat gui itself is still open. If you opened another GUI in between, it gets closed instead.

You have to open the GUI a tick later.

That makes sense! I'll try that. Thank you :)

Link to comment
Share on other sites

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.