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

So I want to have a button added in a GUI that is in a base class, that would trigger a method in my mod. It sounded like it would be simple, (because forge API covers almost everything  :) ) but I discovered only "coremods" can do this. I found only a few posts on this topic and 1 tutorial: http://www.minecraftforge.net/wiki/Using_Access_Transformers but In that tutorial the coremod did not give me an error, but I was not sure what exactly it did  :P. I downloaded a few examples of coremods, like chickenbonescore and ars magica (I had to decompile it). I was unsuccessful at finding how these worked. Another post on the forums said "only advanced modders who know what they're doing should use this tool" (or something along those lines), but If no one learns it in the first place, they can't become an advanced modder, can't they? Can anyone out there enlighten me on this topic? Not many tutorials show how this work, and I really want to know more about how this works, thanks.

 

 

P.S. Is there a way of doing this so that the regular mod doesn't have to be converted to a core mod, just have the core mod trigger a method in the regular mod? (eg. ars magica uses 2 mods, a core and a regular, since converting the regular to the core might be difficult) Oh yea, and if you could explain it rather than redirecting me too an api doc that would be nice!

  • Author

I just tried to do the part where i add a button, I don't know to much about java reflection so I probably made many boo boos! it does print "tick" on my screen when I open the book though, (YAY!)

	
        @Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if (Minecraft.getMinecraft().currentScreen instanceof GuiScreenBook) {
		Minecraft.getMinecraft().thePlayer.addChatMessage("tick");
		try {
			Class<?> c = Minecraft.getMinecraft().currentScreen.getClass();
			Field f = c.getDeclaredField("controlList");
			f.set(Minecraft.getMinecraft().currentScreen, new GuiButton(3,
					Minecraft.getMinecraft().currentScreen.width / 2 + 104,
					4 + Minecraft.getMinecraft().currentScreen.height, 98,
					20, StatCollector.translateToLocal("book.signButton")));
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

Do I need to read the GuiScreenBook 's width and height? or can I use Minecrafts Gui height and width

P.S. it gives me an error at Field f = c.getDeclaredField("controlList");

 

	
        @Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if (Minecraft.getMinecraft().currentScreen instanceof GuiScreenBook) {
		Minecraft.getMinecraft().thePlayer.addChatMessage("tick");
		try {
			Class<?> c = Minecraft.getMinecraft().currentScreen.getClass();
			Field f = c.getDeclaredField("controlList");
			f.set(Minecraft.getMinecraft().currentScreen, new GuiButton(3,
					Minecraft.getMinecraft().currentScreen.width / 2 + 104,
					4 + Minecraft.getMinecraft().currentScreen.height, 98,
					20, StatCollector.translateToLocal("book.signButton")));
		} catch...{
			e.printStackTrace();
		}
	}

I don't have much experience with reflection so it may not be entrirely true what I'm writing. Using relection is not cheap, it doesn't seem right to me to do in every tick when GUI is open. Also you're in every tick creating a new button? And with that button you are rewriting collection with GUI elements? I might be reading it wrong though...

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

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.