Posted October 26, 20222 yr 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); } } }
October 26, 20222 yr 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.