Posted October 30, 20168 yr From what I understand, FML is supposed to make sure all mods can work together by adding its own ways of adding stuff..... I want to add a button element to the "esc menu" of the game that I can direct to my own gui.... The only way I know of to do that is by listening to gui changes and checking for that gui, then overriding it with my own clone of it... I looked a bit online with no luck of finding any answer so I came to the forum as usall... Doing stuff n' things
October 30, 20168 yr Instead of Overriding just add a button like you would with your own gui, not sure if reflection is necessary though. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
October 30, 20168 yr Or... you can just create your event handler and listen to GuiScreenEvent.InitGuiEvent.Pre, check whether given GUI is instance of GuiIngameMenu, and then add additional buttons to the button list via event.getButtonList() (which is a List<GuiButton>). Blockbuster – simple machinimas and cinematics for Minecraft
October 30, 20168 yr Giant there something that prevents overlapping? If I get you correctly (stupid autocorrect? ), you'll need to calculate the button position yourself (to put your button under other buttons). Or you could just place your button in the corner. By the way, you'll probably need to subscribe to ActionPerformedEvent also to add a callback when the button was clicked in GuiIngameMenu. Blockbuster – simple machinimas and cinematics for Minecraft
October 30, 20168 yr Author Yes.. stupid auto correct... I guess ill have to just place a button in hopes that no one uses its place.. But, is there a change you can show me an example on how you would register/use/imply the event on such button in the esc menu? Im not on pc do i cant test stuff... Doing stuff n' things
October 30, 20168 yr mod file : //preinit new AddButtonToGuiEvent(); //custom class public class AddButtonToGuiEvent{ public AddButtonToGuiEvent(){ MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public void onGuiEvent(TheEventIwantToUse event){ event.getbuttonlist.add(new guibutton(stuff,foo,bar,things); } } very rudamentary implementation. for example only. https://minecraft.curseforge.com/members/Subaraki/projects
October 30, 20168 yr Yes.. stupid auto correct... I guess ill have to just place a button in hopes that no one uses its place.. But, is there a change you can show me an example on how you would register/use/imply the event on such button in the esc menu? Im not on pc do i cant test stuff... /* In your proxy on pre initialization (FMLPreInitializationEvent) or * initialization (FMLInitializationEvent): */ GuiEventHandler handler = new GuiEventHandler(); MinecraftForge.EVENT_BUS.register(handler); /* The class itself */ public class GuiEventHandler { @SubscribeEvent public void onGuiInit(InitGuiEvent.Pre event) { if (event.getGui() instanceof GuiIngameMenu) { /* Add button to top-left corner of the screen */ event.getButtonList().add(new GuiButton(42, 10, 10, ...)); } } @SubscribeEvent public void onGuiActionPerformed(ActionPerformedEvent event) { if (event.getGui() instanceof GuiIngameMenu && event.getButton().id == 42) { /* Do something... */ } } } My code doesn't really differ from SenpaiSuburaki's code, but there are few important features added/changed. Check for GuiIngameMenu – it is really important since without this check you may accidentally add your button to every GUI in the game. ActionPerformed event listener was added – where the comment "Do something..." you should write your custom code that should happen after your added button was clicked (i.e. open other GUI, Minecraft.getMinecraft().displayGuiScreen(...)). Moved registration of event handler outside of the class. Why? Because it's bad, in my opinion, since it will hardcode (add hard dependency, coupling) MinecraftForge.EVENT_BUS to this class. The code provided above is untested, but I believe it should work with minor adjustments (i.e. add imports and change some parameters to desired values). Blockbuster – simple machinimas and cinematics for Minecraft
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.