Alright, so I'm trying to have a command open up a GUI. Unfortunately, when I just put Code: this.mod.mc.displayGuiScreen(new GuiModMenu()); it won't do anything. I know that it's because I have to wait a tick before this happens, but I don't know how I would do this. I have my EventTick called in the Minecraft class at Code: runGameLoop() but from there I don't know what I'm supposed to do. I have seen Hyperium's way of doing it, but I'm not using Mixins or Forge for my thing, nor do I want to just copy and paste Hyperium's command system (for when I did this, the command worked (but always it had an "Unknown Command" message every time despite it working)), so what would/should I do? Thanks.
You could simply wait a tick (subscribe to the ClientTickEvent ) , then activate your GUI. When done, you can unsubscribe from the tickEvent and put the counter back to 0 if you so wish
This would be true IF I was using Forge, but I'm not. I'm editing vanilla minecraft straight from the source, no forge. However, say I was using Forge, would I use Code: onPostClientTick() or Code: onPreClientTick() in order to do this, and then would it just be using a Code: @SubscribeEvent above the command to do this or how would I do as you say?
A little rusty on my Java. In Forge: Code: // ... @Override public void processCommand(ICommandSender sender, String[] args) { // Start to listen for events MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { // As soon as a tick occurs, show the screen and stop listening for events this.mod.mc.displayGuiScreen(new GuiModMenu()); MinecraftForge.EVENT_BUS.unregister(this); } // ... Using a helper class like this one makes this easier: Code: // ... @Override public void processCommand(ICommandSender sender, String[] args) { new TickDelay(() -> { this.mod.mc.displayGuiScreen(new GuiModMenu()); }, 1); } // ...
The simplest way to open a gui by command in forge, would be to register a command in the clientCommandHandler during init. For example, @EventHandler private void init(FMLInitializationEvent event) { ClientCommandHandler h = ClientCommandHandler.instance; h.registerCommand(new <your command class here>()); } Then inside of the command class, extend it off of CommandBase and override the processCommand method to run your code to call your gui. public void processCommand(ICommandSender sender, String[] args) throws CommandException { Minecraft.getMinecraft().displayGuiScreen(new <your gui here>()); } Hope this helps.