Jump to content

[1.7.2] Give a button a function?


Pardeep

Recommended Posts

I've added a button to the GuiOptions of vanilla minecraft using Java Reflection. However, now I don't know how to get it so that a new GuiOpens when the button is pressed, as I don't know how to access the actionPerformed method of GuiOptions and use it.

 

Is there a way to do this, or is there possibly an eventhandler I could use?

 

Thanks in advance?

 

Here's my code if it helps:

public void onRenderTick(RenderTickEvent event)
{
	try
	{
		GuiScreen activeGUI = Minecraft.getMinecraft().currentScreen;

		if(activeGUI != null && activeGUI instanceof GuiOptions) //whatever GUI you want to add a/multiple button/s to
		{
			Field field1 = GuiScreen.class.getDeclaredField("buttonList");
			field1.setAccessible(true);
			List buttonList = (List) field1.get(activeGUI);			
			buttonList.add(new CustomButton(300, 1, 1, 100, 20, "Update Checker")); //you have to make a class extending GuiButton to add function to your button	
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}

NB: the button is visible 100% and works. Just don't know how to add function.

Link to comment
Share on other sites

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.