Jump to content

Recommended Posts

Posted

I have the following code and when I click the button it doesn't seem to execute the code but once hovered over it will execute the code printing "Hovered!"
 

@SubscribeEvent
    public static void openInventoryGui(ScreenEvent e) {
        Minecraft minecraft = Minecraft.getInstance();
        if (minecraft.screen != null) {
            Screen current = e.getScreen();
            if (current.passEvents) {
                int pX = (minecraft.getWindow().getGuiScaledWidth() / 2) + 88;
                int pY = (minecraft.getWindow().getGuiScaledHeight() / 2) + 60;
                Button button = new Button(pX, pY, 25, 20, Component.literal(">"),
                        (b) -> EasyEffectDisplayMod.LOGGER.info("CLICKED!"),
                        (pButton, pPoseStack, pMouseX, pMouseY) -> EasyEffectDisplayMod.LOGGER.info("Hover!"));
                e.getScreen().renderables.clear();
                e.getScreen().renderables.add(button);
            }
        }
    }

 

Posted

You are replacing the button on every screen event (including mouse clicked).

There are many subclasses for specific events, you probably want ScreenEvent.Init.Post which fires after the initialisation of the screen.

Also you can get the screen using event.getScreen()

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.