Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am trying to add a button to the options GUI, but I can't find any forge way to make it work!  I tried to make a normal ModLoader mod to use the onTickInGUI funstion, but it never triggered.  I know how to do this using ASM, but I would like to avoid that if possible.  Is there a way to do this?

 

EDIT:  To clarify, I am not trying to make a modloader mod.  I have a modloader mod that works, but I would like to port it to a forge mod.

 

Why do you ask this in a forum for Minecraft FORGE? Forge contains classes like BaseMod to allow compability with mods designed for ModLoader, not for making ModLoader mods. If you really want to use ModLoader (i recommend switching to forge), this is the wrong forum.

But now back to your question:

 

With Forge yes (pretty easily), with Modloader i dont know.

  • Author

I know this is for forge, and that's why I was asking!  I am trying to update an old ModLoader mod to forge, and I could not find a forge way to add the button to the GUI.  If you know a way (without using ModLoader and preferably without ASM), then please tell me!

I know this is for forge, and that's why I was asking!  I am trying to update an old ModLoader mod to forge, and I could not find a forge way to add the button to the GUI.  If you know a way (without using ModLoader and preferably without ASM), then please tell me!

You need to be a little more informative in your posts, but about your question, I have only one thing to say: search trough the javadoc if you can find any forge hooks.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

I looked a bit through the javadocs, but I don't know what classes the hooks are stored in besides ForgeHooks and ForgeHooksClient, and neither has what I want.  I am mostly new to forge but I have used it before.  I have never had to change a vanilla GUI before... 

  • Author

Would it work if I made a BaseMod class and used the old modloader onTickInGUI method?  Or would having a basemod and an @Mod for the same mod clash?

Even with forge this is not cleanly possible without using ASM.

I dont know what you consider as cleanly but its possible with reflection.

 

Here is how to do it:

 

First create a new TickHandler (similar to onTick in ModLoader):

import java.lang.reflect.Field;
import java.util.EnumSet;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiChest;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class TickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{		
	try
	{
		GuiScreen activeGUI = Minecraft.getMinecraft().currentScreen;

		if(activeGUI != null && activeGUI instanceof GuiChest) //whatever GUI you want to add a/multiple button/s to
		{
			Field field = GuiScreen.class.getDeclaredField("buttonList");
			field.setAccessible(true);

			List buttonList = (List) field.get(activeGUI);

			if(buttonList.size() < 1) //this has to be one smaller than the number of buttons it usually has, else you will keep adding your button over and oever again
			{
				buttonList.add(new GuiButton(1, 2, 5, "Test")); //you have to make a class extending GuiButton to add function to your button
			}
		}
	}

	catch(Exception e)
	{
		e.printStackTrace();
	}



}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{

}

@Override
public EnumSet<TickType> ticks()
{		
	return EnumSet.of(TickType.RENDER);
}

@Override
public String getLabel()
{		
	return "GUI TickHandler"; //Or however you want to name it
}

}

 

Then you have to register it in your load/init method

TickRegistry.registerTickHandler(new TickHandler(), Side.CLIENT);

 

Thats basically it, you will now have an additional button in the GUI(I used the chest as an example):

72ffavdt.png

  • Author

Thank you for pointing that out.  I was pretty sure ASM would be smoother, but when I did try it it kept refusing to load my class, even though I did it just like my other ASM classes that work just fine.

speaking of ASM, I keep getting this error to do with something like com.google.event.EventBus or something and how it does not exist. This error gets thrown on my CoreMod's dmmycontainer. But it only gets that error when I extend DummyModContainer... Any ideas why?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

  • Author

I don't use DummyModContainer, so I don't know how much I can help.  But I think your IDE may be trying to import the wrong class.  I'm pretty sure there is an event bus class somewhere in FML that has the same name.  If you'r IDE has an autocomplete function (eclipse, Intell-j, probably more), try referencing "EventBus" and see what import options it gives.

I already tried that :/ It still gave the error. And the error was underneath the p in "package mew.core;"

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

  • Author

What IDE are you using?  If its intelli-j try doing a full rebuild or restarting it.  Mine will glitch up like that sometimes.

What IDE are you using?  If its intelli-j try doing a full rebuild or restarting it.  Mine will glitch up like that sometimes.

 

I am using eclipse. I will try it again with my rebuilt workspace. Thanks for the Idea :D

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

  • Author

Your welcome!  It's what I do with everything:  "If it stops working for no apparent reason: turn it off and on again."  It works for nearly everything.

Ill agree to that :P

 

Unless it is out of battery and that's why it stops working :P

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

And what do you know it worked :D

 

Now I just have to figure out why it is disabled :/

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.