Jump to content

Recommended Posts

Posted

I am trying to make a command open a GuiScreen, but when I send the command it doesn't open. I've heard it's because when the chat closes it closes all open GUIs, so I tried listeneing to GuiOpen event and if it's my GUI set a boolean to true, and if the GUI is null and the boolean is true set it to false and open my GUI. But still nothing happens. No errors or anything.

Code:

GuiScreen:

private List<GuiButton> overlayConfig = new ArrayList<GuiButton>();

@Override
public void initGui() {
    super.initGui();
    overlayConfig.add(new GuiButton(0, 50, 50, "True"));
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    drawDefaultBackground();
    overlayConfig.get(0).drawButton(Minecraft.getMinecraft(), mouseX, mouseY);
    overlayConfig.get(0).displayString = "";
    super.drawScreen(mouseX, mouseY, partialTicks);
}

@Override
protected void mouseClicked(int x, int y, int button) {
    for (GuiButton config : overlayConfig) {
        if (config.mousePressed(Minecraft.getMinecraft(), x, y)) {
            config.enabled = !config.enabled;
        }
    }
}

Command execute code:

if (sender.getEntityWorld().isRemote)
            Minecraft.getMinecraft().displayGuiScreen(new ConfigMenu());

Event listener to try and fix my problems:

@SubscribeEvent
    public void onGuiClose(GuiOpenEvent event) {
        if(event.gui == null && justOpened) {
            Minecraft.getMinecraft().displayGuiScreen(new ConfigMenu());
            justOpened = false;
        }
        if(event.gui != null && event.gui.getClass().equals(ConfigMenu.class)) {
            justOpened = true;
        }
    }

The event is registered in my ClientProxy's postInit.

Posted (edited)
3 hours ago, diesieben07 said:
  • Assuming this is a client-side command (ClientCommandHandler). If not, you need packets and ignore the remaining points.
  • The isRemote check is completely pointless, you are already on the client.
  • You need to wait a tick, i.e. listen for ClientTickEvent (make sure to check TickEvent#phase).

How would I wait a tick? Would I add it into the command's code, and just delay the entire thing a tick? I don't think I could do that because I think the mod is on the same thread as Minecraft. Idk I just need you to be a little less vague maybe on I should go about this.

 

Nevermind I figured it out myself. I just added a event every tick to check a boolean to see if the command was run, if so set another boolean to true and set boolean 1 to false, then if boolean 1 is false and boolean 2 is true I run the cmd.

Edited by Big_Bad_E

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.